Mercurial > hg > digilib-old
annotate servlet2/src/main/java/digilib/servlet/DigilibServletConfiguration.java @ 1092:4964a1e252eb
first step towards a find region functionality
author | hertzhaft |
---|---|
date | Thu, 18 Oct 2012 17:22:55 +0200 |
parents | 4e368c85cce4 |
children | 2ee261676828 |
rev | line source |
---|---|
903 | 1 /* |
2 * DigilibConfiguration -- Holding all parameters for digilib servlet. | |
3 * | |
4 * Digital Image Library servlet components | |
5 * | |
6 * Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de) | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify it | |
9 * under the terms of the GNU General Public License as published by the Free | |
10 * Software Foundation; either version 2 of the License, or (at your option) | |
11 * any later version. | |
12 * | |
13 * Please read license.txt for the full details. A copy of the GPL may be found | |
14 * at http://www.gnu.org/copyleft/lgpl.html | |
15 * | |
16 * You should have received a copy of the GNU General Public License along with | |
17 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
18 * Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 package digilib.servlet; | |
23 | |
24 import java.io.File; | |
25 import java.util.Map; | |
26 import java.util.Map.Entry; | |
27 | |
28 import javax.servlet.ServletContext; | |
29 import javax.servlet.ServletException; | |
30 | |
31 import digilib.image.DocuImageImpl; | |
32 import digilib.io.FileOps; | |
33 import digilib.util.Parameter; | |
34 import digilib.util.XMLListLoader; | |
35 | |
36 /** | |
37 * Class to hold the digilib servlet configuration parameters. The parameters | |
38 * can be read from the digilib-config file and be passed to other servlets or | |
39 * beans. <br>errorImgFileName: image file to send in case of error. <br> | |
40 * denyImgFileName: image file to send if access is denied. <br>baseDirs: | |
41 * array of base directories in order of preference (prescaled versions first). | |
42 * <br>useAuth: use authentication information. <br>authConfPath: | |
43 * authentication configuration file. <br>... <br> | |
44 * | |
45 * @author casties | |
46 * | |
47 */ | |
48 public class DigilibServletConfiguration extends DigilibConfiguration { | |
49 | |
50 /** | |
51 * Definition of parameters and default values. | |
52 */ | |
53 protected void initParams() { | |
54 /* | |
55 * Definition of parameters and default values. System parameters that | |
56 * are not read from config file have a type 's'. | |
57 */ | |
58 | |
59 // digilib servlet version | |
60 newParameter( | |
61 "servlet.version", | |
62 digilib.servlet.Scaler.getVersion(), | |
63 null, | |
64 's'); | |
65 // configuration file location | |
66 newParameter("servlet.config.file", null, null, 's'); | |
67 // DocuDirCache instance | |
68 newParameter("servlet.dir.cache", null, null, 's'); | |
69 // DocuImage class instance | |
70 newParameter( | |
71 "servlet.docuimage.class", | |
960
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
911
diff
changeset
|
72 digilib.image.ImageLoaderDocuImage.class, |
903 | 73 null, |
74 's'); | |
1032
4e368c85cce4
CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7)
robcast
parents:
960
diff
changeset
|
75 // DocuImage version |
4e368c85cce4
CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7)
robcast
parents:
960
diff
changeset
|
76 newParameter("servlet.docuimage.version", |
4e368c85cce4
CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7)
robcast
parents:
960
diff
changeset
|
77 "?", null, 's'); |
903 | 78 // AuthOps instance for authentication |
79 newParameter("servlet.auth.op", null, null, 's'); | |
80 // Executor for image operations | |
81 newParameter("servlet.worker.imageexecutor", null, null, 's'); | |
82 // Executor for PDF operations | |
83 newParameter("servlet.worker.pdfexecutor", null, null, 's'); | |
84 // Executor for PDF-image operations | |
85 newParameter("servlet.worker.pdfimageexecutor", null, null, 's'); | |
86 | |
87 /* | |
88 * parameters that can be read from config file have a type 'f' | |
89 */ | |
90 | |
91 // image file to send in case of error | |
92 newParameter( | |
93 "error-image", | |
94 new File("img/digilib-error.png"), | |
95 null, | |
96 'f'); | |
97 // image file to send if access is denied | |
98 newParameter( | |
99 "denied-image", | |
100 new File("img/digilib-denied.png"), | |
101 null, | |
102 'f'); | |
103 // image file to send if image file not found | |
104 newParameter( | |
105 "notfound-image", | |
106 new File("img/digilib-notfound.png"), | |
107 null, | |
108 'f'); | |
109 // base directories in order of preference (prescaled versions last) | |
110 String[] bd = { "/docuserver/images", "/docuserver/scaled/small" }; | |
111 newParameter("basedir-list", bd, null, 'f'); | |
112 // use authentication information | |
113 newParameter("use-authorization", Boolean.FALSE, null, 'f'); | |
114 // authentication configuration file | |
115 newParameter("auth-file", new File("digilib-auth.xml"), null, 'f'); | |
116 // sending image files as-is allowed | |
117 newParameter("sendfile-allowed", Boolean.TRUE, null, 'f'); | |
118 // Type of DocuImage instance | |
119 newParameter( | |
120 "docuimage-class", | |
960
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
911
diff
changeset
|
121 "digilib.image.ImageLoaderDocuImage", |
903 | 122 null, |
123 'f'); | |
124 // part of URL used to indicate authorized access | |
125 newParameter("auth-url-path", "authenticated/", null, 'f'); | |
126 // degree of subsampling on image load | |
127 newParameter("subsample-minimum", new Float(2f), null, 'f'); | |
128 // default scaling quality | |
129 newParameter("default-quality", new Integer(1), null, 'f'); | |
130 // use mapping file to translate paths | |
131 newParameter("use-mapping", Boolean.FALSE, null, 'f'); | |
132 // mapping file location | |
133 newParameter("mapping-file", new File("digilib-map.xml"), null, 'f'); | |
134 // log4j config file location | |
135 newParameter("log-config-file", new File("log4j-config.xml"), null, 'f'); | |
136 // maximum destination image size (0 means no limit) | |
137 newParameter("max-image-size", new Integer(0), null, 'f'); | |
138 // number of working threads | |
139 newParameter("worker-threads", new Integer(1), null, 'f'); | |
140 // max number of waiting threads | |
141 newParameter("max-waiting-threads", new Integer(20), null, 'f'); | |
142 // number of pdf-generation threads | |
143 newParameter("pdf-worker-threads", new Integer(1), null, 'f'); | |
144 // max number of waiting pdf-generation threads | |
145 newParameter("pdf-max-waiting-threads", new Integer(20), null, 'f'); | |
146 // number of pdf-image generation threads | |
147 newParameter("pdf-image-worker-threads", new Integer(1), null, 'f'); | |
148 // max number of waiting pdf-image generation threads | |
149 newParameter("pdf-image-max-waiting-threads", new Integer(10), null, 'f'); | |
150 // PDF generation temp directory | |
151 newParameter("pdf-temp-dir", "pdf_temp", null, 'f'); | |
152 // PDF generation cache directory | |
153 newParameter("pdf-cache-dir", "pdf_cache", null, 'f'); | |
154 // allow image toolkit to use disk cache | |
155 newParameter("img-diskcache-allowed", Boolean.TRUE, null, 'f'); | |
156 // default type of error message (image, text, code) | |
157 newParameter("default-errmsg-type", "image", null, 'f'); | |
158 } | |
159 | |
160 /** | |
161 * Constructor taking a ServletConfig. Reads the config file location from | |
162 * an init parameter and loads the config file. Calls <code>readConfig()</code>. | |
163 * | |
164 * @see readConfig() | |
165 */ | |
166 public DigilibServletConfiguration(ServletContext c) throws Exception { | |
167 readConfig(c); | |
168 } | |
169 | |
911 | 170 /** |
171 * read parameter list from the XML file in init parameter "config-file" or | |
172 * file digilib-config.xml | |
173 */ | |
174 @SuppressWarnings("unchecked") | |
903 | 175 public void readConfig(ServletContext c) throws Exception { |
176 | |
911 | 177 /* |
178 * Get config file name. The file name is first looked for as an init | |
179 * parameter, then in a fixed location in the webapp. | |
180 */ | |
181 if (c == null) { | |
182 // no config no file... | |
183 return; | |
184 } | |
185 String fn = c.getInitParameter("config-file"); | |
186 if (fn == null) { | |
187 fn = ServletOps.getConfigFile("digilib-config.xml", c); | |
188 if (fn == null) { | |
189 logger.fatal("readConfig: no param config-file"); | |
190 throw new ServletException("ERROR: no digilib config file!"); | |
191 } | |
192 } | |
193 File f = new File(fn); | |
194 // setup config file list reader | |
195 XMLListLoader lilo = new XMLListLoader("digilib-config", "parameter", | |
196 "name", "value"); | |
197 // read config file into HashMap | |
198 Map<String, String> confTable = lilo.loadURL(f.toURL().toString()); | |
903 | 199 |
911 | 200 // set config file path parameter |
201 setValue("servlet.config.file", f.getCanonicalPath()); | |
903 | 202 |
911 | 203 /* |
204 * read parameters | |
205 */ | |
903 | 206 |
911 | 207 for (Entry<String, String> confEntry : confTable.entrySet()) { |
208 Parameter p = get(confEntry.getKey()); | |
209 if (p != null) { | |
210 if (p.getType() == 's') { | |
211 // type 's' Parameters are not overwritten. | |
212 continue; | |
213 } | |
214 if (!p.setValueFromString(confEntry.getValue())) { | |
215 /* | |
216 * automatic conversion failed -- try special cases | |
217 */ | |
903 | 218 |
911 | 219 // basedir-list |
220 if (confEntry.getKey().equals("basedir-list")) { | |
221 // split list into directories | |
222 String[] dirs = FileOps.pathToArray(confEntry.getValue()); | |
223 for (int j = 0; j < dirs.length; j++) { | |
224 // make relative directory paths be inside the webapp | |
225 dirs[j] = ServletOps.getFile(dirs[j], c); | |
226 } | |
227 if (dirs != null) { | |
228 p.setValue(dirs); | |
229 } | |
230 } | |
231 } | |
232 } else { | |
233 // parameter unknown -- just add | |
234 newParameter(confEntry.getKey(), null, confEntry.getValue(), | |
235 'f'); | |
236 } | |
237 } | |
238 // initialise static DocuImage class instance | |
239 DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class | |
240 .forName(getAsString("docuimage-class")); | |
1032
4e368c85cce4
CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7)
robcast
parents:
960
diff
changeset
|
241 setValue("servlet.docuimage.version", getDocuImageInstance().getVersion()); |
911 | 242 } |
903 | 243 |
244 } |