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