changeset 911:0cea7e608080

add relative-basedir back in. fix digicat.
author robcast
date Tue, 24 May 2011 13:48:37 -0400
parents 91e5f20a7c56
children cbfc94584d3b
files servlet2/src/main/java/digilib/servlet/DigilibServletConfiguration.java servlet3/src/main/java/digilib/servlet/DigilibServletConfiguration.java webapp/src/main/webapp/oldskin/dcMain.jsp
diffstat 3 files changed, 223 insertions(+), 225 deletions(-) [+]
line wrap: on
line diff
--- a/servlet2/src/main/java/digilib/servlet/DigilibServletConfiguration.java	Tue May 24 08:17:02 2011 -0400
+++ b/servlet2/src/main/java/digilib/servlet/DigilibServletConfiguration.java	Tue May 24 13:48:37 2011 -0400
@@ -164,71 +164,77 @@
 		readConfig(c);
 	}
 
-	/**
-	 * read parameter list from the XML file in init parameter "config-file"
-	 * or file digilib-config.xml
-	 */
-	@SuppressWarnings("unchecked")
+    /**
+     * read parameter list from the XML file in init parameter "config-file" or
+     * file digilib-config.xml
+     */
+    @SuppressWarnings("unchecked")
     public void readConfig(ServletContext c) 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) {
-			// no config no file...
-			return;
-		}
-		String fn = c.getInitParameter("config-file");
-		if (fn == null) {
-			fn = ServletOps.getConfigFile("digilib-config.xml", c);
-			if (fn == null) {
-				logger.fatal("readConfig: no param config-file");
-				throw new ServletException("ERROR: no digilib config file!");
-			}
-		}
-		File f = new File(fn);
-		// setup config file list reader
-		XMLListLoader lilo =
-			new XMLListLoader("digilib-config", "parameter", "name", "value");
-		// read config file into HashMap
-		Map<String,String> confTable = lilo.loadURL(f.toURL().toString());
+        /*
+         * 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) {
+            // no config no file...
+            return;
+        }
+        String fn = c.getInitParameter("config-file");
+        if (fn == null) {
+            fn = ServletOps.getConfigFile("digilib-config.xml", c);
+            if (fn == null) {
+                logger.fatal("readConfig: no param config-file");
+                throw new ServletException("ERROR: no digilib config file!");
+            }
+        }
+        File f = new File(fn);
+        // setup config file list reader
+        XMLListLoader lilo = new XMLListLoader("digilib-config", "parameter",
+                "name", "value");
+        // read config file into HashMap
+        Map<String, String> confTable = lilo.loadURL(f.toURL().toString());
 
-		// set config file path parameter
-		setValue("servlet.config.file", f.getCanonicalPath());
+        // set config file path parameter
+        setValue("servlet.config.file", f.getCanonicalPath());
 
-		/*
-		 * read parameters
-		 */
+        /*
+         * read parameters
+         */
 
-		for (Entry<String, String> confEntry: confTable.entrySet()) {
-			Parameter p = get(confEntry.getKey());
-			if (p != null) {
-				if (p.getType() == 's') {
-					// type 's' Parameters are not overwritten.
-					continue;
-				}
-				if (!p.setValueFromString(confEntry.getValue())) {
-					/*
-					 * automatic conversion failed -- try special cases
-					 */
+        for (Entry<String, String> confEntry : confTable.entrySet()) {
+            Parameter p = get(confEntry.getKey());
+            if (p != null) {
+                if (p.getType() == 's') {
+                    // type 's' Parameters are not overwritten.
+                    continue;
+                }
+                if (!p.setValueFromString(confEntry.getValue())) {
+                    /*
+                     * automatic conversion failed -- try special cases
+                     */
 
-					// basedir-list
-					if (confEntry.getKey().equals("basedir-list")) {
-						// split list into directories
-						String[] sa = FileOps.pathToArray(confEntry.getValue());
-						if (sa != null) {
-							p.setValue(sa);
-						}
-					}
-				}
-			} else {
-				// parameter unknown -- just add
-				newParameter(confEntry.getKey(), null, confEntry.getValue(), 'f');
-			}
-		}
-		// initialise static DocuImage class instance
-		DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class.forName(getAsString("docuimage-class"));
-	}
+                    // basedir-list
+                    if (confEntry.getKey().equals("basedir-list")) {
+                        // split list into directories
+                        String[] dirs = FileOps.pathToArray(confEntry.getValue());
+                        for (int j = 0; j < dirs.length; j++) {
+                            // make relative directory paths be inside the webapp
+                            dirs[j] = ServletOps.getFile(dirs[j], c);
+                        }
+                        if (dirs != null) {
+                            p.setValue(dirs);
+                        }
+                    }
+                }
+            } else {
+                // parameter unknown -- just add
+                newParameter(confEntry.getKey(), null, confEntry.getValue(),
+                        'f');
+            }
+        }
+        // initialise static DocuImage class instance
+        DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class
+                .forName(getAsString("docuimage-class"));
+    }
 
 }
