Mercurial > hg > digilib-old
annotate servlet3/src/main/java/digilib/servlet/DigilibServletConfiguration.java @ 1158:2ee261676828 default tip
better out-of-the box experience:
* digilib works without config files using sensible defaults
* new sample images folder used by default
* config files moved to templates
author | robcast |
---|---|
date | Tue, 19 Feb 2013 17:32:25 +0100 |
parents | 4e368c85cce4 |
children |
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 | |
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 | |
937 | 53 /** time the webapp (i.e. this class) was loaded */ |
54 public final Long webappStartTime = System.currentTimeMillis(); | |
1158 | 55 |
937 | 56 /** counter for HttpRequests (mostly for debugging) */ |
57 public AtomicInteger webappRequestCnt = new AtomicInteger(0); | |
58 | |
930 | 59 /** counter for open HttpRequests (mostly for debugging) */ |
60 public AtomicInteger openRequestCnt = new AtomicInteger(0); | |
61 | |
911 | 62 /** |
63 * Definition of parameters and default values. | |
64 */ | |
65 protected void initParams() { | |
66 /* | |
67 * Definition of parameters and default values. System parameters that | |
68 * are not read from config file have a type 's'. | |
69 */ | |
903 | 70 |
911 | 71 // digilib servlet version |
1158 | 72 newParameter("servlet.version", digilib.servlet.Scaler.getVersion(), null, 's'); |
911 | 73 // configuration file location |
74 newParameter("servlet.config.file", null, null, 's'); | |
75 // DocuDirCache instance | |
76 newParameter("servlet.dir.cache", null, null, 's'); | |
77 // DocuImage class instance | |
1158 | 78 newParameter("servlet.docuimage.class", digilib.image.ImageLoaderDocuImage.class, null, 's'); |
1032
4e368c85cce4
CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7)
robcast
parents:
960
diff
changeset
|
79 // DocuImage version |
1158 | 80 newParameter("servlet.docuimage.version", "?", null, 's'); |
911 | 81 // AuthOps instance for authentication |
82 newParameter("servlet.auth.op", null, null, 's'); | |
903 | 83 // Executor for image operations |
84 newParameter("servlet.worker.imageexecutor", null, null, 's'); | |
85 // Executor for PDF operations | |
86 newParameter("servlet.worker.pdfexecutor", null, null, 's'); | |
87 // Executor for PDF-image operations | |
88 newParameter("servlet.worker.pdfimageexecutor", null, null, 's'); | |
89 | |
911 | 90 /* |
91 * parameters that can be read from config file have a type 'f' | |
92 */ | |
903 | 93 |
911 | 94 // image file to send in case of error |
1158 | 95 newParameter("error-image", new File("img/digilib-error.png"), null, 'f'); |
911 | 96 // image file to send if access is denied |
1158 | 97 newParameter("denied-image", new File("img/digilib-denied.png"), null, 'f'); |
911 | 98 // image file to send if image file not found |
1158 | 99 newParameter("notfound-image", new File("img/digilib-notfound.png"), null, 'f'); |
911 | 100 // base directories in order of preference (prescaled versions last) |
1158 | 101 String[] bd = { "sample-images" }; |
911 | 102 newParameter("basedir-list", bd, null, 'f'); |
103 // use authentication information | |
104 newParameter("use-authorization", Boolean.FALSE, null, 'f'); | |
105 // authentication configuration file | |
106 newParameter("auth-file", new File("digilib-auth.xml"), null, 'f'); | |
107 // sending image files as-is allowed | |
108 newParameter("sendfile-allowed", Boolean.TRUE, null, 'f'); | |
109 // Type of DocuImage instance | |
960
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
937
diff
changeset
|
110 newParameter("docuimage-class", "digilib.image.ImageLoaderDocuImage", null, 'f'); |
911 | 111 // part of URL used to indicate authorized access |
112 newParameter("auth-url-path", "authenticated/", null, 'f'); | |
113 // degree of subsampling on image load | |
114 newParameter("subsample-minimum", new Float(2f), null, 'f'); | |
115 // default scaling quality | |
1158 | 116 newParameter("default-quality", new Integer(2), null, 'f'); |
911 | 117 // use mapping file to translate paths |
118 newParameter("use-mapping", Boolean.FALSE, null, 'f'); | |
119 // mapping file location | |
120 newParameter("mapping-file", new File("digilib-map.xml"), null, 'f'); | |
121 // log4j config file location | |
122 newParameter("log-config-file", new File("log4j-config.xml"), null, 'f'); | |
123 // maximum destination image size (0 means no limit) | |
124 newParameter("max-image-size", new Integer(0), null, 'f'); | |
125 // number of working threads | |
126 newParameter("worker-threads", new Integer(1), null, 'f'); | |
127 // max number of waiting threads | |
128 newParameter("max-waiting-threads", new Integer(20), null, 'f'); | |
925
66f1ba72d07b
added timeout-parameter and timeout-handler to AsyncServletWorker.
robcast
parents:
911
diff
changeset
|
129 // timeout for worker threads (ms) |
66f1ba72d07b
added timeout-parameter and timeout-handler to AsyncServletWorker.
robcast
parents:
911
diff
changeset
|
130 newParameter("worker-timeout", new Integer(60000), null, 'f'); |
911 | 131 // number of pdf-generation threads |
132 newParameter("pdf-worker-threads", new Integer(1), null, 'f'); | |
133 // max number of waiting pdf-generation threads | |
134 newParameter("pdf-max-waiting-threads", new Integer(20), null, 'f'); | |
135 // number of pdf-image generation threads | |
136 newParameter("pdf-image-worker-threads", new Integer(1), null, 'f'); | |
137 // max number of waiting pdf-image generation threads | |
1158 | 138 newParameter("pdf-image-max-waiting-threads", new Integer(10), null, 'f'); |
903 | 139 // PDF generation temp directory |
140 newParameter("pdf-temp-dir", "pdf_temp", null, 'f'); | |
141 // PDF generation cache directory | |
142 newParameter("pdf-cache-dir", "pdf_cache", null, 'f'); | |
143 // allow image toolkit to use disk cache | |
144 newParameter("img-diskcache-allowed", Boolean.TRUE, null, 'f'); | |
145 // default type of error message (image, text, code) | |
146 newParameter("default-errmsg-type", "image", null, 'f'); | |
911 | 147 } |
903 | 148 |
911 | 149 /** |
150 * Constructor taking a ServletConfig. Reads the config file location from | |
151 * an init parameter and loads the config file. Calls | |
152 * <code>readConfig()</code>. | |
153 * | |
154 * @see readConfig() | |
155 */ | |
156 public DigilibServletConfiguration(ServletContext c) throws Exception { | |
157 readConfig(c); | |
158 } | |
903 | 159 |
911 | 160 /** |
161 * read parameter list from the XML file in init parameter "config-file" or | |
162 * file digilib-config.xml | |
163 */ | |
164 @SuppressWarnings("unchecked") | |
903 | 165 public void readConfig(ServletContext c) throws Exception { |
166 | |
911 | 167 /* |
168 * Get config file name. The file name is first looked for as an init | |
169 * parameter, then in a fixed location in the webapp. | |
170 */ | |
171 if (c == null) { | |
172 // no config no file... | |
173 return; | |
174 } | |
175 String fn = c.getInitParameter("config-file"); | |
176 if (fn == null) { | |
1158 | 177 logger.debug("readConfig: no param config-file"); |
911 | 178 fn = ServletOps.getConfigFile("digilib-config.xml", c); |
179 } | |
180 File f = new File(fn); | |
1158 | 181 if (f.canRead()) { |
182 // setup config file list reader | |
183 XMLListLoader lilo = new XMLListLoader("digilib-config", "parameter", "name", "value"); | |
184 // read config file into HashMap | |
185 Map<String, String> confTable = lilo.loadURL(f.toURL().toString()); | |
903 | 186 |
1158 | 187 // set config file path parameter |
188 setValue("servlet.config.file", f.getCanonicalPath()); | |
903 | 189 |
1158 | 190 /* |
191 * read parameters | |
192 */ | |
903 | 193 |
1158 | 194 for (Entry<String, String> confEntry : confTable.entrySet()) { |
195 Parameter p = get(confEntry.getKey()); | |
196 if (p != null) { | |
197 if (p.getType() == 's') { | |
198 // type 's' Parameters are not overwritten. | |
199 continue; | |
200 } | |
201 if (!p.setValueFromString(confEntry.getValue())) { | |
202 /* | |
203 * automatic conversion failed -- try special cases | |
204 */ | |
903 | 205 |
1158 | 206 // basedir-list |
207 if (confEntry.getKey().equals("basedir-list")) { | |
208 // split list into directories | |
209 String[] dirs = FileOps.pathToArray(confEntry.getValue()); | |
210 for (int j = 0; j < dirs.length; j++) { | |
211 // make relative directory paths be inside the | |
212 // webapp | |
213 dirs[j] = ServletOps.getFile(dirs[j], c); | |
214 } | |
215 if (dirs != null) { | |
216 p.setValue(dirs); | |
217 } | |
911 | 218 } |
219 } | |
1158 | 220 } else { |
221 // parameter unknown -- just add | |
222 newParameter(confEntry.getKey(), null, confEntry.getValue(), 'f'); | |
911 | 223 } |
1158 | 224 } |
225 } else { | |
226 logger.warn("No digilib config file! Using defaults!"); | |
227 // update basedir-list | |
228 String[] dirs = (String[]) this.getValue("basedir-list"); | |
229 for (int j = 0; j < dirs.length; j++) { | |
230 // make relative directory paths be inside the | |
231 // webapp | |
232 dirs[j] = ServletOps.getFile(dirs[j], c); | |
911 | 233 } |
234 } | |
235 // initialise static DocuImage class instance | |
1158 | 236 DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class.forName(getAsString("docuimage-class")); |
1032
4e368c85cce4
CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7)
robcast
parents:
960
diff
changeset
|
237 setValue("servlet.docuimage.version", getDocuImageInstance().getVersion()); |
911 | 238 } |
903 | 239 |
240 } |