Mercurial > hg > digilib-old
changeset 524:5658b2e5d444
digilib now treats all relative paths in digilib-config (also basedir-list) as relative to the webapp.
author | robcast |
---|---|
date | Thu, 29 Oct 2009 13:40:11 +0100 |
parents | 7be5771b6473 |
children | 6a5154af3563 |
files | servlet/src/digilib/image/DocuImageImpl.java servlet/src/digilib/servlet/DigilibConfiguration.java servlet/src/digilib/servlet/Initialiser.java servlet/src/digilib/servlet/Scaler.java servlet/src/digilib/servlet/ServletOps.java |
diffstat | 5 files changed, 53 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/image/DocuImageImpl.java Thu Sep 17 19:40:17 2009 +0200 +++ b/servlet/src/digilib/image/DocuImageImpl.java Thu Oct 29 13:40:11 2009 +0100 @@ -20,7 +20,6 @@ package digilib.image; -import java.awt.Image; import java.awt.Rectangle; import java.io.File; import java.io.IOException;
--- a/servlet/src/digilib/servlet/DigilibConfiguration.java Thu Sep 17 19:40:17 2009 +0200 +++ b/servlet/src/digilib/servlet/DigilibConfiguration.java Thu Oct 29 13:40:11 2009 +0100 @@ -140,9 +140,9 @@ // use mapping file to translate paths newParameter("use-mapping", Boolean.FALSE, null, 'f'); // mapping file location - newParameter("mapping-file", new File("digilib-map.xml"), null, 'f'); + newParameter("mapping-file", new File("WEB-INF/digilib-map.xml"), null, 'f'); // log4j config file location - newParameter("log-config-file", new File("log4j-config.xml"), null, 'f'); + newParameter("log-config-file", new File("WEB-INF/log4j-config.xml"), null, 'f'); // maximum destination image size (0 means no limit) newParameter("max-image-size", new Integer(0), null, 'f'); // use safe (but slower) directory indexing @@ -168,36 +168,36 @@ /** * read parameter list from the XML file in init parameter "config-file" */ - public void readConfig(ServletConfig c) throws Exception { + public void readConfig(ServletConfig config) throws Exception { /* * Get config file name. The file name is first looked for as an init * parameter, then in a fixed location in the webapp. */ - if (c == null) { + if (config == null) { // no config no file... return; } - String fn = c.getInitParameter("config-file"); + String fn = config.getInitParameter("config-file"); if (fn == null) { - fn = ServletOps.getConfigFile("digilib-config.xml", c); + fn = ServletOps.getFile("WEB-INF/digilib-config.xml", config); if (fn == null) { logger.fatal("readConfig: no param config-file"); throw new ServletException("ERROR: no digilib config file!"); } } - File f = new File(fn); + File configFile = new File(fn); // setup config file list reader XMLListLoader lilo = new XMLListLoader("digilib-config", "parameter", "name", "value"); // read config file into HashMap - Map confTable = lilo.loadURL(f.toURL().toString()); + Map confTable = lilo.loadURL(configFile.toURL().toString()); // set config file path parameter - setValue("servlet.config.file", f.getCanonicalPath()); + setValue("servlet.config.file", configFile.getCanonicalPath()); /* - * read parameters + * process parameters from file */ for (Iterator i = confTable.keySet().iterator(); i.hasNext();) { @@ -229,6 +229,33 @@ newParameter(key, null, val, 'f'); } } + + /* + * process all parameters + */ + for (Iterator i = this.keySet().iterator(); i.hasNext();) { + String key = (String) i.next(); + Parameter para = (Parameter) this.get(key); + + // basedir-list + if (key.equals("basedir-list")) { + // split list into directories + String[] dirs = (String[]) para.getValue(); + for (int j = 0; j < dirs.length; j++) { + // make relative directory paths be inside the webapp + dirs[j] = ServletOps.getFile(dirs[j], config); + } + para.setValue(dirs); + } + + // File types + if (para.getValue() instanceof File) { + File pf = (File) para.getValue(); + // make relative paths be inside the webapp + para.setValue(ServletOps.getFile(pf, config)); + } + + } }
--- a/servlet/src/digilib/servlet/Initialiser.java Thu Sep 17 19:40:17 2009 +0200 +++ b/servlet/src/digilib/servlet/Initialiser.java Thu Oct 29 13:40:11 2009 +0100 @@ -48,7 +48,7 @@ private static final long serialVersionUID = -5126621114382549343L; /** servlet version */ - public static final String iniVersion = "0.1b2"; + public static final String iniVersion = "0.2"; /** gengeral logger for this class */ private static Logger logger = Logger.getLogger("digilib.init");
--- a/servlet/src/digilib/servlet/Scaler.java Thu Sep 17 19:40:17 2009 +0200 +++ b/servlet/src/digilib/servlet/Scaler.java Thu Oct 29 13:40:11 2009 +0100 @@ -59,7 +59,7 @@ private static final long serialVersionUID = -325080527268912852L; /** digilib servlet version (for all components) */ - public static final String dlVersion = "1.7.0b"; + public static final String dlVersion = "1.7.1b"; /** logger for accounting requests */ private static Logger accountlog = Logger.getLogger("account.request");
--- a/servlet/src/digilib/servlet/ServletOps.java Thu Sep 17 19:40:17 2009 +0200 +++ b/servlet/src/digilib/servlet/ServletOps.java Thu Oct 29 13:40:11 2009 +0100 @@ -112,13 +112,22 @@ * @return */ public static File getConfigFile(File f, ServletConfig sc) { + String fn = f.getPath(); // is the filename absolute? - if (!f.isAbsolute()) { - // relative path -> use getRealPath to resolve in WEB-INF - String fn = sc.getServletContext().getRealPath( - "WEB-INF/" + f.getPath()); - f = new File(fn); + if (f.isAbsolute()) { + // does it exist? + if (f.canRead()) { + // fine + return f; + } else { + // try just the filename as relative + fn = f.getName(); + } } + // relative path -> use getRealPath to resolve in WEB-INF + String newfn = sc.getServletContext().getRealPath( + "WEB-INF/" + fn); + f = new File(newfn); return f; }