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 =
44 Gdome_xslt.processStylesheet (domImpl#createDocumentFromURI ~uri ())
49 (fun collected_styles key ->
50 (List.find (fun (k, _) -> k = key) stylesheets)::collected_styles)
57 if (List.mem_assoc key uris) then
58 raise (Stylesheet_already_in key)
60 uris <- (key, uri) :: uris;
61 stylesheets <- (key, self#process uri) :: stylesheets
67 if not (List.mem_assoc key uris) then
68 raise (Stylesheet_not_found key)
70 uris <- List.remove_assoc key uris;
71 stylesheets <- List.remove_assoc key stylesheets
82 let uris = self#doReader (lazy (
87 (fun (key, uri) -> sprintf "key = %s, uri = %s" key (List.assoc key uris))
93 let uri = List.assoc key uris in
95 (key, self#process uri) :: (List.remove_assoc key stylesheets)
97 raise (Stylesheet_not_found key))
101 self#doWriter (lazy (
102 stylesheets <- List.map (fun (key, uri) -> (key, self#process uri)) uris