2 (* Copyright (C) 2002, HELM Team.
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.
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.
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.
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,
23 * For details, see the HELM World-Wide-Web page,
24 * http://cs.unibo.it/helm/.
29 exception Stylesheet_not_found of string;;
30 exception Stylesheet_already_in of string;;
34 (* INVARIANT: 'stylesheets' and 'uris' are in sync *)
36 inherit Uwobo_common.threadSafe
38 val mutable stylesheets = []
40 val domImpl = Gdome.domImplementation ()
42 (** process an XSLT stylesheet *)
43 method private process uri = domImpl#createDocumentFromURI ~uri ()
47 let rev_keys = List.rev keys in
48 let last_key = List.hd rev_keys in
51 (fun collected_styles key ->
52 let (key, stylesheet) =
54 List.find (fun (k, _) -> k = key) stylesheets
55 with Not_found -> raise (Stylesheet_not_found key)
57 (key, Gdome_xslt.processStylesheet stylesheet)::collected_styles)
62 snd (List.find (fun (k, _) -> k = last_key) stylesheets)
64 (p_stylesheets, last_stylesheet)
69 if (List.mem_assoc key uris) then
70 raise (Stylesheet_already_in key)
72 uris <- (key, uri) :: uris;
73 stylesheets <- (key, self#process uri) :: stylesheets
79 if not (List.mem_assoc key uris) then
80 raise (Stylesheet_not_found key)
82 uris <- List.remove_assoc key uris;
83 stylesheets <- List.remove_assoc key stylesheets
94 let uris = self#doReader (lazy (
99 (fun (key, uri) -> sprintf "key = %s, uri = %s" key (List.assoc key uris))
103 self#doWriter (lazy (
105 let uri = List.assoc key uris in
107 (key, self#process uri) :: (List.remove_assoc key stylesheets)
109 raise (Stylesheet_not_found key))
113 self#doWriter (lazy (
114 stylesheets <- List.map (fun (key, uri) -> (key, self#process uri)) uris