changeset 1168:6c5eb1896cc0

better handling of files and less compiler warnings.
author robcast
date Wed, 27 Mar 2013 13:02:27 +0100
parents 4c7ee297e860
children 888cdaf022fe
files common/src/main/java/digilib/io/AliasingDocuDirCache.java common/src/main/java/digilib/servlet/DigilibConfiguration.java common/src/main/java/digilib/util/Parameter.java common/src/main/java/digilib/util/ParameterMap.java servlet2/src/main/java/digilib/servlet/DigilibServletConfiguration.java servlet2/src/main/java/digilib/servlet/DigilibServletRequest.java servlet2/src/main/java/digilib/servlet/Scaler.java servlet2/src/main/java/digilib/servlet/ServletOps.java servlet3/src/main/java/digilib/servlet/Scaler.java servlet3/src/main/java/digilib/servlet/ServletOps.java
diffstat 10 files changed, 86 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/common/src/main/java/digilib/io/AliasingDocuDirCache.java	Tue Mar 26 11:46:16 2013 +0100
+++ b/common/src/main/java/digilib/io/AliasingDocuDirCache.java	Wed Mar 27 13:02:27 2013 +0100
@@ -59,7 +59,7 @@
 			// load into pathMap
 			XMLListLoader mapLoader = new XMLListLoader("digilib-aliases",
 					"mapping", "link", "dir");
-			pathMap = mapLoader.loadURL(confFile.toURL().toString());
+			pathMap = mapLoader.loadUri(confFile.toURI());
 		} catch (Exception e) {
 			throw new FileOpException("ERROR loading mapping file: " + e);
 		}
--- a/common/src/main/java/digilib/servlet/DigilibConfiguration.java	Tue Mar 26 11:46:16 2013 +0100
+++ b/common/src/main/java/digilib/servlet/DigilibConfiguration.java	Wed Mar 27 13:02:27 2013 +0100
@@ -72,6 +72,7 @@
     /** Definition of parameters and default values.
 	 * 
 	 */
