annotate common/src/main/java/digilib/servlet/DigilibConfiguration.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 28d007673346
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
1 /*
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
2 * DigilibConfiguration -- Holding all parameters for digilib servlet.
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
3 *
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
4 * Digital Image Library servlet components
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
5 *
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
6 * Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de)
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
7 *
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify it
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the Free
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
10 * Software Foundation; either version 2 of the License, or (at your option)
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
11 * any later version.
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
12 *
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
13 * Please read license.txt for the full details. A copy of the GPL may be found
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
14 * at http://www.gnu.org/copyleft/lgpl.html
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
15 *
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License along with
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
17 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
18 * Place, Suite 330, Boston, MA 02111-1307 USA
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
19 *
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
20 */
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
21
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
22 package digilib.servlet;
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
23
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
24 import java.io.IOException;
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
25
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
26 import org.apache.log4j.BasicConfigurator;
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
27 import org.apache.log4j.Logger;
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
28
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
29 import digilib.image.DocuImage;
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
30 import digilib.image.DocuImageImpl;
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
31 import digilib.io.ImageInput;
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
32 import digilib.util.ParameterMap;
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
33
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
34 /**
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
35 * Class to hold the digilib servlet configuration parameters. The parameters
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
36 * can be read from the digilib-config file and be passed to other servlets or
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
37 * beans. <br>
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
38 * errorImgFileName: image file to send in case of error. <br>
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
39 * denyImgFileName: image file to send if access is denied. <br>
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
40 * baseDirs: array of base directories in order of preference (prescaled
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
41 * versions first). <br>
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
42 * useAuth: use authentication information. <br>
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
43 * authConfPath: authentication configuration file. <br>
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
44 * ... <br>
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
45 *
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
46 * @author casties
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
47 *
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
48 */
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
49 public class DigilibConfiguration extends ParameterMap {
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
50
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
51 /** DocuImage class instance */
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
52 protected static Class<DocuImageImpl> docuImageClass = null;
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
53
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
54 /** Log4J logger */
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
55 protected Logger logger = Logger.getLogger("digilib.config");
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
56
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
57 /**
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
58 * Default constructor defines all parameters and their default values.
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
59 *
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
60 */
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
61 public DigilibConfiguration() {
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
62 super(20);
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
63 // we start with a default logger config
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
64 BasicConfigurator.configure();
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
65 initParams();
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
66 }
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
67
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
68 /** Definition of parameters and default values.
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
69 *
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
70 */
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
71 protected void initParams() {
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
72 /*
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
73 * Definition of parameters and default values. System parameters that
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
74 * are not read from config file have a type 's'.
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
75 */
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
76 // digilib servlet version
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
77 newParameter("digilib.version", "2.0b1", null, 's');
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
78 // DocuImage class instance
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
79 newParameter("servlet.docuimage.class",
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
80 digilib.image.ImageLoaderDocuImage.class, null, 's');
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
81 // sending image files as-is allowed
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
82 newParameter("sendfile-allowed", Boolean.TRUE, null, 'f');
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
83 // Type of DocuImage instance
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
84 newParameter("docuimage-class", "digilib.image.ImageLoaderDocuImage", null, 'f');
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
85 // degree of subsampling on image load
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
86 newParameter("subsample-minimum", new Float(2f), null, 'f');
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
87 // default scaling quality
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
88 newParameter("default-quality", new Integer(1), null, 'f');
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
89 // maximum destination image size (0 means no limit)
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
90 newParameter("max-image-size", new Integer(0), null, 'f');
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
91 // allow image toolkit to use disk cache
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
92 newParameter("img-diskcache-allowed", Boolean.TRUE, null, 'f');
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
93 // default type of error message (image, text, code)
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
94 newParameter("default-errmsg-type", "image", null, 'f');
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
95
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
96 // initialise static DocuImage class instance
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
97 try {
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
98 DigilibConfiguration.docuImageClass = (Class<DocuImageImpl>) Class.forName(getAsString("docuimage-class"));
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
99 } catch (ClassNotFoundException e) {
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
100 logger.error("Unable to set docuImageClass!");
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
101 }
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
102 }
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
103
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
104 /**
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
105 * Creates a new DocuImage instance.
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
106 *
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
107 * The type of DocuImage is specified by docuimage-class.
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
108 *
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
109 * @return DocuImage
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
110 */
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
111 public static DocuImage getDocuImageInstance() {
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
112 DocuImageImpl di = null;
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
113 try {
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
114 di = docuImageClass.newInstance();
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
115 } catch (Exception e) {
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
116 }
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
117 return di;
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
118 }
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
119
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
120 /**
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
121 * Check image size and type and store in ImageFile imgf
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
122 *
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
123 * @param imgf
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
124 * @return
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
125 * @throws IOException
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
126 */
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
127 public static ImageInput identifyDocuImage(ImageInput imgf)
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
128 throws IOException {
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
129 // use fresh DocuImage instance
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
130 DocuImage di = getDocuImageInstance();
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
131 return di.identify(imgf);
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
132 }
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
133
906
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
134 /**
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
135 * @return Returns the docuImageClass.
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
136 */
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
137 public static Class<DocuImageImpl> getDocuImageClass() {
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
138 return docuImageClass;
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
139 }
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
140
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
141 /**
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
142 * @param docuImageClass
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
143 * The docuImageClass to set.
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
144 */
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
145 public static void setDocuImageClass(Class<DocuImageImpl> dic) {
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
146 docuImageClass = dic;
28d007673346 really works with streams now.
robcast
parents: 903
diff changeset
147 }
903
7779b37d1d05 refactored into maven modules per servlet type.
robcast
parents:
diff changeset
148 }