Mercurial > hg > digilib-old
annotate servlet3/src/main/java/digilib/servlet/DigilibServletConfiguration.java @ 934:065dd6895ce7
improved busy cursor
author | robcast |
---|---|
date | Wed, 21 Dec 2011 17:01:13 +0100 |
parents | 333e60e5cae9 |
children | 7bcc6765c209 |
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; | |
930 | 27 import java.util.concurrent.atomic.AtomicInteger; |
903 | 28 |
29 import javax.servlet.ServletContext; | |
30 import javax.servlet.ServletException; | |
31 | |
32 import digilib.image.DocuImageImpl; | |
33 import digilib.io.FileOps; | |
34 import digilib.util.Parameter; | |
35 import digilib.util.XMLListLoader; | |
36 | |
37 /** | |
38 * Class to hold the digilib servlet configuration parameters. The parameters | |
39 * can be read from the digilib-config file and be passed to other servlets or | |
911 | 40 * beans. <br> |
41 * errorImgFileName: image file to send in case of error. <br> | |
42 * denyImgFileName: image file to send if access is denied. <br> | |
43 * baseDirs: array of base directories in order of preference (prescaled | |
44 * versions first). <br> | |
45 * useAuth: use authentication information. <br> | |
46 * authConfPath: authentication configuration file. <br> | |
47 * ... <br> | |
903 | 48 * |
49 * @author casties | |
911 | 50 * |
903 | 51 */ |
52 public class DigilibServletConfiguration extends DigilibConfiguration { | |
53 | |
930 | 54 /** counter for open HttpRequests (mostly for debugging) */ |
55 public AtomicInteger openRequestCnt = new AtomicInteger(0); | |
56 | |
911 | 57 /** |
58 * Definition of parameters and default values. | |
59 */ | |
60 protected void initParams() { | |
61 /* | |
62 * Definition of parameters and default values. System parameters that | |
63 * are not read from config file have a type 's'. | |
64 */ | |
903 | 65 |
911 | 66 // digilib servlet version |
67 newParameter("servlet.version", digilib.servlet.Scaler.getVersion(), | |
68 null, 's'); | |
69 // configuration file location | |
70 newParameter("servlet.config.file", null, null, 's'); | |
71 // DocuDirCache instance | |
72 newParameter("servlet.dir.cache", null, null, 's'); | |
73 // DocuImage class instance | |
74 newParameter("servlet.docuimage.class", | |
75 digilib.image.JAIDocuImage.class, null, 's'); | |
76 // AuthOps instance for authentication | |
77 newParameter("servlet.auth.op", null, null, 's'); | |
903 | 78 // Executor for image operations |
79 newParameter("servlet.worker.imageexecutor", null, null, 's'); | |
80 // Executor for PDF operations | |
81 newParameter("servlet.worker.pdfexecutor", null, null, 's'); | |
82 // Executor for PDF-image operations | |
83 newParameter("servlet.worker.pdfimageexecutor", null, null, 's'); | |
84 | |
911 | 85 /* |
86 * parameters that can be read from config file have a type 'f' | |
87 */ | |
903 | 88 |
911 | 89 // image file to send in case of error |
90 newParameter("error-image", new File("img/digilib-error.png"), null, | |
91 'f'); | |
92 // image file to send if access is denied | |
93 newParameter("denied-image", new File("img/digilib-denied.png"), null, | |
94 'f'); | |
95 // image file to send if image file not found | |
96 newParameter("notfound-image", new File("img/digilib-notfound.png"), | |
97 null, 'f'); | |
98 // base directories in order of preference (prescaled versions last) | |
99 String[] bd = { "/docuserver/images", "/docuserver/scaled/small" }; | |
100 newParameter("basedir-list", bd, null, 'f'); | |
101 // use authentication information | |
102 newParameter("use-authorization", Boolean.FALSE, null, 'f'); | |
103 // authentication configuration file | |
104 newParameter("auth-file", new File("digilib-auth.xml"), null, 'f'); | |
105 // sending image files as-is allowed | |
106 newParameter("sendfile-allowed", Boolean.TRUE, null, 'f'); | |
107 // Type of DocuImage instance | |
108 newParameter("docuimage-class", "digilib.image.JAIDocuImage", null, 'f'); | |
109 // part of URL used to indicate authorized access | |
110 newParameter("auth-url-path", "authenticated/", null, 'f'); | |
111 // degree of subsampling on image load | |
112 newParameter("subsample-minimum", new Float(2f), null, 'f'); | |
113 // default scaling quality | |
114 newParameter("default-quality", new Integer(1), null, 'f'); | |
115 // use mapping file to translate paths | |
116 newParameter("use-mapping", Boolean.FALSE, null, 'f'); | |
117 // mapping file location | |
118 newParameter("mapping-file", new File("digilib-map.xml"), null, 'f'); | |
119 // log4j config file location | |
120 newParameter("log-config-file", new File("log4j-config.xml"), null, 'f'); | |
121 // maximum destination image size (0 means no limit) | |
122 newParameter("max-image-size", new Integer(0), null, 'f'); | |
123 // number of working threads | |
124 newParameter("worker-threads", new Integer(1), null, 'f'); | |
125 // max number of waiting threads | |
126 newParameter("max-waiting-threads", new Integer(20), null, 'f'); | |
925
66f1ba72d07b
added timeout-parameter and timeout-handler to AsyncServletWorker.
robcast
parents:
911
diff
changeset
|
127 // timeout for worker threads (ms) |
66f1ba72d07b
added timeout-parameter and timeout-handler to AsyncServletWorker.
robcast
parents:
911
diff
changeset
|
128 newParameter("worker-timeout", new Integer(60000), null, 'f'); |
911 | 129 // number of pdf-generation threads |
130 newParameter("pdf-worker-threads", new Integer(1), null, 'f'); | |
131 // max number of waiting pdf-generation threads | |
132 newParameter("pdf-max-waiting-threads", new Integer(20), null, 'f'); | |
133 // number of pdf-image generation threads | |
134 newParameter("pdf-image-worker-threads", new Integer(1), null, 'f'); | |
135 // max number of waiting pdf-image generation threads | |
136 newParameter("pdf-image-max-waiting-threads", new Integer(10), null, | |
137 'f'); | |
903 | 138 // PDF generation temp directory |
139 newParameter("pdf-temp-dir", "pdf_temp", null, 'f'); | |
140 // PDF generation cache directory | |
141 newParameter("pdf-cache-dir", "pdf_cache", null, 'f'); | |
142 // allow image toolkit to use disk cache | |
143 newParameter("img-diskcache-allowed", Boolean.TRUE, null, 'f'); | |
144 // default type of error message (image, text, code) | |
145 newParameter("default-errmsg-type", "image", null, 'f'); | |
911 | 146 } |
903 | 147 |
911 | 148 /** |
149 * Constructor taking a ServletConfig. Reads the config file location from | |
150 * an init parameter and loads the config file. Calls | |
151 * <code>readConfig()</code>. | |
152 * | |
153 * @see readConfig() | |
154 */ | |
155 public DigilibServletConfiguration(ServletContext c) throws Exception { | |
156 readConfig(c); | |
157 } | |
903 | 158 |
911 | 159 /** |
160 * read parameter list from the XML file in init parameter "config-file" or | |
161 * file digilib-config.xml | |
162 */ | |
163 @SuppressWarnings("unchecked") | |
903 | 164 public void readConfig(ServletContext c) throws Exception { |
165 | |
911 | 166 /* |
167 * Get config file name. The file name is first looked for as an init | |
168 * parameter, then in a fixed location in the webapp. | |
169 */ | |
170 if (c == null) { | |
171 // no config no file... | |
172 return; | |
173 } | |
174 String fn = c.getInitParameter("config-file"); | |
175 if (fn == null) { | |
176 fn = ServletOps.getConfigFile("digilib-config.xml", c); | |
177 if (fn == null) { | |
178 logger.fatal("readConfig: no param config-file"); | |
179 throw new ServletException("ERROR: no digilib config file!"); | |
180 } | |
181 } | |
182 File f = new File(fn); | |
183 // setup config file list reader | |
184 XMLListLoader lilo = new XMLListLoader("digilib-config", "parameter", | |
185 "name", "value"); | |
186 // read config file into HashMap | |
187 Map<String, String> confTable = lilo.loadURL(f.toURL().toString()); | |
903 | 188 |
911 | 189 // set config file path parameter |
190 setValue("servlet.config.file", f.getCanonicalPath()); | |
903 | 191 |
911 | 192 /* |
193 * read parameters | |
194 */ | |
903 | 195 |
911 | 196 for (Entry<String, String> confEntry : confTable.entrySet()) { |
197 Parameter p = get(confEntry.getKey()); | |
198 if (p != null) { | |
199 if (p.getType() == 's') { | |
200 // type 's' Parameters are not overwritten. | |
201 continue; | |
202 } | |
203 if (!p.setValueFromString(confEntry.getValue())) { | |
204 /* | |
205 * automatic conversion failed -- try special cases | |
206 */ | |
903 | 207 |
911 | 208 // basedir-list |
209 if (confEntry.getKey().equals("basedir-list")) { | |
210 // split list into directories | |
211 String[] dirs = FileOps.pathToArray(confEntry.getValue()); | |
212 for (int j = 0; j < dirs.length; j++) { | |
213 // make relative directory paths be inside the webapp | |
214 dirs[j] = ServletOps.getFile(dirs[j], c); | |
215 } | |
216 if (dirs != null) { | |
217 p.setValue(dirs); | |
218 } | |
219 } | |
220 } | |
221 } else { | |
222 // parameter unknown -- just add | |
223 newParameter(confEntry.getKey(), null, confEntry.getValue(), | |
224 'f'); | |
225 } | |
226 } | |
227 // initialise static DocuImage class instance | |
228 DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class | |
229 .forName(getAsString("docuimage-class")); | |
230 } | |
903 | 231 |
232 } |