+    @SuppressWarnings("unchecked")
     protected void initParams() {
         /*
          * Definition of parameters and default values. System parameters that
--- a/common/src/main/java/digilib/util/Parameter.java	Tue Mar 26 11:46:16 2013 +0100
+++ b/common/src/main/java/digilib/util/Parameter.java	Wed Mar 27 13:02:27 2013 +0100
@@ -178,22 +178,44 @@
 		return (value != null) ? value : defval;
 	}
 
+    /**
+     * Get the value as Object.
+     * 
+     * Returns the default if the value is not set.
+     * 
+     * @return
+     */
 	public int getAsInt() {
 		Integer i = (Integer) getValue();
 		return (i != null) ? i.intValue() : 0;
 	}
 
+    /**
+     * Get the value as float.
+     * 
+     * Returns the default if the value is not set.
+     * 
+     * @return
+     */
 	public float getAsFloat() {
 		Float f = (Float) getValue();
 		return (f != null) ? f.floatValue() : 0f;
 	}
 
+    /**
+     * Get the value as String.
+     * 
+     * Returns the default if the value is not set.
+     * 
+     * @return
+     */
 	public String getAsString() {
 		Object s = getValue();
 		if (s == null) {
 			return "";
 		}
 		if (s.getClass() == File.class) {
+		    // get Files as CanonicalPath
 			try {
 				return ((File) s).getCanonicalPath();
 			} catch (IOException e) {
@@ -203,11 +225,30 @@
 		return s.toString();
 	}
 
+    /**
+     * Get the value as boolean.
+     * 
+     * Returns the default if the value is not set.
+     * 
+     * @return
+     */
 	public boolean getAsBoolean() {
 		Boolean b = (Boolean) getValue();
 		return (b != null) ? b.booleanValue() : false;
 	}
 
+    /**
+     * Get the value as File.
+     * 
+     * Returns the default if the value is not set.
+     * 
+     * @return
+     */
+    public File getAsFile() {
+        File f = (File) getValue();
+        return f;
+    }
+
 	public String[] parseAsArray(String separator) {
 		String s = getAsString();
 		String[] sa = s.split(separator);
--- a/common/src/main/java/digilib/util/ParameterMap.java	Tue Mar 26 11:46:16 2013 +0100
+++ b/common/src/main/java/digilib/util/ParameterMap.java	Wed Mar 27 13:02:27 2013 +0100
@@ -27,6 +27,7 @@
  * Created on 02.09.2003 by casties
  */
 
+import java.io.File;
 import java.util.HashMap;
 
 
@@ -172,6 +173,18 @@
 		return (p != null) ? p.getAsBoolean() : false;
 	}
 
+    /** Get the Parameter with the corresponding key.
+     * 
+     * Returns null if no element is associated with key.
+     * 
+     * @param key
+     * @return
+     */
+    public File getAsFile(String key) {
+        Parameter p = params.get(key);
+        return (p != null) ? p.getAsFile() : null;
+    }
+
 	/** Returns if the Parameter's value has been set.
 	 * 
 	 * @param key
--- a/servlet2/src/main/java/digilib/servlet/DigilibServletConfiguration.java	Tue Mar 26 11:46:16 2013 +0100
+++ b/servlet2/src/main/java/digilib/servlet/DigilibServletConfiguration.java	Wed Mar 27 13:02:27 2013 +0100
@@ -187,7 +187,7 @@
             // 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());
+            Map<String, String> confTable = lilo.loadUri(f.toURI());
 
             // set config file path parameter
             setValue("servlet.config.file", f.getCanonicalPath());
--- a/servlet2/src/main/java/digilib/servlet/DigilibServletRequest.java	Tue Mar 26 11:46:16 2013 +0100
+++ b/servlet2/src/main/java/digilib/servlet/DigilibServletRequest.java	Wed Mar 27 13:02:27 2013 +0100
@@ -392,7 +392,8 @@
     public void setWithParamRequest(ServletRequest request) {
         setValue("servlet.request", request);
         // go through all request parameters
-        for (Enumeration<String> i = request.getParameterNames(); i.hasMoreElements();) {
+        for (@SuppressWarnings("unchecked")
+        Enumeration<String> i = request.getParameterNames(); i.hasMoreElements();) {
             String name = (String) i.nextElement();
             // is this a known parameter?
             if (params.containsKey(name)) {
--- a/servlet2/src/main/java/digilib/servlet/Scaler.java	Tue Mar 26 11:46:16 2013 +0100
+++ b/servlet2/src/main/java/digilib/servlet/Scaler.java	Wed Mar 27 13:02:27 2013 +0100
@@ -59,7 +59,7 @@
     private static final long serialVersionUID = -5439198888139362735L;
 
     /** digilib servlet version (for all components) */
-    public static final String version = "2.1b4 noasync";
+    public static final String version = "2.1.4 noasync";
 
     /** servlet error codes */
     public static enum Error {UNKNOWN, AUTH, FILE, IMAGE};
@@ -110,6 +110,7 @@
      * 
      * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
      */
+    @SuppressWarnings("unchecked")
     public void init(ServletConfig config) throws ServletException {
         super.init(config);
 
@@ -142,12 +143,9 @@
         imageJobCenter = (DigilibJobCenter<DocuImage>) dlConfig
                 .getValue("servlet.worker.imageexecutor");
 
-        denyImgFile = ServletOps.getFile(
-                (File) dlConfig.getValue("denied-image"), context);
-        errorImgFile = ServletOps.getFile(
-                (File) dlConfig.getValue("error-image"), context);
-        notfoundImgFile = ServletOps.getFile(
-                (File) dlConfig.getValue("notfound-image"), context);
+        denyImgFile = ServletOps.getFile(dlConfig.getAsFile("denied-image"), context);
+        errorImgFile = ServletOps.getFile(dlConfig.getAsFile("error-image"), context);
+        notfoundImgFile = ServletOps.getFile(dlConfig.getAsFile("notfound-image"), context);
         sendFileAllowed = dlConfig.getAsBoolean("sendfile-allowed");
     }
 
--- a/servlet2/src/main/java/digilib/servlet/ServletOps.java	Tue Mar 26 11:46:16 2013 +0100
+++ b/servlet2/src/main/java/digilib/servlet/ServletOps.java	Wed Mar 27 13:02:27 2013 +0100
@@ -51,7 +51,7 @@
 
     /**
      * convert a string with a list of pathnames into an array of strings using
-     * the system's path seperator string
+     * the system's path separator string
      */
     public static String[] getPathArray(String paths) {
         // split list into directories
@@ -84,6 +84,10 @@
         if (!f.isAbsolute()) {
             // relative path -> use getRealPath to resolve in WEB-INF
             String fn = sc.getRealPath(f.getPath());
+            if (fn == null) {
+                // TODO: use getResourceAsStream?
+                return null;
+            }
             f = new File(fn);
         }
         return f;
@@ -134,6 +138,10 @@
         }
         // relative path -> use getRealPath to resolve in WEB-INF
         String newfn = sc.getRealPath("WEB-INF/" + fn);
+        if (fn == null) {
+            // TODO: use getResourceAsStream?
+            return null;
+        }
         f = new File(newfn);
         return f;
     }
--- a/servlet3/src/main/java/digilib/servlet/Scaler.java	Tue Mar 26 11:46:16 2013 +0100
+++ b/servlet3/src/main/java/digilib/servlet/Scaler.java	Wed Mar 27 13:02:27 2013 +0100
@@ -57,7 +57,7 @@
     private static final long serialVersionUID = 5289386646192471549L;
 
     /** digilib servlet version (for all components) */
-    public static final String version = "2.1b4 async";
+    public static final String version = "2.1.4 async";
 
     /** servlet error codes */
     public static enum Error {
@@ -148,12 +148,9 @@
         imageJobCenter = (DigilibJobCenter<DocuImage>) dlConfig
                 .getValue("servlet.worker.imageexecutor");
 
-        denyImgFile = ServletOps.getFile(
-                (File) dlConfig.getValue("denied-image"), context);
-        errorImgFile = ServletOps.getFile(
-                (File) dlConfig.getValue("error-image"), context);
-        notfoundImgFile = ServletOps.getFile(
-                (File) dlConfig.getValue("notfound-image"), context);
+        denyImgFile = ServletOps.getFile(dlConfig.getAsFile("denied-image"), context);
+        errorImgFile = ServletOps.getFile(dlConfig.getAsFile("error-image"), context);
+        notfoundImgFile = ServletOps.getFile(dlConfig.getAsFile("notfound-image"), context);
         sendFileAllowed = dlConfig.getAsBoolean("sendfile-allowed");
         try {
             defaultErrMsgType = ErrMsg.valueOf(dlConfig
--- a/servlet3/src/main/java/digilib/servlet/ServletOps.java	Tue Mar 26 11:46:16 2013 +0100
+++ b/servlet3/src/main/java/digilib/servlet/ServletOps.java	Wed Mar 27 13:02:27 2013 +0100
@@ -53,7 +53,7 @@
 
     /**
      * convert a string with a list of pathnames into an array of strings using
-     * the system's path seperator string
+     * the system's path separator string
      */
     public static String[] getPathArray(String paths) {
         // split list into directories
@@ -86,6 +86,10 @@
         if (!f.isAbsolute()) {
             // relative path -> use getRealPath to resolve in WEB-INF
             String fn = sc.getRealPath(f.getPath());
+            if (fn == null) {
+                // TODO: use getResourceAsStream?
+                return null;
+            }
             f = new File(fn);
         }
         return f;
@@ -136,6 +140,10 @@
         }
         // relative path -> use getRealPath to resolve in WEB-INF
         String newfn = sc.getRealPath("WEB-INF/" + fn);
+        if (fn == null) {
+            // TODO: use getResourceAsStream?
+            return null;
+        }
         f = new File(newfn);
         return f;
     }