From: Claudio Sacerdoti Coen Date: Fri, 17 Nov 2000 10:31:18 +0000 (+0000) Subject: Initial revision X-Git-Tag: nogzip~167 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=cd3f2cc347f7d74ad8bf8146f03dd21c6cf7b9a8;p=helm.git Initial revision --- diff --git a/helm/xsltd/Makefile b/helm/xsltd/Makefile new file mode 100644 index 000000000..83c51d9d5 --- /dev/null +++ b/helm/xsltd/Makefile @@ -0,0 +1,29 @@ +start-xaland: + java -ss1024K -oss8192K \ + xaland 12345 12346 \ + $(HELM_STYLES_DIR)/rootcontent.xsl \ + $(HELM_STYLES_DIR)/annotatedpres.xsl \ + $(HELM_STYLES_DIR)/theory_content.xsl \ + $(HELM_STYLES_DIR)/theory_pres.xsl + +start-xaland-2: + java -ss1024K -oss8192K \ + xaland2 12345 12346 \ + $(HELM_STYLES_DIR)/rootcontent.xsl \ + $(HELM_STYLES_DIR)/annotatedpres.xsl \ + $(HELM_STYLES_DIR)/theory_content.xsl \ + $(HELM_STYLES_DIR)/theory_pres.xsl + +start-xaland-old: + java xaland 12345 12346 \ + $(HELM_STYLES_DIR)/style_prima_del_linguaggio_naturale/rootcontent.xsl \ + $(HELM_STYLES_DIR)/style_prima_del_linguaggio_naturale/annotatedpres.xsl \ + $(HELM_STYLES_DIR)/style_prima_del_linguaggio_naturale/theory_content.xsl \ + $(HELM_STYLES_DIR)/style_prima_del_linguaggio_naturale/theory_pres.xsl + +start-xaland3: + java xaland 12347 12348 \ + $(HELM_STYLES_DIR)/rootcontent.xsl \ + $(HELM_STYLES_DIR)/annotatedpres.xsl \ + $(HELM_STYLES_DIR)/theory_content.xsl \ + $(HELM_STYLES_DIR)/theory_pres.xsl diff --git a/helm/xsltd/cadet b/helm/xsltd/cadet new file mode 100755 index 000000000..6206c54cd --- /dev/null +++ b/helm/xsltd/cadet @@ -0,0 +1,11 @@ +#! /bin/sh + +export PATH=~/HELM/installation/jdk118/bin:$PATH + +#export CLASSPATH=/home/cadet/sacerdot/xalan-j_1_1/xalan.jar:/home/cadet/sacerdot/xalan-j_1_1/xerces.jar:. +export CLASSPATH=~/HELM/installation/xalan-j_1_2/xalan.jar:~/HELM/installation/xalan-j_1_2/xerces.jar:. +#export CLASSPATH=~/HELM/installation/xalan-j_1_2_1/xalan.jar:~/HELM/installation/xalan-j_1_2_1/xerces.jar:. +#export CLASSPATH=/home/cadet/sacerdot/xalan-j_2_0_D01/bin/xalan.jar:/home/cadet/sacerdot/xalan-j_2_0_D01/bin/xerces.jar:. + +export HELM_STYLES_DIR=../V6.2/examples/style +#export HELM_STYLES_DIR=../V7/examples/style diff --git a/helm/xsltd/isterix b/helm/xsltd/isterix new file mode 100755 index 000000000..e11d92c8b --- /dev/null +++ b/helm/xsltd/isterix @@ -0,0 +1,10 @@ +#! /bin/sh + +export PATH=$PATH:/opt/java/jdk118/bin/ + +export CLASSPATH=. +export CLASSPATH=$CLASSPATH:/home/lpadovan/helm/java/xalan_1_1/xalan.jar +export CLASSPATH=$CLASSPATH:/home/lpadovan/helm/java/xalan_1_1/xerces.jar +export CLASSPATH=$CLASSPATH:/home/lpadovan/helm/java/saxon-5.3.2/saxon.jar + +export HELM_STYLES_DIR=../V6.2/examples/style diff --git a/helm/xsltd/xaland-cpp/xaland.cpp b/helm/xsltd/xaland-cpp/xaland.cpp new file mode 100644 index 000000000..e22140267 --- /dev/null +++ b/helm/xsltd/xaland-cpp/xaland.cpp @@ -0,0 +1,207 @@ +// Base header file. Must be first. +#include + +#include +#include + +#include + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +int main(int argc, const char* []) +{ +#if !defined(XALAN_NO_NAMESPACES) + using std::cerr; + using std::endl; + using std::ofstream; +#endif + + if (argc != 1) { + cerr << "Usage: SimpleTransform" + << endl + << endl; + } else { + try { + // Call the static initializer for Xerces... + XMLPlatformUtils::Initialize(); + + { + // Initialize the Xalan XSLT subsystem... + XSLTInit theInit; + + // Create the support objects that are necessary for + // running the processor... + XercesDOMSupport theDOMSupport; + XercesParserLiaison theParserLiaison(theDOMSupport); + XPathSupportDefault theXPathSupport(theDOMSupport); + XSLTProcessorEnvSupportDefault theXSLTProcessorEnvSupport; + XObjectFactoryDefault theXObjectFactory; + XPathFactoryDefault theXPathFactory; + + // Create a processor... + XSLTEngineImpl theProcessor( + theParserLiaison, + theXPathSupport, + theXSLTProcessorEnvSupport, + theDOMSupport, + theXObjectFactory, + theXPathFactory); + + // Connect the processor to the support object... + theXSLTProcessorEnvSupport.setProcessor(&theProcessor); + + // Create a stylesheet construction context, and a stylesheet + // execution context... + StylesheetConstructionContextDefault theConstructionContext( + theProcessor, + theXSLTProcessorEnvSupport, + theXPathFactory); + + StylesheetExecutionContextDefault theExecutionContext( + theProcessor, + theXSLTProcessorEnvSupport, + theXPathSupport, + theXObjectFactory); + + // Our input files...The assumption is that the executable will be + // run from same directory as the input files. + const XalanDOMString theXMLFileName("foo.xml"); + const XalanDOMString theXSLFileName("foo.xsl"); + + // Our input sources... + XSLTInputSource theInputSource(c_wstr(theXMLFileName)); + XSLTInputSource theStylesheetSource(c_wstr(theXSLFileName)); + + // Our output target... + const XalanDOMString theOutputFileName("foo.out"); + XSLTResultTarget theResultTarget(theOutputFileName); + + theProcessor.process( + theInputSource, + theStylesheetSource, + theResultTarget, + theConstructionContext, + theExecutionContext); + + } + + // Call the static terminator for Xerces... + XMLPlatformUtils::Terminate(); + } + catch(...) { + cerr << "Exception caught!!!" + << endl + << endl; + } + } + + return 0; +} + +/**************************************************/ +/* + +public class xaland { + public static void Transform(StylesheetRoot style, String xmlSourceURL, String OutputURL) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException + { + XSLTInputSource xmlSource = new XSLTInputSource (xmlSourceURL); + XSLTResultTarget xmlResult = new XSLTResultTarget (OutputURL); + style.process(xmlSource, xmlResult); + } + + public static void main(String argv[]) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException + { + int port = Integer.parseInt(argv[0]); + int port2 = Integer.parseInt(argv[1]); + String xsl1 = argv[2]; + String xsl2 = argv[3]; + String theory_xsl1 = argv[4]; + String theory_xsl2 = argv[5]; + + XSLTProcessor theory_processor = + XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison()); + StylesheetRoot theory_style1 = + theory_processor.processStylesheet(theory_xsl1); + theory_processor.reset(); + StylesheetRoot theory_style2 = + theory_processor.processStylesheet(theory_xsl2); + theory_processor.setStylesheet(theory_style2); + + XSLTProcessor processor = + XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison()); + StylesheetRoot style1 = processor.processStylesheet(xsl1); + processor.reset(); + StylesheetRoot style2 = processor.processStylesheet(xsl2); + processor.setStylesheet(style2); + + DatagramSocket socket = new DatagramSocket(port); + + System.out.println("Demon activated on input port " + port + + " and output port " + port2); + while(true) { + System.out.print("Ready..."); + + /* Warning: the packet must be a fresh one! * / + DatagramPacket packet = new DatagramPacket(new byte[1024],1024); + socket.receive(packet); + byte data[] = packet.getData(); + int datalen = packet.getLength(); + String received = new String(data,0,datalen); + + int first = received.indexOf(' '); + int last = received.lastIndexOf(' '); + String mode = received.substring(0,first); + String input = received.substring(first+1,last); + String output = received.substring(last+1); + + System.out.println("request received! Parameters are"); + System.out.println("Mode: " + mode + " "); + System.out.println("Input file: \"" + input + "\""); + System.out.println("Output file: \"" + output + "\"\n"); + + if ((new File(output)).exists()) { + System.out.println("Using cached version\n"); + } else { + FileOutputStream fout = new FileOutputStream(output); + if (mode.equals("cic")) { + processor.setDocumentHandler(style2.getSAXSerializer(fout)); + XSLTResultTarget content = new XSLTResultTarget(processor); + style1.process(new XSLTInputSource(input), content); + } else if (mode.equals("theory")) { + theory_processor.setDocumentHandler( + theory_style2.getSAXSerializer(fout)); + XSLTResultTarget content = + new XSLTResultTarget(theory_processor); + theory_style1.process(new XSLTInputSource(input), content); + } + } + + InetAddress address = InetAddress.getLocalHost(); + DatagramSocket socket2 = new DatagramSocket(); + + byte buf[] = new byte[0]; + DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2); + + socket2.send(packet2); + } + } +} + +*/ diff --git a/helm/xsltd/xaland-java/rompi.class b/helm/xsltd/xaland-java/rompi.class new file mode 100644 index 000000000..4abfe3865 Binary files /dev/null and b/helm/xsltd/xaland-java/rompi.class differ diff --git a/helm/xsltd/xaland-java/rompi.java b/helm/xsltd/xaland-java/rompi.java new file mode 100644 index 000000000..6a633dbc9 --- /dev/null +++ b/helm/xsltd/xaland-java/rompi.java @@ -0,0 +1,12 @@ +import java.net.*; + +public class rompi { + public static void main(String argv[]) throws java.io.IOException, java.net.MalformedURLException + { + /* Wait forever ;-) */ + DatagramSocket socket2 = new DatagramSocket(12346); + DatagramPacket packet2 = new DatagramPacket(new byte[1],1); + System.out.println("Ho preso il socket e non lo lascio piu', caro pu, caro pu"); + socket2.receive(packet2); + } +} diff --git a/helm/xsltd/xaland-java/sped.class b/helm/xsltd/xaland-java/sped.class new file mode 100644 index 000000000..cc6f53dac Binary files /dev/null and b/helm/xsltd/xaland-java/sped.class differ diff --git a/helm/xsltd/xaland-java/sped.java b/helm/xsltd/xaland-java/sped.java new file mode 100644 index 000000000..9d96610d4 --- /dev/null +++ b/helm/xsltd/xaland-java/sped.java @@ -0,0 +1,28 @@ +import java.net.*; + +public class sped { + public static void main(String argv[]) throws java.io.IOException, java.net.MalformedURLException + { + String input = argv[0]; + String out1 = argv[1]; + String out2 = argv[2]; + + String sent = input + " " + out1 + " " + out2; + + InetAddress address = InetAddress.getLocalHost(); + DatagramSocket socket = new DatagramSocket(); + + int strlen = sent.length(); + byte buf[] = new byte[strlen]; + sent.getBytes(0,strlen,buf,0); + DatagramPacket packet = new DatagramPacket(buf,strlen,address,12345); + + socket.send(packet); + + + /* Wait for answer (or forever ;-) */ + DatagramSocket socket2 = new DatagramSocket(12346); + DatagramPacket packet2 = new DatagramPacket(new byte[1],1); + socket2.receive(packet2); + } +} diff --git a/helm/xsltd/xaland-java/xaland.class b/helm/xsltd/xaland-java/xaland.class new file mode 100644 index 000000000..6871fda4b Binary files /dev/null and b/helm/xsltd/xaland-java/xaland.class differ diff --git a/helm/xsltd/xaland-java/xaland.java b/helm/xsltd/xaland-java/xaland.java new file mode 100644 index 000000000..1b9312c46 --- /dev/null +++ b/helm/xsltd/xaland-java/xaland.java @@ -0,0 +1,91 @@ +import org.apache.xalan.xslt.*; +import java.net.*; +import java.io.*; + +public class xaland { +/* + public static void Transform(StylesheetRoot style, String xmlSourceURL, String OutputURL) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException + { + XSLTInputSource xmlSource = new XSLTInputSource (xmlSourceURL); + XSLTResultTarget xmlResult = new XSLTResultTarget (OutputURL); + style.process(xmlSource, xmlResult); + } +*/ + + public static void main(String argv[]) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException + { + int port = Integer.parseInt(argv[0]); + int port2 = Integer.parseInt(argv[1]); + String xsl1 = argv[2]; + String xsl2 = argv[3]; + String theory_xsl1 = argv[4]; + String theory_xsl2 = argv[5]; + + XSLTProcessor theory_processor = + XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison()); + StylesheetRoot theory_style1 = + theory_processor.processStylesheet(theory_xsl1); + theory_processor.reset(); + StylesheetRoot theory_style2 = + theory_processor.processStylesheet(theory_xsl2); + theory_processor.setStylesheet(theory_style2); + + XSLTProcessor processor = + XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison()); + StylesheetRoot style1 = processor.processStylesheet(xsl1); + processor.reset(); + StylesheetRoot style2 = processor.processStylesheet(xsl2); + processor.setStylesheet(style2); + + DatagramSocket socket = new DatagramSocket(port); + + System.out.println("Demon activated on input port " + port + + " and output port " + port2); + while(true) { + System.out.print("Ready..."); + + /* Warning: the packet must be a fresh one! */ + DatagramPacket packet = new DatagramPacket(new byte[1024],1024); + socket.receive(packet); + byte data[] = packet.getData(); + int datalen = packet.getLength(); + String received = new String(data,0,datalen); + + int first = received.indexOf(' '); + int last = received.lastIndexOf(' '); + String mode = received.substring(0,first); + String input = received.substring(first+1,last); + String output = received.substring(last+1); + + System.out.println("request received! Parameters are"); + System.out.println("Mode: " + mode + " "); + System.out.println("Input file: \"" + input + "\""); + System.out.println("Output file: \"" + output + "\"\n"); + + if ((new File(output)).exists()) { + System.out.println("Using cached version\n"); + } else { + FileOutputStream fout = new FileOutputStream(output); + if (mode.equals("cic")) { + processor.setDocumentHandler(style2.getSAXSerializer(fout)); + XSLTResultTarget content = new XSLTResultTarget(processor); + style1.process(new XSLTInputSource(input), content); + } else if (mode.equals("theory")) { + theory_processor.setDocumentHandler( + theory_style2.getSAXSerializer(fout)); + XSLTResultTarget content = + new XSLTResultTarget(theory_processor); + theory_style1.process(new XSLTInputSource(input), content); + } + } + + InetAddress address = InetAddress.getLocalHost(); + DatagramSocket socket2 = new DatagramSocket(); + + byte buf[] = new byte[0]; + DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2); + + socket2.send(packet2); + } + } +} diff --git a/helm/xsltd/xaland-java/xaland.java.prima_del_loro_baco b/helm/xsltd/xaland-java/xaland.java.prima_del_loro_baco new file mode 100644 index 000000000..b46ffa6aa --- /dev/null +++ b/helm/xsltd/xaland-java/xaland.java.prima_del_loro_baco @@ -0,0 +1,85 @@ +import org.apache.xalan.xslt.*; +import java.net.*; +import java.io.*; + +public class xaland { + public static void Transform(StylesheetRoot style, String xmlSourceURL, String OutputURL) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException + { + XSLTInputSource xmlSource = new XSLTInputSource (xmlSourceURL); + XSLTResultTarget xmlResult = new XSLTResultTarget (OutputURL); + style.process(xmlSource, xmlResult); + } + + public static void main(String argv[]) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException + { + int port = Integer.parseInt(argv[0]); + int port2 = Integer.parseInt(argv[1]); + String xsl1 = argv[2]; + String xsl2 = argv[3]; + String theory_xsl1 = argv[4]; + String theory_xsl2 = argv[5]; + + XSLTProcessor theory_processor = XSLTProcessorFactory.getProcessor(); + StylesheetRoot theory_style1 = + theory_processor.processStylesheet(theory_xsl1); + StylesheetRoot theory_style2 = + theory_processor.processStylesheet(theory_xsl2); + theory_processor.setStylesheet(theory_style2); + + XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); + StylesheetRoot style1 = processor.processStylesheet(xsl1); + StylesheetRoot style2 = processor.processStylesheet(xsl2); + processor.setStylesheet(style2); + + DatagramSocket socket = new DatagramSocket(port); + + System.out.println("Demon activated on input port " + port + + " and output port " + port2); + while(true) { + System.out.print("Ready..."); + + /* Warning: the packet must be a fresh one! */ + DatagramPacket packet = new DatagramPacket(new byte[1024],1024); + socket.receive(packet); + byte data[] = packet.getData(); + int datalen = packet.getLength(); + String received = new String(data,0,datalen); + + int first = received.indexOf(' '); + int last = received.lastIndexOf(' '); + String mode = received.substring(0,first); + String input = received.substring(first+1,last); + String output = received.substring(last+1); + + System.out.println("request received! Parameters are"); + System.out.println("Mode: " + mode + " "); + System.out.println("Input file: \"" + input + "\""); + System.out.println("Output file: \"" + output + "\"\n"); + + if ((new File(output)).exists()) { + System.out.println("Using cached version\n"); + } else { + FileOutputStream fout = new FileOutputStream(output); + if (mode.equals("cic")) { + processor.setDocumentHandler(style2.getSAXSerializer(fout)); + XSLTResultTarget content = new XSLTResultTarget(processor); + style1.process(new XSLTInputSource(input), content); + } else if (mode.equals("theory")) { + theory_processor.setDocumentHandler( + theory_style2.getSAXSerializer(fout)); + XSLTResultTarget content = + new XSLTResultTarget(theory_processor); + theory_style1.process(new XSLTInputSource(input), content); + } + } + + InetAddress address = InetAddress.getLocalHost(); + DatagramSocket socket2 = new DatagramSocket(); + + byte buf[] = new byte[0]; + DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2); + + socket2.send(packet2); + } + } +} diff --git a/helm/xsltd/xaland-java/xaland.java.prima_del_loro_baco_ma_dopo_i_reset b/helm/xsltd/xaland-java/xaland.java.prima_del_loro_baco_ma_dopo_i_reset new file mode 100644 index 000000000..1467cdd2e --- /dev/null +++ b/helm/xsltd/xaland-java/xaland.java.prima_del_loro_baco_ma_dopo_i_reset @@ -0,0 +1,87 @@ +import org.apache.xalan.xslt.*; +import java.net.*; +import java.io.*; + +public class xaland { + public static void Transform(StylesheetRoot style, String xmlSourceURL, String OutputURL) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException + { + XSLTInputSource xmlSource = new XSLTInputSource (xmlSourceURL); + XSLTResultTarget xmlResult = new XSLTResultTarget (OutputURL); + style.process(xmlSource, xmlResult); + } + + public static void main(String argv[]) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException + { + int port = Integer.parseInt(argv[0]); + int port2 = Integer.parseInt(argv[1]); + String xsl1 = argv[2]; + String xsl2 = argv[3]; + String theory_xsl1 = argv[4]; + String theory_xsl2 = argv[5]; + + XSLTProcessor theory_processor = XSLTProcessorFactory.getProcessor(); + StylesheetRoot theory_style1 = + theory_processor.processStylesheet(theory_xsl1); + theory_processor.reset(); + StylesheetRoot theory_style2 = + theory_processor.processStylesheet(theory_xsl2); + theory_processor.setStylesheet(theory_style2); + + XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); + StylesheetRoot style1 = processor.processStylesheet(xsl1); + processor.reset(); + StylesheetRoot style2 = processor.processStylesheet(xsl2); + processor.setStylesheet(style2); + + DatagramSocket socket = new DatagramSocket(port); + + System.out.println("Demon activated on input port " + port + + " and output port " + port2); + while(true) { + System.out.print("Ready..."); + + /* Warning: the packet must be a fresh one! */ + DatagramPacket packet = new DatagramPacket(new byte[1024],1024); + socket.receive(packet); + byte data[] = packet.getData(); + int datalen = packet.getLength(); + String received = new String(data,0,datalen); + + int first = received.indexOf(' '); + int last = received.lastIndexOf(' '); + String mode = received.substring(0,first); + String input = received.substring(first+1,last); + String output = received.substring(last+1); + + System.out.println("request received! Parameters are"); + System.out.println("Mode: " + mode + " "); + System.out.println("Input file: \"" + input + "\""); + System.out.println("Output file: \"" + output + "\"\n"); + + if ((new File(output)).exists()) { + System.out.println("Using cached version\n"); + } else { + FileOutputStream fout = new FileOutputStream(output); + if (mode.equals("cic")) { + processor.setDocumentHandler(style2.getSAXSerializer(fout)); + XSLTResultTarget content = new XSLTResultTarget(processor); + style1.process(new XSLTInputSource(input), content); + } else if (mode.equals("theory")) { + theory_processor.setDocumentHandler( + theory_style2.getSAXSerializer(fout)); + XSLTResultTarget content = + new XSLTResultTarget(theory_processor); + theory_style1.process(new XSLTInputSource(input), content); + } + } + + InetAddress address = InetAddress.getLocalHost(); + DatagramSocket socket2 = new DatagramSocket(); + + byte buf[] = new byte[0]; + DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2); + + socket2.send(packet2); + } + } +} diff --git a/helm/xsltd/xaland-java2/xaland2.class b/helm/xsltd/xaland-java2/xaland2.class new file mode 100644 index 000000000..95b42c712 Binary files /dev/null and b/helm/xsltd/xaland-java2/xaland2.class differ diff --git a/helm/xsltd/xaland-java2/xaland2.java b/helm/xsltd/xaland-java2/xaland2.java new file mode 100644 index 000000000..9d91d37fb --- /dev/null +++ b/helm/xsltd/xaland-java2/xaland2.java @@ -0,0 +1,134 @@ +import java.net.*; +import java.io.*; + +// Imported TraX classes +import org.apache.trax.Processor; +import org.apache.trax.Templates; +import org.apache.trax.Transformer; +import org.apache.trax.Result; +import org.apache.trax.ProcessorException; +import org.apache.trax.ProcessorFactoryException; +import org.apache.trax.TransformException; + +// Imported SAX classes +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.Parser; +import org.xml.sax.helpers.ParserAdapter; +import org.xml.sax.helpers.XMLReaderFactory; +import org.xml.sax.XMLReader; +import org.xml.sax.ContentHandler; +import org.xml.sax.ext.LexicalHandler; + +// Imported DOM classes +import org.w3c.dom.Node; + +// Imported Serializer classes +import org.apache.serialize.OutputFormat; +import org.apache.serialize.Serializer; +import org.apache.serialize.SerializerFactory; + +// Imported JAVA API for XML Parsing 1.0 classes +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + + +public class xaland2 { + public static void main(String argv[]) throws IOException, MalformedURLException, SAXException, ParserConfigurationException + { + int port = Integer.parseInt(argv[0]); + int port2 = Integer.parseInt(argv[1]); + String xsl1 = argv[2]; + String xsl2 = argv[3]; + String theory_xsl1 = argv[4]; + String theory_xsl2 = argv[5]; + + Processor theory_processor = Processor.newInstance("xslt"); + Templates theory_style1 = theory_processor.process(new InputSource(theory_xsl1)); + Transformer theory_transformer1 = theory_style1.newTransformer(); + + Templates theory_style2 = theory_processor.process(new InputSource(theory_xsl2)); + Transformer theory_transformer2 = theory_style2.newTransformer(); + + + Processor processor = Processor.newInstance("xslt"); + Templates style1 = processor.process(new InputSource(xsl1)); + Transformer transformer1 = style1.newTransformer(); + + Templates style2 = processor.process(new InputSource(xsl2)); + Transformer transformer2 = style2.newTransformer(); + + + DatagramSocket socket = new DatagramSocket(port); + + System.out.println("Demon activated on input port " + port + + " and output port " + port2); + while(true) { + System.out.print("Ready..."); + + /* Warning: the packet must be a fresh one! */ + DatagramPacket packet = new DatagramPacket(new byte[1024],1024); + socket.receive(packet); + byte data[] = packet.getData(); + int datalen = packet.getLength(); + String received = new String(data,0,datalen); + + int first = received.indexOf(' '); + int last = received.lastIndexOf(' '); + String mode = received.substring(0,first); + String input = received.substring(first+1,last); + String output = received.substring(last+1); + + System.out.println("request received! Parameters are"); + System.out.println("Mode: " + mode + " "); + System.out.println("Input file: \"" + input + "\""); + System.out.println("Output file: \"" + output + "\"\n"); + + if ((new File(output)).exists()) { + System.out.println("Using cached version\n"); + } else { + FileOutputStream fout = new FileOutputStream(output); + if (mode.equals("cic")) { + XMLReader reader = XMLReaderFactory.createXMLReader(); + ContentHandler chandler = transformer1.getInputContentHandler(); + reader.setContentHandler(chandler); + if (chandler instanceof LexicalHandler) + reader.setProperty("http://xml.org/sax/properties/lexical-handler", chandler); + else + reader.setProperty("http://xml.org/sax/properties/lexical-handler", null); + + transformer1.setContentHandler(transformer2.getInputContentHandler()); + Serializer serializer = SerializerFactory.getSerializer("xml"); + serializer.setOutputStream(fout); + transformer2.setContentHandler(serializer.asContentHandler()); + + reader.parse(input); + } else if (mode.equals("theory")) { + XMLReader reader = XMLReaderFactory.createXMLReader(); + ContentHandler chandler = theory_transformer1.getInputContentHandler(); + reader.setContentHandler(chandler); + if (chandler instanceof LexicalHandler) + reader.setProperty("http://xml.org/sax/properties/lexical-handler", chandler); + else + reader.setProperty("http://xml.org/sax/properties/lexical-handler", null); + + theory_transformer1.setContentHandler(theory_transformer2.getInputContentHandler()); + Serializer serializer = SerializerFactory.getSerializer("xml"); + serializer.setOutputStream(fout); + theory_transformer2.setContentHandler(serializer.asContentHandler()); + + reader.parse(input); + } + } + + InetAddress address = InetAddress.getLocalHost(); + DatagramSocket socket2 = new DatagramSocket(); + + byte buf[] = new byte[0]; + DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2); + + socket2.send(packet2); + } + } +}