Mercurial > hg > digilib-old
annotate servlet3/src/main/java/digilib/servlet/DigilibServletConfiguration.java @ 1113:7affda55c10e
using annotator in digilib works somewhat now.
| author | robcast |
|---|---|
| date | Thu, 01 Nov 2012 18:38:11 +0100 |
| parents | 4e368c85cce4 |
| children | 2ee261676828 |
| rev | line source |
|---|---|
| 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; | |
| 930 | 27 import java.util.concurrent.atomic.AtomicInteger; |
| 903 | 28 |
| 29 import javax.servlet.ServletContext; | |
| 30 import javax.servlet.ServletException; | |
| 31 | |
| 32 import digilib.image.DocuImageImpl; | |
| 33 import digilib.io.FileOps; | |
| 34 import digilib.util.Parameter; | |
| 35 import digilib.util.XMLListLoader; | |
| 36 | |
| 37 /** | |
| 38 * Class to hold the digilib servlet configuration parameters. The parameters | |
| 39 * can be read from the digilib-config file and be passed to other servlets or | |
| 911 | 40 * 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 * ... <br> | |
| 903 | 48 * |
| 49 * @author casties | |
| 911 | 50 * |
| 903 | 51 */ |
| 52 public class DigilibServletConfiguration extends DigilibConfiguration { | |
| 53 | |
| 937 | 54 /** time the webapp (i.e. this class) was loaded */ |
| 55 public final Long webappStartTime = System.currentTimeMillis(); | |
| 56 | |
| 57 /** counter for HttpRequests (mostly for debugging) */ | |
| 58 public AtomicInteger webappRequestCnt = new AtomicInteger(0); | |
| 59 | |
| 930 | 60 /** counter for open HttpRequests (mostly for debugging) */ |
| 61 public AtomicInteger openRequestCnt = new AtomicInteger(0); | |
| 62 | |
| 911 | 63 /** |
| 64 * Definition of parameters and default values. | |
| 65 */ | |
| 66 protected void initParams() { | |
| 67 /* | |
| 68 * Definition of parameters and default values. System parameters that | |
| 69 * are not read from config file have a type 's'. | |
| 70 */ | |
| 903 | 71 |
| 911 | 72 // digilib servlet version |
| 73 newParameter("servlet.version", digilib.servlet.Scaler.getVersion(), | |
| 74 null, 's'); | |
| 75 // configuration file location | |
| 76 newParameter("servlet.config.file", null, null, 's'); | |
| 77 // DocuDirCache instance | |
| 78 newParameter("servlet.dir.cache", null, null, 's'); | |
| 79 // DocuImage class instance | |
| 80 newParameter("servlet.docuimage.class", | |
|
960
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
937
diff
changeset
|
81 digilib.image.ImageLoaderDocuImage.class, null, 's'); |
|
1032
4e368c85cce4
CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7)
robcast
parents:
960
diff
changeset
|
82 // DocuImage version |
|
4e368c85cce4
CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7)
robcast
parents:
960
diff
changeset
|
83 newParameter("servlet.docuimage.version", |
|
4e368c85cce4
CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7)
robcast
parents:
960
diff
changeset
|
84 "?", null, 's'); |
| 911 | 85 // AuthOps instance for authentication |
| 86 newParameter("servlet.auth.op", null, null, 's'); | |
| 903 | 87 // Executor for image operations |
| 88 newParameter("servlet.worker.imageexecutor", null, null, 's'); | |
| 89 // Executor for PDF operations | |
| 90 newParameter("servlet.worker.pdfexecutor", null, null, 's'); | |
| 91 // Executor for PDF-image operations | |
| 92 newParameter("servlet.worker.pdfimageexecutor", null, null, 's'); | |
| 93 | |
| 911 | 94 /* |
| 95 * parameters that can be read from config file have a type 'f' | |
| 96 */ | |
| 903 | 97 |
| 911 | 98 // image file to send in case of error |
| 99 newParameter("error-image", new File("img/digilib-error.png"), null, | |
| 100 'f'); | |
| 101 // image file to send if access is denied | |
| 102 newParameter("denied-image", new File("img/digilib-denied.png"), null, | |
| 103 'f'); | |
| 104 // image file to send if image file not found | |
| 105 newParameter("notfound-image", new File("img/digilib-notfound.png"), | |
| 106 null, 'f'); | |
| 107 // base directories in order of preference (prescaled versions last) | |
| 108 String[] bd = { "/docuserver/images", "/docuserver/scaled/small" }; | |
| 109 newParameter("basedir-list", bd, null, 'f'); | |
| 110 // use authentication information | |
| 111 newParameter("use-authorization", Boolean.FALSE, null, 'f'); | |
| 112 // authentication configuration file | |
| 113 newParameter("auth-file", new File("digilib-auth.xml"), null, 'f'); | |
| 114 // sending image files as-is allowed | |
| 115 newParameter("sendfile-allowed", Boolean.TRUE, null, 'f'); | |
| 116 // Type of DocuImage instance | |
|
960
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
937
diff
changeset
|
117 newParameter("docuimage-class", "digilib.image.ImageLoaderDocuImage", null, 'f'); |
| 911 | 118 // part of URL used to indicate authorized access |
| 119 newParameter("auth-url-path", "authenticated/", null, 'f'); | |
| 120 // degree of subsampling on image load | |
| 121 newParameter("subsample-minimum", new Float(2f), null, 'f'); | |
| 122 // default scaling quality | |
| 123 newParameter("default-quality", new Integer(1), null, 'f'); | |
| 124 // use mapping file to translate paths | |
| 125 newParameter("use-mapping", Boolean.FALSE, null, 'f'); | |
| 126 // mapping file location | |
| 127 newParameter("mapping-file", new File("digilib-map.xml"), null, 'f'); | |
| 128 // log4j config file location | |
| 129 newParameter("log-config-file", new File("log4j-config.xml"), null, 'f'); | |
| 130 // maximum destination image size (0 means no limit) | |
| 131 newParameter("max-image-size", new Integer(0), null, 'f'); | |
| 132 // number of working threads | |
| 133 newParameter("worker-threads", new Integer(1), null, 'f'); | |
| 134 // max number of waiting threads | |
| 135 newParameter("max-waiting-threads", new Integer(20), null, 'f'); | |
|
925
66f1ba72d07b
added timeout-parameter and timeout-handler to AsyncServletWorker.
robcast
parents:
911
diff
changeset
|
136 // timeout for worker threads (ms) |
|
66f1ba72d07b
added timeout-parameter and timeout-handler to AsyncServletWorker.
robcast
parents:
911
diff
changeset
|
137 newParameter("worker-timeout", new Integer(60000), null, 'f'); |
| 911 | 138 // number of pdf-generation threads |
| 139 newParameter("pdf-worker-threads", new Integer(1), null, 'f'); | |
| 140 // max number of waiting pdf-generation threads | |
| 141 newParameter("pdf-max-waiting-threads", new Integer(20), null, 'f'); | |
| 142 // number of pdf-image generation threads | |
| 143 newParameter("pdf-image-worker-threads", new Integer(1), null, 'f'); | |
| 144 // max number of waiting pdf-image generation threads | |
| 145 newParameter("pdf-image-max-waiting-threads", new Integer(10), null, | |
| 146 'f'); | |
| 903 | 147 // PDF generation temp directory |
| 148 newParameter("pdf-temp-dir", "pdf_temp", null, 'f'); | |
| 149 // PDF generation cache directory | |
| 150 newParameter("pdf-cache-dir", "pdf_cache", null, 'f'); | |
| 151 // allow image toolkit to use disk cache | |
| 152 newParameter("img-diskcache-allowed", Boolean.TRUE, null, 'f'); | |
| 153 // default type of error message (image, text, code) | |
| 154 newParameter("default-errmsg-type", "image", null, 'f'); | |
| 911 | 155 } |
| 903 | 156 |
| 911 | 157 /** |
| 158 * Constructor taking a ServletConfig. Reads the config file location from | |
| 159 * an init parameter and loads the config file. Calls | |
| 160 * <code>readConfig()</code>. | |
| 161 * | |
| 162 * @see readConfig() | |
| 163 */ | |
| 164 public DigilibServletConfiguration(ServletContext c) throws Exception { | |
| 165 readConfig(c); | |
| 166 } | |
| 903 | 167 |
| 911 | 168 /** |
| 169 * read parameter list from the XML file in init parameter "config-file" or | |
| 170 * file digilib-config.xml | |
| 171 */ | |
| 172 @SuppressWarnings("unchecked") | |
| 903 | 173 public void readConfig(ServletContext c) throws Exception { |
| 174 | |
| 911 | 175 /* |
| 176 * Get config file name. The file name is first looked for as an init | |
| 177 * parameter, then in a fixed location in the webapp. | |
| 178 */ | |
| 179 if (c == null) { | |
| 180 // no config no file... | |
| 181 return; | |
| 182 } | |
| 183 String fn = c.getInitParameter("config-file"); | |
| 184 if (fn == null) { | |
| 185 fn = ServletOps.getConfigFile("digilib-config.xml", c); | |
| 186 if (fn == null) { | |
| 187 logger.fatal("readConfig: no param config-file"); | |
| 188 throw new ServletException("ERROR: no digilib config file!"); | |
| 189 } | |
| 190 } | |
| 191 File f = new File(fn); | |
| 192 // setup config file list reader | |
| 193 XMLListLoader lilo = new XMLListLoader("digilib-config", "parameter", | |
| 194 "name", "value"); | |
| 195 // read config file into HashMap | |
| 196 Map<String, String> confTable = lilo.loadURL(f.toURL().toString()); | |
| 903 | 197 |
| 911 | 198 // set config file path parameter |
| 199 setValue("servlet.config.file", f.getCanonicalPath()); | |
| 903 | 200 |
| 911 | 201 /* |
| 202 * read parameters | |
| 203 */ | |
| 903 | 204 |
| 911 | 205 for (Entry<String, String> confEntry : confTable.entrySet()) { |
| 206 Parameter p = get(confEntry.getKey()); | |
| 207 if (p != null) { | |
| 208 if (p.getType() == 's') { | |
| 209 // type 's' Parameters are not overwritten. | |
| 210 continue; | |
| 211 } | |
| 212 if (!p.setValueFromString(confEntry.getValue())) { | |
| 213 /* | |
| 214 * automatic conversion failed -- try special cases | |
| 215 */ | |
| 903 | 216 |
| 911 | 217 // basedir-list |
| 218 if (confEntry.getKey().equals("basedir-list")) { | |
| 219 // split list into directories | |
| 220 String[] dirs = FileOps.pathToArray(confEntry.getValue()); | |
| 221 for (int j = 0; j < dirs.length; j++) { | |
| 222 // make relative directory paths be inside the webapp | |
| 223 dirs[j] = ServletOps.getFile(dirs[j], c); | |
| 224 } | |
| 225 if (dirs != null) { | |
| 226 p.setValue(dirs); | |
| 227 } | |
| 228 } | |
| 229 } | |
| 230 } else { | |
| 231 // parameter unknown -- just add | |
|
1032
4e368c85cce4
CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7)
robcast
parents:
960
diff
changeset
|
232 newParameter(confEntry.getKey(), null, confEntry.getValue(), 'f'); |
| 911 | 233 } |
| 234 } | |
| 235 // initialise static DocuImage class instance | |
| 236 DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class | |
| 237 .forName(getAsString("docuimage-class")); | |
|
1032
4e368c85cce4
CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7)
robcast
parents:
960
diff
changeset
|
238 setValue("servlet.docuimage.version", getDocuImageInstance().getVersion()); |
| 911 | 239 } |
| 903 | 240 |
| 241 } |
