]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/uwobo/src/it/unibo/cs/helm/uwobo/Servlet.java
1) New syntax: methods add, reload and remove can now process multiple
[helm.git] / helm / uwobo / src / it / unibo / cs / helm / uwobo / Servlet.java
index 3b4766250a42298964bd9612dcd00399aaf23fa4..7158bc6464a12d113d09d117f3b4e205d12d20bd 100644 (file)
@@ -7,24 +7,24 @@ import javax.servlet.http.*;
 import javax.xml.transform.*;
 import org.xml.sax.*;
 
+// WARNING: next comment is obsolete!!!!!
 /*
 *
 * usage:
-*   http://aristotele/helm/servlet/uwobo/help
-*   http://aristotele/helm/servlet/uwobo/add?xsluri=&key=
-*   http://aristotele/helm/servlet/uwobo/remove[?key=]
-*   http://aristotele/helm/servlet/uwobo/list
-*   http://aristotele/helm/servlet/uwobo/reload[?key=]
-*   http://aristotele/helm/servlet/uwobo/update[?key=]
-*   http://aristotele/helm/servlet/uwobo/apply?xmluri=&keys=[&param.=]*
+*   http://hostname/helm/servlet/uwobo/help
+*   http://hostname/helm/servlet/uwobo/add?bind=key,stylesheet[&bind=key,stylesheet]*
+*   http://hostname/helm/servlet/uwobo/remove[?keys=key_1,...,key_n]
+*   http://hostname/helm/servlet/uwobo/list
+*   http://hostname/helm/servlet/uwobo/reload[?keys=key_1,...,key_n]
+*   http://hostname/helm/servlet/uwobo/apply?xmluri=xmldata&keys=key_1,...,key_n[&param.name=value]*[&param.key.name=value]*[&prop.name=[value]]*
 *
 * example:
-*   http://aristotele/helm/servlet/uwobo/add?xsluri=file:///D:/Archivio/Progetti/helm/resources/xsl/foo1.xsl&key=foo1
-*   http://aristotele/helm/servlet/uwobo/add?xsluri=file:///D:/Archivio/Progetti/helm/resources/xsl/foo2.xsl&key=foo2
-*   http://aristotele/helm/servlet/uwobo/apply?xmluri=file:///D:/Archivio/Progetti/helm/resources/xsl/foo.xml&key=foo1&key=foo2
+*   http://aristotele/helm/servlet/uwobo/add?bind=foo1,file:///D:/Archivio/Progetti/helm/resources/xsl/foo1.xsl
+*   http://aristotele/helm/servlet/uwobo/add?bind=foo2,file:///D:/Archivio/Progetti/helm/resources/xsl/foo2.xsl
+*   http://aristotele/helm/servlet/uwobo/apply?xmluri=file:///D:/Archivio/Progetti/helm/resources/xsl/foo.xml&keys=foo1,foo2
 *
 * installation notes (Tomcat):
-*      replace parser.jar and jaxp.jar from /lib with xerces.jar
+*      replace parser.jar and jaxp.jar from /lib with xerces.jar and add xalan.jar
 *
 *      add in conf/server.xml
 *              <Context path="/helm" 
@@ -37,8 +37,6 @@ import org.xml.sax.*;
 *      add in uriworkermap.properties
 *              /helm/*=ajp12
 *
-* bugs:
-*      directory base stylesheet inclusi
 *
 * @author The HELM team
 */
