]> matita.cs.unibo.it Git - helm.git/blob - helm/xsltd/xaland-cpp/xaland.cpp
1. Several files in grafite that should be in grafite_parser moved there.
[helm.git] / helm / xsltd / xaland-cpp / xaland.cpp
1 // Base header file.  Must be first.
2 #include <Include/PlatformDefinitions.hpp>
3
4 #include <iostream>
5 #include <fstream>
6
7 #include <util/PlatformUtils.hpp>
8
9 #include <PlatformSupport/DOMStringHelper.hpp>
10
11 #include <DOMSupport/DOMSupportDefault.hpp>
12
13 #include <XPath/XObjectFactoryDefault.hpp>
14 #include <XPath/XPathSupportDefault.hpp>
15 #include <XPath/XPathFactoryDefault.hpp>
16
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>
24
25 #include <XercesParserLiaison/XercesDOMSupport.hpp>
26 #include <XercesParserLiaison/XercesParserLiaison.hpp>
27
28 int main(int argc, const char* [])
29 {
30 #if !defined(XALAN_NO_NAMESPACES)
31    using std::cerr;
32    using std::endl;
33    using std::ofstream;
34 #endif
35
36    if (argc != 1) {
37       cerr << "Usage: SimpleTransform"
38            << endl
39            << endl;
40    } else {
41       try {
42          // Call the static initializer for Xerces...
43          XMLPlatformUtils::Initialize();
44
45          {
46             // Initialize the Xalan XSLT subsystem...
47             XSLTInit theInit;
48
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;
57
58             // Create a processor...
59             XSLTEngineImpl theProcessor(
60                theParserLiaison,
61                theXPathSupport,
62                theXSLTProcessorEnvSupport,
63                theDOMSupport,
64                theXObjectFactory,
65                theXPathFactory);
66
67             // Connect the processor to the support object...
68            theXSLTProcessorEnvSupport.setProcessor(&theProcessor);
69
70            // Create a stylesheet construction context, and a stylesheet
71            // execution context...
72            StylesheetConstructionContextDefault theConstructionContext(
73               theProcessor,
74               theXSLTProcessorEnvSupport,
75               theXPathFactory);
76
77            StylesheetExecutionContextDefault theExecutionContext(
78               theProcessor,
79               theXSLTProcessorEnvSupport,
80               theXPathSupport,
81               theXObjectFactory);
82
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");
87
88            // Our input sources...
89            XSLTInputSource theInputSource(c_wstr(theXMLFileName));
90            XSLTInputSource theStylesheetSource(c_wstr(theXSLFileName));
91
92            // Our output target...
93            const XalanDOMString theOutputFileName("foo.out");
94            XSLTResultTarget theResultTarget(theOutputFileName);
95
96            theProcessor.process(
97               theInputSource,
98               theStylesheetSource,
99               theResultTarget,
100               theConstructionContext,
101               theExecutionContext);
102
103          }
104
105          // Call the static terminator for Xerces...
106          XMLPlatformUtils::Terminate();
107       }
108       catch(...) {
109          cerr << "Exception caught!!!"
110               << endl
111               << endl;
112       }
113    }
114
115    return 0;
116 }
117
118 /**************************************************/
119 /*
120
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
123    {
124       XSLTInputSource xmlSource = new XSLTInputSource (xmlSourceURL);
125       XSLTResultTarget xmlResult = new XSLTResultTarget (OutputURL);
126       style.process(xmlSource, xmlResult);
127    }
128
129    public static void main(String argv[]) throws  java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException
130    {
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];
137
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);
146
147       XSLTProcessor processor =
148        XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison());
149       StylesheetRoot style1 = processor.processStylesheet(xsl1);
150       processor.reset();
151       StylesheetRoot style2 = processor.processStylesheet(xsl2);
152       processor.setStylesheet(style2);
153
154       DatagramSocket socket = new DatagramSocket(port);
155
156       System.out.println("Demon activated on input port " + port +
157        " and output port " + port2);
158       while(true) {
159          System.out.print("Ready...");
160
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);
167
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);
173
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");
178
179          if ((new File(output)).exists()) {
180             System.out.println("Using cached version\n");
181          } else {
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);
193             }
194          }
195
196          InetAddress address = InetAddress.getLocalHost();
197          DatagramSocket socket2 = new DatagramSocket();
198
199          byte buf[] = new byte[0];
200          DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2);
201
202          socket2.send(packet2);
203       }
204    }
205 }
206
207 */