]> matita.cs.unibo.it Git - helm.git/blob - helm/uwobo/uwobo_common.ml
pretty print errors using red color instead of h1 text (close #50)
[helm.git] / helm / uwobo / uwobo_common.ml
1 (*
2  * Copyright (C) 2003:
3  *    Stefano Zacchiroli <zack@cs.unibo.it>
4  *    for the HELM Team http://helm.cs.unibo.it/
5  *
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.
9  *
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.
14  *
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.
19  *
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,
23  *  MA  02111-1307, USA.
24  *
25  *  For details, see the HELM World-Wide-Web page,
26  *  http://helm.cs.unibo.it/
27  *)
28
29 open Printf;;
30
31 exception Uwobo_failure of string;;
32
33 let supported_properties = [
34   "cdata-section-elements";
35   "doctype-public";
36   "doctype-system";
37   "encoding";
38   "indent";
39   "media-type";
40   "method";
41   "omit-xml-declaration";
42   "standalone";
43   "version"
44 ]
45
46 let is_supported_property name = List.mem name supported_properties
47
48 let version = "0.2.0" ;;
49
50 let usage_string =
51   sprintf
52 "
53 <html>
54   <head>
55     <title>UWOBO's help message</title>
56   </head>
57   <body>
58     <h1>UWOBO (version: %s)</h1>
59     <h2>Information</h2>
60     Version: %s
61     <h2>Usage</h2>
62     <p>
63     Usage: <kbd>http://hostname:uwoboport/</kbd><em>command</em>
64     </p>
65     <p>
66     Available commands:
67     </p>
68     <p>
69       <b><kbd>help</kbd></b><br />
70       display this help message
71     </p>
72     <p>
73       <b><kbd>add?bind=key,uri[&bind=key,uri[&...]]</kbd></b><br />
74       load a new stylesheet, specified by <em>uri</em>, and bind it to key
75           <em>key</em>
76     </p>
77     <p>
78       <b><kbd>remove[?keys=key1,key2,...]</kbd></b><br />
79       unload stylesheets specified by <em>key1, key2, ...</em> or all
80           stylesheets if no key was given
81     </p>
82     <p>
83       <b><kbd>reload[?keys=key1,key2,...]</kbd></b><br />
84       reload stylesheets specified by <em>key1, key2, ...</em> or all
85           stylesheets if no key was given
86     </p>
87     <p>
88       <b><kbd>list</kbd></b><br />
89       return a list of loaded stylesheets
90     </p>
91     <p>
92       <b><kbd>apply?xmluri=uri&keys=key1,key2,...[&param.name=value[&param.name=value[&...]]][&param.key.name=value[&param.key.name=value[&...]]][&prop.name[=value][&prop.name[=value][&...]]]</kbd></b><br />
93       apply a chain of stylesheets, specified by <em>key1, key2, ...</em>, to an
94       input document, specified by <em>uri</em>.<br />
95       Additional parameters can be set for each stylesheet application: global
96       parameters (i.e. parameters passed to all stylesheets) are set using
97       <em>param.name=value</em> syntax, per stylesheet parameters are set using
98       <em>param.key.name=value</em> where <em>key</em> is the key of a loaded
99       stylesheet.<br />
100       Properties of the final chain output can be set too: valueless properties
101       can be set using <em>prop.name</em> syntax, others can be set using
102       <em>prop.name=value</em> syntax.<br />
103       Current supported properties are: %s.
104     </p>
105   </body>
106 </html>
107 "
108   version version
109   (String.concat ", " supported_properties) (* supported properties *)
110 ;;
111
112 let pp_error =
113   sprintf "<html><body><span style=\"color:red\">Error: %s</span></body></html>"
114 ;;
115 let return_error msg outchan =
116   Http_daemon.respond ~body:(pp_error msg) outchan;;
117 let bad_request body outchan =
118   Http_daemon.respond_error ~code:400 ~body outchan
119 ;;
120