]> matita.cs.unibo.it Git - helm.git/blob - helm/uwobo/src/ocaml/uwobo_engine.ml
bda9b1804e9a7f1ba550d0ca23649d61b6a193c5
[helm.git] / helm / uwobo / src / ocaml / uwobo_engine.ml
1
2 (* Copyright (C) 2002, HELM Team.
3  * 
4  * This file is part of HELM, an Hypertextual, Electronic
5  * Library of Mathematics, developed at the Computer Science
6  * Department, University of Bologna, Italy.
7  * 
8  * HELM is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  * 
13  * HELM is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with HELM; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21  * MA  02111-1307, USA.
22  * 
23  * For details, see the HELM World-Wide-Web page,
24  * http://cs.unibo.it/helm/.
25  *)
26
27 open Printf;;
28 open Uwobo_common;;
29
30 let dump_args keys params props =
31   (sprintf "
32 Keys: %s<br />
33 Parameters:<br />
34 %s
35 Props: %s<br />
36 "
37     (String.concat ", " keys)
38     (String.concat
39       "<br />\n"
40       (List.map
41         (fun key ->
42           (sprintf
43             "Key: %s, Params: %s"
44             key
45             (String.concat
46               ", "
47               (List.map
48                 (fun (key,value) -> sprintf "%s:%s" key value)
49                 (params key)))))
50         keys))
51     (String.concat
52       ", "
53       (List.map (fun (key,value) -> sprintf "%s:%s" key value) props)))
54
55   (* TODO add global mutex, stylesheets are freezed at the request moment *)
56 let apply
57   ~(logger: Uwobo_logger.sysLogger)
58   ~(styles: Uwobo_styles.styles)
59   ~keys ~params ~props ~input =
60   let stylesheets = styles#get keys in
61   logger#log `Debug (dump_args keys params props);
62   logger#log `Debug "Creating input document ...";
63   List.fold_left
64     (fun source (key, stylesheet) ->
65       logger#log `Debug (sprintf "Applying stylesheet %s ..." key);
66       try
67         let params =
68           List.map (fun (key,value) -> (key, "'" ^ value ^ "'")) (params key)
69         in
70         Gdome_xslt.applyStylesheet ~source ~stylesheet ~params
71       with e -> raise (Uwobo_failure (Printexc.to_string e)))
72     input
73     stylesheets
74