--- a/servlet3/src/main/java/digilib/servlet/DigilibServletConfiguration.java	Tue May 24 08:17:02 2011 -0400
+++ b/servlet3/src/main/java/digilib/servlet/DigilibServletConfiguration.java	Tue May 24 13:48:37 2011 -0400
@@ -36,44 +36,41 @@
 /**
  * Class to hold the digilib servlet configuration parameters. The parameters
  * can be read from the digilib-config file and be passed to other servlets or
- * beans. <br>errorImgFileName: image file to send in case of error. <br>
- * denyImgFileName: image file to send if access is denied. <br>baseDirs:
- * array of base directories in order of preference (prescaled versions first).
- * <br>useAuth: use authentication information. <br>authConfPath:
- * authentication configuration file. <br>... <br>
+ * beans. <br>
+ * errorImgFileName: image file to send in case of error. <br>
+ * denyImgFileName: image file to send if access is denied. <br>
+ * baseDirs: array of base directories in order of preference (prescaled
+ * versions first). <br>
+ * useAuth: use authentication information. <br>
+ * authConfPath: authentication configuration file. <br>
+ * ... <br>
  * 
  * @author casties
- *  
+ * 
  */
 public class DigilibServletConfiguration extends DigilibConfiguration {
 
-	/**
-	 * Definition of parameters and default values.
-	 */
-	protected void initParams() {
-		/*
-		 * Definition of parameters and default values. System parameters that
-		 * are not read from config file have a type 's'.
-		 */
+    /**
+     * Definition of parameters and default values.
+     */
+    protected void initParams() {
+        /*
+         * Definition of parameters and default values. System parameters that
+         * are not read from config file have a type 's'.
+         */
 
-		// digilib servlet version
-		newParameter(
-			"servlet.version",
-			digilib.servlet.Scaler.getVersion(),
-			null,
-			's');
-		// configuration file location
-		newParameter("servlet.config.file", null, null, 's');
-		// DocuDirCache instance
-		newParameter("servlet.dir.cache", null, null, 's');
-		// DocuImage class instance
-		newParameter(
-			"servlet.docuimage.class",
-			digilib.image.JAIDocuImage.class,
-			null,
-			's');
-		// AuthOps instance for authentication
-		newParameter("servlet.auth.op", null, null, 's');
+        // digilib servlet version
+        newParameter("servlet.version", digilib.servlet.Scaler.getVersion(),
+                null, 's');
+        // configuration file location
+        newParameter("servlet.config.file", null, null, 's');
+        // DocuDirCache instance
+        newParameter("servlet.dir.cache", null, null, 's');
+        // DocuImage class instance
+        newParameter("servlet.docuimage.class",
+                digilib.image.JAIDocuImage.class, null, 's');
+        // AuthOps instance for authentication
+        newParameter("servlet.auth.op", null, null, 's');
         // Executor for image operations
         newParameter("servlet.worker.imageexecutor", null, null, 's');
         // Executor for PDF operations
@@ -81,69 +78,57 @@
         // Executor for PDF-image operations
         newParameter("servlet.worker.pdfimageexecutor", null, null, 's');
 
-		/*
-		 * parameters that can be read from config file have a type 'f'
-		 */
+        /*
+         * parameters that can be read from config file have a type 'f'
+         */
 
-		// image file to send in case of error
-		newParameter(
-			"error-image",
-			new File("img/digilib-error.png"),
-			null,
-			'f');
-		// image file to send if access is denied
-		newParameter(
-			"denied-image",
-			new File("img/digilib-denied.png"),
-			null,
-			'f');
-		// image file to send if image file not found
-		newParameter(
-			"notfound-image",
-			new File("img/digilib-notfound.png"),
-			null,
-			'f');
-		// base directories in order of preference (prescaled versions last)
-		String[] bd = { "/docuserver/images", "/docuserver/scaled/small" };
-		newParameter("basedir-list", bd, null, 'f');
-		// use authentication information
-		newParameter("use-authorization", Boolean.FALSE, null, 'f');
-		// authentication configuration file
-		newParameter("auth-file", new File("digilib-auth.xml"), null, 'f');
-		// sending image files as-is allowed
-		newParameter("sendfile-allowed", Boolean.TRUE, null, 'f');
-		// Type of DocuImage instance
-		newParameter(
-			"docuimage-class",
-			"digilib.image.JAIDocuImage",
-			null,
-			'f');
-		// part of URL used to indicate authorized access
-		newParameter("auth-url-path", "authenticated/", null, 'f');
-		// degree of subsampling on image load
-		newParameter("subsample-minimum", new Float(2f), null, 'f');
-		// default scaling quality
-		newParameter("default-quality", new Integer(1), null, 'f');
-		// 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');
-		// log4j config file location
-		newParameter("log-config-file", new File("log4j-config.xml"), null, 'f');
-		// maximum destination image size (0 means no limit)
-		newParameter("max-image-size", new Integer(0), null, 'f');
-		// number of working threads
-		newParameter("worker-threads", new Integer(1), null, 'f');
-		// max number of waiting threads
-		newParameter("max-waiting-threads", new Integer(20), null, 'f');
-		// number of pdf-generation threads
-		newParameter("pdf-worker-threads", new Integer(1), null, 'f');
-		// max number of waiting pdf-generation threads
-		newParameter("pdf-max-waiting-threads", new Integer(20), null, 'f');
-		// number of pdf-image generation threads
-		newParameter("pdf-image-worker-threads", new Integer(1), null, 'f');
-		// max number of waiting pdf-image generation threads
-		newParameter("pdf-image-max-waiting-threads", new Integer(10), null, 'f');
+        // image file to send in case of error
+        newParameter("error-image", new File("img/digilib-error.png"), null,
+                'f');
+        // image file to send if access is denied
+        newParameter("denied-image", new File("img/digilib-denied.png"), null,
+                'f');
+        // image file to send if image file not found
+        newParameter("notfound-image", new File("img/digilib-notfound.png"),
+                null, 'f');
+        // base directories in order of preference (prescaled versions last)
+        String[] bd = { "/docuserver/images", "/docuserver/scaled/small" };
+        newParameter("basedir-list", bd, null, 'f');
+        // use authentication information
+        newParameter("use-authorization", Boolean.FALSE, null, 'f');
+        // authentication configuration file
+        newParameter("auth-file", new File("digilib-auth.xml"), null, 'f');
+        // sending image files as-is allowed
+        newParameter("sendfile-allowed", Boolean.TRUE, null, 'f');
+        // Type of DocuImage instance
+        newParameter("docuimage-class", "digilib.image.JAIDocuImage", null, 'f');
+        // part of URL used to indicate authorized access
+        newParameter("auth-url-path", "authenticated/", null, 'f');
+        // degree of subsampling on image load
+        newParameter("subsample-minimum", new Float(2f), null, 'f');
+        // default scaling quality
+        newParameter("default-quality", new Integer(1), null, 'f');
+        // 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');
+        // log4j config file location
+        newParameter("log-config-file", new File("log4j-config.xml"), null, 'f');
+        // maximum destination image size (0 means no limit)
+        newParameter("max-image-size", new Integer(0), null, 'f');
+        // number of working threads
+        newParameter("worker-threads", new Integer(1), null, 'f');
+        // max number of waiting threads
+        newParameter("max-waiting-threads", new Integer(20), null, 'f');
+        // number of pdf-generation threads
+        newParameter("pdf-worker-threads", new Integer(1), null, 'f');
+        // max number of waiting pdf-generation threads
+        newParameter("pdf-max-waiting-threads", new Integer(20), null, 'f');
+        // number of pdf-image generation threads
+        newParameter("pdf-image-worker-threads", new Integer(1), null, 'f');
+        // max number of waiting pdf-image generation threads
+        newParameter("pdf-image-max-waiting-threads", new Integer(10), null,
+                'f');
         // PDF generation temp directory
         newParameter("pdf-temp-dir", "pdf_temp", null, 'f');
         // PDF generation cache directory
@@ -152,83 +137,90 @@
         newParameter("img-diskcache-allowed", Boolean.TRUE, null, 'f');
         // default type of error message (image, text, code)
         newParameter("default-errmsg-type", "image", null, 'f');
-	}
+    }
 
-	/**
-	 * Constructor taking a ServletConfig. Reads the config file location from
-	 * an init parameter and loads the config file. Calls <code>readConfig()</code>.
-	 * 
-	 * @see readConfig()
-	 */
-	public DigilibServletConfiguration(ServletContext c) throws Exception {
-		readConfig(c);
-	}
+    /**
+     * Constructor taking a ServletConfig. Reads the config file location from
+     * an init parameter and loads the config file. Calls
+     * <code>readConfig()</code>.
+     * 
+     * @see readConfig()
+     */
+    public DigilibServletConfiguration(ServletContext c) throws Exception {
+        readConfig(c);
+    }
 
-	/**
-	 * read parameter list from the XML file in init parameter "config-file"
-	 * or file digilib-config.xml
-	 */
-	@SuppressWarnings("unchecked")
+    /**
+     * read parameter list from the XML file in init parameter "config-file" or
+     * file digilib-config.xml
+     */
+    @SuppressWarnings("unchecked")
     public void readConfig(ServletContext c) 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) {
-			// no config no file...
-			return;
-		}
-		String fn = c.getInitParameter("config-file");
-		if (fn == null) {
-			fn = ServletOps.getConfigFile("digilib-config.xml", c);
-			if (fn == null) {
-				logger.fatal("readConfig: no param config-file");
-				throw new ServletException("ERROR: no digilib config file!");
-			}
-		}
-		File f = new File(fn);
-		// setup config file list reader
-		XMLListLoader lilo =
-			new XMLListLoader("digilib-config", "parameter", "name", "value");
-		// read config file into HashMap
-		Map<String,String> confTable = lilo.loadURL(f.toURL().toString());
+        /*
+         * 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) {
+            // no config no file...
+            return;
+        }
+        String fn = c.getInitParameter("config-file");
+        if (fn == null) {
+            fn = ServletOps.getConfigFile("digilib-config.xml", c);
+            if (fn == null) {
+                logger.fatal("readConfig: no param config-file");
+                throw new ServletException("ERROR: no digilib config file!");
+            }
+        }
+        File f = new File(fn);
+        // setup config file list reader
+        XMLListLoader lilo = new XMLListLoader("digilib-config", "parameter",
+                "name", "value");
+        // read config file into HashMap
+        Map<String, String> confTable = lilo.loadURL(f.toURL().toString());
 
-		// set config file path parameter
-		setValue("servlet.config.file", f.getCanonicalPath());
+        // set config file path parameter
+        setValue("servlet.config.file", f.getCanonicalPath());
 
-		/*
-		 * read parameters
-		 */
+        /*
+         * read parameters
+         */
 
