]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/applyStylesheets.ml
61adcb42c17cb4314d942e9c0095b937429e30c6
[helm.git] / helm / gTopLevel / applyStylesheets.ml
1 (* Copyright (C) 2000-2002, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (******************************************************************************)
27 (*                                                                            *)
28 (*                               PROJECT HELM                                 *)
29 (*                                                                            *)
30 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
31 (*                                 30/01/2002                                 *)
32 (*                                                                            *)
33 (*                                                                            *)
34 (******************************************************************************)
35
36 (** stylesheets and parameters list **)
37
38 let parseStyle name =
39  let style =
40   Misc.domImpl#createDocumentFromURI
41    (* ~uri:("http://phd.cs.unibo.it:8081/getxslt?uri=" ^ name) ?mode:None *)
42    ~uri:("styles/" ^ name) ()
43  in
44   Gdome_xslt.processStylesheet style
45 ;;
46
47 let d_c = parseStyle "drop_coercions.xsl";;
48 let tc1 = parseStyle "objtheorycontent.xsl";;
49 let hc2 = parseStyle "content_to_html.xsl";;
50 let l   = parseStyle "link.xsl";;
51
52 let c1 = parseStyle "rootcontent.xsl";;
53 let g  = parseStyle "genmmlid.xsl";;
54 let c2 = parseStyle "annotatedpres.xsl";;
55
56
57 let getterURL = Configuration.getter_url;;
58 let processorURL = Configuration.processor_url;;
59
60 let mml_styles = [d_c ; c1 ; g ; c2 ; l];;
61 let mml_args ~explode_all =
62  ("explodeall",(if explode_all then "true()" else "false()"))::
63   ["processorURL", "'" ^ processorURL ^ "'" ;
64    "getterURL", "'" ^ getterURL ^ "'" ;
65    "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
66    "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
67    "UNICODEvsSYMBOL", "'symbol'" ;
68    "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
69    "encoding", "'iso-8859-1'" ;
70    "media-type", "'text/html'" ;
71    "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
72    "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
73    "naturalLanguage", "'yes'" ;
74    "annotations", "'no'" ;
75    "URLs_or_URIs", "'URIs'" ;
76    "topurl", "'http://phd.cs.unibo.it/helm'" ;
77    "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
78 ;;
79
80 let sequent_styles = [d_c ; c1 ; g ; c2 ; l];;
81 let sequent_args =
82  ["processorURL", "'" ^ processorURL ^ "'" ;
83   "getterURL", "'" ^ getterURL ^ "'" ;
84   "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
85   "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
86   "UNICODEvsSYMBOL", "'symbol'" ;
87   "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
88   "encoding", "'iso-8859-1'" ;
89   "media-type", "'text/html'" ;
90   "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
91   "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
92   "naturalLanguage", "'no'" ;
93   "annotations", "'no'" ;
94   "explodeall", "true()" ;
95   "URLs_or_URIs", "'URIs'" ;
96   "topurl", "'http://phd.cs.unibo.it/helm'" ;
97   "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
98 ;;
99
100 (** Stylesheets application **)
101
102 let apply_stylesheets input styles args =
103  List.fold_left (fun i style -> Gdome_xslt.applyStylesheet i style args)
104   input styles
105 ;;
106
107 let apply_proof_stylesheets proof_doc ~explode_all =
108  apply_stylesheets proof_doc mml_styles (mml_args ~explode_all)
109 ;;
110
111 let apply_sequent_stylesheets sequent_doc =
112  apply_stylesheets sequent_doc sequent_styles sequent_args
113 ;;
114
115 (** Utility functions to map objects to MathML Presentation **)
116
117 (*CSC: the getter should handle the innertypes, not the FS *)
118
119 let innertypesfile =
120  try
121   Sys.getenv "GTOPLEVEL_INNERTYPESFILE"
122  with
123   Not_found -> "/public/innertypes"
124 ;;
125
126 let constanttypefile =
127  try
128   Sys.getenv "GTOPLEVEL_CONSTANTTYPEFILE"
129  with
130   Not_found -> "/public/constanttype"
131 ;;
132
133 let mml_of_cic_term metano term =
134  let metasenv =
135   match !ProofEngine.proof with
136      None -> []
137    | Some (_,metasenv,_,_) -> metasenv
138  in
139  let context =
140   match !ProofEngine.goal with
141      None -> []
142    | Some metano ->
143       let (_,canonical_context,_) =
144        List.find (function (m,_,_) -> m=metano) metasenv
145       in
146        canonical_context
147  in
148    let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
149     SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
150    in
151     let sequent_doc =
152      Xml2Gdome.document_of_xml Misc.domImpl sequent_gdome
153     in
154      let res = apply_sequent_stylesheets sequent_doc in
155       res, (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
156 ;;
157
158 let
159  mml_of_cic_object ~explode_all uri annobj ids_to_inner_sorts ids_to_inner_types
160 =
161 (*CSC: ????????????????? *)
162  let xml, bodyxml =
163   Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:true
164    annobj 
165  in
166  let xmlinnertypes =
167   Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
168    ~ask_dtd_to_the_getter:true
169  in
170   let input =
171    match bodyxml with
172       None -> Xml2Gdome.document_of_xml Misc.domImpl xml
173     | Some bodyxml' ->
174        Xml.pp xml (Some constanttypefile) ;
175        Xml2Gdome.document_of_xml Misc.domImpl bodyxml'
176   in
177 (*CSC: We save the innertypes to disk so that we can retrieve them in the  *)
178 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
179 (*CSC: local.                                                              *)
180    Xml.pp xmlinnertypes (Some innertypesfile) ;
181    let output = apply_proof_stylesheets input ~explode_all in
182     output
183 ;;