]> matita.cs.unibo.it Git - helm.git/blob - helm/xsltd/xaland-java/xaland.java
xaland that uses DOM created, but seems to be bugged and not working
[helm.git] / helm / xsltd / xaland-java / xaland.java
1 import org.apache.xalan.xslt.*;
2 import java.net.*;
3 import java.io.*;
4
5 public class xaland {
6    public static void main(String argv[]) throws  java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException
7    {
8       int port    = Integer.parseInt(argv[0]);
9       int port2   = Integer.parseInt(argv[1]);
10       String xsl1 = argv[2];
11       String xsl2 = argv[3];
12       String theory_xsl1 = argv[4];
13       String theory_xsl2 = argv[5];
14
15       XSLTProcessor theory_processor =
16        XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison());
17       StylesheetRoot theory_style1 =
18          theory_processor.processStylesheet(theory_xsl1);
19       theory_processor.reset();
20       StylesheetRoot theory_style2 =
21          theory_processor.processStylesheet(theory_xsl2);
22       theory_processor.setStylesheet(theory_style2);
23
24       XSLTProcessor processor =
25        XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison());
26       StylesheetRoot style1 = processor.processStylesheet(xsl1);
27       processor.reset();
28       StylesheetRoot style2 = processor.processStylesheet(xsl2);
29       processor.setStylesheet(style2);
30
31       DatagramSocket socket = new DatagramSocket(port);
32
33       System.out.println("Demon activated on input port " + port +
34        " and output port " + port2);
35       while(true) {
36          System.out.print("Ready...");
37
38          /* Warning: the packet must be a fresh one! */
39          DatagramPacket packet = new DatagramPacket(new byte[1024],1024);
40          socket.receive(packet);
41          byte data[] = packet.getData();
42          int datalen = packet.getLength();
43          String received = new String(data,0,datalen);
44
45          int first = received.indexOf(' ');
46          int last  = received.lastIndexOf(' ');
47          String mode = received.substring(0,first);
48          String input = received.substring(first+1,last);
49          String output = received.substring(last+1);
50
51          System.out.println("request received! Parameters are");
52          System.out.println("Mode: " + mode + " ");
53          System.out.println("Input file: \"" + input + "\"");
54          System.out.println("Output file: \"" + output  + "\"\n");
55
56          if ((new File(output)).exists()) {
57             System.out.println("Using cached version\n");
58          } else {
59             FileOutputStream fout = new FileOutputStream(output);
60             if (mode.equals("cic")) {
61                processor.setDocumentHandler(style2.getSAXSerializer(fout));
62                XSLTResultTarget content = new XSLTResultTarget(processor);
63                style1.process(new XSLTInputSource(input), content);
64             } else if (mode.equals("theory")) {
65                theory_processor.setDocumentHandler(
66                   theory_style2.getSAXSerializer(fout));
67                XSLTResultTarget content =
68                   new XSLTResultTarget(theory_processor);
69                theory_style1.process(new XSLTInputSource(input), content);
70             }
71          }
72
73          InetAddress address = InetAddress.getLocalHost();
74          DatagramSocket socket2 = new DatagramSocket();
75
76          byte buf[] = new byte[0];
77          DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2);
78
79          socket2.send(packet2);
80       }
81    }
82 }