1 import org.apache.xalan.xslt.*;
6 public static void Transform(StylesheetRoot style, String xmlSourceURL, String OutputURL) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException
8 XSLTInputSource xmlSource = new XSLTInputSource (xmlSourceURL);
9 XSLTResultTarget xmlResult = new XSLTResultTarget (OutputURL);
10 style.process(xmlSource, xmlResult);
13 public static void main(String argv[]) throws java.io.IOException, java.net.MalformedURLException, org.xml.sax.SAXException
15 int port = Integer.parseInt(argv[0]);
16 int port2 = Integer.parseInt(argv[1]);
17 String xsl1 = argv[2];
18 String xsl2 = argv[3];
19 String theory_xsl1 = argv[4];
20 String theory_xsl2 = argv[5];
22 XSLTProcessor theory_processor = XSLTProcessorFactory.getProcessor();
23 StylesheetRoot theory_style1 =
24 theory_processor.processStylesheet(theory_xsl1);
25 StylesheetRoot theory_style2 =
26 theory_processor.processStylesheet(theory_xsl2);
27 theory_processor.setStylesheet(theory_style2);
29 XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
30 StylesheetRoot style1 = processor.processStylesheet(xsl1);
31 StylesheetRoot style2 = processor.processStylesheet(xsl2);
32 processor.setStylesheet(style2);
34 DatagramSocket socket = new DatagramSocket(port);
36 System.out.println("Demon activated on input port " + port +
37 " and output port " + port2);
39 System.out.print("Ready...");
41 /* Warning: the packet must be a fresh one! */
42 DatagramPacket packet = new DatagramPacket(new byte[1024],1024);
43 socket.receive(packet);
44 byte data[] = packet.getData();
45 int datalen = packet.getLength();
46 String received = new String(data,0,datalen);
48 int first = received.indexOf(' ');
49 int last = received.lastIndexOf(' ');
50 String mode = received.substring(0,first);
51 String input = received.substring(first+1,last);
52 String output = received.substring(last+1);
54 System.out.println("request received! Parameters are");
55 System.out.println("Mode: " + mode + " ");
56 System.out.println("Input file: \"" + input + "\"");
57 System.out.println("Output file: \"" + output + "\"\n");
59 if ((new File(output)).exists()) {
60 System.out.println("Using cached version\n");
62 FileOutputStream fout = new FileOutputStream(output);
63 if (mode.equals("cic")) {
64 processor.setDocumentHandler(style2.getSAXSerializer(fout));
65 XSLTResultTarget content = new XSLTResultTarget(processor);
66 style1.process(new XSLTInputSource(input), content);
67 } else if (mode.equals("theory")) {
68 theory_processor.setDocumentHandler(
69 theory_style2.getSAXSerializer(fout));
70 XSLTResultTarget content =
71 new XSLTResultTarget(theory_processor);
72 theory_style1.process(new XSLTInputSource(input), content);
76 InetAddress address = InetAddress.getLocalHost();
77 DatagramSocket socket2 = new DatagramSocket();
79 byte buf[] = new byte[0];
80 DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2);
82 socket2.send(packet2);