Mercurial > hg > digilib-old
changeset 161:ace2a4a0ba74
servlet version 1.16a4
- rather experimental
- new Texter servlet for sending text
- reads and caches text files in DocuDirCache
- DocuFile renamed to ImageFile (-Set)
- new TextFile
author | robcast |
---|---|
date | Tue, 16 Sep 2003 18:32:28 +0200 |
parents | aecb57fb8f96 |
children | dd070f97e446 |
files | client/digitallibrary/WEB-INF/lib/DigilibServlet.jar servlet/src/digilib/servlet/DigilibConfiguration.java servlet/src/digilib/servlet/Scaler.java servlet/src/digilib/servlet/Texter.java |
diffstat | 4 files changed, 220 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/servlet/DigilibConfiguration.java Tue Sep 16 18:32:00 2003 +0200 +++ b/servlet/src/digilib/servlet/DigilibConfiguration.java Tue Sep 16 18:32:28 2003 +0200 @@ -99,7 +99,7 @@ // 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'); + putParameter("auth-file", "digilib-auth.xml", null, 'f'); // sending image files as-is allowed putParameter("sendfile-allowed", Boolean.TRUE, null, 'f'); // Debug level @@ -199,7 +199,8 @@ util.setDebugLevel(getAsInt("debug-level")); // directory cache String[] bd = (String[]) getValue("basedir-list"); - DocuDirCache dirCache = new DocuDirCache(bd); + int[] fcs = { FileOps.CLASS_IMAGE, FileOps.CLASS_TEXT}; + DocuDirCache dirCache = new DocuDirCache(bd, fcs); setValue("servlet.dir.cache", dirCache); // useAuthentication if (getAsBoolean("use-authorization")) { @@ -207,11 +208,18 @@ //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); + } AuthOps authOp = new XMLAuthOps(util, authConfPath); setValue("servlet.auth.op", authOp); } // DocuImage class - docuImageClass = (Class) getValue("servlet.docuimage.class"); + String s = getAsString("docuimage-class"); + Class cl = Class.forName(getAsString("docuimage-class")); + docuImageClass = Class.forName(getAsString("docuimage-class")); + setValue("servlet.docuimage.class", docuImageClass); } /** Creates a new DocuImage instance.
--- a/servlet/src/digilib/servlet/Scaler.java Tue Sep 16 18:32:00 2003 +0200 +++ b/servlet/src/digilib/servlet/Scaler.java Tue Sep 16 18:32:28 2003 +0200 @@ -43,8 +43,8 @@ import digilib.image.ImageOpException; import digilib.image.ImageSize; import digilib.io.DocuDirCache; -import digilib.io.DocuFile; -import digilib.io.DocuFileset; +import digilib.io.ImageFile; +import digilib.io.ImageFileset; import digilib.io.FileOpException; import digilib.io.FileOps; @@ -58,7 +58,7 @@ public class Scaler extends HttpServlet { // digilib servlet version (for all components) - public static final String dlVersion = "1.16a2"; + public static final String dlVersion = "1.16a4"; // Utils instance with debuglevel Utils util; @@ -70,7 +70,7 @@ ServletOps servletOp; // DocuDirCache instance DocuDirCache dirCache; - + // deny image file File denyImgFile; // error image file @@ -320,8 +320,8 @@ //"big" try for all file/image actions try { - // DocuFileset of the image to load - DocuFileset fileset = null; + // ImageFileset of the image to load + ImageFileset fileset = null; // new DocuInfo instance DocuInfo docuInfo = new ImageLoaderImageInfoDocuInfo(); @@ -359,8 +359,12 @@ } // find the file(set) - DocuFile fileToLoad; - fileset = dirCache.getFileset(loadPathName, dlRequest.getPn()); + ImageFile fileToLoad; + fileset = + (ImageFileset) dirCache.getFile( + loadPathName, + dlRequest.getPn(), + FileOps.CLASS_IMAGE); if (fileset == null) { throw new FileOpException( "File " @@ -642,10 +646,7 @@ subf = 1 / scaleXY; // for higher quality reduce subsample factor by minSubsample if (scaleQual > 0) { - subsamp = - Math.max( - Math.floor(subf / minSubsample), - 1d); + subsamp = Math.max(Math.floor(subf / minSubsample), 1d); } else { subsamp = Math.floor(subf); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/servlet/Texter.java Tue Sep 16 18:32:28 2003 +0200 @@ -0,0 +1,196 @@ +/* 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 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 + * + */ +package digilib.servlet; + +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import digilib.Utils; +import digilib.auth.AuthOps; +import digilib.io.DocuDirCache; +import digilib.io.FileOpException; +import digilib.io.FileOps; +import digilib.io.TextFile; + +/** Servlet for displaying text + * + * @author casties + * + */ +public class Texter extends HttpServlet { + + /** Servlet version */ + public static String tlVersion = "0.1a1"; + /** DigilibConfiguration instance */ + DigilibConfiguration dlConfig = null; + /** Utils instance with debuglevel */ + Utils util; + /** FileOps instance */ + FileOps fileOp; + /** AuthOps instance */ + AuthOps authOp; + /** ServletOps instance */ + ServletOps servletOp; + /** DocuDirCache instance */ + DocuDirCache dirCache; + + /** use authentication */ + boolean useAuthentication = false; + + /* (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 + + ") *****"); + + // get our ServletContext + ServletContext context = config.getServletContext(); + // see if there is a Configuration instance + dlConfig = + (DigilibConfiguration) context.getAttribute( + "digilib.servlet.configuration"); + if (dlConfig == null) { + // create new Configuration + try { + dlConfig = new DigilibConfiguration(config); + context.setAttribute("digilib.servlet.configuration", dlConfig); + } catch (Exception e) { + throw new ServletException(e); + } + } + // first we need an Utils + util = dlConfig.getUtil(); + // set our AuthOps + 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 = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); + } + + /* (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 { + // create new request with defaults + DigilibRequest dlReq = new DigilibRequest(); + // set with request parameters + dlReq.setWithRequest(request); + // add DigilibRequest to ServletRequest + request.setAttribute("digilib.servlet.request", dlReq); + // do the processing + processRequest(request, response); + } + + /* (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 { + // create new request with defaults + DigilibRequest dlReq = new DigilibRequest(); + // set with request parameters + dlReq.setWithRequest(request); + // add DigilibRequest to ServletRequest + request.setAttribute("digilib.servlet.request", dlReq); + // do the processing + processRequest(request, response); + } + + protected void processRequest( + HttpServletRequest request, + HttpServletResponse response) + throws ServletException, IOException { + + /* + * request parameters + */ + + DigilibRequest dlRequest = + (DigilibRequest) request.getAttribute("digilib.servlet.request"); + + try { + + /* + * find the file to load/send + */ + + // get PathInfo + String loadPathName = dlRequest.getFilePath(); + // find the file(set) + TextFile fileToLoad = + (TextFile) dirCache.getFile( + loadPathName, + dlRequest.getPn(), + FileOps.CLASS_TEXT); + if (fileToLoad == null) { + throw new FileOpException( + "File " + + loadPathName + + "(" + + dlRequest.getPn() + + ") not found."); + } + + /* + * do something with the file + */ + + + + /* + * send the result + */ + + servletOp.sendFile(fileToLoad.getFile(), response); + + + } catch (FileOpException e) { + util.dprintln(1, "ERROR: File IO Error: " + e); + try { + ServletOps.htmlMessage("ERROR: File IO Error: " + e, response); + } catch (FileOpException ex) { + } // so we don't get a loop + } + + } + +}