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