X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=helm%2Fuwobo%2Fuwobo_common.ml;h=87a640b4306d156753c0df050ba71a511360acfc;hb=bb236c2ac110124de92fa2d0fb2882d273a7f7eb;hp=c71024ce8c40427dae4804cf209c2af03fd58a0d;hpb=aa39605bc50cc876067b768ed8b0a348415b3a91;p=helm.git diff --git a/helm/uwobo/uwobo_common.ml b/helm/uwobo/uwobo_common.ml index c71024ce8..87a640b43 100644 --- a/helm/uwobo/uwobo_common.ml +++ b/helm/uwobo/uwobo_common.ml @@ -26,9 +26,12 @@ * http://helm.cs.unibo.it/ *) -open Printf;; +open Printf ;; -exception Uwobo_failure of string;; +exception Uwobo_failure of string ;; + +let uwobo_namespace = "http://helm.cs.unibo.it/uwobo" ;; +let xsl_namespace = "http://helm.cs.unibo.it/uwobo" ;; let supported_properties = [ "cdata-section-elements"; @@ -45,7 +48,7 @@ let supported_properties = [ let is_supported_property name = List.mem name supported_properties -let version = "0.2.0" ;; +let version = "0.2.1" ;; let usage_string = sprintf @@ -69,18 +72,26 @@ let usage_string = help
display this help message

+

+ newsession?port=p
+ starts a new daemon on a given port p +

+

+ kill
+ kills the daemon. The log file is mantained. +

add?bind=key,uri[&bind=key,uri[&...]]
load a new stylesheet, specified by uri, and bind it to key key

- remove[?keys=key1,key2,...]
+ remove?keys=[key1,key2,...]
unload stylesheets specified by key1, key2, ... or all stylesheets if no key was given

- reload[?keys=key1,key2,...]
+ reload?keys=[key1,key2,...]
reload stylesheets specified by key1, key2, ... or all stylesheets if no key was given

@@ -89,19 +100,76 @@ let usage_string = return a list of loaded stylesheets

- apply?xmluri=uri&keys=key1,key2,...[¶m.name=value[¶m.name=value[&...]]][¶m.key.name=value[¶m.key.name=value[&...]]][&prop.name[=value][&prop.name[=value][&...]]]
+ apply?xmluri=uri&keys=key1,key2,...[&errormode={ignore|comment|embed}][&debugmode={ignore|comment|embed}][&profile=id][&password=password][¶m.name=value[¶m.name=value[&...]]][¶m.key.name=value[¶m.key.name=value[&...]]][&prop.name[=value][&prop.name[=value][&...]]]
apply a chain of stylesheets, specified by key1, key2, ..., to an input document, specified by uri.
+ Error and debugging modes could be ste to three different values. + ignore means that LibXSLT messages are ignored; comment + meanst that LibXSLT messages are embedded in the result document inside an + XML like comment; embed means that LibXSLT messages are embedded + at the beginning of the result document (as childs of the root node) in + XML elements in the UWOBO namespace
Additional parameters can be set for each stylesheet application: global parameters (i.e. parameters passed to all stylesheets) are set using param.name=value syntax, per stylesheet parameters are set using param.key.name=value where key is the key of a loaded stylesheet.
+ Moreover, it is possible to specify a profile that is searched for + additional global and local parameters. The parameters stored in the profile + have lower precedence with respect to those provided in the URL. A + password for the profile must be provided if the read permission + of the profile is set to false.
Properties of the final chain output can be set too: valueless properties can be set using prop.name syntax, others can be set using prop.name=value syntax.
Current supported properties are: %s.

+

+ listprofiles
+ return the list of profiles available +

+

+ createprofile?[id=id][&orig=orig][&origpassword=origpassword][&readperm={true|false}][&writeperm={true|false}][&adminperm={true|false}][&password=password]
+ creates a new profile. The id of the created profile is id (if provided); otherwise it is a fresh id. + The parameters are inherited from the profile orig, if provided. origpassword is the password of the + profile being copied in case the read permission of that profile is set to false. The defaults for + password and readper,writeperm,adminperm are respectively true, true, true and no password. +

+

+ removeprofile?id=id[&password=password]
+ completely removes the profile id. The password is required if the profile administrative permission + is set to false. +

+

+ setparam?id=id[&password=password]&key=key[&value=value]
+ sets the property key to value, if value is provided; otherwise + the parameter is unset. The password is required if the profile writing permission is set to + false. +

+

+ setpassword?id=id[&oldpassword=oldpassword][&password=password]
+ changes or unset the password. The old password is required if it was set. +

+

+ setpermission?id=id[&password=password]&permission={read|write|admin}&value={true|false}
+ changes the permission permission. The password is required if the administrative permission + is set to false. +

+

+ getparams?id=id[&password=password]
+ returns all the params of the profile id. The password is required if the read permission + is set to false. +

+

+ getparam?id=id[&password=password]&key=key
+ returns the value of the param key of the profile id. The password is required if the read permission + is set to false. +

+

+ getpermission?id=id[&password=password]&for={read|write|admin}
+ returns the value of the permission key of the profile id. The password is required if the administrative + permission is set to false. +

" @@ -110,11 +178,66 @@ let usage_string = ;; let pp_error = - sprintf "Error: %s" + sprintf + "Error: %s%s" ;; -let return_error msg outchan = - Http_daemon.respond ~body:(pp_error msg) outchan;; +let return_error msg ?(body = "") outchan = + Http_daemon.respond ~body:(pp_error msg body) outchan;; let bad_request body outchan = - Http_daemon.respond_error ~code:400 ~body outchan + Http_daemon.respond_error ~code:(`Code 400) ~body outchan +;; + + (** {2 LibXSLT logging} *) + +type xslt_msg = + | LibXsltErrorMsg of string + | LibXsltDebugMsg of string +;; + +let string_of_xslt_msg = function + | LibXsltErrorMsg msg -> "LibXSLT ERROR: " ^ msg + | LibXsltDebugMsg msg -> "LibXSLT DEBUG: " ^ msg +;; + +type xslt_msg_mode = + | LibXsltMsgIgnore + | LibXsltMsgComment + | LibXsltMsgEmbed +;; + +class libXsltLogger = + let is_libxslt_error = function LibXsltErrorMsg _ -> true | _ -> false in + let is_libxslt_debug = function LibXsltDebugMsg _ -> true | _ -> false in + let flatten_libxslt_msg = function + | LibXsltErrorMsg msg -> msg + | LibXsltDebugMsg msg -> msg + in + object (self) + + initializer + Gdome_xslt.setErrorCallback + (Some (fun msg -> self#appendMsg (LibXsltErrorMsg msg))); + Gdome_xslt.setDebugCallback + (Some (fun msg -> self#appendMsg (LibXsltDebugMsg msg))) + + val mutable libXsltMsgs = [] (** libxslt's error and debugging messages *) + + (* libxslt's error and debugging messages handling *) + + method private appendMsg msg = libXsltMsgs <- msg :: libXsltMsgs + + method clearMsgs = libXsltMsgs <- [] + method clearErrorMsgs = + libXsltMsgs <- List.filter is_libxslt_debug libXsltMsgs + method clearDebugMsgs = + libXsltMsgs <- List.filter is_libxslt_error libXsltMsgs + + method msgs = libXsltMsgs + method errorMsgs = + List.map flatten_libxslt_msg (List.filter is_libxslt_error libXsltMsgs) + method debugMsgs = + List.map flatten_libxslt_msg (List.filter is_libxslt_debug libXsltMsgs) + + end ;;