changeset 185:91f28e4fee8f

Servlet version 1.18b2 - added max-image-size parameter for digilib-config - small fixes for the removal of the digilib.Utils class
author robcast
date Tue, 25 Nov 2003 19:26:45 +0100
parents 754c90861f95
children 26b2a74e2fe5
files servlet/src/digilib/image/DocuImageImpl.java servlet/src/digilib/image/JAIDocuImage.java servlet/src/digilib/image/JIMIDocuImage.java servlet/src/digilib/io/FileOps.java servlet/src/digilib/servlet/DigilibConfiguration.java servlet/src/digilib/servlet/DigilibRequest.java servlet/src/digilib/servlet/ParameterMap.java servlet/src/digilib/servlet/Scaler.java
diffstat 8 files changed, 59 insertions(+), 103 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/image/DocuImageImpl.java	Tue Nov 25 19:25:02 2003 +0100
+++ b/servlet/src/digilib/image/DocuImageImpl.java	Tue Nov 25 19:26:45 2003 +0100
@@ -24,7 +24,6 @@
 
 import org.apache.log4j.Logger;
 
-import digilib.Utils;
 import digilib.io.FileOpException;
 import digilib.io.ImageFile;
 
@@ -41,9 +40,6 @@
 	/** logger */
 	protected Logger logger = Logger.getLogger(this.getClass());
 	
-	/** Internal utils object. */
-	protected Utils util = null;
-
 	/** Interpolation quality. */
 	protected int quality = 0;
 	
@@ -53,27 +49,6 @@
 	/** image mime-type */
 	protected String mimeType = null;
 
-	/** Default constructor. */
-	public DocuImageImpl() {
-		util = new Utils();
-	}
-
-	/** Contructor taking an utils object.
-	 * 
-	 * @param u Utils object.
-	 */
-	public DocuImageImpl(Utils u) {
-		util = u;
-	}
-
-	/** Set local Utils object.
-	 * 
-	 * @param u Utils object.
-	 */
-	public void setUtils(Utils u) {
-		util = u;
-	}
-
 	/** Internal knownFileTypes. */
 	protected String[] knownFileTypes = { "jpg", "png", "gif", "tiff" };
 
--- a/servlet/src/digilib/image/JAIDocuImage.java	Tue Nov 25 19:25:02 2003 +0100
+++ b/servlet/src/digilib/image/JAIDocuImage.java	Tue Nov 25 19:26:45 2003 +0100
@@ -34,7 +34,6 @@
 import javax.media.jai.operator.TransposeDescriptor;
 import javax.media.jai.operator.TransposeType;
 
-import digilib.Utils;
 import digilib.io.ImageFile;
 import digilib.io.FileOpException;
 
@@ -44,17 +43,6 @@
 	protected RenderedImage img;
 	protected Interpolation interpol = null;
 