-		for (Entry<String, String> confEntry: confTable.entrySet()) {
-			Parameter p = get(confEntry.getKey());
-			if (p != null) {
-				if (p.getType() == 's') {
-					// type 's' Parameters are not overwritten.
-					continue;
-				}
-				if (!p.setValueFromString(confEntry.getValue())) {
-					/*
-					 * automatic conversion failed -- try special cases
-					 */
+        for (Entry<String, String> confEntry : confTable.entrySet()) {
+            Parameter p = get(confEntry.getKey());
+            if (p != null) {
+                if (p.getType() == 's') {
+                    // type 's' Parameters are not overwritten.
+                    continue;
+                }
+                if (!p.setValueFromString(confEntry.getValue())) {
+                    /*
+                     * automatic conversion failed -- try special cases
+                     */
 
-					// basedir-list
-					if (confEntry.getKey().equals("basedir-list")) {
-						// split list into directories
-						String[] sa = FileOps.pathToArray(confEntry.getValue());
-						if (sa != null) {
-							p.setValue(sa);
-						}
-					}
-				}
-			} else {
-				// parameter unknown -- just add
-				newParameter(confEntry.getKey(), null, confEntry.getValue(), 'f');
-			}
-		}
-		// initialise static DocuImage class instance
-		DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class.forName(getAsString("docuimage-class"));
-	}
+                    // basedir-list
+                    if (confEntry.getKey().equals("basedir-list")) {
+                        // split list into directories
+                        String[] dirs = FileOps.pathToArray(confEntry.getValue());
+                        for (int j = 0; j < dirs.length; j++) {
+                            // make relative directory paths be inside the webapp
+                            dirs[j] = ServletOps.getFile(dirs[j], c);
+                        }
+                        if (dirs != null) {
+                            p.setValue(dirs);
+                        }
+                    }
+                }
+            } else {
+                // parameter unknown -- just add
+                newParameter(confEntry.getKey(), null, confEntry.getValue(),
+                        'f');
+            }
+        }
+        // initialise static DocuImage class instance
+        DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class
+                .forName(getAsString("docuimage-class"));
+    }
 
 }
--- a/webapp/src/main/webapp/oldskin/dcMain.jsp	Tue May 24 08:17:02 2011 -0400
+++ b/webapp/src/main/webapp/oldskin/dcMain.jsp	Tue May 24 13:48:37 2011 -0400
@@ -18,7 +18,7 @@
 // parsing the query
 // -----------------
 
-digilib.servlet.DigilibRequest dcRequest = new digilib.servlet.DigilibRequest(request);
+digilib.servlet.DigilibServletRequest dcRequest = new digilib.servlet.DigilibServletRequest(request);
 // check if authentication is needed and redirect if necessary
 docBean.doAuthentication(dcRequest, response);
 // set number of pages