Mercurial > hg > digilib-old
annotate servlet3/src/main/java/digilib/servlet/DigilibServletConfiguration.java @ 1016:168e8aa7e9a5
get rid of another callback loop
| author | hertzhaft |
|---|---|
| date | Sat, 18 Feb 2012 19:57:04 +0100 |
| parents | b2d97b842612 |
| children | 4e368c85cce4 |
| 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'); |
| 911 | 82 // AuthOps instance for authentication |
| 83 newParameter("servlet.auth.op", null, null, 's'); | |
| 903 | 84 // Executor for image operations |
| 85 newParameter("servlet.worker.imageexecutor", null, null, 's'); | |
| 86 // Executor for PDF operations | |
| 87 newParameter("servlet.worker.pdfexecutor", null, null, 's'); | |
| 88 // Executor for PDF-image operations | |
| 89 newParameter("servlet.worker.pdfimageexecutor", null, null, 's'); | |
| 90 | |
| 911 | 91 /* |
| 92 * parameters that can be read from config file have a type 'f' | |
| 93 */ | |
| 903 | 94 |
| 911 | 95 // image file to send in case of error |
| 96 newParameter("error-image", new File("img/digilib-error.png"), null, | |
| 97 'f'); | |
| 98 // image file to send if access is denied | |
| 99 newParameter("denied-image", new File("img/digilib-denied.png"), null, | |
| 100 'f'); | |
| 101 // image file to send if image file not found | |
| 102 newParameter("notfound-image", new File("img/digilib-notfound.png"), | |
| 103 null, 'f'); | |
| 104 // base directories in order of preference (prescaled versions last) | |
| 105 String[] bd = { "/docuserver/images", "/docuserver/scaled/small" }; | |
| 106 newParameter("basedir-list", bd, null, 'f'); | |
| 107 // use authentication information | |
| 108 newParameter("use-authorization", Boolean.FALSE, null, 'f'); | |
| 109 // authentication configuration file | |
| 110 newParameter("auth-file", new File("digilib-auth.xml"), null, 'f'); | |
| 111 // sending image files as-is allowed | |
| 112 newParameter("sendfile-allowed", Boolean.TRUE, null, 'f'); | |
| 113 // Type of DocuImage instance | |
|
960
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
937
diff
changeset
|
114 newParameter("docuimage-class", "digilib.image.ImageLoaderDocuImage", null, 'f'); |
| 911 | 115 // part of URL used to indicate authorized access |
| 116 newParameter("auth-url-path", "authenticated/", null, 'f'); | |
| 117 // degree of subsampling on image load | |
| 118 newParameter("subsample-minimum", new Float(2f), null, 'f'); | |
| 119 // default scaling quality | |
| 120 newParameter("default-quality", new Integer(1), null, 'f'); | |
| 121 // use mapping file to translate paths | |
| 122 newParameter("use-mapping", Boolean.FALSE, null, 'f'); | |
| 123 // mapping file location | |
| 124 newParameter("mapping-file", new File("digilib-map.xml"), null, 'f'); | |
| 125 // log4j config file location | |
| 126 newParameter("log-config-file", new File("log4j-config.xml"), null, 'f'); | |
| 127 // maximum destination image size (0 means no limit) | |
| 128 newParameter("max-image-size", new Integer(0), null, 'f'); | |
| 129 // number of working threads | |
| 130 newParameter("worker-threads", new Integer(1), null, 'f'); | |
| 131 // max number of waiting threads | |
| 132 newParameter("max-waiting-threads", new Integer(20), null, 'f'); | |
|
925
66f1ba72d07b
added timeout-parameter and timeout-handler to AsyncServletWorker.
robcast
parents:
911
diff
changeset
|
133 // timeout for worker threads (ms) |
|
66f1ba72d07b
added timeout-parameter and timeout-handler to AsyncServletWorker.
robcast
parents:
911
diff
changeset
|
134 newParameter("worker-timeout", new Integer(60000), null, 'f'); |
| 911 | 135 // number of pdf-generation threads |
| 136 newParameter("pdf-worker-threads", new Integer(1), null, 'f'); | |
| 137 // max number of waiting pdf-generation threads | |
| 138 newParameter("pdf-max-waiting-threads", new Integer(20), null, 'f'); | |
| 139 // number of pdf-image generation threads | |
| 140 newParameter("pdf-image-worker-threads", new Integer(1), null, 'f'); | |
| 141 // max number of waiting pdf-image generation threads | |
| 142 newParameter("pdf-image-max-waiting-threads", new Integer(10), null, | |
| 143 'f'); | |
| 903 | 144 // PDF generation temp directory |
| 145 newParameter("pdf-temp-dir", "pdf_temp", null, 'f'); | |
| 146 // PDF generation cache directory | |
| 147 newParameter("pdf-cache-dir", "pdf_cache", null, 'f'); | |
| 148 // allow image toolkit to use disk cache | |
| 149 newParameter("img-diskcache-allowed", Boolean.TRUE, null, 'f'); | |
| 150 // default type of error message (image, text, code) | |
| 151 newParameter("default-errmsg-type", "image", null, 'f'); | |
| 911 | 152 } |
| 903 | 153 |
| 911 | 154 /** |
| 155 * Constructor taking a ServletConfig. Reads the config file location from | |
| 156 * an init parameter and loads the config file. Calls | |
| 157 * <code>readConfig()</code>. | |
| 158 * | |
| 159 * @see readConfig() | |
| 160 */ | |
| 161 public DigilibServletConfiguration(ServletContext c) throws Exception { | |
| 162 readConfig(c); | |
| 163 } | |
| 903 | 164 |
| 911 | 165 /** |
| 166 * read parameter list from the XML file in init parameter "config-file" or | |
| 167 * file digilib-config.xml | |
| 168 */ | |
| 169 @SuppressWarnings("unchecked") | |
| 903 | 170 public void readConfig(ServletContext c) throws Exception { |
| 171 | |
| 911 | 172 /* |
| 173 * Get config file name. The file name is first looked for as an init | |
| 174 * parameter, then in a fixed location in the webapp. | |
| 175 */ | |
| 176 if (c == null) { | |
| 177 // no config no file... | |
| 178 return; | |
| 179 } | |
| 180 String fn = c.getInitParameter("config-file"); | |
| 181 if (fn == null) { | |
| 182 fn = ServletOps.getConfigFile("digilib-config.xml", c); | |
| 183 if (fn == null) { | |
| 184 logger.fatal("readConfig: no param config-file"); | |
| 185 throw new ServletException("ERROR: no digilib config file!"); | |
| 186 } | |
| 187 } | |
| 188 File f = new File(fn); | |
| 189 // setup config file list reader | |
| 190 XMLListLoader lilo = new XMLListLoader("digilib-config", "parameter", | |
| 191 "name", "value"); | |
| 192 // read config file into HashMap | |
| 193 Map<String, String> confTable = lilo.loadURL(f.toURL().toString()); | |
| 903 | 194 |
| 911 | 195 // set config file path parameter |
| 196 setValue("servlet.config.file", f.getCanonicalPath()); | |
| 903 | 197 |
| 911 | 198 /* |
| 199 * read parameters | |
| 200 */ | |
| 903 | 201 |
| 911 | 202 for (Entry<String, String> confEntry : confTable.entrySet()) { |
| 203 Parameter p = get(confEntry.getKey()); | |
| 204 if (p != null) { | |
| 205 if (p.getType() == 's') { | |
| 206 // type 's' Parameters are not overwritten. | |
| 207 continue; | |
| 208 } | |
| 209 if (!p.setValueFromString(confEntry.getValue())) { | |
| 210 /* | |
| 211 * automatic conversion failed -- try special cases | |
| 212 */ | |
| 903 | 213 |
| 911 | 214 // basedir-list |
| 215 if (confEntry.getKey().equals("basedir-list")) { | |
| 216 // split list into directories | |
| 217 String[] dirs = FileOps.pathToArray(confEntry.getValue()); | |
| 218 for (int j = 0; j < dirs.length; j++) { | |
| 219 // make relative directory paths be inside the webapp | |
| 220 dirs[j] = ServletOps.getFile(dirs[j], c); | |
| 221 } | |
| 222 if (dirs != null) { | |
| 223 p.setValue(dirs); | |
| 224 } | |
| 225 } | |
| 226 } | |
| 227 } else { | |
| 228 // parameter unknown -- just add | |
| 229 newParameter(confEntry.getKey(), null, confEntry.getValue(), | |
| 230 'f'); | |
| 231 } | |
| 232 } | |
| 233 // initialise static DocuImage class instance | |
| 234 DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class | |
| 235 .forName(getAsString("docuimage-class")); | |
| 236 } | |
| 903 | 237 |
| 238 } |
