# HG changeset patch
# User robcast
# Date 1062543376 -7200
# Node ID 4980c969be4c255d8cb13722f7bb03e642a08267
# Parent f4a5cfe3746990101d3439ee2ead24a371046a8e
Servlet version 1.16a1
- cleanup of DigilibConfig class
- now uses new Parameter and ParameterMap classes
- new parameter default-quality
diff -r f4a5cfe37469 -r 4980c969be4c servlet/src/digilib/servlet/DigilibConfiguration.java
--- a/servlet/src/digilib/servlet/DigilibConfiguration.java Wed Sep 03 00:54:38 2003 +0200
+++ b/servlet/src/digilib/servlet/DigilibConfiguration.java Wed Sep 03 00:56:16 2003 +0200
@@ -22,7 +22,7 @@
import java.io.File;
import java.util.HashMap;
-import java.util.StringTokenizer;
+import java.util.Iterator;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@@ -33,6 +33,7 @@
import digilib.image.DocuImage;
import digilib.image.DocuImageImpl;
import digilib.io.DocuDirCache;
+import digilib.io.FileOps;
import digilib.io.XMLListLoader;
/** Class to hold the digilib servlet configuration parameters.
@@ -50,203 +51,167 @@
* @author casties
*
*/
-public class DigilibConfiguration {
- // digilib servlet version
- private String servletVersion = digilib.servlet.Scaler.dlVersion;
- // configuration file location
- private String dlConfPath = "";
- // image file to send in case of error
- private String errorImgFileName = "/docuserver/images/icons/scalerror.gif";
- private String errorImgParam = "error-image";
- // image file to send if access is denied
- private String denyImgFileName = "/docuserver/images/icons/denied.gif";
- private String denyImgParam = "denied-image";
- // base directories in order of preference (prescaled versions last)
- private String[] baseDirs =
- { "/docuserver/images", "/docuserver/scaled/small" };
- private String baseDirParam = "basedir-list";
- // use authentication information
- private boolean useAuthentication = true;
- private String useAuthParam = "use-authorization";
- // authentication configuration file
- private String authConfPath =
- "/docuserver/www/digitallibrary/WEB-INF/digilib-auth.xml";
- private String authConfParam = "auth-file";
- // sending image files as-is allowed
- private boolean sendFileAllowed = true;
- private String sendFileAllowedParam = "sendfile-allowed";
- // AuthOps instance for authentication
- private AuthOps authOp;
- // Debug level
- private int debugLevel = 5;
- private String debugLevelParam = "debug-level";
- // Utils instance
- private Utils util = new Utils(debugLevel);
- // HashTable for parameters
- private HashMap confTable = null;
- // Type of DocuImage instance
- private String docuImageType = "digilib.image.JAIDocuImage";
- private String docuImageTypeParam = "docuimage-class";
- // part of URL used to indicate authorized access
- private String authURLPath = "authenticated/";
- private String AuthURLPathParam = "auth-url-path";
- // degree of subsampling on image load
- private float minSubsample = 2;
- private String minSubsampleParam = "subsample-minimum";
- // DocuDirCache instance
- private DocuDirCache dirCache = null;
- // DocuImage class instance
+public class DigilibConfiguration extends ParameterMap {
+
+ /** DocuImage class instance */
private Class docuImageClass = null;
+
+ /** Utils instance */
+ private Utils util = new Utils(5);
+
+
+ /** Default constructor defines all parameters and their default values.
+ *
+ */
+ public DigilibConfiguration() {
+ // create HashMap(20)
+ super(20);
+
+ /*
+ * Definition of parameters and default values.
+ * System parameters that are not read from config file have a type 's'.
+ */
+
+ // digilib servlet version
+ putParameter("servlet.version", digilib.servlet.Scaler.dlVersion, null, 's');
+ // configuration file location
+ putParameter("servlet.config.file", null, null, 's');
+ // Utils instance
+ putParameter("servlet.util", util, null, 's');
+ // DocuDirCache instance
+ putParameter("servlet.dir.cache", null, null, 's');
+ // DocuImage class instance
+ putParameter("servlet.docuimage.class", digilib.image.JAIDocuImage.class, null, 's');
+ // AuthOps instance for authentication
+ putParameter("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("error-image", "/docuserver/images/icons/scalerror.gif", null, 'f');
+ // image file to send if access is denied
+ putParameter("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');
+ // use authentication information
+ putParameter("use-authorization", Boolean.TRUE, null, 'f');
+ // authentication configuration file
+ putParameter("auth-file", "/docuserver/www/digitallibrary/WEB-INF/digilib-auth.xml", null, 'f');
+ // sending image files as-is allowed
+ putParameter("sendfile-allowed", Boolean.TRUE, null, 'f');
+ // Debug level
+ putParameter("debug-level", new Integer(5), null, 'f');
+ // Type of DocuImage instance
+ putParameter("docuimage-class", "digilib.image.JAIDocuImage", null, 'f');
+ // part of URL used to indicate authorized access
+ putParameter("auth-url-path", "authenticated/", null, 'f');
+ // degree of subsampling on image load
+ putParameter("subsample-minimum", new Float(2f), null, 'f');
+ // default scaling quality
+ putParameter("default-quality", new Integer(1), null, 'f');
+ }
/** Constructor taking a ServletConfig.
* Reads the config file location from an init parameter and loads the
- * config file. Calls init
.
+ * config file. Calls readConfig()
.
*
- * @see init()
+ * @see readConfig()
*/
public DigilibConfiguration(ServletConfig c) throws Exception {
- init(c);
+ this();
+ readConfig(c);
}
-
+
/**
* read parameter list from the XML file in init parameter "config-file"
*/
- public void init(ServletConfig c) throws Exception {
- // reset parameter table
- confTable = null;
+ public void readConfig(ServletConfig 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;
}
- // get config file name
String fn = c.getInitParameter("config-file");
if (fn == null) {
- util.dprintln(4, "setConfig: no param config-file");
- throw new ServletException("ERROR no digilib config file!");
+ fn = c.getServletContext().getRealPath("WEB-INF/digilib-config.xml");
+ if (fn == null) {
+ util.dprintln(4, "setConfig: 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");
- confTable = lilo.loadURL(f.toURL().toString());
- dlConfPath = f.getCanonicalPath();
+ // read config file into HashMap
+ HashMap confTable = lilo.loadURL(f.toURL().toString());
+
+ // set config file path parameter
+ setValue("servlet.config.file", f.getCanonicalPath());
/*
* read parameters
*/
+ for (Iterator i = confTable.keySet().iterator(); i.hasNext();) {
+ String key = (String) i.next();
+ String val = (String) confTable.get(key);
+ Parameter p = get(key);
+ if (p != null) {
+ if (p.getType() == 's') {
+ // type 's' Parameters are not overwritten.
+ continue;
+ }
+ if (! p.setValueFromString(val)) {
+ /*
+ * automatic conversion failed -- try special cases
+ */
+
+ // basedir-list
+ if (key == "basedir-list") {
+ // split list into directories
+ String[] sa = FileOps.pathToArray(val);
+ if (sa != null) {
+ p.setValue(sa);
+ }
+ }
+
+ }
+ } else {
+ // parameter unknown -- just add
+ putParameter(key, null, val, 'f');
+ }
+ }
+
+ /*
+ * further initialization
+ */
+
// debugLevel
- debugLevel = tryToGetInitParam(debugLevelParam, debugLevel);
- util.setDebugLevel(debugLevel);
- // errorImgFileName
- errorImgFileName = tryToGetInitParam(errorImgParam, errorImgFileName);
- // denyImgFileName
- denyImgFileName = tryToGetInitParam(denyImgParam, denyImgFileName);
- // docuImageType
- docuImageType = tryToGetInitParam(docuImageTypeParam, docuImageType);
- // sendFileAllowed
- sendFileAllowed =
- tryToGetInitParam(sendFileAllowedParam, sendFileAllowed);
- // baseDirs
- String baseDirList =
- tryToGetInitParam(
- baseDirParam,
- "/docuserver/images/:/docuserver/scaled/small/");
- // split list into directories
- String[] sa = splitPathArray(baseDirList);
- baseDirs = (sa != null) ? sa : baseDirs;
+ util.setDebugLevel(getAsInt("debug-level"));
// directory cache
- dirCache = new DocuDirCache(baseDirs);
+ String[] bd = (String[]) getValue("basedir-list");
+ DocuDirCache dirCache = new DocuDirCache(bd);
+ setValue("servlet.dir.cache", dirCache);
// useAuthentication
- useAuthentication = tryToGetInitParam(useAuthParam, useAuthentication);
- if (useAuthentication) {
+ if (getAsBoolean("use-authorization")) {
// DB version
//authOp = new DBAuthOpsImpl(util);
// XML version
- authConfPath = tryToGetInitParam(authConfParam, authConfPath);
- authOp = new XMLAuthOps(util, authConfPath);
- }
- // minSubsample
- minSubsample =
- tryToGetInitParam(minSubsampleParam, minSubsample);
- }
-
- /**
- * convert a string with a list of pathnames into an array of strings
- * using the system's path separator string
- */
- public String[] splitPathArray(String paths) {
- // split list into directories
- StringTokenizer dirs =
- new StringTokenizer(paths, File.pathSeparator);
- int n = dirs.countTokens();
- if (n < 1) {
- return null;
- }
- // add directories into array
- String[] pathArray = new String[n];
- for (int i = 0; i < n; i++) {
- String s = dirs.nextToken();
- // make shure the dir name ends with a directory separator
- if (s.endsWith(File.separator)) {
- pathArray[i] = s;
- } else {
- pathArray[i] = s + File.separator;
- }
+ String authConfPath = getAsString("auth-file");
+ AuthOps authOp = new XMLAuthOps(util, authConfPath);
+ setValue("servlet.auth.op", authOp);
}
- return pathArray;
- }
-
- /**
- * get an init parameter from config and return it if set, otherwise return default
- */
- public int tryToGetInitParam(String s, int i) {
- //System.out.println("trytogetInitParam("+s+", "+i+")");
- try {
- //System.out.println("trytogetInitParam: "+(String)confTable.get(s));
- i = Integer.parseInt((String) confTable.get(s));
- } catch (Exception e) {
- util.dprintln(4, "trytogetInitParam(int) failed on param " + s);
- //e.printStackTrace();
- }
- return i;
- }
- public float tryToGetInitParam(String s, float f) {
- try {
- f = Float.parseFloat((String) confTable.get(s));
- } catch (Exception e) {
- util.dprintln(4, "trytoGetInitParam(float) failed on param " + s);
- //e.printStackTrace();
- }
- return f;
- }
- public String tryToGetInitParam(String s, String x) {
- if ((confTable != null) && ((String) confTable.get(s) != null)) {
- x = (String) confTable.get(s);
- } else {
- util.dprintln(4, "trytoGetInitParam(string) failed on param " + s);
- }
- return x;
- }
- public boolean tryToGetInitParam(String s, boolean b) {
- String bs;
- boolean bb = b;
- if ((confTable != null) && ((String) confTable.get(s) != null)) {
- bs = (String) confTable.get(s);
-
- if ((bs.indexOf("false") > -1) || (bs.indexOf("FALSE") > -1)) {
- bb = false;
- } else if (
- (bs.indexOf("true") > -1) || (bs.indexOf("TRUE") > -1)) {
- bb = true;
- } else {
- util.dprintln(
- 4,
- "trytoGetInitParam(string) failed on param " + s);
- }
- } else {
- util.dprintln(4, "trytoGetInitParam(string) failed on param " + s);
- }
- return bb;
+ // DocuImage class
+ docuImageClass = (Class) getValue("servlet.docuimage.class");
}
/** Creates a new DocuImage instance.
@@ -259,7 +224,7 @@
DocuImageImpl di = null;
try {
if (docuImageClass == null) {
- docuImageClass = Class.forName(docuImageType);
+ docuImageClass = Class.forName(getAsString("docuimage-class"));
}
di = (DocuImageImpl) docuImageClass.newInstance();
di.setUtils(util);
@@ -269,247 +234,10 @@
}
/**
- * Returns the authConfPath.
- * @return String
- */
- public String getAuthConfPath() {
- return authConfPath;
- }
-
- /**
- * Returns the authOp.
- * @return AuthOps
- */
- public AuthOps getAuthOp() {
- return authOp;
- }
-
- /**
- * Returns the denyImgFileName.
- * @return String
- */
- public String getDenyImgFileName() {
- return denyImgFileName;
- }
-
- /**
- * Returns the errorImgFileName.
- * @return String
- */
- public String getErrorImgFileName() {
- return errorImgFileName;
- }
-
- /**
- * Returns the useAuth.
- * @return boolean
- */
- public boolean isUseAuthentication() {
- return useAuthentication;
- }
-
- /**
- * Sets the authConfPath.
- * @param authConfPath The authConfPath to set
- */
- public void setAuthConfPath(String authConfPath) {
- this.authConfPath = authConfPath;
- }
-
- /**
- * Sets the authOp.
- * @param authOp The authOp to set
- */
- public void setAuthOp(AuthOps authOp) {
- this.authOp = authOp;
- }
-
- /**
- * Sets the denyImgFileName.
- * @param denyImgFileName The denyImgFileName to set
- */
- public void setDenyImgFileName(String denyImgFileName) {
- this.denyImgFileName = denyImgFileName;
- }
-
- /**
- * Sets the errorImgFileName.
- * @param errorImgFileName The errorImgFileName to set
- */
- public void setErrorImgFileName(String errorImgFileName) {
- this.errorImgFileName = errorImgFileName;
- }
-
- /**
- * Returns the baseDirs.
- * @return String[]
- */
- public String[] getBaseDirs() {
- return baseDirs;
- }
-
- /**
- * Returns the baseDirs as String.
- * @return String
- */
- public String getBaseDirList() {
- String s = "";
- java.util.Iterator i = java.util.Arrays.asList(baseDirs).iterator();
- while (i.hasNext()) {
- s += (i.next() + "; ");
- }
- return s;
- }
-
- /**
- * Sets the baseDirs.
- * @param baseDirs The baseDirs to set
- */
- public void setBaseDirs(String[] baseDirs) {
- this.baseDirs = baseDirs;
- dirCache = new DocuDirCache(baseDirs);
- }
-
- /**
- * Returns the debugLevel.
- * @return int
- */
- public int getDebugLevel() {
- return debugLevel;
- }
-
- /**
- * Sets the debugLevel.
- * @param debugLevel The debugLevel to set
- */
- public void setDebugLevel(int debugLevel) {
- this.debugLevel = debugLevel;
- }
-
- /**
- * Returns the util.
- * @return Utils
+ * @return
*/
public Utils getUtil() {
return util;
}
- /**
- * Sets the util.
- * @param util The util to set
- */
- public void setUtil(Utils util) {
- this.util = util;
- }
-
- /**
- * Returns the servletVersion.
- * @return String
- */
- public String getServletVersion() {
- return servletVersion;
- }
-
- /**
- * Sets the servletVersion.
- * @param servletVersion The servletVersion to set
- */
- public void setServletVersion(String servletVersion) {
- this.servletVersion = servletVersion;
- }
-
- /**
- * Returns the docuImageType.
- * @return String
- */
- public String getDocuImageType() {
- return docuImageType;
- }
-
- /**
- * Sets the docuImageType.
- * @param docuImageType The docuImageType to set
- */
- public void setDocuImageType(String docuImageType) {
- this.docuImageType = docuImageType;
- }
-
- /**
- * Returns the sendFileAllowed.
- * @return boolean
- */
- public boolean isSendFileAllowed() {
- return sendFileAllowed;
- }
-
- /**
- * Sets the sendFileAllowed.
- * @param sendFileAllowed The sendFileAllowed to set
- */
- public void setSendFileAllowed(boolean sendFileAllowed) {
- this.sendFileAllowed = sendFileAllowed;
- }
-
- /**
- * Returns the authURLPath.
- * @return String
- */
- public String getAuthURLPath() {
- return authURLPath;
- }
-
- /**
- * Sets the authURLPath.
- * @param authURLPath The authURLPath to set
- */
- public void setAuthURLPath(String authURLPath) {
- this.authURLPath = authURLPath;
- }
-
- /**
- * Sets the useAuthentication.
- * @param useAuthentication The useAuthentication to set
- */
- public void setUseAuthentication(boolean useAuthentication) {
- this.useAuthentication = useAuthentication;
- }
-
- /**
- * Returns the dlConfPath.
- * @return String
- */
- public String getDlConfPath() {
- return dlConfPath;
- }
-
- /**
- * @return float
- */
- public float getMinSubsample() {
- return minSubsample;
- }
-
- /**
- * Sets the minSubsample.
- * @param minSubsample The minSubsample to set
- */
- public void setMinSubsample(float f) {
- this.minSubsample = f;
- }
-
- /**
- * @return DocuDirCache
- */
- public DocuDirCache getDirCache() {
- return dirCache;
- }
-
- /**
- * Sets the dirCache.
- * @param dirCache The dirCache to set
- */
- public void setDirCache(DocuDirCache dirCache) {
- this.dirCache = dirCache;
- }
-
}
diff -r f4a5cfe37469 -r 4980c969be4c servlet/src/digilib/servlet/DocumentBean.java
--- a/servlet/src/digilib/servlet/DocumentBean.java Wed Sep 03 00:54:38 2003 +0200
+++ b/servlet/src/digilib/servlet/DocumentBean.java Wed Sep 03 00:56:16 2003 +0200
@@ -20,13 +20,20 @@
package digilib.servlet;
-import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
+import java.util.List;
-import digilib.*;
-import digilib.io.*;
-import digilib.auth.*;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import digilib.Utils;
+import digilib.auth.AuthOpException;
+import digilib.auth.AuthOps;
+import digilib.io.DocuDirCache;
+import digilib.io.DocuDirectory;
+import digilib.io.FileOps;
public class DocumentBean {
@@ -38,6 +45,8 @@
private FileOps fileOp = new FileOps(util);
// use authorization database
private boolean useAuthentication = true;
+ // path to add for authenticated access
+ private String authURLPath = "";
// DocuDirCache
private DocuDirCache dirCache = null;
@@ -80,13 +89,14 @@
// get util
util = dlConfig.getUtil();
// get cache
- dirCache = dlConfig.getDirCache();
+ dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache");
/*
* authentication
*/
- useAuthentication = dlConfig.isUseAuthentication();
- authOp = dlConfig.getAuthOp();
+ useAuthentication = dlConfig.getAsBoolean("use-authorization");
+ authOp = (AuthOps) dlConfig.getValue("servlet.auth.op");
+ authURLPath = dlConfig.getAsString("auth-url-path");
}
/**
@@ -147,7 +157,7 @@
util.dprintln(3, "auth required, redirect");
// we are not yet authenticated -> redirect
response.sendRedirect(
- dlConfig.getAuthURLPath()
+ authURLPath
+ ((HttpServletRequest) request.getServletRequest())
.getServletPath()
+ "?"
@@ -172,7 +182,10 @@
*/
public int getNumPages(DigilibRequest request) throws Exception {
util.dprintln(10, "getNumPages");
- DocuDirectory dd = (dirCache != null) ? dirCache.getDirectory(request.getFilePath()) : null;
+ DocuDirectory dd =
+ (dirCache != null)
+ ? dirCache.getDirectory(request.getFilePath())
+ : null;
if (dd != null) {
return dd.size();
}
diff -r f4a5cfe37469 -r 4980c969be4c servlet/src/digilib/servlet/Parameter.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/src/digilib/servlet/Parameter.java Wed Sep 03 00:56:16 2003 +0200
@@ -0,0 +1,199 @@
+/* Parameter -- General digilib parameter class.
+
+ Digital Image Library servlet components
+
+ Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de)
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ Please read license.txt for the full details. A copy of the GPL
+ may be found at http://www.gnu.org/copyleft/lgpl.html
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ *
+ * Created on 02.09.2003 by casties
+ *
+ */
+package digilib.servlet;
+
+/** General digilib parameter class.
+ *
+ * @author casties
+ *
+ */
+public class Parameter {
+ /** real value */
+ protected Object value = null;
+
+ /** default value */
+ protected Object defval = null;
+
+ /** parameter name (e.g. in config file) */
+ protected String name = null;
+
+ /** parameter type */
+ protected int type = 0;
+
+ /** Default constructor.
+ *
+ */
+ public Parameter() {
+ super();
+ }
+
+ /** Constructor with name, default, and value.
+ *
+ * @param value
+ * @param defval
+ */
+ public Parameter(String name, Object defval, Object value) {
+ this.name = name;
+ this.value = value;
+ this.defval = defval;
+ }
+
+ /** Constructor with name, default, value, and type.
+ * @param value
+ * @param defval
+ */
+ public Parameter(String name, Object defval, Object value, int type) {
+ this.name = name;
+ this.value = value;
+ this.defval = defval;
+ this.type = type;
+ }
+
+ /** Is the value valid.
+ *
+ * @return
+ */
+ public boolean hasValue() {
+ return (value != null);
+ }
+
+ /** Try to set the value from a String.
+ *
+ * Tries to convert the String to the same type as the default value.
+ * Sets the value anyway if the default is null.
+ * Returns if the value could be set.
+ *
+ * @param val
+ * @return
+ */
+ public boolean setValueFromString(String val) {
+ if (defval == null) {
+ this.value = val;
+ return true;
+ }
+ Class c = defval.getClass();
+ // take String as is
+ if (c == String.class) {
+ this.value = val;
+ return true;
+ }
+ // set Boolean if string == "true"
+ if (c == Boolean.class) {
+ this.value = new Boolean(val.compareToIgnoreCase("true") == 0);
+ return true;
+ }
+ // set Integer
+ if (c == Integer.class) {
+ this.value = new Integer(Integer.parseInt(val));
+ return true;
+ }
+ // set Float
+ if (c == Float.class) {
+ this.value = new Float(Float.parseFloat(val));
+ return true;
+ }
+ // then it's unknown
+ return false;
+ }
+
+ /** Get the default as Object.
+ *
+ * @return
+ */
+ public Object getDefault() {
+ return defval;
+ }
+
+ /** Set the default.
+ * @param defval
+ */
+ public void setDefault(Object defval) {
+ this.defval = defval;
+ }
+
+ /** Get the value as Object.
+ *
+ * Returns the default if the value is not set.
+ *
+ * @return
+ */
+ public Object getValue() {
+ return (value != null) ? value : defval;
+ }
+
+ public int getAsInt() {
+ Integer i = (Integer) getValue();
+ return (i != null) ? i.intValue() : 0;
+ }
+
+ public float getAsFloat() {
+ Float f = (Float) getValue();
+ return (f != null) ? f.floatValue() : 0f;
+ }
+
+ public String getAsString() {
+ return (String) getValue();
+ }
+
+ public boolean getAsBoolean() {
+ Boolean b = (Boolean) getValue();
+ return (b != null) ? b.booleanValue() : false;
+ }
+
+ /** Set the value.
+ *
+ * @param value
+ */
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ /**
+ * @return
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return
+ */
+ public int getType() {
+ return type;
+ }
+
+ /**
+ * @param type
+ */
+ public void setType(int type) {
+ this.type = type;
+ }
+
+}
diff -r f4a5cfe37469 -r 4980c969be4c servlet/src/digilib/servlet/ParameterMap.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/src/digilib/servlet/ParameterMap.java Wed Sep 03 00:56:16 2003 +0200
@@ -0,0 +1,154 @@
+/* ParameterMap.java -- HashMap of Parameters.
+
+ Digital Image Library servlet components
+
+ Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de)
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ Please read license.txt for the full details. A copy of the GPL
+ may be found at http://www.gnu.org/copyleft/lgpl.html
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ * Created on 02.09.2003 by casties
+ *
+ */
+package digilib.servlet;
+
+import java.util.HashMap;
+
+/** HashMap of digilib.servlet.Parameter's.
+ *
+ * Keys are Strings. Values are Parameters.
+ *
+ * @author casties
+ *
+ */
+public class ParameterMap extends HashMap {
+
+
+ /** Default constructor.
+ *
+ */
+ public ParameterMap() {
+ super();
+ }
+
+ /** Construcotr with initial size.
+ * @param arg0
+ */
+ public ParameterMap(int arg0) {
+ super(arg0);
+ }
+
+ /** Get the Parameter with the corresponding key.
+ *
+ * Returns null if no element is associated with key.
+ *
+ * @param key
+ * @return
+ */
+ public Parameter get(String key) {
+ return (Parameter) super.get(key);
+ }
+
+ public Object getValue(String key) {
+ Parameter p = (Parameter) super.get(key);
+ return (p != null) ? p.getValue() : null;
+ }
+
+ public String getAsString(String key) {
+ Parameter p = (Parameter) super.get(key);
+ return (p != null) ? p.getAsString() : null;
+ }
+
+ public int getAsInt(String key) {
+ Parameter p = (Parameter) super.get(key);
+ return (p != null) ? p.getAsInt() : 0;
+ }
+
+ public float getAsFloat(String key) {
+ Parameter p = (Parameter) super.get(key);
+ return (p != null) ? p.getAsFloat() : 0f;
+ }
+
+ public boolean getAsBoolean(String key) {
+ Parameter p = (Parameter) super.get(key);
+ return (p != null) ? p.getAsBoolean() : false;
+ }
+
+ /** Add the Parameter to the map with a certain key.
+ *
+ * Returns the value that was previously associated with key.
+ *
+ * @param key
+ * @param val
+ * @return
+ */
+ public Parameter put(String key, Parameter val) {
+ return (Parameter) super.put(key, val);
+ }
+
+ /** Add the Parameter val to the map, using val's name.
+ *
+ * Returns the value that was previously associated with val's name.
+ *
+ * @param val
+ * @return
+ */
+ public Parameter put(Parameter val) {
+ return (Parameter) super.put(val.getName(), val);
+ }
+
+ /** Add a new Parameter with name, default and value.
+ *
+ * Returns the key that was previously associated with name.
+ *
+ * @param name
+ * @param def
+ * @param val
+ * @return
+ */
+ public Parameter putParameter(String name, Object def, Object val) {
+ Parameter p = new Parameter(name, def, val);
+ return (Parameter) super.put(name, p);
+ }
+
+ /** Add a new Parameter with name, default, value and type.
+ *
+ * Returns the key that was previously associated with name.
+ *
+ * @param name
+ * @param def
+ * @param val
+ * @param type
+ * @return
+ */
+ public Parameter putParameter(String name, Object def, Object val, int type) {
+ Parameter p = new Parameter(name, def, val, type);
+ return (Parameter) super.put(name, p);
+ }
+
+ /** Set the value of an existing parameter.
+ *
+ * Sets the value and returns true if the parameter exists.
+ *
+ * @param key
+ * @param val
+ * @return
+ */
+ public boolean setValue(String key, Object val) {
+ Parameter p = get(key);
+ if (p != null) {
+ p.setValue(val);
+ return true;
+ }
+ return false;
+ }
+}
diff -r f4a5cfe37469 -r 4980c969be4c servlet/src/digilib/servlet/Scaler.java
--- a/servlet/src/digilib/servlet/Scaler.java Wed Sep 03 00:54:38 2003 +0200
+++ b/servlet/src/digilib/servlet/Scaler.java Wed Sep 03 00:56:16 2003 +0200
@@ -58,7 +58,7 @@
public class Scaler extends HttpServlet {
// digilib servlet version (for all components)
- public static final String dlVersion = "1.15b1";
+ public static final String dlVersion = "1.16a1";
// Utils instance with debuglevel
Utils util;
@@ -70,6 +70,17 @@
ServletOps servletOp;
// DocuDirCache instance
DocuDirCache dirCache;
+
+ // deny image file
+ File denyImgFile;
+ // error image file
+ File errorImgFile;
+ // subsampling before scaling
+ float minSubsample = 2f;
+ // send files as is?
+ boolean sendFileAllowed = true;
+ // default scaling quality
+ int defaultQuality = 1;
// DigilibConfiguration instance
DigilibConfiguration dlConfig;
@@ -90,6 +101,7 @@
// Debuggin!
//TCTool tctool = new TCTool();
+
System.out.println(
"***** Digital Image Library Servlet (version "
+ dlVersion
@@ -110,19 +122,22 @@
throw new ServletException(e);
}
}
- // set the servlet version
- dlConfig.setServletVersion(dlVersion);
// first we need an Utils
util = dlConfig.getUtil();
// set our AuthOps
- useAuthentication = dlConfig.isUseAuthentication();
- authOp = dlConfig.getAuthOp();
+ useAuthentication = dlConfig.getAsBoolean("use-authorization");
+ authOp = (AuthOps) dlConfig.getValue("servlet.auth.op");
// FileOps instance
fileOp = new FileOps(util);
// AuthOps instance
servletOp = new ServletOps(util);
// DocuDirCache instance
- dirCache = dlConfig.getDirCache();
+ dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache");
+ denyImgFile = new File(dlConfig.getAsString("denied-image"));
+ errorImgFile = new File(dlConfig.getAsString("error-image"));
+ sendFileAllowed = dlConfig.getAsBoolean("sendfile-allowed");
+ minSubsample = dlConfig.getAsFloat("subsample-minimum");
+ defaultQuality = dlConfig.getAsInt("default-quality");
}
/** Process the HTTP Get request*/
@@ -183,7 +198,7 @@
// use hires images only
boolean hiresOnly = false;
// interpolation to use for scaling
- int scaleQual = 1;
+ int scaleQual = defaultQuality;
// send html error message (or image file)
boolean errorMsgHtml = false;
// mirror the image
@@ -265,7 +280,7 @@
} else if (dlRequest.isOption("file")) {
scaleToFit = false;
absoluteScale = false;
- if (dlConfig.isSendFileAllowed()) {
+ if (sendFileAllowed) {
cropToFit = false;
sendFile = true;
} else {
@@ -336,9 +351,7 @@
"ERROR: Unauthorized access!",
response);
} else {
- servletOp.sendFile(
- new File(dlConfig.getDenyImgFileName()),
- response);
+ servletOp.sendFile(denyImgFile, response);
}
return;
}
@@ -445,7 +458,8 @@
if ((loresOnly
&& imageSendable
&& fileToLoad.getSize().isSmallerThan(expectedSourceSize))
- || (!(loresOnly || hiresOnly) && fileToLoad.getSize().fitsIn(expectedSourceSize))
+ || (!(loresOnly || hiresOnly)
+ && fileToLoad.getSize().fitsIn(expectedSourceSize))
|| sendFile) {
util.dprintln(1, "Sending File as is.");
@@ -630,7 +644,7 @@
if (scaleQual > 0) {
subsamp =
Math.max(
- Math.floor(subf / dlConfig.getMinSubsample()),
+ Math.floor(subf / minSubsample),
1d);
} else {
subsamp = Math.floor(subf);
@@ -762,9 +776,7 @@
"ERROR: File IO Error: " + e,
response);
} else {
- servletOp.sendFile(
- new File(dlConfig.getErrorImgFileName()),
- response);
+ servletOp.sendFile(errorImgFile, response);
}
} catch (FileOpException ex) {
} // so we don't get a loop
@@ -776,9 +788,7 @@
"ERROR: Authorization error: " + e,
response);
} else {
- servletOp.sendFile(
- new File(dlConfig.getErrorImgFileName()),
- response);
+ servletOp.sendFile(errorImgFile, response);
}
} catch (FileOpException ex) {
} // so we don't get a loop
@@ -790,9 +800,7 @@
"ERROR: Image Operation Error: " + e,
response);
} else {
- servletOp.sendFile(
- new File(dlConfig.getErrorImgFileName()),
- response);
+ servletOp.sendFile(errorImgFile, response);
}
} catch (FileOpException ex) {
} // so we don't get a loop
@@ -805,9 +813,7 @@
"ERROR: Other Image Operation Error: " + e,
response);
} else {
- servletOp.sendFile(
- new File(dlConfig.getErrorImgFileName()),
- response);
+ servletOp.sendFile(errorImgFile, response);
}
} catch (FileOpException ex) {
} // so we don't get a loop