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');
|
|
123 // number of pdf-generation threads
|
|
124 newParameter("pdf-worker-threads", new Integer(1), null, 'f');
|
|
125 // max number of waiting pdf-generation threads
|
|
126 newParameter("pdf-max-waiting-threads", new Integer(20), null, 'f');
|
|
127 // number of pdf-image generation threads
|
|
128 newParameter("pdf-image-worker-threads", new Integer(1), null, 'f');
|
|
129 // max number of waiting pdf-image generation threads
|
|
130 newParameter("pdf-image-max-waiting-threads", new Integer(10), null,
|
|
131 'f');
|
903
|
132 // PDF generation temp directory
|
|
133 newParameter("pdf-temp-dir", "pdf_temp", null, 'f');
|
|
134 // PDF generation cache directory
|
|
135 newParameter("pdf-cache-dir", "pdf_cache", null, 'f');
|
|
136 // allow image toolkit to use disk cache
|
|
137 newParameter("img-diskcache-allowed", Boolean.TRUE, null, 'f');
|
|
138 // default type of error message (image, text, code)
|
|
139 newParameter("default-errmsg-type", "image", null, 'f');
|
911
|
140 }
|
903
|
141
|
911
|
142 /**
|
|
143 * Constructor taking a ServletConfig. Reads the config file location from
|
|
144 * an init parameter and loads the config file. Calls
|
|
145 * <code>readConfig()</code>.
|
|
146 *
|
|
147 * @see readConfig()
|
|
148 */
|
|
149 public DigilibServletConfiguration(ServletContext c) throws Exception {
|
|
150 readConfig(c);
|
|
151 }
|
903
|
152
|
911
|
153 /**
|
|
154 * read parameter list from the XML file in init parameter "config-file" or
|
|
155 * file digilib-config.xml
|
|
156 */
|
|
157 @SuppressWarnings("unchecked")
|
903
|
158 public void readConfig(ServletContext c) throws Exception {
|
|
159
|
911
|
160 /*
|
|
161 * Get config file name. The file name is first looked for as an init
|
|
162 * parameter, then in a fixed location in the webapp.
|
|
163 */
|
|
164 if (c == null) {
|
|
165 // no config no file...
|
|
166 return;
|
|
167 }
|
|
168 String fn = c.getInitParameter("config-file");
|
|
169 if (fn == null) {
|
|
170 fn = ServletOps.getConfigFile("digilib-config.xml", c);
|
|
171 if (fn == null) {
|
|
172 logger.fatal("readConfig: no param config-file");
|
|
173 throw new ServletException("ERROR: no digilib config file!");
|
|
174 }
|
|
175 }
|
|
176 File f = new File(fn);
|
|
177 // setup config file list reader
|
|
178 XMLListLoader lilo = new XMLListLoader("digilib-config", "parameter",
|
|
179 "name", "value");
|
|
180 // read config file into HashMap
|
|
181 Map<String, String> confTable = lilo.loadURL(f.toURL().toString());
|
903
|
182
|
911
|
183 // set config file path parameter
|
|
184 setValue("servlet.config.file", f.getCanonicalPath());
|
903
|
185
|
911
|
186 /*
|
|
187 * read parameters
|
|
188 */
|
903
|
189
|
911
|
190 for (Entry<String, String> confEntry : confTable.entrySet()) {
|
|
191 Parameter p = get(confEntry.getKey());
|
|
192 if (p != null) {
|
|
193 if (p.getType() == 's') {
|
|
194 // type 's' Parameters are not overwritten.
|
|
195 continue;
|
|
196 }
|
|
197 if (!p.setValueFromString(confEntry.getValue())) {
|
|
198 /*
|
|
199 * automatic conversion failed -- try special cases
|
|
200 */
|
903
|
201
|
911
|
202 // basedir-list
|
|
203 if (confEntry.getKey().equals("basedir-list")) {
|
|
204 // split list into directories
|
|
205 String[] dirs = FileOps.pathToArray(confEntry.getValue());
|
|
206 for (int j = 0; j < dirs.length; j++) {
|
|
207 // make relative directory paths be inside the webapp
|
|
208 dirs[j] = ServletOps.getFile(dirs[j], c);
|
|
209 }
|
|
210 if (dirs != null) {
|
|
211 p.setValue(dirs);
|
|
212 }
|
|
213 }
|
|
214 }
|
|
215 } else {
|
|
216 // parameter unknown -- just add
|
|
217 newParameter(confEntry.getKey(), null, confEntry.getValue(),
|
|
218 'f');
|
|
219 }
|
|
220 }
|
|
221 // initialise static DocuImage class instance
|
|
222 DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class
|
|
223 .forName(getAsString("docuimage-class"));
|
|
224 }
|
903
|
225
|
|
226 }
|