]> matita.cs.unibo.it Git - helm.git/commitdiff
uses XmlPushParser instead of Pxp for parsing getter resolve answer
authorStefano Zacchiroli <zack@upsilon.cc>
Tue, 14 Jun 2005 11:15:07 +0000 (11:15 +0000)
committerStefano Zacchiroli <zack@upsilon.cc>
Tue, 14 Jun 2005 11:15:07 +0000 (11:15 +0000)
helm/ocaml/getter/Makefile
helm/ocaml/getter/http_getter.ml
helm/ocaml/getter/http_getter_env.ml

index 820b1628ee58e38f8154b8daec214262b3d348cc..2895f12e1fb581c077ae7d88900a7025b28fa980 100644 (file)
@@ -3,7 +3,7 @@ PACKAGE = getter
 
 REQUIRES = \
        http dbm pcre shell zip \
-       helm-pxp helm-thread helm-logger helm-urimanager helm-registry
+       helm-xml helm-thread helm-logger helm-urimanager helm-registry
 
 INTERFACE_FILES = \
        tree.mli \
index d0ecf9ba22d241851933a343fd6406a82cc390cb..58c94ac957c8dc2ccce93d7546f7bed42ea53ff8 100644 (file)
@@ -35,8 +35,6 @@ open Http_getter_types
 exception Not_implemented of string
 exception UnexpectedGetterOutput
 
-(* resolve_result is needed because it is not possible to raise *)
-(* an exception in a pxp ever-processing callback. Too bad.     *)
 type resolve_result =
   | Unknown
   | Exception of exn
@@ -262,22 +260,26 @@ let resolve_remote uri =
   (* deliver resolve request to http_getter *)
   let doc = ClientHTTP.get (sprintf "%sresolve?uri=%s" (getter_url ()) uri) in
   let res = ref Unknown in
-   Pxp_ev_parser.process_entity PxpHelmConf.pxp_config (`Entry_content [])
-    (Pxp_ev_parser.create_entity_manager ~is_document:true
-      PxpHelmConf.pxp_config (Pxp_yacc.from_string doc))
-    (function
-      | Pxp_types.E_start_tag ("url",["value",url],_,_) -> res := Resolved url
-      | Pxp_types.E_start_tag ("unresolvable",[],_,_) ->
-          res := Exception (Unresolvable_URI uri)
-      | Pxp_types.E_start_tag ("not_found",[],_,_) ->
-          res := Exception (Key_not_found uri)
-      | Pxp_types.E_start_tag (x,_,_,_) -> 
-         res := Exception UnexpectedGetterOutput
-      | _ -> ());
-   match !res with
-   | Unknown -> raise UnexpectedGetterOutput
-   | Exception e -> raise e
-   | Resolved url -> url
+  let start_element tag attrs =
+    match tag with
+    | "url" ->
+        (try
+          res := Resolved (List.assoc "value" attrs)
+        with Not_found -> ())
+    | "unresolvable" -> res := Exception (Unresolvable_URI uri)
+    | "not_found" -> res := Exception (Key_not_found uri)
+    | _ -> ()
+  in
+  let callbacks = {
+    XmlPushParser.default_callbacks with
+      XmlPushParser.start_element = Some start_element
+  } in
+  let xml_parser = XmlPushParser.create_parser callbacks in
+  XmlPushParser.parse xml_parser (`String doc);
+  match !res with
+  | Unknown -> raise UnexpectedGetterOutput
+  | Exception e -> raise e
+  | Resolved url -> url
 
 let register_remote ~uri ~url =
   ClientHTTP.send (sprintf "%sregister?uri=%s&url=%s" (getter_url ()) uri url)
index 575207057b60a4d85a429fae90d5d0a9f584913a..be278da6e63eb78fac5e4455bffbbe9d4da9c78c 100644 (file)
@@ -27,9 +27,6 @@
  *)
 
 open Printf
-open Pxp_document
-open Pxp_types
-open Pxp_yacc
 
 open Http_getter_types