]> matita.cs.unibo.it Git - helm.git/blob - helm/xsltd/xaland-uwobo/xaland_uwobo.java
ocaml 3.09 transition
[helm.git] / helm / xsltd / xaland-uwobo / xaland_uwobo.java
1 //import org.apache.xalan.xslt.*;
2 import java.net.*;
3 import java.io.*;
4
5 public class xaland_uwobo {
6    static DatagramSocket uwobo_socket;
7    static int portuwobo;
8
9    public static void send_to_uwobo(String cmd)
10    throws java.io.IOException
11    {
12       /*CSC: UDP based, but not fault-tolerant */
13       byte[] cmdBytes = cmd.getBytes();
14       DatagramPacket packet =
15        new DatagramPacket(cmdBytes, cmdBytes.length,
16         InetAddress.getLocalHost(), portuwobo);
17       uwobo_socket.send(packet);
18       DatagramPacket rcv = new DatagramPacket(new byte[0], 0);
19       uwobo_socket.receive(rcv);
20    }
21
22    public static void main(String argv[]) throws  java.io.IOException, java.net.MalformedURLException//, org.xml.sax.SAXException
23    {
24       int port  = Integer.parseInt(argv[0]);
25       int port2 = Integer.parseInt(argv[1]);
26       portuwobo = Integer.parseInt(argv[2]);
27       String xsl1 = argv[3];
28       String xsl2 = argv[4];
29       String theory_xsl1 = argv[5];
30       String theory_xsl2 = argv[6];
31
32       DatagramSocket socket = new DatagramSocket(port);
33       uwobo_socket = new DatagramSocket();
34
35       /* Initialize uwobo */
36       send_to_uwobo("add " + xsl1 + " ciccontent");
37       send_to_uwobo("add " + xsl2 + " cicpres");
38       send_to_uwobo("add " + theory_xsl1 + " theorycontent");
39       send_to_uwobo("add " + theory_xsl2 + " theorypres");
40
41
42       System.out.println("Demon activated on input port " + port +
43        " and output port " + port2);
44       while(true) {
45          System.out.print("Ready...");
46
47          /* Warning: the packet must be a fresh one! */
48          DatagramPacket packet = new DatagramPacket(new byte[1024],1024);
49          socket.receive(packet);
50          byte data[] = packet.getData();
51          int datalen = packet.getLength();
52          String received = new String(data,0,datalen);
53
54          int first = received.indexOf(' ');
55          int last  = received.lastIndexOf(' ');
56          String mode = received.substring(0,first-1);
57          String input = received.substring(first+1,last);
58          String output = received.substring(last+1);
59
60          System.out.println("request received! Parameters are");
61          System.out.println("Mode: \"" + mode + "\"");
62          System.out.println("Input file: \"" + input + "\"");
63          System.out.println("Output file: \"" + output  + "\"\n");
64
65          if (mode == "cic")
66             send_to_uwobo("apply " + input + " " + output + " ciccontent cicpres");
67          else
68             send_to_uwobo("apply " + input + " " + output + " theorycontent theorypres");
69
70          InetAddress address = InetAddress.getLocalHost();
71          DatagramSocket socket2 = new DatagramSocket();
72
73          byte buf[] = new byte[0];
74          DatagramPacket packet2 = new DatagramPacket(buf,0,address,port2);
75
76          socket2.send(packet2);
77       }
78    }
79 }