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.IOException;
|
|
25
|
|
26 import org.apache.log4j.BasicConfigurator;
|
|
27 import org.apache.log4j.Logger;
|
|
28
|
|
29 import digilib.image.DocuImage;
|
|
30 import digilib.image.DocuImageImpl;
|
|
31 import digilib.io.ImageInput;
|
|
32 import digilib.util.ParameterMap;
|
|
33
|
|
34 /**
|
|
35 * Class to hold the digilib servlet configuration parameters. The parameters
|
|
36 * can be read from the digilib-config file and be passed to other servlets or
|
906
|
37 * beans. <br>
|
|
38 * errorImgFileName: image file to send in case of error. <br>
|
|
39 * denyImgFileName: image file to send if access is denied. <br>
|
|
40 * baseDirs: array of base directories in order of preference (prescaled
|
|
41 * versions first). <br>
|
|
42 * useAuth: use authentication information. <br>
|
|
43 * authConfPath: authentication configuration file. <br>
|
|
44 * ... <br>
|
903
|
45 *
|
|
46 * @author casties
|
906
|
47 *
|
903
|
48 */
|
906
|
49 public class DigilibConfiguration extends ParameterMap {
|
903
|
50
|
906
|
51 /** DocuImage class instance */
|
|
52 protected static Class<DocuImageImpl> docuImageClass = null;
|
903
|
53
|
906
|
54 /** Log4J logger */
|
|
55 protected Logger logger = Logger.getLogger("digilib.config");
|
903
|
56
|
906
|
57 /**
|
|
58 * Default constructor defines all parameters and their default values.
|
|
59 *
|
|
60 */
|
|
61 public DigilibConfiguration() {
|
|
62 super(20);
|
|
63 // we start with a default logger config
|
|
64 BasicConfigurator.configure();
|
|
65 initParams();
|
|
66 }
|
903
|
67
|
906
|
68 /** Definition of parameters and default values.
|
903
|
69 *
|
|
70 */
|
906
|
71 protected void initParams() {
|
|
72 /*
|
|
73 * Definition of parameters and default values. System parameters that
|
|
74 * are not read from config file have a type 's'.
|
|
75 */
|
|
76 // digilib servlet version
|
|
77 newParameter("digilib.version", "2.0b1", null, 's');
|
|
78 // DocuImage class instance
|
|
79 newParameter("servlet.docuimage.class",
|
|
80 digilib.image.ImageLoaderDocuImage.class, null, 's');
|
|
81 // sending image files as-is allowed
|
|
82 newParameter("sendfile-allowed", Boolean.TRUE, null, 'f');
|
|
83 // Type of DocuImage instance
|
|
84 newParameter("docuimage-class", "digilib.image.ImageLoaderDocuImage", null, 'f');
|
|
85 // degree of subsampling on image load
|
|
86 newParameter("subsample-minimum", new Float(2f), null, 'f');
|
|
87 // default scaling quality
|
|
88 newParameter("default-quality", new Integer(1), null, 'f');
|
|
89 // maximum destination image size (0 means no limit)
|
|
90 newParameter("max-image-size", new Integer(0), null, 'f');
|
|
91 // allow image toolkit to use disk cache
|
|
92 newParameter("img-diskcache-allowed", Boolean.TRUE, null, 'f');
|
|
93 // default type of error message (image, text, code)
|
|
94 newParameter("default-errmsg-type", "image", null, 'f');
|
903
|
95
|
906
|
96 // initialise static DocuImage class instance
|
|
97 try {
|
|
98 DigilibConfiguration.docuImageClass = (Class<DocuImageImpl>) Class.forName(getAsString("docuimage-class"));
|
|
99 } catch (ClassNotFoundException e) {
|
|
100 logger.error("Unable to set docuImageClass!");
|
|
101 }
|
|
102 }
|
|
103
|
|
104 /**
|
|
105 * Creates a new DocuImage instance.
|
|
106 *
|
|
107 * The type of DocuImage is specified by docuimage-class.
|
|
108 *
|
|
109 * @return DocuImage
|
|
110 */
|
903
|
111 public static DocuImage getDocuImageInstance() {
|
906
|
112 DocuImageImpl di = null;
|
|
113 try {
|
|
114 di = docuImageClass.newInstance();
|
|
115 } catch (Exception e) {
|
|
116 }
|
|
117 return di;
|
|
118 }
|
903
|
119
|
906
|
120 /**
|
903
|
121 * Check image size and type and store in ImageFile imgf
|
|
122 *
|
906
|
123 * @param imgf
|
|
124 * @return
|
|
125 * @throws IOException
|
|
126 */
|
|
127 public static ImageInput identifyDocuImage(ImageInput imgf)
|
|
128 throws IOException {
|
|
129 // use fresh DocuImage instance
|
|
130 DocuImage di = getDocuImageInstance();
|
|
131 return di.identify(imgf);
|
|
132 }
|
903
|
133
|
906
|
134 /**
|
|
135 * @return Returns the docuImageClass.
|
|
136 */
|
|
137 public static Class<DocuImageImpl> getDocuImageClass() {
|
|
138 return docuImageClass;
|
|
139 }
|
|
140
|
|
141 /**
|
|
142 * @param docuImageClass
|
|
143 * The docuImageClass to set.
|
|
144 */
|
|
145 public static void setDocuImageClass(Class<DocuImageImpl> dic) {
|
|
146 docuImageClass = dic;
|
|
147 }
|
903
|
148 }
|