Mercurial > hg > digilib-old
changeset 246:aaf6eace011d
Servlet version 1.19b4
- bug fixes
- new stuff in DocumentBean
author | robcast |
---|---|
date | Wed, 04 Aug 2004 20:42:48 +0200 (2004-08-04) |
parents | e93a1d525df2 |
children | ffea3e39d9ee |
files | servlet/src/digilib/io/DocuDirCache.java servlet/src/digilib/io/DocuDirectory.java servlet/src/digilib/io/FileOps.java servlet/src/digilib/io/XMLMetaLoader.java servlet/src/digilib/servlet/DigilibRequest.java servlet/src/digilib/servlet/DocumentBean.java servlet/src/digilib/servlet/Scaler.java servlet/src/digilib/servlet/ServletOps.java servlet/src/digilib/servlet/Texter.java |
diffstat | 9 files changed, 340 insertions(+), 210 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/io/DocuDirCache.java Wed Aug 04 20:36:08 2004 +0200 +++ b/servlet/src/digilib/io/DocuDirCache.java Wed Aug 04 20:42:48 2004 +0200 @@ -160,6 +160,8 @@ * digilib pathname * @param in * file index + * @param fc + * file class * @return */ public DocuDirent getFile(String fn, int in, int fc) { @@ -187,7 +189,7 @@ */ // get the parent directory string (like we store it in the // cache) - String d = fn.substring(0, fn.lastIndexOf("/")); + String d = FileOps.parent(fn); // try it in the cache dd = (DocuDirectory) map.get(d); if (dd == null) {
--- a/servlet/src/digilib/io/DocuDirectory.java Wed Aug 04 20:36:08 2004 +0200 +++ b/servlet/src/digilib/io/DocuDirectory.java Wed Aug 04 20:42:48 2004 +0200 @@ -365,6 +365,10 @@ return -1; } } + // empty directory? + if (list[fc] == null) { + return -1; + } // linear search -> worst performance int n = list[fc].size(); for (int i = 0; i < n; i++) {
--- a/servlet/src/digilib/io/FileOps.java Wed Aug 04 20:36:08 2004 +0200 +++ b/servlet/src/digilib/io/FileOps.java Wed Aug 04 20:42:48 2004 +0200 @@ -178,6 +178,24 @@ return ""; } + /** + * Extract the parent directory of a (digilib) path name. + * + * Returns the parent directory of a path name. The parent is the part before + * the last slash in the path name. If the path name has no slash the empty + * string is returned. + * + * @param fn + * @return + */ + public static String parent(String fn) { + int i = fn.lastIndexOf('/'); + if (i > 0) { + return fn.substring(0, i); + } + return ""; + } + /** Normalize a path name. * * Removes leading and trailing slashes. Returns null if there is other
--- a/servlet/src/digilib/io/XMLMetaLoader.java Wed Aug 04 20:36:08 2004 +0200 +++ b/servlet/src/digilib/io/XMLMetaLoader.java Wed Aug 04 20:42:48 2004 +0200 @@ -88,7 +88,7 @@ StringBuffer s = new StringBuffer(); for (int i = 0; i < attrs.getLength(); i++) { String key = getName(attrs.getLocalName(i), attrs.getQName(i)); - s.append(" "+key+"=\""+attrs.getValue(i)); + s.append(" "+key+"=\""+attrs.getValue(i)+"\""); } return s.toString(); }
--- a/servlet/src/digilib/servlet/DigilibRequest.java Wed Aug 04 20:36:08 2004 +0200 +++ b/servlet/src/digilib/servlet/DigilibRequest.java Wed Aug 04 20:42:48 2004 +0200 @@ -4,22 +4,22 @@ * lightweight class carrying all parameters for a request to digilib * - Digital Image Library servlet components + Digital Image Library servlet components - Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de), - Christian Luginbuehl + Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de), + Christian Luginbuehl - 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 + 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 + 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 27. August 2002, 19:43 */ @@ -51,25 +51,35 @@ import digilib.image.DocuImage; import digilib.io.FileOps; -/** Class holding the parameters of a digilib user request. - * The parameters are mostly named like the servlet parameters:<br> - * request_path: url of the page/document.<br> fn: url of the page/document. - * <br> pn: page number.<br> dw: width of result window in pixels.<br> dh: - * height of result window in pixels.<br> wx: left edge of image area (float - * from 0 to 1).<br> wy: top edge of image area (float from 0 to 1).<br> ww: - * width of image area(float from 0 to 1).<br> wh: height of image area(float - * from 0 to 1).<br> ws: scale factor.<br> mo: special options like 'fit' for - * gifs.<br> mk: list of marks.<br> pt: total number of pages (generated by - * sevlet).<br> baseURL: base URL (from http:// to below /servlet). +/** + * Class holding the parameters of a digilib user request. The parameters are + * mostly named like the servlet parameters: <br> + * request_path: url of the page/document. <br> + * fn: url of the page/document. <br> + * pn: page number. <br> + * dw: width of result window in pixels. <br> + * dh: height of result window in pixels. <br> + * wx: left edge of image area (float from 0 to 1). <br> + * wy: top edge of image area (float from 0 to 1). <br> + * ww: width of image area(float from 0 to 1). <br> + * wh: height of image area(float from 0 to 1). <br> + * ws: scale factor. <br> + * mo: special options like 'fit' for gifs. <br> + * mk: list of marks. <br> + * pt: total number of pages (generated by sevlet). <br> + * baseURL: base URL (from http:// to below /servlet). * * @author casties - * + * */ public class DigilibRequest extends ParameterMap { private Logger logger = Logger.getLogger(this.getClass()); + private boolean boolRDF = false; // use RDF Parameters + private DocuImage image; // internal DocuImage instance for this request + private ServletRequest servletRequest; // internal ServletRequest /** Creates a new instance of DigilibRequest and sets default values. */ @@ -78,8 +88,8 @@ super(30); /* - * Definition of parameters and default values. - * Parameter of type 's' are for the servlet. + * Definition of parameters and default values. Parameter of type 's' + * are for the servlet. */ // url of the page/document (second part) @@ -138,7 +148,7 @@ * Parameter of type 'c' are for the clients internal use */ - // display level of digilib (0 = just image, 1 = one HTML page + // display level of digilib (0 = just image, 1 = one HTML page // 2 = in frameset, 3 = XUL-'frameset' // 4 = XUL-Sidebar ) newParameter("lv", new Integer(2), null, 'c'); @@ -149,9 +159,9 @@ } - /** Creates a new instance of DigilibRequest with parameters from a - * ServletRequest. - * All undefined parameters are set to default values. + /** + * Creates a new instance of DigilibRequest with parameters from a + * ServletRequest. All undefined parameters are set to default values. * * @param request */ @@ -160,7 +170,8 @@ setWithRequest(request); } - /** Populate the request object with data from a ServletRequest. + /** + * Populate the request object with data from a ServletRequest. * * * @param request @@ -183,9 +194,11 @@ setBaseURL((HttpServletRequest) request); } - /** Populate a request from a string in the old "++++" parameter form. - * - * @param queryString String with paramters in the old "+++" form. + /** + * Populate a request from a string in the old "++++" parameter form. + * + * @param queryString + * String with paramters in the old "+++" form. */ public void setWithOldString(String queryString) { if (queryString == null) { @@ -286,9 +299,10 @@ } } - /** Return the request parameters as a String in the parameter form + /** + * Return the request parameters as a String in the parameter form * 'fn=/icons&pn=1'. Empty (undefined) fields are not included. - * + * * @return String of request parameters in parameter form. */ public String getAsString() { @@ -298,12 +312,12 @@ Parameter p = (Parameter) i.next(); String name = p.getName(); /* - * handling special cases + * handling special cases */ - // request_path adds to fn + // request_path adds to fn if (name.equals("fn")) { - s.append( - "&fn=" + getAsString("request.path") + getAsString("fn")); + s.append("&fn=" + getAsString("request.path") + + getAsString("fn")); continue; } /* @@ -320,8 +334,9 @@ return s.toString(); } - /** Returns request parameters in old '++++' form. - * + /** + * Returns request parameters in old '++++' form. + * * @return String with parameters in old '++++' form. */ public String getAsOldString() { @@ -339,17 +354,17 @@ return s.toString(); } - /** Set request parameters from javax.servlet.ServletRequest. Uses the Requests - * getParameter methods for 'fn=foo' style parameters. - * - * @param request ServletRequest to get parameters from. + /** + * Set request parameters from javax.servlet.ServletRequest. Uses the + * Requests getParameter methods for 'fn=foo' style parameters. + * + * @param request + * ServletRequest to get parameters from. */ public void setWithParamRequest(ServletRequest request) { setValue("servlet.request", request); // go through all request parameters - for (Enumeration i = request.getParameterNames(); - i.hasMoreElements(); - ) { + for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) { String name = (String) i.nextElement(); // is this a known parameter? if (this.containsKey(name)) { @@ -369,8 +384,8 @@ } /** - * - * + * + * */ public void setWithRDF(ServletRequest request) { String strRDF; @@ -403,8 +418,8 @@ StringReader sr = new StringReader(strRDF); model.read(sr, ""); // get Property fn -> digilib - Property p = - model.getProperty("http://echo.unibe.ch/digilib/rdf#", "fn"); + Property p = model.getProperty("http://echo.unibe.ch/digilib/rdf#", + "fn"); if (p != null) { // get URI String strURI = null; @@ -412,8 +427,8 @@ if (i.hasNext()) { strURI = "urn:echo:" + i.next().toString(); Resource r = model.getResource(strURI); - Selector selector = - new SelectorImpl(r, null, (RDFNode) null); + Selector selector = new SelectorImpl(r, null, + (RDFNode) null); // list the statements in the graph StmtIterator iter = model.listStatements(selector); // add predicate and object to Hashtable @@ -434,10 +449,8 @@ // object is a literal strValue = object.toString(); } - String strDigilibKey = - strKey.substring( - strKey.indexOf("#") + 1, - strKey.length()); + String strDigilibKey = strKey.substring(strKey + .indexOf("#") + 1, strKey.length()); hashParams.put(strDigilibKey, strValue); } } @@ -448,22 +461,29 @@ return hashParams; } - /** Test if option string <code>opt</code> is set. - * Checks if the substring <code>opt</code> is contained in the options - * string <code>param</code>. + /** + * Test if option string <code>opt</code> is set. Checks if the substring + * <code>opt</code> is contained in the options string <code>param</code>. * - * @param opt Option string to be tested. + * @param opt + * Option string to be tested. * @return boolean */ public boolean hasOption(String param, String opt) { String s = getAsString(param); - if ((s != null) && (s.indexOf(opt) >= 0)) { - return true; + if (s != null) { + StringTokenizer i = new StringTokenizer(s, ","); + while (i.hasMoreTokens()) { + if (i.nextToken().equals(opt)) { + return true; + } + } } return false; } - /** The image file path to be accessed. + /** + * The image file path to be accessed. * * The mage file path is assembled from the servlets RequestPath and * Parameter fn and normalized. @@ -478,8 +498,12 @@ /* Property getter and setter */ - /** Set the requests base URL parameter from a javax.sevlet.http.HttpServletRequest. - * @param request HttpServletRequest to set the base URL. + /** + * Set the requests base URL parameter from a + * javax.sevlet.http.HttpServletRequest. + * + * @param request + * HttpServletRequest to set the base URL. */ public void setBaseURL(javax.servlet.http.HttpServletRequest request) { String baseURL = null; @@ -490,9 +514,7 @@ baseURL = s.substring(0, eop); } else { // fall back - baseURL = - "http://" - + request.getServerName() + baseURL = "http://" + request.getServerName() + "/docuserver/digitallibrary"; } setValue("base.url", baseURL); @@ -500,6 +522,7 @@ /** * Returns the image. + * * @return DocuImage */ public DocuImage getImage() { @@ -508,7 +531,9 @@ /** * Sets the image. - * @param image The image to set + * + * @param image + * The image to set */ public void setImage(DocuImage image) { this.image = image; @@ -526,4 +551,4 @@ return servletRequest; } -} +} \ No newline at end of file
--- a/servlet/src/digilib/servlet/DocumentBean.java Wed Aug 04 20:36:08 2004 +0200 +++ b/servlet/src/digilib/servlet/DocumentBean.java Wed Aug 04 20:42:48 2004 +0200 @@ -1,22 +1,23 @@ -/* DocumentBean -- Access control bean for JSP - - Digital Image Library servlet components - - Copyright (C) 2001, 2002, 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 - -*/ +/* + * DocumentBean -- Access control bean for JSP + * + * Digital Image Library servlet components + * + * Copyright (C) 2001, 2002, 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 + * + */ package digilib.servlet; @@ -39,18 +40,25 @@ // general logger Logger logger = Logger.getLogger("digilib.docubean"); + // AuthOps object to check authorization private AuthOps authOp; + // use authorization database private boolean useAuthentication = true; + // path to add for authenticated access private String authURLPath = ""; + // DocuDirCache private DocuDirCache dirCache = null; // DigilibConfiguration object private DigilibConfiguration dlConfig; + // DigilibRequest object + private DigilibRequest dlRequest = null; + /** * Constructor for DocumentBean. */ @@ -71,9 +79,8 @@ // get our ServletContext ServletContext context = conf.getServletContext(); // see if there is a Configuration instance - dlConfig = - (DigilibConfiguration) context.getAttribute( - "digilib.servlet.configuration"); + dlConfig = (DigilibConfiguration) context + .getAttribute("digilib.servlet.configuration"); if (dlConfig == null) { // create new Configuration try { @@ -88,37 +95,37 @@ dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); /* - * authentication + * authentication */ 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!"); + throw new ServletException( + "ERROR: use-authorization configured but no AuthOp!"); } } /** - * check if the request must be authorized to access filepath + * check if the request must be authorized to access filepath */ public boolean isAuthRequired(DigilibRequest request) - throws AuthOpException { + throws AuthOpException { logger.debug("isAuthRequired"); return useAuthentication ? authOp.isAuthRequired(request) : false; } /** - * check if the request is allowed to access filepath + * check if the request is allowed to access filepath */ - public boolean isAuthorized(DigilibRequest request) - throws AuthOpException { + public boolean isAuthorized(DigilibRequest request) throws AuthOpException { logger.debug("isAuthorized"); return useAuthentication ? authOp.isAuthorized(request) : true; } /** - * return a list of authorization roles needed for request - * to access the specified path + * return a list of authorization roles needed for request to access the + * specified path */ public List rolesForPath(DigilibRequest request) throws AuthOpException { logger.debug("rolesForPath"); @@ -130,46 +137,48 @@ */ public boolean isRoleAuthorized(List roles, DigilibRequest request) { logger.debug("isRoleAuthorized"); - return useAuthentication - ? authOp.isRoleAuthorized(roles, request) - : true; + return useAuthentication ? authOp.isRoleAuthorized(roles, request) + : true; } /** * check for authenticated access and redirect if necessary */ - public boolean doAuthentication( - DigilibRequest request, - HttpServletResponse response) - throws Exception { + public boolean doAuthentication(HttpServletResponse response) + throws Exception { + return doAuthentication(dlRequest, response); + } + + /** + * check for authenticated access and redirect if necessary + */ + public boolean doAuthentication(DigilibRequest request, + HttpServletResponse response) throws Exception { logger.debug("doAuthentication"); if (!useAuthentication) { // shortcut if no authentication return true; } // check if we are already authenticated - if (((HttpServletRequest) request.getServletRequest()).getRemoteUser() - == null) { + if (((HttpServletRequest) request.getServletRequest()).getRemoteUser() == null) { logger.debug("unauthenticated so far"); // if not maybe we must? if (isAuthRequired(request)) { logger.debug("auth required, redirect"); // we are not yet authenticated -> redirect - response.sendRedirect( - authURLPath + response.sendRedirect(authURLPath + ((HttpServletRequest) request.getServletRequest()) - .getServletPath() + .getServletPath() + "?" + ((HttpServletRequest) request.getServletRequest()) - .getQueryString()); + .getQueryString()); } } return true; } /** - * get the first page number in the directory - * (not yet functional) + * get the first page number in the directory (not yet functional) */ public int getFirstPage(DigilibRequest request) { logger.debug("getFirstPage"); @@ -177,14 +186,19 @@ } /** - * get the number of pages/files in the directory + * get the number of pages/files in the directory + */ + public int getNumPages() throws Exception { + return getNumPages(dlRequest); + } + + /** + * get the number of pages/files in the directory */ public int getNumPages(DigilibRequest request) throws Exception { logger.debug("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(); } @@ -193,10 +207,69 @@ /** * Returns the dlConfig. + * * @return DigilibConfiguration */ public DigilibConfiguration getDlConfig() { return dlConfig; } -} + /** + * returns if the zoom area in the request can be moved + * + * @return + */ + public boolean canMoveRight() { + float ww = dlRequest.getAsFloat("ww"); + float wx = dlRequest.getAsFloat("wx"); + return (ww + wx < 1.0); + } + + /** + * returns if the zoom area in the request can be moved + * + * @return + */ + public boolean canMoveLeft() { + float ww = dlRequest.getAsFloat("ww"); + float wx = dlRequest.getAsFloat("wx"); + return ((ww < 1.0) && (wx > 0)); + } + + /** + * returns if the zoom area in the request can be moved + * + * @return + */ + public boolean canMoveUp() { + float wh = dlRequest.getAsFloat("wh"); + float wy = dlRequest.getAsFloat("wy"); + return ((wh < 1.0) && (wy > 0)); + } + + /** + * returns if the zoom area in the request can be moved + * + * @return + */ + public boolean canMoveDown() { + float wh = dlRequest.getAsFloat("wh"); + float wy = dlRequest.getAsFloat("wy"); + return (wh + wy < 1.0); + } + + /** + * @return Returns the dlRequest. + */ + public DigilibRequest getRequest() { + return dlRequest; + } + + /** + * @param dlRequest + * The dlRequest to set. + */ + public void setRequest(DigilibRequest dlRequest) { + this.dlRequest = dlRequest; + } +} \ No newline at end of file
--- a/servlet/src/digilib/servlet/Scaler.java Wed Aug 04 20:36:08 2004 +0200 +++ b/servlet/src/digilib/servlet/Scaler.java Wed Aug 04 20:42:48 2004 +0200 @@ -59,7 +59,7 @@ public class Scaler extends HttpServlet { // digilib servlet version (for all components) - public static final String dlVersion = "1.19b1"; + public static final String dlVersion = "1.19b4"; // logger for accounting requests Logger accountlog = Logger.getLogger("account.request");
--- a/servlet/src/digilib/servlet/ServletOps.java Wed Aug 04 20:36:08 2004 +0200 +++ b/servlet/src/digilib/servlet/ServletOps.java Wed Aug 04 20:42:48 2004 +0200 @@ -5,10 +5,10 @@ * * Copyright (C) 2001, 2002 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. + * 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 @@ -47,8 +47,8 @@ */ public static String[] getPathArray(String paths) { // split list into directories - StringTokenizer dirs = - new StringTokenizer(paths, java.io.File.pathSeparator); + StringTokenizer dirs = new StringTokenizer(paths, + java.io.File.pathSeparator); int n = dirs.countTokens(); if (n < 1) { return null; @@ -61,11 +61,11 @@ return pathArray; } - - /** get a real file name for a config file pathname. + /** + * 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. + * 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 @@ -76,24 +76,31 @@ // is the filename absolute? if (!f.isAbsolute()) { // relative path -> use getRealPath to resolve in WEB-INF - filename = - sc.getServletContext().getRealPath("WEB-INF/" + filename); + filename = sc.getServletContext() + .getRealPath("WEB-INF/" + filename); } return filename; } - - + /** * print a servlet response and exit */ - public static void htmlMessage(String s, HttpServletResponse response) - throws IOException { + public static void htmlMessage(String msg, HttpServletResponse response) + throws IOException { + htmlMessage("Scaler", msg, response); + } + + /** + * print a servlet response and exit + */ + public static void htmlMessage(String title, String msg, + HttpServletResponse response) throws IOException { response.setContentType("text/html; charset=iso-8859-1"); PrintWriter out = response.getWriter(); out.println("<html>"); - out.println("<head><title>Scaler</title></head>"); + out.println("<head><title>" + title + "</title></head>"); out.println("<body>"); - out.println("<p>" + s + "</p>"); + out.println("<p>" + msg + "</p>"); out.println("</body></html>"); } @@ -114,7 +121,7 @@ * Exception is thrown for a IOException. */ public static void sendFile(File f, String mt, ServletResponse response) - throws FileOpException { + throws FileOpException { logger.debug("sendRawFile(" + mt + ", " + f + ")"); if (mt == null) { // auto-detect mime-type @@ -140,4 +147,4 @@ } } -} +} \ No newline at end of file
--- a/servlet/src/digilib/servlet/Texter.java Wed Aug 04 20:36:08 2004 +0200 +++ b/servlet/src/digilib/servlet/Texter.java Wed Aug 04 20:42:48 2004 +0200 @@ -1,16 +1,19 @@ -/* - * Texter.java -- Servlet for displaying text Digital Image Library servlet - * components Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) +/* Texter.java -- Servlet for displaying text + * 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 + * 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 15.09.2003 by - * casties + * Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 15.09.2003 by casties */ + package digilib.servlet; import java.io.IOException; @@ -35,22 +38,28 @@ * * * @author casties - * + * */ public class Texter extends HttpServlet { /** Servlet version */ - public static String tlVersion = "0.1a3"; + public static String tlVersion = "0.1b1"; + /** DigilibConfiguration instance */ DigilibConfiguration dlConfig = null; + /** general logger */ Logger logger = Logger.getLogger("digilib.texter"); + /** FileOps instance */ FileOps fileOp; + /** AuthOps instance */ AuthOps authOp; + /** ServletOps instance */ ServletOps servletOp; + /** DocuDirCache instance */ DocuDirCache dirCache; @@ -58,22 +67,21 @@ boolean useAuthentication = false; /* - * (non-Javadoc) @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) + * (non-Javadoc) + * + * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) */ public void init(ServletConfig config) throws ServletException { super.init(config); - System.out.println( - "***** Digital Image Library Text Servlet (version " - + tlVersion - + ") *****"); - + System.out.println("***** Digital Image Library Text Servlet (version " + + tlVersion + ") *****"); + // get our ServletContext ServletContext context = config.getServletContext(); // see if there is a Configuration instance - dlConfig = - (DigilibConfiguration) context.getAttribute( - "digilib.servlet.configuration"); + dlConfig = (DigilibConfiguration) context + .getAttribute("digilib.servlet.configuration"); if (dlConfig == null) { // create new Configuration try { @@ -84,11 +92,9 @@ } } // say hello in the log file - logger.info( - "***** Digital Image Library Text Servlet (version " - + tlVersion - + ") *****"); - + logger.info("***** Digital Image Library Text Servlet (version " + + tlVersion + ") *****"); + // set our AuthOps useAuthentication = dlConfig.getAsBoolean("use-authorization"); authOp = (AuthOps) dlConfig.getValue("servlet.auth.op"); @@ -97,13 +103,13 @@ } /* - * (non-Javadoc) @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, - * javax.servlet.http.HttpServletResponse) + * (non-Javadoc) + * + * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) */ - protected void doGet( - HttpServletRequest request, - HttpServletResponse response) - throws ServletException, IOException { + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { // create new request with defaults DigilibRequest dlReq = new DigilibRequest(); // set with request parameters @@ -115,13 +121,13 @@ } /* - * (non-Javadoc) @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, - * javax.servlet.http.HttpServletResponse) + * (non-Javadoc) + * + * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) */ - protected void doPost( - HttpServletRequest request, - HttpServletResponse response) - throws ServletException, IOException { + protected void doPost(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { // create new request with defaults DigilibRequest dlReq = new DigilibRequest(); // set with request parameters @@ -132,31 +138,28 @@ processRequest(request, response); } - protected void processRequest( - HttpServletRequest request, - HttpServletResponse response) - throws ServletException, IOException { +protected void processRequest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { /* * request parameters */ - DigilibRequest dlRequest = - (DigilibRequest) request.getAttribute("digilib.servlet.request"); + DigilibRequest dlRequest = (DigilibRequest) request.getAttribute("digilib.servlet.request"); try { /* * find the file to load/send */ - if (this.getTextFile(dlRequest, "/txt") != null) { - ServletOps.sendFile( - this.getTextFile(dlRequest, "txt").getFile(), - null, response); - } else if (this.getTextFile(dlRequest, "") != null) { - ServletOps.sendFile( - this.getTextFile(dlRequest, "").getFile(), - null, response); + TextFile f = getTextFile(dlRequest, "/txt"); + if (f != null) { + ServletOps.sendFile(f.getFile(), null, response); } else { - ServletOps.htmlMessage("No Text-File!", response); + f = getTextFile(dlRequest, ""); + if (f != null) { + ServletOps.sendFile(f.getFile(), null, response); + } else { + ServletOps.htmlMessage("No Text-File!", response); + } } } catch (FileOpException e) { @@ -166,26 +169,24 @@ } catch (FileOpException ex) { } // so we don't get a loop } - } + } + /** * Looks for a file in the given subDirectory. * * @param dlRequest - * The received request which has the file path. + * The received request which has the file path. * @param subDirectory - * The subDirectory of the file path where the file should be - * found. + * The subDirectory of the file path where the file should + * be found. * @return The wanted Textfile or null if there wasn't a file. */ - private TextFile getTextFile( - DigilibRequest dlRequest, - String subDirectory) { + + private TextFile getTextFile(DigilibRequest dlRequest, String subDirectory) { String loadPathName = dlRequest.getFilePath() + subDirectory; // find the file(set) - return (TextFile) dirCache.getFile( - loadPathName, - dlRequest.getAsInt("pn"), - FileOps.CLASS_TEXT); + return (TextFile) dirCache.getFile(loadPathName, dlRequest + .getAsInt("pn"), FileOps.CLASS_TEXT); } -} +} \ No newline at end of file