changeset 196:8125a068af80

Servlet version 1.18b5 - fix for config file names on non-unix systems
author robcast
date Mon, 08 Dec 2003 16:50:59 +0100
parents f921735dc578
children bb4ed821d06e
files client/digitallibrary/WEB-INF/lib/DigilibServlet.jar servlet/src/digilib/servlet/DigilibConfiguration.java servlet/src/digilib/servlet/DocumentBean.java servlet/src/digilib/servlet/Scaler.java servlet/src/digilib/servlet/ServletOps.java
diffstat 5 files changed, 40 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
Binary file client/digitallibrary/WEB-INF/lib/DigilibServlet.jar has changed
--- a/servlet/src/digilib/servlet/DigilibConfiguration.java	Wed Dec 03 18:52:26 2003 +0100
+++ b/servlet/src/digilib/servlet/DigilibConfiguration.java	Mon Dec 08 16:50:59 2003 +0100
@@ -48,7 +48,7 @@
  * 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>
+ * authentication configuration file. <br>... <br>
  * 
  * @author casties
  *  
@@ -70,7 +70,7 @@
 		super(20);
 		// we start with a default logger config
 		BasicConfigurator.configure();
-		
+
 		/*
 		 * Definition of parameters and default values. System parameters that
 		 * are not read from config file have a type 's'.
@@ -142,7 +142,7 @@
 		newParameter("log-config-file", "log4j-config.xml", null, 'f');
 		// maximum destination image size (0 means no limit)
 		newParameter("max-image-size", new Integer(0), null, 'f');
-		
+
 	}
 
 	/**
@@ -171,8 +171,7 @@
 		}
 		String fn = c.getInitParameter("config-file");
 		if (fn == null) {
-			fn =
-				c.getServletContext().getRealPath("WEB-INF/digilib-config.xml");
+			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!");
@@ -227,25 +226,18 @@
 		 */
 
 		// set up logger
-		String logConfPath = getAsString("log-config-file");
-		if (!logConfPath.startsWith("/")) {
-			// relative path -> use getRealPath to resolve in WEB-INF
-			logConfPath =
-				c.getServletContext().getRealPath("WEB-INF/" + logConfPath);
-		}
+		String logConfPath =
+			ServletOps.getConfigFile(getAsString("log-config-file"), c);
 		DOMConfigurator.configure(logConfPath);
 		// directory cache
 		String[] bd = (String[]) getValue("basedir-list");
-		int[] fcs = { FileOps.CLASS_IMAGE, FileOps.CLASS_TEXT, FileOps.CLASS_SVG };
+		int[] fcs =
+			{ FileOps.CLASS_IMAGE, FileOps.CLASS_TEXT, FileOps.CLASS_SVG };
 		DocuDirCache dirCache;
 		if (getAsBoolean("use-mapping")) {
 			// with mapping file
-			String mapConfPath = getAsString("mapping-file");
-			if (!mapConfPath.startsWith("/")) {
-				// relative path -> use getRealPath to resolve in WEB-INF
-				mapConfPath =
-					c.getServletContext().getRealPath("WEB-INF/" + mapConfPath);
-			}
+			String mapConfPath =
+				ServletOps.getConfigFile(getAsString("mapping-file"), c);
 			dirCache = new AliasingDocuDirCache(bd, fcs, mapConfPath);
 		} else {
 			// without mapping
@@ -257,13 +249,8 @@
 			// DB version
 			//authOp = new DBAuthOpsImpl(util);
 			// XML version
-			String authConfPath = getAsString("auth-file");
-			if (!authConfPath.startsWith("/")) {
-				// relative path -> use getRealPath to resolve in WEB-INF
-				authConfPath =
-					c.getServletContext().getRealPath(
-						"WEB-INF/" + authConfPath);
-			}
+			String authConfPath =
+				ServletOps.getConfigFile(getAsString("auth-file"), c);
 			AuthOps authOp = new XMLAuthOps(authConfPath);
 			setValue("servlet.auth.op", authOp);
 		}
@@ -271,7 +258,7 @@
 		String s = getAsString("docuimage-class");
 		Class cl = Class.forName(getAsString("docuimage-class"));
 		docuImageClass = Class.forName(getAsString("docuimage-class"));
-		setValue("servlet.docuimage.class", docuImageClass);
+		setValue("servlet.docuimage.class", docuImageClass.getName());
 	}
 
 	/**
--- a/servlet/src/digilib/servlet/DocumentBean.java	Wed Dec 03 18:52:26 2003 +0100
+++ b/servlet/src/digilib/servlet/DocumentBean.java	Mon Dec 08 16:50:59 2003 +0100
@@ -93,6 +93,9 @@
 		useAuthentication = dlConfig.getAsBoolean("use-authorization");
 		authOp = (AuthOps) dlConfig.getValue("servlet.auth.op");
 		authURLPath = dlConfig.getAsString("auth-url-path");
+		if (useAuthentication && (authOp == null)) {
+			throw new ServletException("ERROR: use-authorization configured but no AuthOp!");
+		}
 	}
 
 	/**
--- a/servlet/src/digilib/servlet/Scaler.java	Wed Dec 03 18:52:26 2003 +0100
+++ b/servlet/src/digilib/servlet/Scaler.java	Mon Dec 08 16:50:59 2003 +0100
@@ -59,7 +59,7 @@
 public class Scaler extends HttpServlet {
 
 	// digilib servlet version (for all components)
-	public static final String dlVersion = "1.18b4";
+	public static final String dlVersion = "1.18b5";
 
 	// logger for accounting requests
 	Logger accountlog = Logger.getLogger("account.request");
--- a/servlet/src/digilib/servlet/ServletOps.java	Wed Dec 03 18:52:26 2003 +0100
+++ b/servlet/src/digilib/servlet/ServletOps.java	Mon Dec 08 16:50:59 2003 +0100
@@ -28,6 +28,7 @@
 import java.io.PrintWriter;
 import java.util.StringTokenizer;
 
+import javax.servlet.ServletConfig;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletResponse;
 
@@ -60,6 +61,28 @@
 		return pathArray;
 	}
 
+	
+	/** get a real file name for a config file pathname.
+	 * 
+	 * If filename starts with "/" its treated as absolute else the path is appended 
+	 * to the WEB-INF directory of the web-app.
+	 * 
+	 * @param filename
+	 * @param sc
+	 * @return
+	 */
+	public static String getConfigFile(String filename, ServletConfig sc) {
+		File f = new File(filename);
+		// is the filename absolute?
+		if (!f.isAbsolute()) {
+			// relative path -> use getRealPath to resolve in WEB-INF
+			filename =
+			sc.getServletContext().getRealPath("WEB-INF/" + filename);
+		}
+		return filename;
+	}
+	
+	
 	/**
 	 * print a servlet response and exit
 	 */