# HG changeset patch # User robcast # Date 1069370251 -3600 # Node ID afe7ff98bb7150497fbdc1899cc5fc5bd1600e12 # Parent bd87f802bea1843059c3d00801dd07f9fa3549b9 Servlet version 1.18b1 - new transfer mode "rawfile" with mime-type application/octet-stream - finally proper logging with Log4J! - therefore a lot of debugging-prints changed - the Util class is now useless - ServletOps and FileOps are now purely static diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/Utils.java --- a/servlet/src/digilib/Utils.java Fri Nov 21 00:11:18 2003 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* Utils -- general utility classes for scaler servlet - - Digital Image Library servlet components - - 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. - - 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; - -public class Utils { - - private int debugLevel = 10; - - public Utils() { - } - - public Utils(int dbg) { - debugLevel = dbg; - } - - public void setDebugLevel(int lvl) { - debugLevel = lvl; - } - public int getDebugLevel() { - return debugLevel; - } - - /** - * Debugging help - * dprintln(1, "blabla"); - * will be printed on stdout if debug >= 1 - */ - public void dprintln(int dbg, String s) { - if (debugLevel >= dbg) { - String ind = ""; - // indent by debuglevel - for (int i = 0; i < dbg; i++) { - ind += " "; - } - System.out.println(ind+s); - } - } -} diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/auth/AuthOpsImpl.java --- a/servlet/src/digilib/auth/AuthOpsImpl.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/auth/AuthOpsImpl.java Fri Nov 21 00:17:31 2003 +0100 @@ -20,10 +20,14 @@ package digilib.auth; +import java.util.List; +import java.util.ListIterator; + import javax.servlet.http.HttpServletRequest; -import java.util.*; -import digilib.*; +import org.apache.log4j.Logger; + +import digilib.Utils; import digilib.servlet.DigilibRequest; /** Basic implementation of AuthOps interface. @@ -33,12 +37,11 @@ */ public abstract class AuthOpsImpl implements AuthOps { - /** Local utils object. */ - protected Utils util; - + /** general logger for this class */ + protected Logger logger = Logger.getLogger(this.getClass()); + /** Default constructor. */ public AuthOpsImpl() { - util = new Utils(); try { init(); } catch (AuthOpException e) { @@ -49,7 +52,6 @@ * @param u utils object. */ public AuthOpsImpl(Utils u) { - util = u; try { init(); } catch (AuthOpException e) { @@ -111,9 +113,9 @@ String s = ""; while (r.hasNext()) { s = (String)r.next(); - util.dprintln(5, "Testing role: "+s); + logger.debug("Testing role: "+s); if (request.isUserInRole(s)) { - util.dprintln(5, "Role Authorized"); + logger.debug("Role Authorized"); return true; } } @@ -128,9 +130,9 @@ String s = ""; while (r.hasNext()) { s = (String)r.next(); - util.dprintln(5, "Testing role: "+s); + logger.debug("Testing role: "+s); if (((HttpServletRequest)request.getServletRequest()).isUserInRole(s)) { - util.dprintln(5, "Role Authorized"); + logger.debug("Role Authorized"); return true; } } diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/auth/HashTree.java --- a/servlet/src/digilib/auth/HashTree.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/auth/HashTree.java Fri Nov 21 00:17:31 2003 +0100 @@ -57,7 +57,6 @@ b += twigSep + twig.nextToken(); } m = (String)table.get(b); - //System.out.println("CHECK: "+b+" = "+m); if (m != null) { if (m.indexOf(leafSep) < 0) { // single leaf diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/auth/XMLAuthOps.java --- a/servlet/src/digilib/auth/XMLAuthOps.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/auth/XMLAuthOps.java Fri Nov 21 00:17:31 2003 +0100 @@ -20,12 +20,13 @@ package digilib.auth; +import java.io.File; +import java.util.HashMap; +import java.util.List; + import javax.servlet.http.HttpServletRequest; -import java.util.*; -import java.io.*; -import digilib.*; -import digilib.io.*; +import digilib.io.XMLListLoader; import digilib.servlet.DigilibRequest; /** Implementation of AuthOps using XML files. @@ -46,8 +47,7 @@ * @param confFile Configuration file name. * @throws AuthOpException Exception thrown on error. */ - public XMLAuthOps(Utils u, String confFile) throws AuthOpException { - util = u; + public XMLAuthOps(String confFile) throws AuthOpException { configFile = confFile; init(); } @@ -69,7 +69,7 @@ * @throws AuthOpException Exception thrown on error. */ public void init() throws AuthOpException { - util.dprintln(10, "xmlauthops.init (" + configFile + ")"); + logger.debug("xmlauthops.init (" + configFile + ")"); HashMap pathList = null; HashMap ipList = null; try { @@ -110,9 +110,7 @@ */ public List rolesForPath(String filepath, HttpServletRequest request) throws digilib.auth.AuthOpException { - util.dprintln( - 4, - "rolesForPath (" + logger.debug("rolesForPath (" + filepath + ") by [" + request.getRemoteAddr() @@ -142,9 +140,7 @@ * @see digilib.auth.AuthOps#rolesForPath(digilib.servlet.DigilibRequest) */ public List rolesForPath(DigilibRequest request) throws AuthOpException { - util.dprintln( - 4, - "rolesForPath (" + logger.debug("rolesForPath (" + request.getFilePath() + ") by [" + request.getServletRequest().getRemoteAddr() diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/image/DocuImageImpl.java --- a/servlet/src/digilib/image/DocuImageImpl.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/image/DocuImageImpl.java Fri Nov 21 00:17:31 2003 +0100 @@ -22,9 +22,11 @@ import java.awt.Rectangle; +import org.apache.log4j.Logger; + import digilib.Utils; +import digilib.io.FileOpException; import digilib.io.ImageFile; -import digilib.io.FileOpException; /** Simple abstract implementation of the DocuImage interface. * @@ -36,6 +38,9 @@ */ public abstract class DocuImageImpl implements DocuImage { + /** logger */ + protected Logger logger = Logger.getLogger(this.getClass()); + /** Internal utils object. */ protected Utils util = null; diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/image/ImageLoaderDocuImage.java --- a/servlet/src/digilib/image/ImageLoaderDocuImage.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java Fri Nov 21 00:17:31 2003 +0100 @@ -43,7 +43,7 @@ /** Implementation of DocuImage using the ImageLoader API of Java 1.4 and Java2D. */ public class ImageLoaderDocuImage extends DocuImageImpl { - + /** image object */ protected BufferedImage img; /** interpolation type */ @@ -62,10 +62,10 @@ quality = qual; // setup interpolation quality if (qual > 0) { - util.dprintln(4, "quality q1"); + logger.debug("quality q1"); interpol = AffineTransformOp.TYPE_BILINEAR; } else { - util.dprintln(4, "quality q0"); + logger.debug("quality q0"); interpol = AffineTransformOp.TYPE_NEAREST_NEIGHBOR; } } @@ -79,7 +79,7 @@ h = img.getHeight(); } } catch (IOException e) { - e.printStackTrace(); + logger.debug("error in getHeight", e); } return h; } @@ -93,19 +93,18 @@ w = img.getWidth(); } } catch (IOException e) { - e.printStackTrace(); + logger.debug("error in getHeight", e); } return w; } /* load image file */ public void loadImage(ImageFile f) throws FileOpException { - util.dprintln(10, "loadImage!"); + logger.debug("loadImage!"); //System.gc(); try { img = ImageIO.read(f.getFile()); if (img == null) { - util.dprintln(3, "ERROR(loadImage): unable to load file"); throw new FileOpException("Unable to load File!"); } } catch (IOException e) { @@ -129,14 +128,13 @@ Iterator readers = ImageIO.getImageReadersByMIMEType(f.getMimetype()); reader = (ImageReader) readers.next(); /* are there more readers? */ - System.out.println("this reader: " + reader.getClass()); + logger.debug("this reader: " + reader.getClass()); while (readers.hasNext()) { - System.out.println("next reader: " + readers.next().getClass()); + logger.debug("next reader: " + readers.next().getClass()); } //*/ reader.setInput(istream); if (reader == null) { - util.dprintln(3, "ERROR(loadImage): unable to load file"); throw new FileOpException("Unable to load File!"); } imgFile = f.getFile(); @@ -157,11 +155,9 @@ // read image img = reader.read(0, readParam); } catch (IOException e) { - util.dprintln(3, "ERROR(loadImage): unable to load file"); throw new FileOpException("Unable to load File!"); } if (img == null) { - util.dprintln(3, "ERROR(loadImage): unable to load file"); throw new FileOpException("Unable to load File!"); } } @@ -169,7 +165,7 @@ /* write image of type mt to Stream */ public void writeImage(String mt, OutputStream ostream) throws FileOpException { - util.dprintln(10, "writeImage!"); + logger.debug("writeImage!"); try { // setup output String type = "png"; @@ -179,7 +175,6 @@ type = "png"; } else { // unknown mime type - util.dprintln(2, "ERROR(writeImage): Unknown mime type " + mt); throw new FileOpException("Unknown mime type: " + mt); } @@ -188,7 +183,7 @@ * image to RGB :-( *Java2D BUG* */ if ((type == "jpeg") && (img.getColorModel().hasAlpha())) { - util.dprintln(2, "BARF: JPEG with transparency!!"); + logger.debug("BARF: JPEG with transparency!!"); int w = img.getWidth(); int h = img.getHeight(); // BufferedImage.TYPE_INT_RGB seems to be fastest (JDK1.4.1, @@ -207,7 +202,6 @@ throw new FileOpException("Error writing image: Unknown image format!"); } } catch (IOException e) { - // e.printStackTrace(); throw new FileOpException("Error writing image."); } } @@ -236,16 +230,13 @@ } scaledImg = scaleOp.filter(img, scaledImg); //DEBUG - util.dprintln( - 3, - "SCALE: " + logger.debug("SCALE: " + scale + " ->" + scaledImg.getWidth() + "x" + scaledImg.getHeight()); if (scaledImg == null) { - util.dprintln(2, "ERROR(cropAndScale): error in scale"); throw new ImageOpException("Unable to scale"); } img = scaledImg; @@ -253,7 +244,7 @@ public void blur(int radius) throws ImageOpException { //DEBUG - util.dprintln(4, "blur: " + radius); + logger.debug("blur: " + radius); // minimum radius is 2 int klen = Math.max(radius, 2); int ksize = klen * klen; @@ -277,7 +268,6 @@ } blurredImg = blurOp.filter(img, blurredImg); if (blurredImg == null) { - util.dprintln(2, "ERROR(cropAndScale): error in scale"); throw new ImageOpException("Unable to scale"); } img = blurredImg; @@ -287,14 +277,11 @@ throws ImageOpException { // setup Crop BufferedImage croppedImg = img.getSubimage(x_off, y_off, width, height); - util.dprintln( - 3, - "CROP:" + croppedImg.getWidth() + "x" + croppedImg.getHeight()); + logger.debug("CROP:" + croppedImg.getWidth() + "x" + croppedImg.getHeight()); //DEBUG // util.dprintln(2, " time // "+(System.currentTimeMillis()-startTime)+"ms"); if (croppedImg == null) { - util.dprintln(2, "ERROR(cropAndScale): error in crop"); throw new ImageOpException("Unable to crop"); } img = croppedImg; @@ -330,9 +317,7 @@ int ncol = img.getColorModel().getNumColorComponents(); if ((ncol != 3) || (rgbm.length != 3) || (rgba.length != 3)) { - util.dprintln( - 2, - "ERROR(enhance): unknown number of color bands or coefficients (" + logger.debug("ERROR(enhance): unknown number of color bands or coefficients (" + ncol + ")"); return; @@ -410,7 +395,6 @@ // calculate new bounding box //Rectangle2D bounds = rotOp.getBounds2D(img); if (rotImg == null) { - util.dprintln(2, "ERROR: error in rotate"); throw new ImageOpException("Unable to rotate"); } img = rotImg; @@ -450,7 +434,6 @@ interpol); BufferedImage mirImg = mirOp.filter(img, null); if (mirImg == null) { - util.dprintln(2, "ERROR: error in mirror"); throw new ImageOpException("Unable to mirror"); } img = mirImg; @@ -458,7 +441,6 @@ /* (non-Javadoc) @see java.lang.Object#finalize() */ protected void finalize() throws Throwable { - //System.out.println("FIN de ImageLoaderDocuImage!"); // we must dispose the ImageReader because it keeps the filehandle // open! reader.dispose(); diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/image/ImageLoaderImageInfoDocuInfo.java --- a/servlet/src/digilib/image/ImageLoaderImageInfoDocuInfo.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/image/ImageLoaderImageInfoDocuInfo.java Fri Nov 21 00:17:31 2003 +0100 @@ -29,6 +29,7 @@ import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; +import org.apache.log4j.Logger; import org.marcoschmidt.image.ImageInfo; import digilib.io.FileOpException; @@ -41,6 +42,8 @@ * */ public class ImageLoaderImageInfoDocuInfo implements DocuInfo { + + private Logger logger = Logger.getLogger(this.getClass()); /* check image size and type and store in ImageFile f */ public boolean checkFile(ImageFile imgf) throws IOException { @@ -76,9 +79,9 @@ } ImageReader reader = (ImageReader) readers.next(); /* are there more readers? */ - System.out.println("this reader: " + reader.getClass()); + logger.debug("this reader: " + reader.getClass()); while (readers.hasNext()) { - System.out.println("next reader: " + readers.next().getClass()); + logger.debug("next reader: " + readers.next().getClass()); } reader.setInput(istream); ImageSize d = diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/image/JAIDocuImage.java --- a/servlet/src/digilib/image/JAIDocuImage.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/image/JAIDocuImage.java Fri Nov 21 00:17:31 2003 +0100 @@ -60,7 +60,6 @@ System.gc(); img = JAI.create("fileload", f.getFile().getAbsolutePath()); if (img == null) { - util.dprintln(3, "ERROR(loadImage): unable to load file"); throw new FileOpException("Unable to load File!"); } } @@ -79,7 +78,6 @@ pb3.add("PNG"); } else { // unknown mime type - util.dprintln(2, "ERROR(writeImage): Unknown mime type " + mt); throw new FileOpException("Unknown mime type: " + mt); } // render output @@ -97,13 +95,13 @@ quality = qual; // setup interpolation quality if (qual > 1) { - util.dprintln(4, "quality q2"); + logger.debug("quality q2"); interpol = Interpolation.getInstance(Interpolation.INTERP_BICUBIC); } else if (qual == 1) { - util.dprintln(4, "quality q1"); + logger.debug("quality q1"); interpol = Interpolation.getInstance(Interpolation.INTERP_BILINEAR); } else { - util.dprintln(4, "quality q0"); + logger.debug("quality q0"); interpol = Interpolation.getInstance(Interpolation.INTERP_NEAREST); } } @@ -152,16 +150,14 @@ } //DEBUG - util.dprintln( - 3, - "SCALE: " + scale + " ->" + img.getWidth() + "x" + img.getHeight()); + logger.debug("SCALE: " + scale + " ->" + img.getWidth() + "x" + img.getHeight()); } public void scaleAll(float scale) throws ImageOpException { RenderedImage scaledImg; //DEBUG - util.dprintln(4, "scaleAll: " + scale); + logger.debug("scaleAll: " + scale); ParameterBlockJAI param = new ParameterBlockJAI("Scale"); param.addSource(img); param.setParameter("xScale", scale); @@ -176,7 +172,6 @@ scaledImg = JAI.create("Scale", param, hint); if (scaledImg == null) { - util.dprintln(2, "ERROR(scale): error in scale"); throw new ImageOpException("Unable to scale"); } img = scaledImg; @@ -185,7 +180,7 @@ public void blur(int radius) throws ImageOpException { RenderedImage blurredImg; //DEBUG - util.dprintln(4, "blur: " + radius); + logger.debug("blur: " + radius); int klen = Math.max(radius, 2); int ksize = klen * klen; float f = 1f / ksize; @@ -204,7 +199,6 @@ BorderExtender.createInstance(BorderExtender.BORDER_COPY)); blurredImg = JAI.create("Convolve", param, hint); if (blurredImg == null) { - util.dprintln(2, "ERROR(scale): error in scale"); throw new ImageOpException("Unable to scale"); } img = blurredImg; @@ -213,7 +207,7 @@ public void scaleBinary(float scale) throws ImageOpException { RenderedImage scaledImg; //DEBUG - util.dprintln(4, "scaleBinary: " + scale); + logger.debug("scaleBinary: " + scale); ParameterBlockJAI param = new ParameterBlockJAI("SubsampleBinaryToGray"); param.addSource(img); @@ -227,7 +221,6 @@ // scale scaledImg = JAI.create("SubsampleBinaryToGray", param, hint); if (scaledImg == null) { - util.dprintln(2, "ERROR(scale): error in scale"); throw new ImageOpException("Unable to scale"); } img = scaledImg; @@ -245,9 +238,7 @@ param.add((float) height); RenderedImage croppedImg = JAI.create("crop", param); - util.dprintln( - 3, - "CROP: " + logger.debug("CROP: " + x_off + "," + y_off @@ -262,7 +253,6 @@ //DEBUG if (croppedImg == null) { - util.dprintln(2, "ERROR(crop): error in crop"); throw new ImageOpException("Unable to crop"); } img = croppedImg; @@ -312,9 +302,7 @@ rotImg = JAI.create("rotate", param); } - util.dprintln( - 3, - "ROTATE: " + logger.debug("ROTATE: " + x + "," + y @@ -330,7 +318,6 @@ //DEBUG if (rotImg == null) { - util.dprintln(2, "ERROR: error in rotate"); throw new ImageOpException("Unable to rotate"); } img = rotImg; @@ -366,7 +353,6 @@ mirImg = JAI.create("transpose", param); if (mirImg == null) { - util.dprintln(2, "ERROR(mirror): error in flip"); throw new ImageOpException("Unable to flip"); } img = mirImg; @@ -384,9 +370,7 @@ param.add(aa); enhImg = JAI.create("rescale", param); - util.dprintln( - 3, - "ENHANCE: *" + logger.debug("ENHANCE: *" + mult + ", +" + add @@ -397,7 +381,6 @@ //DEBUG if (enhImg == null) { - util.dprintln(2, "ERROR(enhance): error in enhance"); throw new ImageOpException("Unable to enhance"); } img = enhImg; @@ -423,9 +406,7 @@ param.add(aa); enhImg = JAI.create("rescale", param); - util.dprintln( - 3, - "ENHANCE_RGB: *" + logger.debug("ENHANCE_RGB: *" + rgbm + ", +" + rgba @@ -436,7 +417,6 @@ //DEBUG if (enhImg == null) { - util.dprintln(2, "ERROR(enhance): error in enhanceRGB"); throw new ImageOpException("Unable to enhanceRGB"); } img = enhImg; diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/image/JAIImageLoaderDocuImage.java --- a/servlet/src/digilib/image/JAIImageLoaderDocuImage.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/image/JAIImageLoaderDocuImage.java Fri Nov 21 00:17:31 2003 +0100 @@ -61,7 +61,7 @@ h = img.getHeight(); } } catch (IOException e) { - e.printStackTrace(); + logger.debug("error in getHeight", e); } return h; } @@ -75,7 +75,7 @@ w = img.getWidth(); } } catch (IOException e) { - e.printStackTrace(); + logger.debug("error in getHeight", e); } return w; } @@ -85,7 +85,6 @@ System.gc(); img = JAI.create("ImageRead", f.getFile().getAbsolutePath()); if (img == null) { - util.dprintln(3, "ERROR(loadImage): unable to load file"); throw new FileOpException("Unable to load File!"); } } @@ -100,7 +99,6 @@ reader = (ImageReader) readers.next(); reader.setInput(istream); if (reader == null) { - util.dprintln(3, "ERROR(loadImage): unable to load file"); throw new FileOpException("Unable to load File!"); } } @@ -126,11 +124,9 @@ img = JAI.create("imageread", pb); */ } catch (IOException e) { - util.dprintln(3, "ERROR(loadImage): unable to load file"); throw new FileOpException("Unable to load File!"); } if (img == null) { - util.dprintln(3, "ERROR(loadImage): unable to load file"); throw new FileOpException("Unable to load File!"); } imgFile = f.getFile(); @@ -151,7 +147,6 @@ pb3.add("PNG"); } else { // unknown mime type - util.dprintln(2, "ERROR(writeImage): Unknown mime type " + mt); throw new FileOpException("Unknown mime type: " + mt); } // render output @@ -165,7 +160,6 @@ * @see java.lang.Object#finalize() */ protected void finalize() throws Throwable { - //System.out.println("FIN de JAIImageLoaderDocuImage!"); // we must dispose the ImageReader because it keeps the filehandle open! reader.dispose(); reader = null; diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/image/JIMIDocuImage.java --- a/servlet/src/digilib/image/JIMIDocuImage.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/image/JIMIDocuImage.java Fri Nov 21 00:17:31 2003 +0100 @@ -58,13 +58,13 @@ try { img = Jimi.getRasterImage(f.getFile().toURL()); } catch (java.net.MalformedURLException e) { - util.dprintln(3, "ERROR(loadImage): MalformedURLException"); + logger.debug("ERROR(loadImage): MalformedURLException"); } catch (JimiException e) { - util.dprintln(3, "ERROR(loadImage): JIMIException"); + logger.debug("ERROR(loadImage): JIMIException"); throw new FileOpException("Unable to load File!" + e); } if (img == null) { - util.dprintln(3, "ERROR(loadImage): unable to load file"); + logger.debug("ERROR(loadImage): unable to load file"); throw new FileOpException("Unable to load File!"); } imgp = img.getImageProducer(); @@ -102,17 +102,16 @@ // setup scale and interpolation quality if (quality > 0) { - util.dprintln(4, "quality q1"); + logger.debug("quality q1"); scaleFilter = new AreaAverageScaleFilter(destWidth, destHeight); } else { - util.dprintln(4, "quality q0"); + logger.debug("quality q0"); scaleFilter = new ReplicatingScaleFilter(destWidth, destHeight); } ImageProducer scaledImg = new FilteredImageSource(imgp, scaleFilter); if (scaledImg == null) { - util.dprintln(2, "ERROR(cropAndScale): error in scale"); throw new ImageOpException("Unable to scale"); } @@ -126,10 +125,8 @@ // setup Crop ImageProducer croppedImg = img.getCroppedImageProducer(x_off, y_off, width, height); - //util.dprintln(3, "CROP:"+croppedImg.getWidth()+"x"+croppedImg.getHeight()); //DEBUG if (croppedImg == null) { - util.dprintln(2, "ERROR(cropAndScale): error in crop"); throw new ImageOpException("Unable to crop"); } imgp = croppedImg; diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/io/AliasingDocuDirCache.java --- a/servlet/src/digilib/io/AliasingDocuDirCache.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/io/AliasingDocuDirCache.java Fri Nov 21 00:17:31 2003 +0100 @@ -85,7 +85,7 @@ */ public void putName(String name, DocuDirectory newdir) { if (map.containsKey(name)) { - System.out.println("Baah, duplicate key in AliasingDocuDirCache.put!"); + logger.warn("Baah, duplicate key in AliasingDocuDirCache.put!"); } else { map.put(name, newdir); } diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/io/DocuDirCache.java --- a/servlet/src/digilib/io/DocuDirCache.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/io/DocuDirCache.java Fri Nov 21 00:17:31 2003 +0100 @@ -28,11 +28,15 @@ import java.util.LinkedList; import java.util.List; +import org.apache.log4j.Logger; + /** * @author casties */ public class DocuDirCache { + /** general logger for this class */ + protected Logger logger = Logger.getLogger(this.getClass()); /** HashMap of directories */ protected HashMap map = null; /** names of base directories */ @@ -88,7 +92,7 @@ public void put(DocuDirectory newdir) { String s = newdir.getDirName(); if (map.containsKey(s)) { - System.out.println("Baah, duplicate key in DocuDirCache.put!"); + logger.warn("Baah, duplicate key in DocuDirCache.put!"); } else { map.put(s, newdir); numFiles += newdir.size(); diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/io/DocuDirectory.java --- a/servlet/src/digilib/io/DocuDirectory.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/io/DocuDirectory.java Fri Nov 21 00:17:31 2003 +0100 @@ -255,11 +255,13 @@ unresolvedFileMeta = fileMeta; } } catch (SAXException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (cache != null) { + cache.logger.warn("error parsing index.meta", e); + } } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (cache != null) { + cache.logger.warn("error reading index.meta", e); + } } } readParentMeta(); diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/io/DocuDirent.java --- a/servlet/src/digilib/io/DocuDirent.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/io/DocuDirent.java Fri Nov 21 00:17:31 2003 +0100 @@ -1,38 +1,42 @@ -/* DocuDirent.java -- Abstract directory entry in a DocuDirectory - - 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 - +/* + * DocuDirent.java -- Abstract directory entry in a DocuDirectory + * + * 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.io; import java.io.File; import java.util.HashMap; -/** Abstract directory entry in a DocuDirectory. +import org.apache.log4j.Logger; + +/** + * Abstract directory entry in a DocuDirectory. * * @author casties - * + * */ public abstract class DocuDirent { /** the file class of this file */ - protected static int fileClass = FileOps.CLASS_NONE; + protected static int fileClass = FileOps.CLASS_NONE; /** HashMap with metadata */ protected HashMap fileMeta = null; /** Is the Metadata valid */ @@ -40,19 +44,22 @@ /** the parent directory */ protected Directory parent = null; - /** Checks metadata and does something with it. - * + /** + * Checks metadata and does something with it. + * */ public abstract void checkMeta(); /** * gets the (default) File + * * @return */ public abstract File getFile(); - /** Reads meta-data for this Fileset if there is any. - * + /** + * Reads meta-data for this Fileset if there is any. + * */ public void readMeta() { if ((fileMeta != null) || (getFile() != null)) { @@ -72,15 +79,15 @@ } fileMeta = (HashMap) meta.get(getName()); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Logger.getLogger(this.getClass()).warn("error reading index.meta", e); } } } - /** The name of the file. + /** + * The name of the file. * - * If this is a Fileset, the method returns the name of the default file + * If this is a Fileset, the method returns the name of the default file * (for image filesets the highest resolution file). * * @return @@ -88,62 +95,55 @@ public String getName() { File f = getFile(); return (f != null) ? f.getName() : null; - } - - /** The filename sans extension. - * - * @return - */ + } /** + * The filename sans extension. + * + * @return + */ public String getBasename() { File f = getFile(); if (f == null) { return null; } return FileOps.basename(f.getName()); - } - - /** Returns the parent Directory. - * - * @return DocuDirectory - */ + } /** + * Returns the parent Directory. + * + * @return DocuDirectory + */ public Directory getParent() { return parent; - } - - /** Sets the parent Directory. - * - * @param parent The parent to set - */ + } /** + * Sets the parent Directory. + * + * @param parent + * The parent to set + */ public void setParent(Directory parent) { this.parent = parent; - } - - /** Returns the meta-data for this file(set). - * - * @return HashMap - */ + } /** + * Returns the meta-data for this file(set). + * + * @return HashMap + */ public HashMap getFileMeta() { return fileMeta; - } - - /** Sets the meta-data for this file(set) - * . - * @param fileMeta The fileMeta to set - */ + } /** + * Sets the meta-data for this file(set) . + * + * @param fileMeta + * The fileMeta to set + */ public void setFileMeta(HashMap fileMeta) { this.fileMeta = fileMeta; - } - - /** - * @return - */ + } /** + * @return + */ public boolean isMetaChecked() { return metaChecked; - } - - /** - * @return - */ + } /** + * @return + */ public static int getFileClass() { return fileClass; } diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/io/FileOps.java --- a/servlet/src/digilib/io/FileOps.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/io/FileOps.java Fri Nov 21 00:17:31 2003 +0100 @@ -69,18 +69,6 @@ public static final int NUM_CLASSES = 2; - public FileOps() { - util = new Utils(); - } - - public FileOps(Utils u) { - util = u; - } - - public void setUtils(Utils u) { - util = u; - } - /** * get the mime type for a file format (by extension) */ diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/io/ImageFileset.java --- a/servlet/src/digilib/io/ImageFileset.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/io/ImageFileset.java Fri Nov 21 00:17:31 2003 +0100 @@ -145,8 +145,6 @@ return f; } } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } return null; @@ -175,8 +173,6 @@ return f; } } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } return null; diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/io/XMLListLoader.java --- a/servlet/src/digilib/io/XMLListLoader.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/io/XMLListLoader.java Fri Nov 21 00:17:31 2003 +0100 @@ -29,6 +29,7 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.apache.log4j.Logger; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; @@ -47,6 +48,7 @@ */ public class XMLListLoader { + private Logger logger = Logger.getLogger(this.getClass()); private String listTag = "list"; private String entryTag = "entry"; private String keyAtt = "key"; @@ -60,7 +62,7 @@ String entry_tag, String key_att, String value_att) { - //System.out.println("xmlListLoader("+list_tag+","+entry_tag+","+key_att+","+value_att+")"); + logger.debug("xmlListLoader("+list_tag+","+entry_tag+","+key_att+","+value_att+")"); listTag = list_tag; entryTag = entry_tag; keyAtt = key_att; @@ -100,8 +102,7 @@ if (qName.equals(entryTag)) { // is it inside a list tag? if ((listTag.length() > 0) && (!tagSpace.contains(listTag))) { - System.out.println( - "BOO: Entry " + logger.error("BOO: Entry " + entryTag + " not inside list " + listTag); @@ -113,8 +114,7 @@ String key = atts.getValue(keyAtt); String val = atts.getValue(valueAtt); if ((key == null) || (val == null)) { - System.out.println( - "BOO: Entry " + logger.error("BOO: Entry " + entryTag + " does not have Attributes " + keyAtt diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/io/XMLMetaLoader.java --- a/servlet/src/digilib/io/XMLMetaLoader.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/io/XMLMetaLoader.java Fri Nov 21 00:17:31 2003 +0100 @@ -28,12 +28,14 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.apache.log4j.Logger; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class XMLMetaLoader { + private Logger logger = Logger.getLogger(this.getClass()); private String outerTag = "resource"; private String metaTag = "meta"; private String fileTag = "file"; diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/servlet/DigilibConfiguration.java --- a/servlet/src/digilib/servlet/DigilibConfiguration.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/servlet/DigilibConfiguration.java Fri Nov 21 00:17:31 2003 +0100 @@ -1,22 +1,23 @@ -/* DigilibConfiguration -- Holding all parameters for digilib servlet. - - Digital Image Library servlet components - - 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. - - 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 - -*/ +/* + * DigilibConfiguration -- Holding all parameters for digilib servlet. + * + * Digital Image Library servlet components + * + * 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. + * + * 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; @@ -27,7 +28,10 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletException; -import digilib.Utils; +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Logger; +import org.apache.log4j.xml.DOMConfigurator; + import digilib.auth.AuthOps; import digilib.auth.XMLAuthOps; import digilib.image.DocuImage; @@ -37,52 +41,58 @@ import digilib.io.FileOps; import digilib.io.XMLListLoader; -/** Class to hold the digilib servlet configuration parameters. - * The parameters can be read from the digilib-config file and be passed to - * other servlets or beans.
- * errorImgFileName: image file to send in case of error.
- * denyImgFileName: image file to send if access is denied.
- * baseDirs: array of base directories in order of preference (prescaled - * versions first).
- * useAuth: use authentication information.
- * authConfPath: authentication configuration file.
- * authOp: AuthOps instance for authentication.
- * ...
+/** + * Class to hold the digilib servlet configuration parameters. The parameters + * can be read from the digilib-config file and be passed to other servlets or + * beans.
errorImgFileName: image file to send in case of error.
+ * denyImgFileName: image file to send if access is denied.
baseDirs: + * array of base directories in order of preference (prescaled versions first). + *
useAuth: use authentication information.
authConfPath: + * authentication configuration file.
authOp: AuthOps instance for + * authentication.
...
* * @author casties - * + * */ public class DigilibConfiguration extends ParameterMap { - + /** DocuImage class instance */ private Class docuImageClass = null; - - /** Utils instance */ - private Utils util = new Utils(5); + + /** Log4J logger */ + private Logger logger = Logger.getLogger("digilib.config"); - - /** Default constructor defines all parameters and their default values. - * + /** + * Default constructor defines all parameters and their default values. + * */ public DigilibConfiguration() { // create HashMap(20) 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'. + * 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'); + 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'); + putParameter( + "servlet.docuimage.class", + digilib.image.JAIDocuImage.class, + null, + 's'); // AuthOps instance for authentication putParameter("servlet.auth.op", null, null, 's'); @@ -91,9 +101,17 @@ */ // image file to send in case of error - putParameter("error-image", "/docuserver/images/icons/scalerror.gif", null, 'f'); + 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'); + 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'); @@ -106,7 +124,11 @@ // Debug level putParameter("debug-level", new Integer(5), null, 'f'); // Type of DocuImage instance - putParameter("docuimage-class", "digilib.image.JAIDocuImage", null, 'f'); + 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 @@ -117,11 +139,14 @@ putParameter("use-mapping", Boolean.FALSE, null, 'f'); // mapping file location putParameter("mapping-file", "digilib-map.xml", null, 'f'); + // log4j config file location + putParameter("log-config-file", "log4j-config.xml", null, 'f'); + } - /** Constructor taking a ServletConfig. - * Reads the config file location from an init parameter and loads the - * config file. Calls readConfig(). + /** + * Constructor taking a ServletConfig. Reads the config file location from + * an init parameter and loads the config file. Calls readConfig(). * * @see readConfig() */ @@ -129,16 +154,15 @@ this(); readConfig(c); } - + /** * read parameter list from the XML file in init parameter "config-file" */ 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. + * 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... @@ -146,10 +170,11 @@ } String fn = c.getInitParameter("config-file"); if (fn == null) { - fn = c.getServletContext().getRealPath("WEB-INF/digilib-config.xml"); + 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!"); + logger.fatal("readConfig: no param config-file"); + throw new ServletException("ERROR: no digilib config file!"); } } File f = new File(fn); @@ -158,11 +183,11 @@ new XMLListLoader("digilib-config", "parameter", "name", "value"); // 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 */ @@ -175,11 +200,11 @@ // type 's' Parameters are not overwritten. continue; } - if (! p.setValueFromString(val)) { + if (!p.setValueFromString(val)) { /* * automatic conversion failed -- try special cases */ - + // basedir-list if (key.equals("basedir-list")) { // split list into directories @@ -188,7 +213,7 @@ p.setValue(sa); } } - + } } else { // parameter unknown -- just add @@ -200,18 +225,25 @@ * further initialization */ - // debugLevel - util.setDebugLevel(getAsInt("debug-level")); + // 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); + } + DOMConfigurator.configure(logConfPath); // directory cache String[] bd = (String[]) getValue("basedir-list"); - int[] fcs = { FileOps.CLASS_IMAGE, FileOps.CLASS_TEXT}; + int[] fcs = { FileOps.CLASS_IMAGE, FileOps.CLASS_TEXT }; DocuDirCache dirCache; if (getAsBoolean("use-mapping")) { // with mapping file String mapConfPath = getAsString("mapping-file"); - if (! mapConfPath.startsWith("/")) { + if (!mapConfPath.startsWith("/")) { // relative path -> use getRealPath to resolve in WEB-INF - mapConfPath = c.getServletContext().getRealPath("WEB-INF/"+mapConfPath); + mapConfPath = + c.getServletContext().getRealPath("WEB-INF/" + mapConfPath); } dirCache = new AliasingDocuDirCache(bd, fcs, mapConfPath); } else { @@ -225,11 +257,13 @@ //authOp = new DBAuthOpsImpl(util); // XML version String authConfPath = getAsString("auth-file"); - if (! authConfPath.startsWith("/")) { + if (!authConfPath.startsWith("/")) { // relative path -> use getRealPath to resolve in WEB-INF - authConfPath = c.getServletContext().getRealPath("WEB-INF/"+authConfPath); + authConfPath = + c.getServletContext().getRealPath( + "WEB-INF/" + authConfPath); } - AuthOps authOp = new XMLAuthOps(util, authConfPath); + AuthOps authOp = new XMLAuthOps(authConfPath); setValue("servlet.auth.op", authOp); } // DocuImage class @@ -239,7 +273,8 @@ setValue("servlet.docuimage.class", docuImageClass); } - /** Creates a new DocuImage instance. + /** + * Creates a new DocuImage instance. * * The type of DocuImage is specified by docuImageType. * @@ -252,17 +287,9 @@ docuImageClass = Class.forName(getAsString("docuimage-class")); } di = (DocuImageImpl) docuImageClass.newInstance(); - di.setUtils(util); } catch (Exception e) { } return di; } - /** - * @return - */ - public Utils getUtil() { - return util; - } - } diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/servlet/DigilibRequest.java --- a/servlet/src/digilib/servlet/DigilibRequest.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/servlet/DigilibRequest.java Fri Nov 21 00:17:31 2003 +0100 @@ -36,6 +36,8 @@ import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; +import org.apache.log4j.Logger; + import com.hp.hpl.mesa.rdf.jena.common.SelectorImpl; import com.hp.hpl.mesa.rdf.jena.mem.ModelMem; import com.hp.hpl.mesa.rdf.jena.model.Model; @@ -65,6 +67,7 @@ */ 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 @@ -373,9 +376,7 @@ String strRDF; strRDF = request.getParameter("rdf"); if (strRDF != null) { - //System.out.println(strRDF); Hashtable hashRDF = rdf2hash(strRDF); - //System.out.println(hashRDF.toString()); // go through all parameters for (Iterator i = hashRDF.keySet().iterator(); i.hasNext();) { String name = (String) i.next(); @@ -404,7 +405,6 @@ // get Property fn -> digilib Property p = model.getProperty("http://echo.unibe.ch/digilib/rdf#", "fn"); - //System.out.println(p.toString()); if (p != null) { // get URI String strURI = null; @@ -412,7 +412,6 @@ if (i.hasNext()) { strURI = "urn:echo:" + i.next().toString(); Resource r = model.getResource(strURI); - //System.out.println(r.toString()); Selector selector = new SelectorImpl(r, null, (RDFNode) null); // list the statements in the graph @@ -444,7 +443,7 @@ } } } catch (Exception e) { - System.out.println("Failed: " + e); + logger.warn("rdf3hash failed", e); } return hashParams; } diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/servlet/DocumentBean.java --- a/servlet/src/digilib/servlet/DocumentBean.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/servlet/DocumentBean.java Fri Nov 21 00:17:31 2003 +0100 @@ -28,21 +28,19 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import digilib.Utils; +import org.apache.log4j.Logger; + import digilib.auth.AuthOpException; import digilib.auth.AuthOps; import digilib.io.DocuDirCache; import digilib.io.DocuDirectory; -import digilib.io.FileOps; public class DocumentBean { - // Utils object for logging - private Utils util = new Utils(0); + // general logger + Logger logger = Logger.getLogger("digilib.docubean"); // AuthOps object to check authorization private AuthOps authOp; - // FileOps object - private FileOps fileOp = new FileOps(util); // use authorization database private boolean useAuthentication = true; // path to add for authenticated access @@ -64,12 +62,12 @@ try { setConfig(conf); } catch (Exception e) { - util.dprintln(2, "ERROR: Unable to read config: " + e.toString()); + logger.fatal("ERROR: Unable to read config: ", e); } } public void setConfig(ServletConfig conf) throws ServletException { - util.dprintln(10, "setConfig"); + logger.debug("setConfig"); // get our ServletContext ServletContext context = conf.getServletContext(); // see if there is a Configuration instance @@ -86,8 +84,6 @@ } } - // get util - util = dlConfig.getUtil(); // get cache dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); @@ -104,7 +100,7 @@ */ public boolean isAuthRequired(DigilibRequest request) throws AuthOpException { - util.dprintln(10, "isAuthRequired"); + logger.debug("isAuthRequired"); return useAuthentication ? authOp.isAuthRequired(request) : false; } @@ -113,7 +109,7 @@ */ public boolean isAuthorized(DigilibRequest request) throws AuthOpException { - util.dprintln(10, "isAuthorized"); + logger.debug("isAuthorized"); return useAuthentication ? authOp.isAuthorized(request) : true; } @@ -122,7 +118,7 @@ * to access the specified path */ public List rolesForPath(DigilibRequest request) throws AuthOpException { - util.dprintln(10, "rolesForPath"); + logger.debug("rolesForPath"); return useAuthentication ? authOp.rolesForPath(request) : null; } @@ -130,7 +126,7 @@ * check request authorization against a list of roles */ public boolean isRoleAuthorized(List roles, DigilibRequest request) { - util.dprintln(10, "isRoleAuthorized"); + logger.debug("isRoleAuthorized"); return useAuthentication ? authOp.isRoleAuthorized(roles, request) : true; @@ -143,7 +139,7 @@ DigilibRequest request, HttpServletResponse response) throws Exception { - util.dprintln(10, "doAuthentication"); + logger.debug("doAuthentication"); if (!useAuthentication) { // shortcut if no authentication return true; @@ -151,10 +147,10 @@ // check if we are already authenticated if (((HttpServletRequest) request.getServletRequest()).getRemoteUser() == null) { - util.dprintln(3, "unauthenticated so far"); + logger.debug("unauthenticated so far"); // if not maybe we must? if (isAuthRequired(request)) { - util.dprintln(3, "auth required, redirect"); + logger.debug("auth required, redirect"); // we are not yet authenticated -> redirect response.sendRedirect( authURLPath @@ -173,7 +169,7 @@ * (not yet functional) */ public int getFirstPage(DigilibRequest request) { - util.dprintln(10, "getFirstPage"); + logger.debug("getFirstPage"); return 1; } @@ -181,7 +177,7 @@ * get the number of pages/files in the directory */ public int getNumPages(DigilibRequest request) throws Exception { - util.dprintln(10, "getNumPages"); + logger.debug("getNumPages"); DocuDirectory dd = (dirCache != null) ? dirCache.getDirectory(request.getFilePath()) diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/servlet/Parameter.java --- a/servlet/src/digilib/servlet/Parameter.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/servlet/Parameter.java Fri Nov 21 00:17:31 2003 +0100 @@ -183,7 +183,6 @@ fa[i] = f; } } catch (Exception e) { - //System.out.println("ERROR: trytoGetParam(int) failed on param "+name); } return fa; diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/servlet/Scaler.java --- a/servlet/src/digilib/servlet/Scaler.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/servlet/Scaler.java Fri Nov 21 00:17:31 2003 +0100 @@ -1,22 +1,23 @@ -/* Scaler -- Scaler servlet main class - - 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 - -*/ +/* + * Scaler -- Scaler servlet main class + * + * 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; @@ -34,7 +35,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import digilib.Utils; +import org.apache.log4j.Logger; + import digilib.auth.AuthOpException; import digilib.auth.AuthOps; import digilib.image.DocuImage; @@ -43,23 +45,30 @@ import digilib.image.ImageOpException; import digilib.image.ImageSize; import digilib.io.DocuDirCache; +import digilib.io.FileOpException; +import digilib.io.FileOps; import digilib.io.ImageFile; import digilib.io.ImageFileset; -import digilib.io.FileOpException; -import digilib.io.FileOps; //import tilecachetool.*; /** - * @author casties */ + * @author casties + */ //public class Scaler extends HttpServlet implements SingleThreadModel { public class Scaler extends HttpServlet { // digilib servlet version (for all components) - public static final String dlVersion = "1.17b2"; + public static final String dlVersion = "1.18b1"; - // Utils instance with debuglevel - Utils util; + // logger for accounting requests + Logger accountlog = Logger.getLogger("account.request"); + // gengeral logger for this class + Logger logger = Logger.getLogger("digilib.servlet"); + // logger for authentication related + Logger authlog = Logger.getLogger("digilib.auth"); + + // FileOps instance FileOps fileOp; // AuthOps instance @@ -121,15 +130,15 @@ throw new ServletException(e); } } - // first we need an Utils - util = dlConfig.getUtil(); + // say hello in the log file + logger.info("***** Digital Image Library Servlet (version " + + dlVersion + + ") *****"); // set our AuthOps useAuthentication = dlConfig.getAsBoolean("use-authorization"); + // AuthOps instance 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"); denyImgFile = new File(dlConfig.getAsString("denied-image")); @@ -139,10 +148,10 @@ defaultQuality = dlConfig.getAsInt("default-quality"); } - /** Process the HTTP Get request*/ + /** Process the HTTP Get request */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - util.dprintln(1, "The servlet has received a GET!"); + accountlog.info("GET from "+request.getRemoteAddr()); // create new request with defaults DigilibRequest dlReq = new DigilibRequest(); // set with request parameters @@ -153,12 +162,12 @@ processRequest(request, response); } - /**Process the HTTP Post request*/ + /** Process the HTTP Post request */ public void doPost( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - util.dprintln(1, "The servlet has received a POST!"); + accountlog.info("POST from "+request.getRemoteAddr()); // create new request with defaults DigilibRequest dlReq = new DigilibRequest(); // set with request parameters @@ -175,6 +184,8 @@ HttpServletResponse response) throws ServletException, IOException { + accountlog.debug("request: "+request.getQueryString()); + // time for benchmarking long startTime = System.currentTimeMillis(); // output mime/type @@ -273,18 +284,6 @@ cropToFit = false; sendFile = false; hiresOnly = true; - } else if (dlRequest.hasOption("mo", "file")) { - scaleToFit = false; - absoluteScale = false; - if (sendFileAllowed) { - cropToFit = false; - sendFile = true; - } else { - // crop to fit if send file not allowed - cropToFit = true; - sendFile = false; - } - hiresOnly = true; } // operation mode: "lores": try to use scaled image, "hires": use // unscaled image @@ -334,18 +333,18 @@ // get a list of required roles (empty if no restrictions) List rolesRequired = authOp.rolesForPath(loadPathName, request); if (rolesRequired != null) { - util.dprintln(1, "Role required: " + rolesRequired); - util.dprintln(2, "User: " + request.getRemoteUser()); + authlog.info("Role required: " + rolesRequired); + authlog.info("User: " + request.getRemoteUser()); // is the current request/user authorized? if (!authOp.isRoleAuthorized(rolesRequired, request)) { // send deny answer and abort - util.dprintln(1, "ERROR: access denied!"); + authlog.error("ERROR: access denied!"); if (errorMsgHtml) { ServletOps.htmlMessage( "ERROR: Unauthorized access!", response); } else { - servletOp.sendFile(denyImgFile, response); + ServletOps.sendFile(denyImgFile, null, response); } return; } @@ -367,7 +366,7 @@ + dlRequest.getAsInt("pn") + ") not found."); } - + /* calculate expected source image size */ ImageSize expectedSourceSize = new ImageSize(); if (scaleToFit) { @@ -402,8 +401,25 @@ fileToLoad = fileset.getBiggest(); } } - util.dprintln(1, "Loading: " + fileToLoad.getFile()); + logger.info("Loading: " + fileToLoad.getFile()); + /* + * send the image if its mo=(raw)file + */ + if (dlRequest.hasOption("mo", "file") + || dlRequest.hasOption("mo", "rawfile")) { + if (sendFileAllowed) { + String mt = null; + if (dlRequest.hasOption("mo", "rawfile")) { + mt = "application/octet-stream"; + } + ServletOps.sendFile(fileToLoad.getFile(), mt, response); + } + } + + /* + * prepare resolution for original size + */ if (absoluteScale) { // get original resolution from metadata fileset.checkMeta(); @@ -448,20 +464,17 @@ * if not autoScale and not scaleToFit nor cropToFit then send as * is (mo=file) */ - if ((loresOnly - && imageSendable - && fileToLoad.getSize().isSmallerThan(expectedSourceSize)) - || (!(loresOnly || hiresOnly) - && fileToLoad.getSize().fitsIn(expectedSourceSize)) - || sendFile) { + if (imageSendable + && ((loresOnly + && fileToLoad.getSize().isSmallerThan(expectedSourceSize)) + || (!(loresOnly || hiresOnly) + && fileToLoad.getSize().fitsIn(expectedSourceSize)))) { - util.dprintln(1, "Sending File as is."); - - servletOp.sendFile(fileToLoad.getFile(), response); + logger.debug("Sending File as is."); - util.dprintln( - 1, - "Done in " + ServletOps.sendFile(fileToLoad.getFile(), null, response); + + logger.info("Done in " + (System.currentTimeMillis() - startTime) + "ms"); return; @@ -475,7 +488,7 @@ // set interpolation quality docuImage.setQuality(scaleQual); - + // set missing dw or dh from aspect ratio double imgAspect = fileToLoad.getAspect(); if (paramDW == 0) { @@ -486,12 +499,8 @@ /* crop and scale the image */ - util.dprintln( - 2, - "IMG: " + imgSize.getWidth() + "x" + imgSize.getHeight()); - util.dprintln( - 2, - "time " + (System.currentTimeMillis() - startTime) + "ms"); + logger.debug("IMG: " + imgSize.getWidth() + "x" + imgSize.getHeight()); + logger.debug("time " + (System.currentTimeMillis() - startTime) + "ms"); // coordinates and scaling double areaXoff; @@ -589,9 +598,7 @@ } } - util.dprintln( - 1, - "Scale " + logger.debug("Scale " + scaleXY + "(" + scaleX @@ -608,9 +615,7 @@ areaXoff = outerUserImgArea.getX(); areaYoff = outerUserImgArea.getY(); - util.dprintln( - 2, - "crop: " + logger.debug("crop: " + areaXoff + "," + areaYoff @@ -624,7 +629,7 @@ || (areaHeight < 1) || (scaleXY * areaWidth < 2) || (scaleXY * areaHeight < 2)) { - util.dprintln(1, "ERROR: invalid scale parameter set!"); + logger.error("ERROR: invalid scale parameter set!"); throw new ImageOpException("Invalid scale parameter set!"); } @@ -632,8 +637,7 @@ // use subimage loading if possible if (docuImage.isSubimageSupported()) { - System.out.println( - "Subimage: scale " + scaleXY + " = " + (1 / scaleXY)); + logger.debug("Subimage: scale " + scaleXY + " = " + (1 / scaleXY)); double subf = 1d; double subsamp = 1d; if (scaleXY < 1) { @@ -646,8 +650,7 @@ subsamp = Math.floor(subf); } scaleXY = subsamp / subf; - System.out.println( - "Using subsampling: " + subsamp + " rest " + scaleXY); + logger.debug("Using subsampling: " + subsamp + " rest " + scaleXY); } docuImage.loadSubimage( @@ -655,8 +658,7 @@ outerUserImgArea.getBounds(), (int) subsamp); - System.out.println( - "SUBSAMP: " + logger.debug("SUBSAMP: " + subsamp + " -> " + docuImage.getWidth() @@ -736,9 +738,7 @@ docuImage.enhance((float) mult, (float) paramBRGT); } - util.dprintln( - 2, - "time " + (System.currentTimeMillis() - startTime) + "ms"); + logger.debug("time " + (System.currentTimeMillis() - startTime) + "ms"); /* write the resulting image */ @@ -755,59 +755,57 @@ // write the image docuImage.writeImage(mimeType, response.getOutputStream()); - util.dprintln( - 1, - "Done in " + (System.currentTimeMillis() - startTime) + "ms"); + logger.info("Done in " + (System.currentTimeMillis() - startTime) + "ms"); /* error handling */ } // end of "big" try catch (IOException e) { - util.dprintln(1, "ERROR: File IO Error: " + e); + logger.fatal("ERROR: File IO Error: ", e); try { if (errorMsgHtml) { ServletOps.htmlMessage( "ERROR: File IO Error: " + e, response); } else { - servletOp.sendFile(errorImgFile, response); + ServletOps.sendFile(errorImgFile, null, response); } } catch (FileOpException ex) { } // so we don't get a loop } catch (AuthOpException e) { - util.dprintln(1, "ERROR: Authorization error: " + e); + logger.fatal("ERROR: Authorization error: ", e); try { if (errorMsgHtml) { ServletOps.htmlMessage( "ERROR: Authorization error: " + e, response); } else { - servletOp.sendFile(errorImgFile, response); + ServletOps.sendFile(errorImgFile, null, response); } } catch (FileOpException ex) { } // so we don't get a loop } catch (ImageOpException e) { - util.dprintln(1, "ERROR: Image Error: " + e); + logger.fatal("ERROR: Image Error: ", e); try { if (errorMsgHtml) { ServletOps.htmlMessage( "ERROR: Image Operation Error: " + e, response); } else { - servletOp.sendFile(errorImgFile, response); + ServletOps.sendFile(errorImgFile, null, response); } } catch (FileOpException ex) { } // so we don't get a loop } catch (RuntimeException e) { // JAI likes to throw RuntimeExceptions ;-( - util.dprintln(1, "ERROR: Other Image Error: " + e); + logger.fatal("ERROR: Other Image Error: ", e); try { if (errorMsgHtml) { ServletOps.htmlMessage( "ERROR: Other Image Operation Error: " + e, response); } else { - servletOp.sendFile(errorImgFile, response); + ServletOps.sendFile(errorImgFile, null, response); } } catch (FileOpException ex) { } // so we don't get a loop diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/servlet/ServletOps.java --- a/servlet/src/digilib/servlet/ServletOps.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/servlet/ServletOps.java Fri Nov 21 00:17:31 2003 +0100 @@ -1,219 +1,120 @@ -/* ServletOps -- Servlet utility class - - Digital Image Library servlet components - - 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. - - 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 - -*/ +/* + * ServletOps -- Servlet utility class + * + * Digital Image Library servlet components + * + * 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. + * + * 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; -import javax.servlet.*; -import javax.servlet.http.*; -import java.io.*; -import java.util.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.StringTokenizer; -import digilib.*; -import digilib.io.*; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletResponse; +import org.apache.log4j.Logger; + +import digilib.io.FileOpException; +import digilib.io.FileOps; public class ServletOps { - private Utils util = null; - private HashMap confTable = null; - - public ServletOps() { - util = new Utils(); - } - - public ServletOps(Utils u) { - util = u; - } - - public ServletOps(Utils u, ServletConfig sc) throws ServletException { - util = u; - setConfig(sc); - } - - public void setUtils(Utils u) { - util = u; - } + private static Logger logger = Logger.getLogger("servlet.op"); - /** - * read parameter list from the XML file in init parameter "config-file" - */ - public void setConfig(ServletConfig c) throws ServletException { - // reset parameter table - confTable = null; - if (c == null) { - return; - } - // get config file name - String fn = c.getInitParameter("config-file"); - if (fn == null) { - util.dprintln(4, "setConfig: no param config-file"); - return; - } - File f = new File(fn); - // setup config file list reader - XMLListLoader lilo = new XMLListLoader("digilib-config", "parameter", "name", "value"); - try { - confTable = lilo.loadURL(f.toURL().toString()); - } catch (Exception e) { - util.dprintln(4, "setConfig: unable to read file "+fn); - throw new ServletException(e); - } - } + /** + * convert a string with a list of pathnames into an array of strings using + * the system's path seperator string + */ + public static String[] getPathArray(String paths) { + // split list into directories + StringTokenizer dirs = + new StringTokenizer(paths, java.io.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++) { + pathArray[i] = dirs.nextToken(); + } + return pathArray; + } - /** - * convert a string with a list of pathnames into an array of strings - * using the system's path seperator string - */ - public String[] getPathArray(String paths) { - // split list into directories - StringTokenizer dirs = new StringTokenizer(paths, java.io.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++) { - pathArray[i] = dirs.nextToken(); - } - return pathArray; - } - - /** - * getPathArray with default fall back - */ - public String[] tryToGetPathArray(String paths, String[] defaultPath) { - String[] pa = getPathArray(paths); - return (pa != null) ? pa : defaultPath; - } - - /** - * print a servlet response and exit - */ - public static void htmlMessage(String s, HttpServletResponse response) throws IOException { - response.setContentType("text/html; charset=iso-8859-1"); - PrintWriter out = response.getWriter(); - out.println(""); - out.println("Scaler"); - out.println(""); - out.println("

"+s+"

"); - out.println(""); - } + /** + * print a servlet response and exit + */ + public static void htmlMessage(String s, HttpServletResponse response) + throws IOException { + response.setContentType("text/html; charset=iso-8859-1"); + PrintWriter out = response.getWriter(); + out.println(""); + out.println("Scaler"); + out.println(""); + out.println("

" + s + "

"); + out.println(""); + } - /** Transfers an image file as-is. - * - * The local file is copied to the OutputStream of the - * ServletResponse. The mime-type for the response is detected - * from the file. - * - * @param f Image file to be sent. - * @param res ServletResponse where the image file will be sent. - * @throws FileOpException Exception is thrown for a IOException. - */ - public void sendFile(File f, ServletResponse response) throws FileOpException { - util.dprintln(4, "sendFile("+f+")"); - String mimeType = FileOps.mimeForFile(f); - if (mimeType == null) { - util.dprintln(2, "ERROR(sendFile): unknown file Type"); - throw new FileOpException("Unknown file type."); - } - response.setContentType(mimeType); - // open file - try { - FileInputStream inFile = new FileInputStream(f); - OutputStream outStream = response.getOutputStream(); - byte dataBuffer[] = new byte[4096]; - int len; - while ((len = inFile.read(dataBuffer)) != -1) { - // copy out file - outStream.write(dataBuffer, 0, len); - } - inFile.close(); - } catch (IOException e) { - util.dprintln(2, "ERROR(sendFile): unable to send file"); - throw new FileOpException("Unable to send file."); + /** + * Transfers an image file as-is with the mime type mt. + * + * The local file is copied to the OutputStream of the + * ServletResponse. If mt is null then the mime-type is + * auto-detected with mimeForFile. + * + * @param mt + * mime-type of the file. + * @param f + * Image file to be sent. + * @param res + * ServletResponse where the image file will be sent. + * @throws FileOpException + * Exception is thrown for a IOException. + */ + public static void sendFile(File f, String mt, ServletResponse response) + throws FileOpException { + logger.debug("sendRawFile(" + mt + ", " + f + ")"); + if (mt == null) { + // auto-detect mime-type + mt = FileOps.mimeForFile(f); + if (mt == null) { + throw new FileOpException("Unknown file type."); + } + } + response.setContentType(mt); + // open file + try { + FileInputStream inFile = new FileInputStream(f); + OutputStream outStream = response.getOutputStream(); + byte dataBuffer[] = new byte[4096]; + int len; + while ((len = inFile.read(dataBuffer)) != -1) { + // copy out file + outStream.write(dataBuffer, 0, len); + } + inFile.close(); + } catch (IOException e) { + throw new FileOpException("Unable to send file."); + } } - } - - - /** - * get a parameter from request and return it if set, otherwise return default - */ - public int tryToGetParam(String s, int i, HttpServletRequest r) { - try { - i = Integer.parseInt(r.getParameter(s)); - } catch(Exception e) { - util.dprintln(4, "trytoGetParam(int) failed on param "+s); - //e.printStackTrace(); - } - return i; - } - public float tryToGetParam(String s, float f, HttpServletRequest r) { - try { - f = Float.parseFloat(r.getParameter(s)); - } catch(Exception e) { - util.dprintln(4, "trytoGetParam(float) failed on param "+s); - //e.printStackTrace(); - } - return f; - } - public String tryToGetParam(String s, String x, HttpServletRequest r) { - if (r.getParameter(s) != null) { - x = r.getParameter(s); - } else { - util.dprintln(4, "trytoGetParam(string) failed on param "+s); - } - return x; - } - - - /** - * 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; - } } diff -r bd87f802bea1 -r afe7ff98bb71 servlet/src/digilib/servlet/Texter.java --- a/servlet/src/digilib/servlet/Texter.java Fri Nov 21 00:11:18 2003 +0100 +++ b/servlet/src/digilib/servlet/Texter.java Fri Nov 21 00:17:31 2003 +0100 @@ -22,7 +22,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import digilib.Utils; +import org.apache.log4j.Logger; + import digilib.auth.AuthOps; import digilib.io.DocuDirCache; import digilib.io.FileOpException; @@ -39,11 +40,11 @@ public class Texter extends HttpServlet { /** Servlet version */ - public static String tlVersion = "0.1a2"; + public static String tlVersion = "0.1a3"; /** DigilibConfiguration instance */ DigilibConfiguration dlConfig = null; - /** Utils instance with debuglevel */ - Utils util; + /** general logger */ + Logger logger = Logger.getLogger("digilib.texter"); /** FileOps instance */ FileOps fileOp; /** AuthOps instance */ @@ -63,10 +64,10 @@ super.init(config); System.out.println( - "***** Digital Image Library Text Servlet (version " + "***** Digital Image Library Text Servlet (version " + tlVersion + ") *****"); - + // get our ServletContext ServletContext context = config.getServletContext(); // see if there is a Configuration instance @@ -82,15 +83,15 @@ throw new ServletException(e); } } - // first we need an Utils - util = dlConfig.getUtil(); + // say hello in the log file + logger.info( + "***** Digital Image Library Text Servlet (version " + + tlVersion + + ") *****"); + // 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"); } @@ -147,19 +148,19 @@ * find the file to load/send */ if (this.getTextFile(dlRequest, "/txt") != null) { - servletOp.sendFile( + ServletOps.sendFile( this.getTextFile(dlRequest, "txt").getFile(), - response); + null, response); } else if (this.getTextFile(dlRequest, "") != null) { - servletOp.sendFile( + ServletOps.sendFile( this.getTextFile(dlRequest, "").getFile(), - response); + null, response); } else { ServletOps.htmlMessage("No Text-File!", response); } } catch (FileOpException e) { - util.dprintln(1, "ERROR: File IO Error: " + e); + logger.error("ERROR: File IO Error: ", e); try { ServletOps.htmlMessage("ERROR: File IO Error: " + e, response); } catch (FileOpException ex) {