73
|
1 /* DigilibConfiguration -- Holding all parameters for digilib servlet.
|
|
2
|
|
3 Digital Image Library servlet components
|
|
4
|
|
5 Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de)
|
|
6
|
|
7 This program is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2 of the License, or (at your
|
|
10 option) any later version.
|
|
11
|
|
12 Please read license.txt for the full details. A copy of the GPL
|
|
13 may be found at http://www.gnu.org/copyleft/lgpl.html
|
|
14
|
|
15 You should have received a copy of the GNU General Public License
|
|
16 along with this program; if not, write to the Free Software
|
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18
|
|
19 */
|
|
20
|
|
21 package digilib.servlet;
|
|
22
|
|
23 import digilib.auth.*;
|
|
24 import digilib.image.*;
|
|
25 import digilib.io.XMLListLoader;
|
|
26 import digilib.Utils;
|
|
27 import javax.servlet.*;
|
|
28 import java.util.*;
|
|
29 import java.io.*;
|
|
30
|
|
31 /** Class to hold the digilib servlet configuration parameters.
|
|
32 * The parameters can be read from the digilib-config file and be passed to
|
|
33 * other servlets or beans.<br>
|
|
34 * errorImgFileName: image file to send in case of error.<br>
|
|
35 * denyImgFileName: image file to send if access is denied.<br>
|
|
36 * baseDirs: array of base directories in order of preference (prescaled
|
|
37 * versions first).<br>
|
|
38 * useAuth: use authentication information.<br>
|
|
39 * authConfPath: authentication configuration file.<br>
|
|
40 * authOp: AuthOps instance for authentication.<br>
|
|
41 * ...<br>
|
|
42 *
|
|
43 * @author casties
|
|
44 *
|
|
45 */
|
|
46 public class DigilibConfiguration {
|
|
47 // digilib servlet version
|
|
48 private String servletVersion = digilib.servlet.Scaler.dlVersion;
|
|
49 // configuration file location
|
|
50 private String dlConfPath = "";
|
|
51 // image file to send in case of error
|
|
52 private String errorImgFileName = "/docuserver/images/icons/scalerror.gif";
|
|
53 private String errorImgParam = "error-image";
|
|
54 // image file to send if access is denied
|
|
55 private String denyImgFileName = "/docuserver/images/icons/denied.gif";
|
|
56 private String denyImgParam = "denied-image";
|
|
57 // base directories in order of preference (prescaled versions first)
|
|
58 private String[] baseDirs =
|
|
59 {
|
|
60 "/docuserver/scaled/small",
|
|
61 "/docuserver/images",
|
|
62 "/docuserver/scans/quellen" };
|
|
63 private String baseDirParam = "basedir-list";
|
|
64 // use authentication information
|
|
65 private boolean useAuthentication = true;
|
|
66 private String useAuthParam = "use-authorization";
|
|
67 // authentication configuration file
|
|
68 private String authConfPath =
|
|
69 "/docuserver/www/digitallibrary/WEB-INF/digilib-auth.xml";
|
|
70 private String authConfParam = "auth-file";
|
|
71 // sending image files as-is allowed
|
|
72 private boolean sendFileAllowed = true;
|
|
73 private String sendFileAllowedParam = "sendfile-allowed";
|
|
74 // AuthOps instance for authentication
|
|
75 private AuthOps authOp;
|
|
76 // Debug level
|
|
77 private int debugLevel = 5;
|
|
78 private String debugLevelParam = "debug-level";
|
|
79 // Utils instance
|
85
|
80 private Utils util = new Utils(debugLevel);
|
73
|
81 // HashTable for parameters
|
|
82 private Hashtable confTable = null;
|
|
83 // Type of DocuImage instance
|
|
84 private String docuImageType = "digilib.image.JAIDocuImage";
|
|
85 private String docuImageTypeParam = "docuimage-class";
|
|
86 // part of URL used to indicate authorized access
|
|
87 private String authURLPath = "authenticated/";
|
|
88 private String AuthURLPathParam = "auth-url-path";
|
85
|
89 // degree of subsampling on image load
|
|
90 private float subsampleDistance = 0;
|
|
91 private String subsampleDistanceParam = "subsample-distance";
|
73
|
92
|
|
93 /** Constructor taking a ServletConfig.
|
|
94 * Reads the config file location from an init parameter and loads the
|
|
95 * config file. Calls <code>init</code>.
|
|
96 *
|
|
97 * @see init()
|
|
98 */
|
|
99 public DigilibConfiguration(ServletConfig c) throws Exception {
|
|
100 init(c);
|
|
101 }
|
|
102
|
|
103 /**
|
|
104 * read parameter list from the XML file in init parameter "config-file"
|
|
105 */
|
|
106 public void init(ServletConfig c) throws Exception {
|
|
107 // reset parameter table
|
|
108 confTable = null;
|
|
109 if (c == null) {
|
|
110 return;
|
|
111 }
|
|
112 // get config file name
|
|
113 String fn = c.getInitParameter("config-file");
|
|
114 if (fn == null) {
|
|
115 util.dprintln(4, "setConfig: no param config-file");
|
|
116 throw new ServletException("ERROR no digilib config file!");
|
|
117 }
|
|
118 File f = new File(fn);
|
|
119 // setup config file list reader
|
|
120 XMLListLoader lilo =
|
|
121 new XMLListLoader("digilib-config", "parameter", "name", "value");
|
|
122 confTable = lilo.loadURL(f.toURL().toString());
|
85
|
123 dlConfPath = f.getCanonicalPath();
|
73
|
124
|
|
125 /*
|
|
126 * read parameters
|
|
127 */
|
|
128
|
|
129 // debugLevel
|
|
130 debugLevel = tryToGetInitParam(debugLevelParam, debugLevel);
|
85
|
131 util.setDebugLevel(debugLevel);
|
73
|
132 // errorImgFileName
|
|
133 errorImgFileName = tryToGetInitParam(errorImgParam, errorImgFileName);
|
|
134 // denyImgFileName
|
|
135 denyImgFileName = tryToGetInitParam(denyImgParam, denyImgFileName);
|
|
136 // docuImageType
|
|
137 docuImageType = tryToGetInitParam(docuImageTypeParam, docuImageType);
|
|
138 // sendFileAllowed
|
|
139 sendFileAllowed =
|
|
140 tryToGetInitParam(sendFileAllowedParam, sendFileAllowed);
|
|
141 // baseDirs
|
|
142 String baseDirList =
|
|
143 tryToGetInitParam(
|
|
144 baseDirParam,
|
|
145 "/docuserver/scaled/small:/docuserver/images:/docuserver/scans/quellen");
|
|
146 // split list into directories
|
|
147 String[] sa = splitPathArray(baseDirList);
|
|
148 baseDirs = (sa != null) ? sa : baseDirs;
|
|
149 // useAuthentication
|
|
150 useAuthentication = tryToGetInitParam(useAuthParam, useAuthentication);
|
|
151 if (useAuthentication) {
|
|
152 // DB version
|
|
153 //authOp = new DBAuthOpsImpl(util);
|
|
154 // XML version
|
|
155 authConfPath = tryToGetInitParam(authConfParam, authConfPath);
|
|
156 authOp = new XMLAuthOps(util, authConfPath);
|
|
157 }
|
85
|
158 // subsampleDistance
|
|
159 subsampleDistance = tryToGetInitParam(subsampleDistanceParam, subsampleDistance);
|
73
|
160 }
|
|
161
|
|
162 /**
|
|
163 * convert a string with a list of pathnames into an array of strings
|
|
164 * using the system's path separator string
|
|
165 */
|
|
166 public String[] splitPathArray(String paths) {
|
|
167 // split list into directories
|
|
168 StringTokenizer dirs =
|
|
169 new StringTokenizer(paths, java.io.File.pathSeparator);
|
|
170 int n = dirs.countTokens();
|
|
171 if (n < 1) {
|
|
172 return null;
|
|
173 }
|
|
174 // add directories into array
|
|
175 String[] pathArray = new String[n];
|
|
176 for (int i = 0; i < n; i++) {
|
|
177 pathArray[i] = dirs.nextToken();
|
|
178 }
|
|
179 return pathArray;
|
|
180 }
|
|
181
|
|
182 /**
|
|
183 * get an init parameter from config and return it if set, otherwise return default
|
|
184 */
|
|
185 public int tryToGetInitParam(String s, int i) {
|
|
186 //System.out.println("trytogetInitParam("+s+", "+i+")");
|
|
187 try {
|
|
188 //System.out.println("trytogetInitParam: "+(String)confTable.get(s));
|
|
189 i = Integer.parseInt((String) confTable.get(s));
|
|
190 } catch (Exception e) {
|
|
191 util.dprintln(4, "trytogetInitParam(int) failed on param " + s);
|
|
192 //e.printStackTrace();
|
|
193 }
|
|
194 return i;
|
|
195 }
|
|
196 public float tryToGetInitParam(String s, float f) {
|
|
197 try {
|
|
198 f = Float.parseFloat((String) confTable.get(s));
|
|
199 } catch (Exception e) {
|
|
200 util.dprintln(4, "trytoGetInitParam(float) failed on param " + s);
|
|
201 //e.printStackTrace();
|
|
202 }
|
|
203 return f;
|
|
204 }
|
|
205 public String tryToGetInitParam(String s, String x) {
|
|
206 if ((confTable != null) && ((String) confTable.get(s) != null)) {
|
|
207 x = (String) confTable.get(s);
|
|
208 } else {
|
|
209 util.dprintln(4, "trytoGetInitParam(string) failed on param " + s);
|
|
210 }
|
|
211 return x;
|
|
212 }
|
|
213 public boolean tryToGetInitParam(String s, boolean b) {
|
|
214 String bs;
|
|
215 boolean bb = b;
|
|
216 if ((confTable != null) && ((String) confTable.get(s) != null)) {
|
|
217 bs = (String) confTable.get(s);
|
|
218
|
|
219 if ((bs.indexOf("false") > -1) || (bs.indexOf("FALSE") > -1)) {
|
|
220 bb = false;
|
|
221 } else if (
|
|
222 (bs.indexOf("true") > -1) || (bs.indexOf("TRUE") > -1)) {
|
|
223 bb = true;
|
|
224 } else {
|
|
225 util.dprintln(
|
|
226 4,
|
|
227 "trytoGetInitParam(string) failed on param " + s);
|
|
228 }
|
|
229 } else {
|
|
230 util.dprintln(4, "trytoGetInitParam(string) failed on param " + s);
|
|
231 }
|
|
232 return bb;
|
|
233 }
|
|
234
|
|
235 /** Creates a new DocuImage instance.
|
|
236 *
|
|
237 * The type of DocuImage is specified by docuImageType.
|
|
238 *
|
|
239 * @return DocuImage
|
|
240 */
|
|
241 public DocuImage getDocuImageInstance() {
|
|
242 DocuImageImpl di = null;
|
|
243 try {
|
|
244 di = (DocuImageImpl) Class.forName(docuImageType).newInstance();
|
|
245 di.setUtils(util);
|
|
246 } catch (Exception e) {
|
|
247 }
|
|
248 return di;
|
|
249 }
|
|
250
|
|
251 /**
|
|
252 * Returns the authConfPath.
|
|
253 * @return String
|
|
254 */
|
|
255 public String getAuthConfPath() {
|
|
256 return authConfPath;
|
|
257 }
|
|
258
|
|
259 /**
|
|
260 * Returns the authOp.
|
|
261 * @return AuthOps
|
|
262 */
|
|
263 public AuthOps getAuthOp() {
|
|
264 return authOp;
|
|
265 }
|
|
266
|
|
267 /**
|
|
268 * Returns the denyImgFileName.
|
|
269 * @return String
|
|
270 */
|
|
271 public String getDenyImgFileName() {
|
|
272 return denyImgFileName;
|
|
273 }
|
|
274
|
|
275 /**
|
|
276 * Returns the errorImgFileName.
|
|
277 * @return String
|
|
278 */
|
|
279 public String getErrorImgFileName() {
|
|
280 return errorImgFileName;
|
|
281 }
|
|
282
|
|
283 /**
|
|
284 * Returns the useAuth.
|
|
285 * @return boolean
|
|
286 */
|
|
287 public boolean isUseAuthentication() {
|
|
288 return useAuthentication;
|
|
289 }
|
|
290
|
|
291 /**
|
|
292 * Sets the authConfPath.
|
|
293 * @param authConfPath The authConfPath to set
|
|
294 */
|
|
295 public void setAuthConfPath(String authConfPath) {
|
|
296 this.authConfPath = authConfPath;
|
|
297 }
|
|
298
|
|
299 /**
|
|
300 * Sets the authOp.
|
|
301 * @param authOp The authOp to set
|
|
302 */
|
|
303 public void setAuthOp(AuthOps authOp) {
|
|
304 this.authOp = authOp;
|
|
305 }
|
|
306
|
|
307 /**
|
|
308 * Sets the denyImgFileName.
|
|
309 * @param denyImgFileName The denyImgFileName to set
|
|
310 */
|
|
311 public void setDenyImgFileName(String denyImgFileName) {
|
|
312 this.denyImgFileName = denyImgFileName;
|
|
313 }
|
|
314
|
|
315 /**
|
|
316 * Sets the errorImgFileName.
|
|
317 * @param errorImgFileName The errorImgFileName to set
|
|
318 */
|
|
319 public void setErrorImgFileName(String errorImgFileName) {
|
|
320 this.errorImgFileName = errorImgFileName;
|
|
321 }
|
|
322
|
|
323 /**
|
|
324 * Returns the baseDirs.
|
|
325 * @return String[]
|
|
326 */
|
|
327 public String[] getBaseDirs() {
|
|
328 return baseDirs;
|
|
329 }
|
|
330
|
|
331 /**
|
|
332 * Returns the baseDirs as String.
|
|
333 * @return String
|
|
334 */
|
|
335 public String getBaseDirList() {
|
|
336 String s = "";
|
|
337 java.util.Iterator i = java.util.Arrays.asList(baseDirs).iterator();
|
|
338 while (i.hasNext()) {
|
|
339 s += ( i.next() + "; ");
|
|
340 }
|
|
341 return s;
|
|
342 }
|
|
343
|
|
344 /**
|
|
345 * Sets the baseDirs.
|
|
346 * @param baseDirs The baseDirs to set
|
|
347 */
|
|
348 public void setBaseDirs(String[] baseDirs) {
|
|
349 this.baseDirs = baseDirs;
|
|
350 }
|
|
351
|
|
352 /**
|
|
353 * Returns the debugLevel.
|
|
354 * @return int
|
|
355 */
|
|
356 public int getDebugLevel() {
|
|
357 return debugLevel;
|
|
358 }
|
|
359
|
|
360 /**
|
|
361 * Sets the debugLevel.
|
|
362 * @param debugLevel The debugLevel to set
|
|
363 */
|
|
364 public void setDebugLevel(int debugLevel) {
|
|
365 this.debugLevel = debugLevel;
|
|
366 }
|
|
367
|
|
368 /**
|
|
369 * Returns the util.
|
|
370 * @return Utils
|
|
371 */
|
|
372 public Utils getUtil() {
|
|
373 return util;
|
|
374 }
|
|
375
|
|
376 /**
|
|
377 * Sets the util.
|
|
378 * @param util The util to set
|
|
379 */
|
|
380 public void setUtil(Utils util) {
|
|
381 this.util = util;
|
|
382 }
|
|
383
|
|
384 /**
|
|
385 * Returns the servletVersion.
|
|
386 * @return String
|
|
387 */
|
|
388 public String getServletVersion() {
|
|
389 return servletVersion;
|
|
390 }
|
|
391
|
|
392 /**
|
|
393 * Sets the servletVersion.
|
|
394 * @param servletVersion The servletVersion to set
|
|
395 */
|
|
396 public void setServletVersion(String servletVersion) {
|
|
397 this.servletVersion = servletVersion;
|
|
398 }
|
|
399
|
|
400 /**
|
|
401 * Returns the docuImageType.
|
|
402 * @return String
|
|
403 */
|
|
404 public String getDocuImageType() {
|
|
405 return docuImageType;
|
|
406 }
|
|
407
|
|
408 /**
|
|
409 * Sets the docuImageType.
|
|
410 * @param docuImageType The docuImageType to set
|
|
411 */
|
|
412 public void setDocuImageType(String docuImageType) {
|
|
413 this.docuImageType = docuImageType;
|
|
414 }
|
|
415
|
|
416 /**
|
|
417 * Returns the sendFileAllowed.
|
|
418 * @return boolean
|
|
419 */
|
|
420 public boolean isSendFileAllowed() {
|
|
421 return sendFileAllowed;
|
|
422 }
|
|
423
|
|
424 /**
|
|
425 * Sets the sendFileAllowed.
|
|
426 * @param sendFileAllowed The sendFileAllowed to set
|
|
427 */
|
|
428 public void setSendFileAllowed(boolean sendFileAllowed) {
|
|
429 this.sendFileAllowed = sendFileAllowed;
|
|
430 }
|
|
431
|
|
432 /**
|
|
433 * Returns the authURLPath.
|
|
434 * @return String
|
|
435 */
|
|
436 public String getAuthURLPath() {
|
|
437 return authURLPath;
|
|
438 }
|
|
439
|
|
440 /**
|
|
441 * Sets the authURLPath.
|
|
442 * @param authURLPath The authURLPath to set
|
|
443 */
|
|
444 public void setAuthURLPath(String authURLPath) {
|
|
445 this.authURLPath = authURLPath;
|
|
446 }
|
|
447
|
|
448 /**
|
|
449 * Sets the useAuthentication.
|
|
450 * @param useAuthentication The useAuthentication to set
|
|
451 */
|
|
452 public void setUseAuthentication(boolean useAuthentication) {
|
|
453 this.useAuthentication = useAuthentication;
|
|
454 }
|
|
455
|
|
456 /**
|
|
457 * Returns the dlConfPath.
|
|
458 * @return String
|
|
459 */
|
|
460 public String getDlConfPath() {
|
|
461 return dlConfPath;
|
|
462 }
|
|
463
|
85
|
464 /**
|
|
465 * @return float
|
|
466 */
|
|
467 public float getSubsampleDistance() {
|
|
468 return subsampleDistance;
|
|
469 }
|
|
470
|
|
471 /**
|
|
472 * Sets the subsampleDistance.
|
|
473 * @param subsampleDistance The subsampleDistance to set
|
|
474 */
|
|
475 public void setSubsampleDistance(float subsampleDistance) {
|
|
476 this.subsampleDistance = subsampleDistance;
|
|
477 }
|
|
478
|
73
|
479 }
|