]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/interface/xsltProcessor.ml
Initial revision
[helm.git] / helm / interface / xsltProcessor.ml
index 3d3690f395154b8c76bd680e7700c736db3a3039..95f1c70d59b5edc7a6a26f892d04e1eb43b52f6e 100644 (file)
  * http://cs.unibo.it/helm/.
  *)
 
-exception XsltProcessorCouldNotSend;;
-exception XsltProcessorCouldNotReceive;;
+let initialize () =
+ Printf.printf "Initializing the UWOBO servlet, please wait" ; flush stdout ;
+ Hashtbl.iter
+  (fun key uri ->
+    let string_to_send = (Configuration.processor_url ^ "add?xsluri=" ^ Configuration.getter_url ^ "getxslt?uri=" ^ uri ^ "&key=" ^ key)
+    in
+     print_char '.' ; flush stdout ;
+     ClientHTTP.send string_to_send
+  )
+  StyleConfiguration.styles ;
+ Printf.printf " ok\n" ; flush stdout
+;;
+
+(* CSC: esempio per vedere se veniva calcolata bene. Rimuovere pure il commento
+http://phd.cs.unibo.it:8080/helm/servlet/uwobo/apply?xmluri=http%3A//phd.cs.unibo.it%3A8081/getxml%3Furi%3Dcic%3A/Coq/Init/Datatypes/nat_ind.con&keys=C1,C2,L&param.processorURL=http%3A//phd.cs.unibo.it%3A8080/helm/servlet/uwobo/&param.getterURL=http%3A//phd.cs.unibo.it%3A8081/&prop.doctype-public=&prop.encoding=&prop.media-type=text/xml&param.doctype-public=&param.encoding=&param.media-type=text/xml&param.keys=C1%2CC2%2CL&param.CICURI=cic:/Coq/Init/Datatypes/nat_ind.con&param.naturalLanguage=yes&param.annotations=NO
+
 
-let portserver = 12345;;
-let portclient = 12346;;
-let time_to_wait = 10;;
+&keys=C1,C2,L
+*)
+
+let process uri usecache mode naturalLanguage annotations =
+ let uri = UriManager.string_of_uri uri in
+ let url = Configuration.getter_url ^ "getxml?uri=" ^ uri in
+ let keys =
+  match StyleConfiguration.key_list_of_mode_name mode with
+    first_key::key_list ->
+     first_key ^
+     (List.fold_right
+      (fun key cmd -> "," ^ key ^ cmd)
+       key_list
+       ""
+      ) 
+  | _ -> prerr_string "Warning: the list of keys for UWOBO is empty\n"; ""
+ in
+ let string_to_send =
+  Configuration.processor_url ^ "apply?xmluri=" ^ url ^
+  "&param.processorURL=" ^ Configuration.processor_url ^
+  "&param.getterURL=" ^ Configuration.getter_url ^
+  "&prop.doctype-public=&prop.encoding=&prop.media-type=text/xml" ^
+  "&keys=" ^ keys ^
+  "&param.keys=" ^ keys ^
+  "&param.CICURI=" ^ uri ^
+  "&param.naturalLanguage=" ^ naturalLanguage ^
+  "&param.annotations=" ^ annotations ^
+  "&param.doctype-public=&param.encoding=&param.media-type=text/xml"
+ in
+  string_to_send
+;;
 
-let rec process uri usecache mode =
- let module U = Unix in
-  let uri = UriManager.string_of_uri uri in
-  let pid = string_of_int (U.getpid ())
-  and filename' =
-   let uri' = Str.replace_first (Str.regexp ".*:") "" uri in
-    Str.global_replace (Str.regexp "/") "_"
-     (Str.global_replace (Str.regexp "_") "__" uri')
-  in let tmpfile = "/tmp/helm_" ^ filename' ^ "_" ^ pid in
-   (* test if the cache can be used *)
-   let tmp_file_exists = Sys.file_exists tmpfile in
-    if usecache && tmp_file_exists then
-     tmpfile
-    else
-     let url = Configuration.getter_url ^ uri in
-      (* purge the cache if asked to *)
-      if not usecache && tmp_file_exists then
-        Sys.remove tmpfile ;
-      (* let string_to_send = mode ^ " " ^ url ^ " " ^ tmpfile in *)
-      let string_to_send = "apply " ^ url ^ " " ^ tmpfile ^
-       match mode with
-          "cic" -> " C1 C2"
-       | "theory" -> " T1 T2"
-      in
-      (* next function is for looping in case the server is not responding *)
-       let socketserver = U.socket U.PF_INET U.SOCK_DGRAM 0 in
-        let rec contact_server () =
-         let n =
-          U.sendto socketserver string_to_send 0 (String.length string_to_send)
-           [] (U.ADDR_INET(U.inet_addr_any,portserver))
-         in
-          if n = -1 then raise XsltProcessorCouldNotSend ;
-          let process_signal _ = () in
-          Sys.set_signal Sys.sigalrm (Sys.Signal_handle process_signal) ;
-          (* if the server does not respond, repeat the query *)
-          ignore (U.alarm time_to_wait) ;
-          try
-           if U.recv socketserver "" 0 0 [] = -1 then
-            raise XsltProcessorCouldNotReceive ;
-           ignore (U.alarm 0) ; (* stop the bomb *)
-           Sys.set_signal Sys.sigalrm Sys.Signal_default ;
-           U.close socketserver ;
-           tmpfile
-          with
-           U.Unix_error(_,"recv",_) ->
-            print_endline "Xaland server not responding. Retrying..." ;
-            flush stdout;
-            contact_server ()
-        in
-        contact_server ()
+(*CSC: ma questa funzione ha senso? Se si', in quale modulo?*)
+(*CSC: tutti i parametri passati alla process sono quasi a caso!!! *)
+let url_of_uri uri =
+ process uri true "cic" "yes" "YES"
 ;;