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