-	/** Default constructor. */
-	public JAIDocuImage() {
-	}
-
-	/** Contructor taking an utils object.
-	 * @param u utils object.
-	 */
-	public JAIDocuImage(Utils u) {
-		util = u;
-	}
-
 	/* Load an image file into the Object. */
 	public void loadImage(ImageFile f) throws FileOpException {
 		System.gc();
--- a/servlet/src/digilib/image/JIMIDocuImage.java	Tue Nov 25 19:25:02 2003 +0100
+++ b/servlet/src/digilib/image/JIMIDocuImage.java	Tue Nov 25 19:26:45 2003 +0100
@@ -31,7 +31,6 @@
 import com.sun.jimi.core.filters.ReplicatingScaleFilter;
 import com.sun.jimi.core.raster.JimiRasterImage;
 
-import digilib.Utils;
 import digilib.io.ImageFile;
 import digilib.io.FileOpException;
 
@@ -43,13 +42,6 @@
 	private int imgWidth = 0;
 	private int imgHeight = 0;
 
-	public JIMIDocuImage() {
-	}
-
-	public JIMIDocuImage(Utils u) {
-		util = u;
-	}
-
 	/**
 	 *  load image file
 	 */
--- a/servlet/src/digilib/io/FileOps.java	Tue Nov 25 19:25:02 2003 +0100
+++ b/servlet/src/digilib/io/FileOps.java	Tue Nov 25 19:26:45 2003 +0100
@@ -26,12 +26,8 @@
 import java.util.Iterator;
 import java.util.StringTokenizer;
 
-import digilib.Utils;
-
 public class FileOps {
 
-	private Utils util = null;
-	
 	public static String[] fileTypes =
 		{
 			"jpg",
--- a/servlet/src/digilib/servlet/DigilibConfiguration.java	Tue Nov 25 19:25:02 2003 +0100
+++ b/servlet/src/digilib/servlet/DigilibConfiguration.java	Tue Nov 25 19:26:45 2003 +0100
@@ -78,70 +78,72 @@
 		 */
 
 		// digilib servlet version
-		putParameter(
+		newParameter(
 			"servlet.version",
 			digilib.servlet.Scaler.dlVersion,
 			null,
 			's');
 		// configuration file location
-		putParameter("servlet.config.file", null, null, 's');
+		newParameter("servlet.config.file", null, null, 's');
 		// DocuDirCache instance
-		putParameter("servlet.dir.cache", null, null, 's');
+		newParameter("servlet.dir.cache", null, null, 's');
 		// DocuImage class instance
-		putParameter(
+		newParameter(
 			"servlet.docuimage.class",
 			digilib.image.JAIDocuImage.class,
 			null,
 			's');
 		// AuthOps instance for authentication
-		putParameter("servlet.auth.op", null, null, 's');
+		newParameter("servlet.auth.op", null, null, 's');
 
 		/*
 		 * parameters that can be read from config file have a type 'f'
 		 */
 
 		// image file to send in case of error
-		putParameter(
+		newParameter(
 			"error-image",
 			"/docuserver/images/icons/scalerror.gif",
 			null,
 			'f');
 		// image file to send if access is denied
-		putParameter(
+		newParameter(
 			"denied-image",
 			"/docuserver/images/icons/denied.gif",
 			null,
 			'f');
 		// base directories in order of preference (prescaled versions last)
 		String[] bd = { "/docuserver/images", "/docuserver/scaled/small" };
-		putParameter("basedir-list", bd, null, 'f');
+		newParameter("basedir-list", bd, null, 'f');
 		// use authentication information
-		putParameter("use-authorization", Boolean.FALSE, null, 'f');
+		newParameter("use-authorization", Boolean.FALSE, null, 'f');
 		// authentication configuration file
-		putParameter("auth-file", "digilib-auth.xml", null, 'f');
+		newParameter("auth-file", "digilib-auth.xml", null, 'f');
 		// sending image files as-is allowed
-		putParameter("sendfile-allowed", Boolean.TRUE, null, 'f');
+		newParameter("sendfile-allowed", Boolean.TRUE, null, 'f');
 		// Debug level
-		putParameter("debug-level", new Integer(5), null, 'f');
+		newParameter("debug-level", new Integer(5), null, 'f');
 		// Type of DocuImage instance
-		putParameter(
+		newParameter(
 			"docuimage-class",
 			"digilib.image.JAIDocuImage",
 			null,
 			'f');
 		// part of URL used to indicate authorized access
-		putParameter("auth-url-path", "authenticated/", null, 'f');
+		newParameter("auth-url-path", "authenticated/", null, 'f');
 		// degree of subsampling on image load
-		putParameter("subsample-minimum", new Float(2f), null, 'f');
+		newParameter("subsample-minimum", new Float(2f), null, 'f');
 		// default scaling quality
-		putParameter("default-quality", new Integer(1), null, 'f');
+		newParameter("default-quality", new Integer(1), null, 'f');
 		// use mapping file to translate paths
-		putParameter("use-mapping", Boolean.FALSE, null, 'f');
+		newParameter("use-mapping", Boolean.FALSE, null, 'f');
 		// mapping file location
-		putParameter("mapping-file", "digilib-map.xml", null, 'f');
+		newParameter("mapping-file", "digilib-map.xml", null, 'f');
 		// log4j config file location
-		putParameter("log-config-file", "log4j-config.xml", null, 'f');
-
+		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');
+		
 	}
 
 	/**
@@ -217,7 +219,7 @@
 				}
 			} else {
 				// parameter unknown -- just add
-				putParameter(key, null, val, 'f');
+				newParameter(key, null, val, 'f');
 			}
 		}
 
--- a/servlet/src/digilib/servlet/DigilibRequest.java	Tue Nov 25 19:25:02 2003 +0100
+++ b/servlet/src/digilib/servlet/DigilibRequest.java	Tue Nov 25 19:26:45 2003 +0100
@@ -83,55 +83,55 @@
 		 */
 
 		// url of the page/document (second part)
-		putParameter("fn", "", null, 's');
+		newParameter("fn", "", null, 's');
 		// page number
-		putParameter("pn", new Integer(1), null, 's');
+		newParameter("pn", new Integer(1), null, 's');
 		// width of client in pixels
-		putParameter("dw", new Integer(0), null, 's');
+		newParameter("dw", new Integer(0), null, 's');
 		// height of client in pixels
-		putParameter("dh", new Integer(0), null, 's');
+		newParameter("dh", new Integer(0), null, 's');
 		// left edge of image (float from 0 to 1)
-		putParameter("wx", new Float(0), null, 's');
+		newParameter("wx", new Float(0), null, 's');
 		// top edge in image (float from 0 to 1)
-		putParameter("wy", new Float(0), null, 's');
+		newParameter("wy", new Float(0), null, 's');
 		// width of image (float from 0 to 1)
-		putParameter("ww", new Float(1), null, 's');
+		newParameter("ww", new Float(1), null, 's');
 		// height of image (float from 0 to 1)
-		putParameter("wh", new Float(1), null, 's');
+		newParameter("wh", new Float(1), null, 's');
 		// scale factor
-		putParameter("ws", new Float(1), null, 's');
+		newParameter("ws", new Float(1), null, 's');
 		// special options like 'fit' for gifs
-		putParameter("mo", "", null, 's');
+		newParameter("mo", "", null, 's');
 		// rotation angle (degree)
-		putParameter("rot", new Float(0), null, 's');
+		newParameter("rot", new Float(0), null, 's');
 		// contrast enhancement factor
-		putParameter("cont", new Float(0), null, 's');
+		newParameter("cont", new Float(0), null, 's');
 		// brightness enhancement factor
-		putParameter("brgt", new Float(0), null, 's');
+		newParameter("brgt", new Float(0), null, 's');
 		// color multiplicative factors
-		putParameter("rgbm", "0/0/0", null, 's');
+		newParameter("rgbm", "0/0/0", null, 's');
 		// color additive factors
-		putParameter("rgba", "0/0/0", null, 's');
+		newParameter("rgba", "0/0/0", null, 's');
 		// display dpi resolution (total)
-		putParameter("ddpi", new Float(0), null, 's');
+		newParameter("ddpi", new Float(0), null, 's');
 		// display dpi X resolution
-		putParameter("ddpix", new Float(0), null, 's');
+		newParameter("ddpix", new Float(0), null, 's');
 		// display dpi Y resolution
-		putParameter("ddpiy", new Float(0), null, 's');
+		newParameter("ddpiy", new Float(0), null, 's');
 
 		/*
 		 * Parameter of type 'i' are not exchanged between client and server
 		 */
 
 		// url of the page/document (first part, may be empty)
-		putParameter("request.path", "", null, 'i');
+		newParameter("request.path", "", null, 'i');
 		// base URL (from http:// to below /servlet)
-		putParameter("base.url", null, null, 'i');
+		newParameter("base.url", null, null, 'i');
 		// DocuImage instance for this request
-		putParameter("docu.image", image, null, 'i');
+		newParameter("docu.image", image, null, 'i');
 		image = null;
 		// HttpServletRequest for this request
-		putParameter("servlet.request", servletRequest, null, 'i');
+		newParameter("servlet.request", servletRequest, null, 'i');
 		servletRequest = null;
 
 		/*
@@ -141,11 +141,11 @@
 		//	display	level of digilib (0 = just image, 1 = one HTML page
 		//        2 = in frameset, 3 = XUL-'frameset'
 		//        4 = XUL-Sidebar )
-		putParameter("lv", new Integer(2), null, 'c');
+		newParameter("lv", new Integer(2), null, 'c');
 		// total number of pages
-		putParameter("pt", new Integer(0), null, 'c');
+		newParameter("pt", new Integer(0), null, 'c');
 		// marks
-		putParameter("mk", "", null, 'c');
+		newParameter("mk", "", null, 'c');
 
 	}
 
@@ -362,7 +362,7 @@
 				continue;
 			}
 			// unknown parameters are just added with type 'r'
-			putParameter(name, null, request.getParameter(name), 'r');
+			newParameter(name, null, request.getParameter(name), 'r');
 		}
 		// add path from request
 		setValue("request.path", ((HttpServletRequest) request).getPathInfo());
--- a/servlet/src/digilib/servlet/ParameterMap.java	Tue Nov 25 19:25:02 2003 +0100
+++ b/servlet/src/digilib/servlet/ParameterMap.java	Tue Nov 25 19:26:45 2003 +0100
@@ -160,7 +160,7 @@
 	 * @param val
 	 * @return
 	 */
-	public Parameter putParameter(String name, Object def, Object val) {
+	public Parameter newParameter(String name, Object def, Object val) {
 		Parameter p = new Parameter(name, def, val);
 		return (Parameter) super.put(name, p);
 	}
@@ -175,7 +175,7 @@
 	 * @param type
 	 * @return
 	 */
-	public Parameter putParameter(String name, Object def, Object val, int type) {
+	public Parameter newParameter(String name, Object def, Object val, int type) {
 		Parameter p = new Parameter(name, def, val, type);
 		return (Parameter) super.put(name, p);
 	}
--- a/servlet/src/digilib/servlet/Scaler.java	Tue Nov 25 19:25:02 2003 +0100
+++ b/servlet/src/digilib/servlet/Scaler.java	Tue Nov 25 19:26:45 2003 +0100
@@ -59,7 +59,7 @@
 public class Scaler extends HttpServlet {
 
 	// digilib servlet version (for all components)
-	public static final String dlVersion = "1.18b1";
+	public static final String dlVersion = "1.18b2";
 
 	// logger for accounting requests
 	Logger accountlog = Logger.getLogger("account.request");
@@ -69,12 +69,8 @@
 	Logger authlog = Logger.getLogger("digilib.auth");
 	
 	
-	// FileOps instance
-	FileOps fileOp;
 	// AuthOps instance
 	AuthOps authOp;
-	// ServletOps instance
-	ServletOps servletOp;
 	// DocuDirCache instance
 	DocuDirCache dirCache;
 
@@ -314,6 +310,13 @@
 			scaleQual = 2;
 		}
 
+		// check with the maximum allowed size (if set)
+		int maxImgSize = dlConfig.getAsInt("max-image-size");
+		if (maxImgSize > 0) {
+			paramDW = (paramDW * paramWS > maxImgSize) ? (int)(maxImgSize / paramWS) : paramDW;
+			paramDH = (paramDH * paramWS > maxImgSize) ? (int)(maxImgSize / paramWS) : paramDH;
+		}
+		
 		//"big" try for all file/image actions
 		try {