1 import org.apache.xalan.xslt.*;
2 import org.w3c.dom.Document;
6 public class xaland_DOM {
7 public static void main(String argv[]) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException
9 int port = Integer.parseInt(argv[0]);
10 int port2 = Integer.parseInt(argv[1]);
11 String xsl1 = argv[2];
12 String xsl2 = argv[3];
13 String theory_xsl1 = argv[4];
14 String theory_xsl2 = argv[5];
16 XSLTProcessor theory_processor =
17 XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison());
18 StylesheetRoot theory_style1 =
19 theory_processor.processStylesheet(theory_xsl1);
20 theory_processor.reset();
21 StylesheetRoot theory_style2 =
22 theory_processor.processStylesheet(theory_xsl2);
23 theory_processor.setStylesheet(theory_style2);
25 XSLTProcessor processor =
26 XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison());
27 StylesheetRoot style1 = processor.processStylesheet(xsl1);
29 StylesheetRoot style2 = processor.processStylesheet(xsl2);
30 processor.setStylesheet(style2);
32 DatagramSocket socket = new DatagramSocket(port);
34 System.out.println("Demon activated on input port " + port +
35 " and output port " + port2);
37 System.out.print("Ready...");
39 /* Warning: the packet must be a fresh one! */
40 DatagramPacket packet = new DatagramPacket(new byte[1024],1024);
41 socket.receive(packet);
42 byte data[] = packet.getData();
43 int datalen = packet.getLength();
44 String received = new String(data,0,datalen);
46 int first = received.indexOf(' ');
47 int last = received.lastIndexOf(' ');
48 String mode = received.substring(0,first);
49 String input = received.substring(first+1,last);
50 String output = received.substring(last+1);
52 System.out.println("request received! Parameters are");
53 System.out.println("Mode: " + mode + " ");
54 System.out.println("Input file: \"" + input + "\"");
55 System.out.println("Output file: \"" + output + "\"\n");
57 if ((new File(output)).exists()) {
58 System.out.println("Using cached version\n");
60 FileOutputStream fout = new FileOutputStream(output);
61 if (mode.equals("cic")) {
62 Document content_doc = new org.apache.xerces.dom.DocumentImpl();
63 XSLTResultTarget content = new XSLTResultTarget(content_doc);
65 processor.setDocumentHandler(style2.getSAXSerializer(fout));
66 XSLTResultTarget content = new XSLTResultTarget(processor);
68 System.out.print("Prima...\n");
69 style1.process(new XSLTInputSource(input), content);
70 System.out.print("Durante...\n");
71 style2.process(new XSLTInputSource(content_doc),new XSLTResultTarget(fout));
72 System.out.print("Dopo...\n");
73 } else if (mode.equals("theory")) {
74 theory_processor.setDocumentHandler(
75 theory_style2.getSAXSerializer(fout));
76 XSLTResultTarget content =
77 new XSLTResultTarget(theory_processor);
78 theory_style1.process(new XSLTInputSource(input), content);
82 InetAddress address = InetAddress.getLocalHost();
83 DatagramSocket socket2 = new DatagramSocket();
85 byte buf[] = new byte[0];
86 DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2);
88 socket2.send(packet2);