1 // Base header file. Must be first.
2 #include <Include/PlatformDefinitions.hpp>
7 #include <util/PlatformUtils.hpp>
9 #include <PlatformSupport/DOMStringHelper.hpp>
11 #include <DOMSupport/DOMSupportDefault.hpp>
13 #include <XPath/XObjectFactoryDefault.hpp>
14 #include <XPath/XPathSupportDefault.hpp>
15 #include <XPath/XPathFactoryDefault.hpp>
17 #include <XSLT/StylesheetConstructionContextDefault.hpp>
18 #include <XSLT/StylesheetExecutionContextDefault.hpp>
19 #include <XSLT/XSLTEngineImpl.hpp>
20 #include <XSLT/XSLTInit.hpp>
21 #include <XSLT/XSLTInputSource.hpp>
22 #include <XSLT/XSLTProcessorEnvSupportDefault.hpp>
23 #include <XSLT/XSLTResultTarget.hpp>
25 #include <XercesParserLiaison/XercesDOMSupport.hpp>
26 #include <XercesParserLiaison/XercesParserLiaison.hpp>
28 int main(int argc, const char* [])
30 #if !defined(XALAN_NO_NAMESPACES)
37 cerr << "Usage: SimpleTransform"
42 // Call the static initializer for Xerces...
43 XMLPlatformUtils::Initialize();
46 // Initialize the Xalan XSLT subsystem...
49 // Create the support objects that are necessary for
50 // running the processor...
51 XercesDOMSupport theDOMSupport;
52 XercesParserLiaison theParserLiaison(theDOMSupport);
53 XPathSupportDefault theXPathSupport(theDOMSupport);
54 XSLTProcessorEnvSupportDefault theXSLTProcessorEnvSupport;
55 XObjectFactoryDefault theXObjectFactory;
56 XPathFactoryDefault theXPathFactory;
58 // Create a processor...
59 XSLTEngineImpl theProcessor(
62 theXSLTProcessorEnvSupport,
67 // Connect the processor to the support object...
68 theXSLTProcessorEnvSupport.setProcessor(&theProcessor);
70 // Create a stylesheet construction context, and a stylesheet
71 // execution context...
72 StylesheetConstructionContextDefault theConstructionContext(
74 theXSLTProcessorEnvSupport,
77 StylesheetExecutionContextDefault theExecutionContext(
79 theXSLTProcessorEnvSupport,
83 // Our input files...The assumption is that the executable will be
84 // run from same directory as the input files.
85 const XalanDOMString theXMLFileName("foo.xml");
86 const XalanDOMString theXSLFileName("foo.xsl");
88 // Our input sources...
89 XSLTInputSource theInputSource(c_wstr(theXMLFileName));
90 XSLTInputSource theStylesheetSource(c_wstr(theXSLFileName));
92 // Our output target...
93 const XalanDOMString theOutputFileName("foo.out");
94 XSLTResultTarget theResultTarget(theOutputFileName);
100 theConstructionContext,
101 theExecutionContext);
105 // Call the static terminator for Xerces...
106 XMLPlatformUtils::Terminate();
109 cerr << "Exception caught!!!"
118 /**************************************************/
121 public class xaland {
122 public static void Transform(StylesheetRoot style, String xmlSourceURL, String OutputURL) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException
124 XSLTInputSource xmlSource = new XSLTInputSource (xmlSourceURL);
125 XSLTResultTarget xmlResult = new XSLTResultTarget (OutputURL);
126 style.process(xmlSource, xmlResult);
129 public static void main(String argv[]) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException
131 int port = Integer.parseInt(argv[0]);
132 int port2 = Integer.parseInt(argv[1]);
133 String xsl1 = argv[2];
134 String xsl2 = argv[3];
135 String theory_xsl1 = argv[4];
136 String theory_xsl2 = argv[5];
138 XSLTProcessor theory_processor =
139 XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison());
140 StylesheetRoot theory_style1 =
141 theory_processor.processStylesheet(theory_xsl1);
142 theory_processor.reset();
143 StylesheetRoot theory_style2 =
144 theory_processor.processStylesheet(theory_xsl2);
145 theory_processor.setStylesheet(theory_style2);
147 XSLTProcessor processor =
148 XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison());
149 StylesheetRoot style1 = processor.processStylesheet(xsl1);
151 StylesheetRoot style2 = processor.processStylesheet(xsl2);
152 processor.setStylesheet(style2);
154 DatagramSocket socket = new DatagramSocket(port);
156 System.out.println("Demon activated on input port " + port +
157 " and output port " + port2);
159 System.out.print("Ready...");
161 /* Warning: the packet must be a fresh one! * /
162 DatagramPacket packet = new DatagramPacket(new byte[1024],1024);
163 socket.receive(packet);
164 byte data[] = packet.getData();
165 int datalen = packet.getLength();
166 String received = new String(data,0,datalen);
168 int first = received.indexOf(' ');
169 int last = received.lastIndexOf(' ');
170 String mode = received.substring(0,first);
171 String input = received.substring(first+1,last);
172 String output = received.substring(last+1);
174 System.out.println("request received! Parameters are");
175 System.out.println("Mode: " + mode + " ");
176 System.out.println("Input file: \"" + input + "\"");
177 System.out.println("Output file: \"" + output + "\"\n");
179 if ((new File(output)).exists()) {
180 System.out.println("Using cached version\n");
182 FileOutputStream fout = new FileOutputStream(output);
183 if (mode.equals("cic")) {
184 processor.setDocumentHandler(style2.getSAXSerializer(fout));
185 XSLTResultTarget content = new XSLTResultTarget(processor);
186 style1.process(new XSLTInputSource(input), content);
187 } else if (mode.equals("theory")) {
188 theory_processor.setDocumentHandler(
189 theory_style2.getSAXSerializer(fout));
190 XSLTResultTarget content =
191 new XSLTResultTarget(theory_processor);
192 theory_style1.process(new XSLTInputSource(input), content);
196 InetAddress address = InetAddress.getLocalHost();
197 DatagramSocket socket2 = new DatagramSocket();
199 byte buf[] = new byte[0];
200 DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2);
202 socket2.send(packet2);