@@ -46,11 +44,10 @@ public class Servlet extends HttpServlet {
    
    public static final String[] usage = {
       "http://<i>hostname</i>/helm/servlet/uwobo/help",
-      "http://<i>hostname</i>/helm/servlet/uwobo/add?key=<i>key</i>,<i>stylesheet</i>[&key=<i>key</i>,<i>stylesheet</i>]*",
+      "http://<i>hostname</i>/helm/servlet/uwobo/add?bind=<i>key</i>,<i>stylesheet</i>[&bind=<i>key</i>,<i>stylesheet</i>]*",
       "http://<i>hostname</i>/helm/servlet/uwobo/remove[?keys=<i>key_1,...,key_n</i>]",
       "http://<i>hostname</i>/helm/servlet/uwobo/list",
       "http://<i>hostname</i>/helm/servlet/uwobo/reload[?keys=<i>key_1,...,key_n</i>]",
-      "http://<i>hostname</i>/helm/servlet/uwobo/update[?keys=<i>key_1,...,key_n</i>]",
       "http://<i>hostname</i>/helm/servlet/uwobo/apply?xmluri=<i>xmldata</i>&keys=<i>key_1,...,key_n</i>[&param.<i>name</i>=<i>value</i>]*[&param.<i>key</i>.<i>name</i>=<i>value</i>]*[&prop.<i>name</i>=[<i>value</i>]]*"
    };
    public static final String help;
@@ -97,7 +94,7 @@ public class Servlet extends HttpServlet {
    throws IOException
    {  
       resp.setContentType("text/html");
-      out.println("<html><body bgcolor=\"#ffffff\"><h1>Uwobo servlet</h1>");
+      out.println("<html><body bgcolor=\"#ffffff\"><h1>" + server.PACKAGE + " servlet</h1>");
    }
    
    private void html_close(ServletOutputStream out)
@@ -109,7 +106,7 @@ public class Servlet extends HttpServlet {
 
    private String msg_out(String message)
    {
-      return message+"<br>";
+      return message+"<br />";
    }
    
    private String exc_out(String message, Exception e)
@@ -121,13 +118,14 @@ public class Servlet extends HttpServlet {
       }
       String local = e.getLocalizedMessage();
       local = local.substring(local.lastIndexOf(':')+1);
-      return "<b>"+message+": "+local+"</b><br>";
+      return "<b>"+message+": "+local+"</b><br />";
    }
    
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
       ServletOutputStream out = response.getOutputStream();
+      String log = "";
       
       response.setHeader("Cache-Control", "no-cache");
       response.setHeader("Pragma", "no-cache");
@@ -140,16 +138,18 @@ public class Servlet extends HttpServlet {
            sendError(response, out, "unknown command", help); return;
         } 
         if (cmd.equals("/add")) {
-           final String[] xslkey = request.getParameterValues("key");
+           final String[] xslkey = request.getParameterValues("bind");
            if (xslkey == null) {
               sendError(response, out, "bad parameters", usage[1]); return;
            } 
            html_open(response, out);
            for (int i = 0; i < xslkey.length; i++) {
               final String data[] = split2(xslkey[i], ",");
-              out.println(msg_out("adding key "+data[0]+" ("+data[1]+")"));
+              out.println(msg_out("adding stylesheet "+data[0]+" ("+data[1]+")"));
               try {
-                 server.add(data[1], data[0]);
+                 log = server.add(data[1], data[0]);
+                  if(!log.equals(""))
+                     out.println(msg_out(log));
                } catch (TransformerConfigurationException tce) {
                   out.println(exc_out("stylesheet error", tce));
                } catch (Exception e) {
@@ -236,10 +236,14 @@ public class Servlet extends HttpServlet {
            for (int i = 0; i < data.length; i++) { 
               if (data[i] == null) {
                  out.println(msg_out("removing all keys"));
-                 server.removeAll();
+                  ArrayList res;
+                 res = server.removeAll();
+                  Iterator j = res.iterator();
+                  while (j.hasNext())
+                     out.println(msg_out((String)j.next()));
               } else {
                  out.println(msg_out("removing key "+data[i]));
-                 server.remove(data[i]);
+                 out.println(msg_out(server.remove(data[i])));
               }
            }
            html_close(out); return;
@@ -261,31 +265,14 @@ public class Servlet extends HttpServlet {
               try {
                  if (data[i] == null) {
                     out.println(msg_out("reloading all keys"));
-                    server.reloadAll();
+                     ArrayList res;
+                    res = server.reloadAll();
+                     Iterator j = res.iterator();
+                     while(j.hasNext())
+                        out.println(msg_out((String)j.next()));
                  } else {
                     out.println(msg_out("reloading key "+data[i]));
-                    server.reload(data[i]);
-                 }
-              } catch (TransformerConfigurationException tce) {
-                  out.println(exc_out("stylesheet error", tce));
-               } catch (Exception e) {
-                 out.println(exc_out(null, e));
-               }
-           }
-           html_close(out); return;
-        }
-         if (cmd.equals("/update")) {
-           final String key = request.getParameter("keys");
-            final String [] data = split(key, ",");
-           html_open(response, out);
-           for (int i = 0; i < data.length; i++) {
-              try {
-                 if (data[i] == null) {
-                    out.println(msg_out("updating all keys")); 
-                    server.updateAll();
-                 } else {
-                    out.println(msg_out("updating key "+data[i]));
-                    server.update(data[i]);
+                    out.println(msg_out(server.reload(data[i])));
                  }
               } catch (TransformerConfigurationException tce) {
                   out.println(exc_out("stylesheet error", tce));
@@ -297,14 +284,21 @@ public class Servlet extends HttpServlet {
         }
         if (cmd.equals("/help")) {
            html_open(response, out);
-           out.println("<h2>"+server.PACKAGE+" servlet - version "+server.VERSION+"</h1>");
+           out.println("<h2>Version "+server.VERSION+"</h1>");
            out.println("<b>compiled "+server.DATE+" at "+server.TIME.substring(0,2)+":"+server.TIME.substring(2)+"</b>");
+            if(Server.SERIALIZATION_DIR.equals("")) {
+               out.println("<p><b>Stylesheet serialization is off.</b>");
+               out.println("(To turn it on, choose a non-empty value for the " +
+                  "SERIALIZATION_DIR property.)</p>");
+            } else
+               out.println("<p><b>Serialized stylesheed are stored in &quot;" +
+                  Server.SERIALIZATION_DIR + "&quot;.</b></p>");
            out.println("<p>usage:</p>"+help+"</body></html>");
            html_close(out); return;
         }
         sendError(response, out, "unknown command", help); return;
       } catch (Exception e) {
-        sendError(response, out, exc_out(null, e),""); // FG: non dovrebbe servire mai
+        sendError(response, out, exc_out(null, e),"");
         return;
       }
    }