3 * Stefano Zacchiroli <zack@cs.unibo.it>
4 * for the HELM Team http://helm.cs.unibo.it/
6 * This file is part of HELM, an Hypertextual, Electronic
7 * Library of Mathematics, developed at the Computer Science
8 * Department, University of Bologna, Italy.
10 * HELM is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * HELM is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with HELM; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * For details, see the HELM World-Wide-Web page,
26 * http://helm.cs.unibo.it/
32 exception Stylesheet_not_found of string ;;
33 exception Stylesheet_already_in of string ;;
37 (* INVARIANT: 'stylesheets' and 'uris' are in sync *)
39 val mutable stylesheets = [] (** association list: key -> Gdome.document *)
40 val mutable uris = [] (** association list: key -> uri *)
42 val domImpl = Gdome.domImplementation ()
44 (** process an XSLT stylesheet *)
45 method private process uri =
46 let dom = domImpl#createDocumentFromURI ~uri () in
47 ignore (Gdome_xslt.processStylesheet dom); (* produce libXSLT messages in
51 (* stylesheets management *)
54 if (List.mem_assoc key uris) then
55 raise (Stylesheet_already_in key)
57 uris <- (key, uri) :: uris;
58 stylesheets <- (key, self#process uri) :: stylesheets
62 if not (List.mem_assoc key uris) then
63 raise (Stylesheet_not_found key)
65 uris <- List.remove_assoc key uris;
66 stylesheets <- List.remove_assoc key stylesheets
75 let uri = List.assoc key uris in
77 (key, self#process uri) :: (List.remove_assoc key stylesheets)
79 raise (Stylesheet_not_found key))
82 stylesheets <- List.map (fun (key, uri) -> (key, self#process uri)) uris
84 (* stylesheets usage *)
86 method keys = List.map fst uris
91 sprintf "key = %s, uri = %s" key (List.assoc key uris))
95 let rev_keys = List.rev keys in
96 let last_key = List.hd rev_keys in
99 (fun collected_styles key ->
100 let (key, stylesheet) =
102 List.find (fun (k, _) -> k = key) stylesheets
103 with Not_found -> raise (Stylesheet_not_found key)
105 (key, Gdome_xslt.processStylesheet stylesheet)::collected_styles)
109 let last_stylesheet =
110 snd (List.find (fun (k, _) -> k = last_key) stylesheets)
112 (p_stylesheets, last_stylesheet)