1 import org.apache.xalan.xslt.*;
6 public static void main(String argv[]) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException
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];
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);
24 XSLTProcessor processor =
25 XSLTProcessorFactory.getProcessor(new org.apache.xalan.xpath.xdom.XercesLiaison());
26 StylesheetRoot style1 = processor.processStylesheet(xsl1);
28 StylesheetRoot style2 = processor.processStylesheet(xsl2);
29 processor.setStylesheet(style2);
31 DatagramSocket socket = new DatagramSocket(port);
33 System.out.println("Demon activated on input port " + port +
34 " and output port " + port2);
36 System.out.print("Ready...");
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);
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);
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");
56 if ((new File(output)).exists()) {
57 System.out.println("Using cached version\n");
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);
73 InetAddress address = InetAddress.getLocalHost();
74 DatagramSocket socket2 = new DatagramSocket();
76 byte buf[] = new byte[0];
77 DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2);
79 socket2.send(packet2);