Mercurial > hg > digilib-old
changeset 170:d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
- more generic class for request parameters
- like already done for DiglibConfig
- changes in JSPs for new request stuff
- changes in ImageSize class so size=0 is "wildcard"
- missing dw and dh parameters now treated as wildcards
- changed package name in imageinfo class
author | robcast |
---|---|
date | Wed, 29 Oct 2003 22:47:15 +0100 |
parents | 93dd5e1c57d3 |
children | 3ca96ec73cc2 |
files | servlet/doc/Scaler.html servlet/src/digilib/image/ImageLoaderDocuImage.java servlet/src/digilib/image/ImageLoaderImageInfoDocuInfo.java servlet/src/digilib/image/ImageSize.java servlet/src/digilib/io/ImageFile.java servlet/src/digilib/io/ImageFileset.java servlet/src/digilib/servlet/DigilibRequest.java servlet/src/digilib/servlet/Parameter.java servlet/src/digilib/servlet/ParameterMap.java servlet/src/digilib/servlet/Scaler.java servlet/src/digilib/servlet/Texter.java |
diffstat | 11 files changed, 904 insertions(+), 1514 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/doc/Scaler.html Wed Oct 29 22:45:51 2003 +0100 +++ b/servlet/doc/Scaler.html Wed Oct 29 22:47:15 2003 +0100 @@ -27,9 +27,11 @@ given by the path. Starts with 1. Ignored if the path points to a file. Default: 1.</li> - <li><b>dw</b> destination image width (pixels).</li> + <li><b>dw</b> destination image width (pixels). If omitted the image is scaled to fit + dh.</li> - <li><b>dh</b> destination image height (pixels).</li> + <li><b>dh</b> destination image height (pixels). If omitted the image is scaled to fit + dw.</li> <li><b>wx</b> relative x offset of the image area to be sent (0 <= wx <= 1). Default: 0.</li> @@ -50,18 +52,21 @@ <ul> <li><b>fit</b>: always scale the image to fit <code>[dw,dh]</code>.<br> + <b>file</b>: send the file as-is (may be very large and all sorts of image types!). If configuration doesn't allow sending files (<code>sendfile-allowed=false</code>) revert to <code>clip</code>.<br> + <b>clip</b>: send the file in its original resolution, cropped to fit <code>[dw,dh]</code>.<br> If none of these flags is set heuristics is used (send unzoomed GIF as-is).<br> + <b>osize</b>: scale to original size based on the image resolution (from the image metadata) and display resolution (from parameter - <code>ddpi</code>) + <code>ddpi</code>). Fails if either resolution is unknown. </li> <li><b>errtxt</b>: send error response as HTML.<br> @@ -71,11 +76,14 @@ (<code>q0</code>: worst, default).</li> <li><b>lores</b>: try to use scaled image (default)<br> + <b>hires</b>: always use unscaled image.<br> + If the image is zoomed (ww, wh < 1) the unscaled image is used in any case.</li> <li><b>vmir</b>: mirror image vertically.<br> + <b>hmir</b>: mirror image horizontally.</li> </ul> </li> @@ -109,7 +117,6 @@ <li><b>ddpix</b>: resolution of client display in x direction for <code>osize</code> mode.</li> - <li><b>ddpiy</b>: resolution of client display in y direction for <code>osize</code> mode.</li>
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java Wed Oct 29 22:45:51 2003 +0100 +++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java Wed Oct 29 22:47:15 2003 +0100 @@ -113,9 +113,7 @@ } } - /** Get an ImageReader for the image file. - * - */ + /** Get an ImageReader for the image file. */ public void preloadImage(ImageFile f) throws IOException { if (reader != null) { // clean up old reader @@ -167,7 +165,7 @@ throw new FileOpException("Unable to load File!"); } } - + /* write image of type mt to Stream */ public void writeImage(String mt, OutputStream ostream) throws FileOpException { @@ -185,14 +183,16 @@ throw new FileOpException("Unknown mime type: " + mt); } - /* JPEG doesn't do transparency so we have to convert any RGBA image - * to RGB :-( *Java2D BUG* + /* + * JPEG doesn't do transparency so we have to convert any RGBA + * image to RGB :-( *Java2D BUG* */ if ((type == "jpeg") && (img.getColorModel().hasAlpha())) { util.dprintln(2, "BARF: JPEG with transparency!!"); int w = img.getWidth(); int h = img.getHeight(); - // BufferedImage.TYPE_INT_RGB seems to be fastest (JDK1.4.1, OSX) + // BufferedImage.TYPE_INT_RGB seems to be fastest (JDK1.4.1, + // OSX) int destType = BufferedImage.TYPE_INT_RGB; BufferedImage img2 = new BufferedImage(w, h, destType); img2.createGraphics().drawImage(img, null, 0, 0); @@ -213,16 +213,12 @@ } public void scale(double scale, double scaleY) throws ImageOpException { - /* - * for downscaling in high quality the image is blurred first - */ + /* for downscaling in high quality the image is blurred first */ if ((scale <= 0.5) && (quality > 1)) { int bl = (int) Math.floor(1 / scale); blur(bl); } - /* - * and scaled - */ + /* and scaled */ AffineTransformOp scaleOp = new AffineTransformOp( AffineTransform.getScaleInstance(scale, scale), @@ -295,7 +291,8 @@ 3, "CROP:" + croppedImg.getWidth() + "x" + croppedImg.getHeight()); //DEBUG - // util.dprintln(2, " time "+(System.currentTimeMillis()-startTime)+"ms"); + // 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"); @@ -303,18 +300,16 @@ img = croppedImg; } - public void enhance(float mult, float add) - throws ImageOpException { /* Only one constant should work regardless of the number of bands - * according to the JDK spec. - * Doesn't work on JDK 1.4 for OSX and Linux (at least). - */ /* RescaleOp scaleOp = - new RescaleOp( - (float)mult, (float)add, - null); - scaleOp.filter(img, img); - */ /* The number of constants must match the number of bands in the image. - */ - int ncol = img.getColorModel().getNumColorComponents(); + public void enhance(float mult, float add) throws ImageOpException { + /* + * Only one constant should work regardless of the number of bands + * according to the JDK spec. Doesn't work on JDK 1.4 for OSX and Linux + * (at least). RescaleOp scaleOp = new RescaleOp( (float)mult, + * (float)add, null); scaleOp.filter(img, img); + */ + + /* The number of constants must match the number of bands in the image. */ + int ncol = img.getColorModel().getNumComponents(); float[] dm = new float[ncol]; float[] da = new float[ncol]; for (int i = 0; i < ncol; i++) { @@ -326,9 +321,13 @@ } public void enhanceRGB(float[] rgbm, float[] rgba) - throws ImageOpException { /* The number of constants must match the number of bands in the image. - * We do only 3 (RGB) bands. - */ + throws ImageOpException { + + /* + * The number of constants must match the number of bands in the image. + * We do only 3 (RGB) bands. + */ + int ncol = img.getColorModel().getNumColorComponents(); if ((ncol != 3) || (rgbm.length != 3) || (rgba.length != 3)) { util.dprintln( @@ -341,20 +340,46 @@ RescaleOp scaleOp = new RescaleOp(rgbOrdered(rgbm), rgbOrdered(rgba), null); scaleOp.filter(img, img); - } /** Ensures that the array f is in the right order to map the images RGB components. - */ + } + + /** + * Ensures that the array f is in the right order to map the images RGB + * components. (not shure what happens + */ public float[] rgbOrdered(float[] fa) { - float[] fb = new float[3]; + /* + * TODO: this is UGLY, UGLY!! + */ + float[] fb; int t = img.getType(); - if ((t == BufferedImage.TYPE_3BYTE_BGR) - || (t == BufferedImage.TYPE_4BYTE_ABGR) - || (t == BufferedImage.TYPE_4BYTE_ABGR_PRE)) { - // BGR Type (actually it looks like RBG...) - fb[0] = fa[0]; - fb[1] = fa[2]; - fb[2] = fa[1]; + if (img.getColorModel().hasAlpha()) { + fb = new float[4]; + if ((t == BufferedImage.TYPE_INT_ARGB) + || (t == BufferedImage.TYPE_INT_ARGB_PRE)) { + // RGB Type + fb[0] = fa[0]; + fb[1] = fa[1]; + fb[2] = fa[2]; + fb[3] = 1f; + } else { + // this isn't tested :-( + fb[0] = 1f; + fb[1] = fa[0]; + fb[2] = fa[1]; + fb[3] = fa[2]; + } } else { - fb = fa; + fb = new float[3]; + if (t == BufferedImage.TYPE_3BYTE_BGR) { + // BGR Type (actually it looks like RBG...) + fb[0] = fa[0]; + fb[1] = fa[2]; + fb[2] = fa[1]; + } else { + fb[0] = fa[0]; + fb[1] = fa[1]; + fb[2] = fa[2]; + } } return fb; } @@ -362,11 +387,12 @@ public void rotate(double angle) throws ImageOpException { // setup rotation double rangle = Math.toRadians(angle); - // create offset to make shure the rotated image has no negative coordinates + // create offset to make shure the rotated image has no negative + // coordinates double w = img.getWidth(); double h = img.getHeight(); AffineTransform trafo = new AffineTransform(); - // center of rotation + // center of rotation double x = (w / 2); double y = (h / 2); trafo.rotate(rangle, x, y); @@ -389,13 +415,11 @@ } img = rotImg; // crop new image (with self-made rounding) - /* img = - rotImg.getSubimage( - (int) (bounds.getX()+0.5), - (int) (bounds.getY()+0.5), - (int) (bounds.getWidth()+0.5), - (int) (bounds.getHeight()+0.5)); - */ + /* + * img = rotImg.getSubimage( (int) (bounds.getX()+0.5), (int) + * (bounds.getY()+0.5), (int) (bounds.getWidth()+0.5), (int) + * (bounds.getHeight()+0.5)); + */ } public void mirror(double angle) throws ImageOpException { @@ -432,12 +456,11 @@ img = mirImg; } - /* (non-Javadoc) - * @see java.lang.Object#finalize() - */ + /* (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! + // we must dispose the ImageReader because it keeps the filehandle + // open! reader.dispose(); reader = null; img = null;
--- a/servlet/src/digilib/image/ImageLoaderImageInfoDocuInfo.java Wed Oct 29 22:45:51 2003 +0100 +++ b/servlet/src/digilib/image/ImageLoaderImageInfoDocuInfo.java Wed Oct 29 22:47:15 2003 +0100 @@ -20,8 +20,6 @@ */ package digilib.image; -import ImageInfo; - import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; @@ -31,9 +29,12 @@ import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; +import org.marcoschmidt.image.ImageInfo; + import digilib.io.FileOpException; import digilib.io.FileOps; import digilib.io.ImageFile; +import digilib.io.ImageFileset; /** * @author casties @@ -43,6 +44,7 @@ /* check image size and type and store in ImageFile f */ public boolean checkFile(ImageFile imgf) throws IOException { + ImageFileset imgfs = imgf.getParent(); File f = imgf.getFile(); if (f == null) { throw new IOException("File not found!"); @@ -59,6 +61,9 @@ new ImageSize(iif.getWidth(), iif.getHeight()); imgf.setSize(d); imgf.setMimetype(iif.getMimeType()); + if (imgfs != null) { + imgfs.setAspect(d); + } raf.close(); } else { // else use ImageReader @@ -82,6 +87,9 @@ String t = reader.getFormatName(); t = FileOps.mimeForFile(f); imgf.setMimetype(t); + if (imgfs != null) { + imgfs.setAspect(d); + } // dispose the reader to free resources reader.dispose(); }
--- a/servlet/src/digilib/image/ImageSize.java Wed Oct 29 22:45:51 2003 +0100 +++ b/servlet/src/digilib/image/ImageSize.java Wed Oct 29 22:47:15 2003 +0100 @@ -1,30 +1,25 @@ -/* ImageFile.java -- digilib image file class. - - Digital Image Library servlet components - - Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - Please read license.txt for the full details. A copy of the GPL - may be found at http://www.gnu.org/copyleft/lgpl.html - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * Created on 26.08.2003 +/* + * ImageFile.java -- digilib image file class. + * Digital Image Library servlet components + * Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) + * This program is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. Please read license.txt for the full details. A copy of the GPL may + * be found at http://www.gnu.org/copyleft/lgpl.html You should have received a + * copy of the GNU General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA Created on 26.08.2003 */ package digilib.image; /** Class for image size (width, height). * + * A width or height of 0 is treated as a 'wildcard' that matches any size. + * * @author casties - * + * */ public class ImageSize { public int width; @@ -49,59 +44,130 @@ this.height = height; } - /** Returns if the size of this image is smaller in every dimension than the other image. + /** + * Returns if the size of this image is smaller in every dimension than the + * other image. + * + * * * @param is * @return */ public boolean isTotallySmallerThan(ImageSize is) { - return ((this.width <= is.width) && (this.height <= is.height)); + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height <= is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width <= is.width); + } + return ((this.width <= is.width)&&(this.height <= is.height)); } - /** Returns if the size of this image is smaller in at least one dimension than the other image. + /** + * Returns if the size of this image is smaller in at least one dimension + * than the other image. * * @param is * @return */ public boolean isSmallerThan(ImageSize is) { + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height <= is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width <= is.width); + } return ((this.width <= is.width) || (this.height <= is.height)); } - /** Returns if the size of this image is bigger in every dimension than the other image. + /** + * Returns if the size of this image is bigger in every dimension than the + * other image. + * + * * * @param is * @return */ public boolean isTotallyBiggerThan(ImageSize is) { + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height >= is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width >= is.width); + } return ((this.width >= is.width) && (this.height >= is.height)); } - /** Returns if the size of this image is bigger in at least one dimension than the other image. + /** + * Returns if the size of this image is bigger in at least one dimension + * than the other image. + * + * * * @param is * @return */ public boolean isBiggerThan(ImageSize is) { + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height >= is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width >= is.width); + } return ((this.width >= is.width) || (this.height >= is.height)); } - /** Returns if this image has the same size or height as the other image. + /** + * Returns if this image has the same size or height as the other image. + * + * * * @param is * @return */ public boolean fitsIn(ImageSize is) { - return ((this.width == is.width)&&(this.height <= is.height) - ||(this.width <= is.width)&&(this.height == is.height)); + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height == is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width == is.width); + } + return ( + (this.width == is.width) + && (this.height <= is.height) + || (this.width <= is.width) + && (this.height == is.height)); } - /** Returns if the size of this image is the same as the other image. + /** + * Returns if the size of this image is the same as the other image. + * + * * * @param is * @return */ public boolean equals(ImageSize is) { - return ((this.width == is.width)&&(this.height == is.height)); + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height == is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width == is.width); + } + return ((this.width == is.width) && (this.height == is.height)); } /** @@ -132,4 +198,15 @@ this.width = width; } + /** + * Returns the aspect ratio. + * + * Aspect ratio is (width/height). So it's <1 for portrait and >1 for + * landscape. + * + * @return + */ + public double getAspect() { + return (height > 0) ? ((double) width / (double) height) : 0; + } }
--- a/servlet/src/digilib/io/ImageFile.java Wed Oct 29 22:45:51 2003 +0100 +++ b/servlet/src/digilib/io/ImageFile.java Wed Oct 29 22:47:15 2003 +0100 @@ -124,5 +124,13 @@ public boolean isChecked() { return (pixelSize != null); } + + /** Returns the aspect ratio of the image (width/height). + * + * @return + */ + public double getAspect() { + return (pixelSize != null) ? pixelSize.getAspect() : 0; + } }
--- a/servlet/src/digilib/io/ImageFileset.java Wed Oct 29 22:45:51 2003 +0100 +++ b/servlet/src/digilib/io/ImageFileset.java Wed Oct 29 22:47:15 2003 +0100 @@ -1,21 +1,15 @@ -/* ImageFileset -- digilib image file info class. - - Digital Image Library servlet components - - Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - Please read license.txt for the full details. A copy of the GPL - may be found at http://www.gnu.org/copyleft/lgpl.html - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +/* + * ImageFileset -- digilib image file info class. Digital Image Library + * servlet components Copyright (C) 2003 Robert Casties + * (robcast@mail.berlios.de) This program is free software; you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. Please read license.txt + * for the full details. A copy of the GPL may be found at + * http://www.gnu.org/copyleft/lgpl.html You should have received a copy of + * the GNU General Public License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA */ package digilib.io; @@ -33,16 +27,21 @@ */ public class ImageFileset extends DocuDirent { - // this is an image file + /** this is an image file */ protected static int fileClass = FileOps.CLASS_IMAGE; - // list of files (ImageFile) + /** list of files (ImageFile) */ private ArrayList list = null; - // resolution (DPI) + /** aspect ratio (width/height) */ + private double aspect = 0; + /** resolution of the biggest image (DPI) */ private double resX = 0; + /** resolution of the biggest image (DPI) */ private double resY = 0; - /** Creator for empty fileset with size for file list. + /** + * Creator for empty fileset with size for file list. + * * * @param initialCapacity */ @@ -50,17 +49,22 @@ list = new ArrayList(initialCapacity); } - /** Creator with a file and base directories. + /** + * Creator with a file and base directories. * - * Reads the file and fills the - * fileset with corresponding files from the other base directories. - * First entry in dirs is the parent of this fileset. + * Reads the file and fills the fileset with corresponding files from the + * other base directories. First entry in dirs is the parent of this + * fileset. + * * * @see fill - * - * @param dirs array of base directories - * @param file first file to read - * @param scalext extension for scaled images + * + * @param dirs + * array of base directories + * @param file + * first file to read + * @param scalext + * extension for scaled images */ public ImageFileset(Directory[] dirs, File file, String scalext) { int nb = dirs.length; @@ -69,12 +73,15 @@ fill(dirs, file, scalext); } - /** Adds a ImageFile to this Fileset. + /** + * Adds a ImageFile to this Fileset. * - * The files should be added in the order of higher to lower resolutions. - * The first file is considered the hires "original". + * The files should be added in the order of higher to lower resolutions. + * The first file is considered the hires "original". * - * @param f file to add + * + * @param f + * file to add * @return true (always) */ public boolean add(ImageFile f) { @@ -82,7 +89,9 @@ return list.add(f); } - /** The number of image files in this Fileset. + /** + * The number of image files in this Fileset. + * * * @return number of image files */ @@ -90,14 +99,17 @@ return (list != null) ? list.size() : 0; } - /** Gets the default File. - * + /** + * Gets the default File. + * */ public File getFile() { return (list != null) ? ((ImageFile) list.get(0)).getFile() : null; } - /** Get the ImageFile at the index. + /** + * Get the ImageFile at the index. + * * * @param index * @return @@ -106,13 +118,14 @@ return (ImageFile) list.get(index); } - /** Get the next smaller ImageFile than the given size. + /** + * Get the next smaller ImageFile than the given size. * - * Returns the ImageFile from the set that has a width and height - * smaller or equal the given size. - * Returns null if there isn't any smaller image. + * Returns the ImageFile from the set that has a width and height smaller + * or equal the given size. Returns null if there isn't any smaller image. * Needs DocuInfo instance to checkFile(). * + * * @param size * @param info * @return @@ -135,13 +148,14 @@ return null; } - /** Get the next bigger ImageFile than the given size. + /** + * Get the next bigger ImageFile than the given size. * - * Returns the ImageFile from the set that has a width or height - * bigger or equal the given size. - * Returns null if there isn't any bigger image. + * Returns the ImageFile from the set that has a width or height bigger or + * equal the given size. Returns null if there isn't any bigger image. * Needs DocuInfo instance to checkFile(). * + * * @param size * @param info * @return @@ -164,38 +178,67 @@ return null; } - /** Get an Iterator for this Fileset starting at the highest resolution + /** + * Returns the biggest ImageFile in the set. + * + * + * @return + */ + public ImageFile getBiggest() { + return this.get(0); + } + + /** + * Returns the biggest ImageFile in the set. + * + * + * @return + */ + public ImageFile getSmallest() { + return this.get(this.size() - 1); + } + + /** + * Get an Iterator for this Fileset starting at the highest resolution * images. * + * * @return */ public ListIterator getHiresIterator() { return list.listIterator(); } - /** Get an Iterator for this Fileset starting at the lowest resolution + /** + * Get an Iterator for this Fileset starting at the lowest resolution * images. * - * The Iterator starts at the last element, so you have to use it backwards + * The Iterator starts at the last element, so you have to use it backwards * with hasPrevious() and previous(). * + * * @return */ public ListIterator getLoresIterator() { return list.listIterator(list.size()); } - /** Fill the ImageFileset with files from different base directories. + /** + * Fill the ImageFileset with files from different base directories. + * * - * @param dirs list of base directories - * @param fl file (from first base dir) - * @param scalext first extension to try in other base dirs + * @param dirs + * list of base directories + * @param fl + * file (from first base dir) + * @param scalext + * first extension to try in other base dirs */ void fill(Directory[] dirs, File fl, String scalext) { int nb = dirs.length; String fn = fl.getName(); String fnx = fn.substring(0, fn.lastIndexOf('.') + 1); - // add the first ImageFile to the ImageFileset + // add the first ImageFile to the ImageFileset add(new ImageFile(fn, this, parent)); // iterate the remaining base directories for (int j = 1; j < nb; j++) { @@ -230,8 +273,9 @@ } } - /** Checks metadata and sets resolution in resX and resY. - * + /** + * Checks metadata and sets resolution in resX and resY. + * */ public void checkMeta() { if (metaChecked) { @@ -330,4 +374,27 @@ return resY; } + /** + * Sets the aspect ratio from an ImageSize. + * + * + * @param f + */ + public void setAspect(ImageSize s) { + aspect = s.getAspect(); + } + + /** + * Returns the aspect ratio. + * + * Aspect ratio is (width/height). So it's <1 for portrait and >1 for + * landscape. + * + * + * @return + */ + public double getAspect() { + return aspect; + } + }
--- a/servlet/src/digilib/servlet/DigilibRequest.java Wed Oct 29 22:45:51 2003 +0100 +++ b/servlet/src/digilib/servlet/DigilibRequest.java Wed Oct 29 22:47:15 2003 +0100 @@ -28,7 +28,9 @@ import java.io.File; import java.io.StringReader; +import java.util.Enumeration; import java.util.Hashtable; +import java.util.Iterator; import java.util.StringTokenizer; import javax.servlet.ServletRequest; @@ -36,7 +38,14 @@ 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.*; +import com.hp.hpl.mesa.rdf.jena.model.Model; +import com.hp.hpl.mesa.rdf.jena.model.NodeIterator; +import com.hp.hpl.mesa.rdf.jena.model.Property; +import com.hp.hpl.mesa.rdf.jena.model.RDFNode; +import com.hp.hpl.mesa.rdf.jena.model.Resource; +import com.hp.hpl.mesa.rdf.jena.model.Selector; +import com.hp.hpl.mesa.rdf.jena.model.Statement; +import com.hp.hpl.mesa.rdf.jena.model.StmtIterator; import digilib.image.DocuImage; @@ -54,66 +63,87 @@ * @author casties * */ -public class DigilibRequest { +public class DigilibRequest extends ParameterMap { - private String request_path; // url of the page/document - private String fn; // url of the page/document - private int pn; // page number - private String pn_s; - private int dw; // width of client in pixels - private String dw_s; - private int dh; // height of client in pixels - private String dh_s; - private float wx; // left edge of image (float from 0 to 1) - private String wx_s; - private float wy; // top edge in image (float from 0 to 1) - private String wy_s; - private float ww; // width of image (float from 0 to 1) - private String ww_s; - private float wh; // height of image (float from 0 to 1) - private String wh_s; - private float ws; // scale factor - private String ws_s; - private String mo; // special options like 'fit' for gifs - private String mk; // marks - private int pt; // total number of pages (generated by sevlet) - private String pt_s; - private String baseURL; // base URL (from http:// to below /servlet) - private float rot; // rotation angle in degrees - private String rot_s; - private float cont; // contrast enhancement factor - private String cont_s; - private float brgt; // brightness enhancement factor - private String brgt_s; - private float[] rgbm; // color multiplicative factors - private String rgbm_s; - private float[] rgba; // color additive factors - private String rgba_s; - private int lv; // level of digilib (0 = just image, 1 = one HTML page - // 2 = in frameset, 3 = XUL-'frameset' - // 4 = XUL-Sidebar ) - private String lv_s; - private float odpi; // resolution of original image - private String odpi_s; - private float ddpi; // resolution of original image - private String ddpi_s; - private float odpix; // x resolution of original image - private String odpix_s; - private float odpiy; // y resolution of original image - private String odpiy_s; - private float ddpix; // x resolution of destination image - private String ddpix_s; - private float ddpiy; // y resolution of destination image - private String ddpiy_s; - + private boolean boolRDF = false; // use RDF Parameters private DocuImage image; // internal DocuImage instance for this request private ServletRequest servletRequest; // internal ServletRequest - private boolean boolRDF=false; // uses RDF Parameters - /** Creates a new instance of DigilibRequest and sets default values. */ public DigilibRequest() { - setToDefault(); + // create HashMap(20) + super(30); + + /* + * Definition of parameters and default values. + * Parameter of type 's' are for the servlet. + */ + + // url of the page/document (second part) + putParameter("fn", "", null, 's'); + // page number + putParameter("pn", new Integer(1), null, 's'); + // width of client in pixels + putParameter("dw", new Integer(0), null, 's'); + // height of client in pixels + putParameter("dh", new Integer(0), null, 's'); + // left edge of image (float from 0 to 1) + putParameter("wx", new Float(0), null, 's'); + // top edge in image (float from 0 to 1) + putParameter("wy", new Float(0), null, 's'); + // width of image (float from 0 to 1) + putParameter("ww", new Float(1), null, 's'); + // height of image (float from 0 to 1) + putParameter("wh", new Float(1), null, 's'); + // scale factor + putParameter("ws", new Float(1), null, 's'); + // special options like 'fit' for gifs + putParameter("mo", "", null, 's'); + // rotation angle (degree) + putParameter("rot", new Float(0), null, 's'); + // contrast enhancement factor + putParameter("cont", new Float(0), null, 's'); + // brightness enhancement factor + putParameter("brgt", new Float(0), null, 's'); + // color multiplicative factors + putParameter("rgbm", "0/0/0", null, 's'); + // color additive factors + putParameter("rgba", "0/0/0", null, 's'); + // display dpi resolution (total) + putParameter("ddpi", new Float(0), null, 's'); + // display dpi X resolution + putParameter("ddpix", new Float(0), null, 's'); + // display dpi Y resolution + putParameter("ddpiy", new Float(0), null, 's'); + + /* + * Parameter of type 'i' are not exchanged between client and server + */ + + // url of the page/document (first part, may be empty) + putParameter("request.path", "", null, 'i'); + // base URL (from http:// to below /servlet) + putParameter("base.url", null, null, 'i'); + // DocuImage instance for this request + putParameter("docu.image", image, null, 'i'); + image = null; + // HttpServletRequest for this request + putParameter("servlet.request", servletRequest, null, 'i'); + servletRequest = null; + + /* + * Parameter of type 'c' are for the clients internal use + */ + + // display level of digilib (0 = just image, 1 = one HTML page + // 2 = in frameset, 3 = XUL-'frameset' + // 4 = XUL-Sidebar ) + putParameter("lv", new Integer(2), null, 'c'); + // total number of pages + putParameter("pt", new Integer(0), null, 'c'); + // marks + putParameter("mk", "", null, 'c'); + } /** Creates a new instance of DigilibRequest with parameters from a @@ -123,9 +153,8 @@ * @param request */ public DigilibRequest(ServletRequest request) { - reset(); + this(); setWithRequest(request); - } /** Populate the request object with data from a ServletRequest. @@ -138,8 +167,8 @@ // decide if it's old-style or new-style String qs = ((HttpServletRequest) request).getQueryString(); if (request.getParameter("rdf") != null) { - boolRDF=true; - setWithRDF(request); + boolRDF = true; + setWithRDF(request); } else if (request.getParameter("fn") != null) { setWithParamRequest(request); } else if ((qs != null) && (qs.indexOf("&") > -1)) { @@ -156,21 +185,17 @@ * @param queryString String with paramters in the old "+++" form. */ public void setWithOldString(String queryString) { - if (queryString == null) { return; } - // enable the passing of delimiter to get empty parameters StringTokenizer query = new StringTokenizer(queryString, "+", true); String token; - // first parameter FN if (query.hasMoreTokens()) { token = query.nextToken(); if (!token.equals("+")) { - fn = token; - request_path = null; + setValueFromString("fn", token); if (query.hasMoreTokens()) { query.nextToken(); } @@ -180,13 +205,7 @@ if (query.hasMoreTokens()) { token = query.nextToken(); if (!token.equals("+")) { - try { - int i = Integer.parseInt(token); - pn = i; - pn_s = token; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } + setValueFromString("pn", token); if (query.hasMoreTokens()) { query.nextToken(); } @@ -196,13 +215,7 @@ if (query.hasMoreTokens()) { token = query.nextToken(); if (!token.equals("+")) { - try { - float f = Float.parseFloat(token); - ws = f; - ws_s = token; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } + setValueFromString("ws", token); if (query.hasMoreTokens()) { query.nextToken(); } @@ -212,7 +225,7 @@ if (query.hasMoreTokens()) { token = query.nextToken(); if (!token.equals("+")) { - mo = token; + setValueFromString("mo", token); if (query.hasMoreTokens()) { query.nextToken(); } @@ -222,7 +235,7 @@ if (query.hasMoreTokens()) { token = query.nextToken(); if (!token.equals("+")) { - mk = token; + setValueFromString("mk", token); if (query.hasMoreTokens()) { query.nextToken(); } @@ -232,13 +245,7 @@ if (query.hasMoreTokens()) { token = query.nextToken(); if (!token.equals("+")) { - try { - float f = Float.parseFloat(token); - wx = f; - wx_s = token; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } + setValueFromString("wx", token); if (query.hasMoreTokens()) { query.nextToken(); } @@ -248,13 +255,7 @@ if (query.hasMoreTokens()) { token = query.nextToken(); if (!token.equals("+")) { - try { - float f = Float.parseFloat(token); - wy = f; - wy_s = token; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } + setValueFromString("wy", token); if (query.hasMoreTokens()) { query.nextToken(); } @@ -264,13 +265,7 @@ if (query.hasMoreTokens()) { token = query.nextToken(); if (!token.equals("+")) { - try { - float f = Float.parseFloat(token); - ww = f; - ww_s = token; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } + setValueFromString("ww", token); if (query.hasMoreTokens()) { query.nextToken(); } @@ -280,13 +275,7 @@ if (query.hasMoreTokens()) { token = query.nextToken(); if (!token.equals("+")) { - try { - float f = Float.parseFloat(token); - wh = f; - wh_s = token; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } + setValueFromString("wh", token); if (query.hasMoreTokens()) { query.nextToken(); } @@ -300,75 +289,32 @@ * @return String of request parameters in parameter form. */ public String getAsString() { - String s = ""; - // request_path adds to fn - if ((fn != null) || (request_path != null)) { - s += "fn=" - + ((request_path != null) ? request_path : "") - + ((fn != null) ? fn : ""); - } - if (pn_s != null) { - s += "&pn=" + pn_s; - } - if (dw_s != null && dw_s != "0") { - s += "&dw=" + dw_s; - } - if (dh_s != null && dh_s != "0") { - s += "&dh=" + dh_s; - } - if (wx_s != null) { - s += "&wx=" + wx_s; - } - if (wy_s != null) { - s += "&wy=" + wy_s; - } - if (ww_s != null) { - s += "&ww=" + ww_s; - } - if (wh_s != null) { - s += "&wh=" + wh_s; - } - if (ws_s != null) { - s += "&ws=" + ws_s; - } - if ((mo != null)&&(mo.length() > 0)) { - s += "&mo=" + mo; + StringBuffer s = new StringBuffer(50); + // go through all values + for (Iterator i = this.values().iterator(); i.hasNext();) { + Parameter p = (Parameter) i.next(); + String name = p.getName(); + /* + * handling special cases + */ + // request_path adds to fn + if (name.equals("fn")) { + s.append( + "&fn=" + getAsString("request.path") + getAsString("fn")); + continue; + } + /* + * the rest is sent with its name + */ + // parameters that are not set or internal are not sent + if ((!p.hasValue()) || (p.getType() == 'i')) { + continue; + } + s.append("&" + name + "=" + p.getAsString()); } - if ((mk != null)&&(mk.length() > 0)) { - s += "&mk=" + mk; - } - if (rot_s != null) { - s += "&rot=" + rot_s; - } - if (cont_s != null) { - s += "&cont=" + cont_s; - } - if (brgt_s != null) { - s += "&brgt=" + brgt_s; - } - if (rgbm_s != null) { - s += "&rgbm=" + rgbm_s; - } - if (rgba_s != null) { - s += "&rgba=" + rgba_s; - } - if (pt_s != null) { - s += "&pt=" + pt_s; - } - if (lv_s != null) { - s += "&lv=" + lv_s; - } - if (ddpi_s != null) { - s += "&ddpi=" + ddpi; - } - if (ddpix_s != null) { - s += "&ddpix=" + ddpix; - } - if (ddpiy_s != null) { - s += "&ddpiy=" + ddpiy; - } - - return s; + // kill first "&" + s.deleteCharAt(0); + return s.toString(); } /** Returns request parameters in old '++++' form. @@ -376,18 +322,18 @@ * @return String with parameters in old '++++' form. */ public String getAsOldString() { - String s = ""; - s += (request_path != null) ? request_path : ""; - s += (fn != null) ? fn : ""; - s += "+" + ((pn_s != null) ? pn_s : ""); - s += "+" + ((ws_s != null) ? ws_s : ""); - s += "+" + ((mo != null) ? mo : ""); - s += "+" + ((mk != null) ? mk : ""); - s += "+" + ((wx_s != null) ? wx_s : ""); - s += "+" + ((wy_s != null) ? wy_s : ""); - s += "+" + ((ww_s != null) ? ww_s : ""); - s += "+" + ((wh_s != null) ? wh_s : ""); - return s; + StringBuffer s = new StringBuffer(50); + s.append(getAsString("request.path")); + s.append(getAsString("fn")); + s.append("+" + getAsString("pn")); + s.append("+" + getAsString("ws")); + s.append("+" + getAsString("mo")); + s.append("+" + getAsString("mk")); + s.append("+" + getAsString("wx")); + s.append("+" + getAsString("wy")); + s.append("+" + getAsString("ww")); + s.append("+" + getAsString("wh")); + return s.toString(); } /** Set request parameters from javax.servlet.ServletRequest. Uses the Requests @@ -396,352 +342,123 @@ * @param request ServletRequest to get parameters from. */ public void setWithParamRequest(ServletRequest request) { - String s; - s = request.getParameter("fn"); - if (s != null) { - setFn(s); - } - s = request.getParameter("pn"); - if (s != null) { - setPn(s); - } - s = request.getParameter("ws"); - if (s != null) { - setWs(s); - } - s = request.getParameter("mo"); - if (s != null) { - setMo(s); - } - s = request.getParameter("mk"); - if (s != null) { - setMk(s); - } - s = request.getParameter("wx"); - if (s != null) { - setWx(s); - } - s = request.getParameter("wy"); - if (s != null) { - setWy(s); - } - s = request.getParameter("ww"); - if (s != null) { - setWw(s); - } - s = request.getParameter("wh"); - if (s != null) { - setWh(s); - } - s = request.getParameter("dw"); - if (s != null) { - setDw(s); - } - s = request.getParameter("dh"); - if (s != null) { - setDh(s); + setValue("servlet.request", request); + // go through all request parameters + for (Enumeration i = request.getParameterNames(); + i.hasMoreElements(); + ) { + String name = (String) i.nextElement(); + // is this a known parameter? + if (this.containsKey(name)) { + Parameter p = (Parameter) this.get(name); + // internal parameters are not set + if (p.getType() == 'i') { + continue; + } + p.setValueFromString(request.getParameter(name)); + continue; + } + // unknown parameters are just added with type 'r' + putParameter(name, null, request.getParameter(name), 'r'); } - s = request.getParameter("rot"); - if (s != null) { - setRot(s); - } - s = request.getParameter("cont"); - if (s != null) { - setCont(s); - } - s = request.getParameter("brgt"); - if (s != null) { - setBrgt(s); - } - s = request.getParameter("rgbm"); - if (s != null) { - setRgbm(s); - } - s = request.getParameter("rgba"); - if (s != null) { - setRgba(s); + // add path from request + setValue("request.path", ((HttpServletRequest) request).getPathInfo()); + } + + /** + * + * + */ + public void setWithRDF(ServletRequest request) { + 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(); + // is this a known parameter? + if (this.containsKey(name)) { + Parameter p = (Parameter) this.get(name); + // internal parameters are not set + if (p.getType() == 'i') { + continue; + } + p.setValueFromString((String) hashRDF.get(name)); + } + } } - s = request.getParameter("pt"); - if (s != null) { - setPt(s); - } - s = request.getParameter("lv"); - if (s != null) { - setLv(s); - } - s = request.getParameter("ddpi"); - if (s != null) { - setDdpi(s); - } - s = request.getParameter("ddpix"); - if (s != null) { - setDdpix(s); - } - s = request.getParameter("ddpiy"); - if (s != null) { - setDdpiy(s); - } - s = ((HttpServletRequest) request).getPathInfo(); - if (s != null) { - setRequestPath(s); - } + // add path from request + setValue("request.path", ((HttpServletRequest) request).getPathInfo()); } -/** - * - * - */ - public void setWithRDF(ServletRequest request) { - String strRDF; - strRDF = request.getParameter("rdf"); - if (strRDF != null) { - //System.out.println(strRDF); - Hashtable hashRDF=rdf2hash(strRDF); - //System.out.println(hashRDF.toString()); - String s; - s = (String)hashRDF.get("fn"); - if (s != null) { - setFn(s); - } - s = (String)hashRDF.get("pn"); - if (s != null) { - setPn(s); - } - s = (String)hashRDF.get("ws"); - if (s != null) { - setWs(s); - } - s = (String)hashRDF.get("mo"); - if (s != null) { - setMo(s); - } - s = (String)hashRDF.get("mk"); - if (s != null) { - setMk(s); - } - s = (String)hashRDF.get("wx"); - if (s != null) { - setWx(s); - } - s = (String)hashRDF.get("wy"); - if (s != null) { - setWy(s); - } - s = (String)hashRDF.get("ww"); - if (s != null) { - setWw(s); - } - s = (String)hashRDF.get("wh"); - if (s != null) { - setWh(s); - } - s = (String)hashRDF.get("dw"); - if (s != null) { - setDw(s); - } - s = (String)hashRDF.get("dh"); - if (s != null) { - setDh(s); - } - s = (String)hashRDF.get("rot"); - if (s != null) { - setRot(s); - } - s = (String)hashRDF.get("cont"); - if (s != null) { - setCont(s); - } - s = (String)hashRDF.get("brgt"); - if (s != null) { - setBrgt(s); - } - s = (String)hashRDF.get("rgbm"); - if (s != null) { - setRgbm(s); - } - s = (String)hashRDF.get("rgba"); - if (s != null) { - setRgba(s); - } - s = (String)hashRDF.get("pt"); - if (s != null) { - setPt(s); - } - s = (String)hashRDF.get("lv"); - if (s != null) { - setLv(s); - } - s = (String)hashRDF.get("ddpi"); - if (s != null) { - setDdpi(s); - } - s = (String)hashRDF.get("ddpix"); - if (s != null) { - setDdpix(s); - } - s = (String)hashRDF.get("ddpiy"); - if (s != null) { - setDdpiy(s); + private Hashtable rdf2hash(String strRDF) { + Hashtable hashParams = new Hashtable(); + try { + // create an empty model + Model model = new ModelMem(); + StringReader sr = new StringReader(strRDF); + model.read(sr, ""); + // 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; + NodeIterator i = model.listObjectsOfProperty(p); + 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 + StmtIterator iter = model.listStatements(selector); + // add predicate and object to Hashtable + while (iter.hasNext()) { + Statement stmt = iter.next(); // get next statement + Resource subject = stmt.getSubject(); + // get the subject + Property predicate = stmt.getPredicate(); + // get the predicate + RDFNode object = stmt.getObject(); // get the object + + String strKey = predicate.toString(); + String strValue = ""; + + if (object instanceof Resource) { + strValue = object.toString(); + } else { + // object is a literal + strValue = object.toString(); + } + String strDigilibKey = + strKey.substring( + strKey.indexOf("#") + 1, + strKey.length()); + hashParams.put(strDigilibKey, strValue); + } + } + } + } catch (Exception e) { + System.out.println("Failed: " + e); } - s = ((HttpServletRequest) request).getPathInfo(); - if (s != null) { - setRequestPath(s); - } - } - } - - private Hashtable rdf2hash(String strRDF){ - Hashtable hashParams=new Hashtable(); - try { - // create an empty model - Model model = new ModelMem(); - StringReader sr=new StringReader(strRDF); - model.read(sr,""); - // 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; - NodeIterator i=model.listObjectsOfProperty(p); - 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 - StmtIterator iter = model.listStatements(selector); - // add predicate and object to Hashtable - while (iter.hasNext()) { - Statement stmt = iter.next(); // get next statement - Resource subject = stmt.getSubject(); // get the subject - Property predicate = stmt.getPredicate(); // get the predicate - RDFNode object = stmt.getObject(); // get the object - - String strKey=predicate.toString(); - String strValue=""; - - if (object instanceof Resource) { - strValue=object.toString(); - } else { - // object is a literal - strValue=object.toString(); - } - String strDigilibKey=strKey.substring(strKey.indexOf("#")+1,strKey.length()); - hashParams.put(strDigilibKey,strValue); - } - } - } - } catch (Exception e) { - System.out.println("Failed: " + e); - } - return hashParams; - } - - - /** Reset all request parameters to null. */ - public void reset() { - request_path = null; // url of the page/document - - lv = 0; // level of digilib cf. variable declaration - lv_s = null; - fn = null; // url of the page/document - pn = 0; // page number - pn_s = null; - dw = 0; // width of client in pixels - dw_s = null; - dh = 0; // height of client in pixels - dh_s = null; - wx = 0f; // left edge of image (float from 0 to 1) - wx_s = null; - wy = 0f; // top edge in image (float from 0 to 1) - wy_s = null; - ww = 0f; // width of image (float from 0 to 1) - ww_s = null; - wh = 0f; // height of image (float from 0 to 1) - wh_s = null; - ws = 0f; // scale factor - ws_s = null; - mo = null; // special options like 'fit' for gifs - mk = null; // marks - pt = 0; // total number of pages - pt_s = null; - rot = 0; - rot_s = null; - cont = 0; - cont_s = null; - brgt = 0; - brgt_s = null; - rgbm = null; - rgbm_s = null; - rgba = null; - rgba_s = null; - ddpi = 0; - ddpi_s = null; - ddpix = 0; - ddpix_s = null; - ddpiy = 0; - ddpiy_s = null; - odpi = 0; - odpi_s = null; - odpix = 0; - odpix_s = null; - odpiy = 0; - odpiy_s = null; - baseURL = null; - image = null; - servletRequest = null; - } - - /** Reset all request parameters to default values. */ - public void setToDefault() { - lv = 2; // default level - lv_s = "2"; - request_path = ""; // url of the page/document - fn = ""; // url of the page/document - pn = 1; // page number - pn_s = "1"; - dw = 0; // width of client in pixels - dw_s = "0"; - dh = 0; // height of client in pixels - dh_s = "0"; - wx = 0f; // left edge of image (float from 0 to 1) - wx_s = "0"; - wy = 0f; // top edge in image (float from 0 to 1) - wy_s = "0"; - ww = 1f; // width of image (float from 0 to 1) - ww_s = "1"; - wh = 1f; // height of image (float from 0 to 1) - wh_s = "1"; - ws = 1f; // scale factor - ws_s = "1"; - mo = ""; // special options like 'fit' for gifs - mk = ""; // marks - pt = 0; // total number of pages - pt_s = null; - rot = 0; - rot_s = null; - cont = 0; - cont_s = null; - brgt = 0; - brgt_s = null; - rgbm = null; - rgbm_s = null; - rgba = null; - baseURL = null; - image = null; - servletRequest = null; + 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>mo</code>. + * string <code>param</code>. * * @param opt Option string to be tested. * @return boolean */ - public boolean isOption(String opt) { - if ((mo != null) && (mo.indexOf(opt) >= 0)) { + public boolean hasOption(String param, String opt) { + String s = getAsString(param); + if ((s != null) && (s.indexOf(opt) >= 0)) { return true; } return false; @@ -755,8 +472,8 @@ * @return String the effective filepath. */ public String getFilePath() { - String s = getRequestPath(); - s += getFn(); + String s = getAsString("request.path"); + s += getAsString("fn"); if (s.startsWith(File.separator)) { return s.substring(1); } else { @@ -766,343 +483,11 @@ /* Property getter and setter */ - /** Getter for property lv. - * @return Value of property lv. - * - */ - public int getLv() { - return lv; - } - - /** Setter for property lv. - * @param lv New value of property lv. - * - */ - public void setLv(int lv) { - this.lv = lv; - lv_s = Integer.toString(lv); - } - public void setLv(String lv) { - try { - int i = Integer.parseInt(lv); - this.lv = i; - this.lv_s = lv; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property dh. - * @return Value of property dh. - * - */ - public int getDh() { - return dh; - } - - /** Setter for property dh. - * @param dh New value of property dh. - * - */ - public void setDh(int dh) { - this.dh = dh; - dh_s = Integer.toString(dh); - } - public void setDh(String dh) { - try { - int i = Integer.parseInt(dh); - this.dh = i; - this.dh_s = dh; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property dw. - * @return Value of property dw. - * - */ - public int getDw() { - return dw; - } - - /** Setter for property dw. - * @param dw New value of property dw. - * - */ - public void setDw(int dw) { - this.dw = dw; - dw_s = Integer.toString(dw); - } - public void setDw(String dw) { - try { - int i = Integer.parseInt(dw); - this.dw = i; - this.dw_s = dw; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property fn. - * @return Value of property fn. - * - */ - public String getFn() { - return (fn != null) ? fn : ""; - } - - /** Setter for property fn. - * @param fn New value of property fn. - * - */ - public void setFn(String fn) { - this.fn = fn; - } - - /** Getter for property mo. - * @return Value of property mo. - * - */ - public String getMo() { - return (mo != null) ? mo : ""; - } - - /** Setter for property mo. - * @param mo New value of property mo. - * - */ - public void setMo(String mo) { - this.mo = mo; - } - - /** Getter for property pn. - * @return Value of property pn. - * - */ - public int getPn() { - return pn; - } - - /** Setter for property pn. - * @param pn New value of property pn. - * - */ - public void setPn(int pn) { - this.pn = pn; - pn_s = Integer.toString(pn); - } - public void setPn(String pn) { - try { - int i = Integer.parseInt(pn); - this.pn = i; - this.pn_s = pn; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property request_path. - * @return Value of property request_path. - * - */ - public String getRequestPath() { - return (request_path != null) ? request_path : ""; - } - - /** Setter for property request_path. - * @param request_path New value of property request_path. - * - */ - public void setRequestPath(String request_path) { - this.request_path = request_path; - } - - /** Getter for property wh. - * @return Value of property wh. - * - */ - public float getWh() { - return wh; - } - - /** Setter for property wh. - * @param wh New value of property wh. - * - */ - public void setWh(float wh) { - this.wh = wh; - wh_s = Float.toString(wh); - } - public void setWh(String wh) { - try { - float f = Float.parseFloat(wh); - this.wh = f; - this.wh_s = wh; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property ws. - * @return Value of property ws. - * - */ - public float getWs() { - return ws; - } - - /** Setter for property ws. - * @param ws New value of property ws. - * - */ - public void setWs(float ws) { - this.ws = ws; - ws_s = Float.toString(ws); - } - public void setWs(String ws) { - try { - float f = Float.parseFloat(ws); - this.ws = f; - this.ws_s = ws; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property ww. - * @return Value of property ww. - * - */ - public float getWw() { - return ww; - } - - /** Setter for property ww. - * @param ww New value of property ww. - * - */ - public void setWw(float ww) { - this.ww = ww; - ww_s = Float.toString(ww); - } - public void setWw(String ww) { - try { - float f = Float.parseFloat(ww); - this.ww = f; - this.ww_s = ww; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property wx. - * @return Value of property wx. - * - */ - public float getWx() { - return wx; - } - - /** Setter for property wx. - * @param wx New value of property wx. - * - */ - public void setWx(float wx) { - this.wx = wx; - wx_s = Float.toString(wx); - } - public void setWx(String wx) { - try { - float f = Float.parseFloat(wx); - this.wx = f; - this.wx_s = wx; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property wy. - * @return Value of property wy. - * - */ - public float getWy() { - return wy; - } - - /** Setter for property wy. - * @param wy New value of property wy. - * - */ - public void setWy(float wy) { - this.wy = wy; - wy_s = Float.toString(wy); - } - public void setWy(String wy) { - try { - float f = Float.parseFloat(wy); - this.wy = f; - this.wy_s = wy; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property mk. - * @return Value of property mk. - * - */ - public String getMk() { - return (mk != null) ? mk : "0/0"; - } - - /** Setter for property mk. - * @param mk New value of property mk. - * - */ - public void setMk(String mk) { - this.mk = mk; - } - - /** Getter for property pt. - * @return Value of property pt. - * - */ - public int getPt() { - return pt; - } - - /** Setter for property pt. - * @param pt New value of property pt. - * - */ - public void setPt(int pt) { - this.pt = pt; - pt_s = Integer.toString(pt); - } - public void setPt(String pt) { - try { - int i = Integer.parseInt(pt); - this.pt = i; - this.pt_s = pt; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Returns the base URL (from http:// up to the base directory without file name or - * /servlet). Base URL has to be set from a request via setBaseURL or - * setWithRequest. - * @return String with the base URL. - */ - public String getBaseURL() { - return (baseURL != null) ? baseURL : ""; - } - /** 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; // calculate base URL string from request (minus last part) String s = request.getRequestURL().toString(); int eop = s.lastIndexOf("/"); @@ -1115,6 +500,7 @@ + request.getServerName() + "/docuserver/digitallibrary"; } + setValue("base.url", baseURL); } /** @@ -1131,347 +517,18 @@ */ public void setImage(DocuImage image) { this.image = image; + setValue("docu.image", image); + } + + public boolean isRDF() { + return boolRDF; } /** - * Returns the servletRequest. - * @return ServletRequest + * @return */ public ServletRequest getServletRequest() { return servletRequest; } - /** - * Sets the servletRequest. - * @param servletRequest The servletRequest to set - */ - public void setServletRequest(ServletRequest servletRequest) { - this.servletRequest = servletRequest; - } - - /** - * Returns the rot. - * @return float - */ - public float getRot() { - return rot; - } - - /** - * Sets the rot. - * @param rot The rot to set - */ - public void setRot(float rot) { - this.rot = rot; - this.rot_s = Float.toString(rot); // lugi - cleanup : war rot_s statt this.rot_s - } - public void setRot(String rot) { - try { - float f = Float.parseFloat(rot); - this.rot = f; - this.rot_s = rot; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** - * Returns the rot. - * @return float - */ - public float getCont() { - return cont; - } - - /** - * Sets the rot. - * @param rot The rot to set - */ - public void setCont(float cont) { - this.cont = cont; - this.cont_s = Float.toString(cont); // lugi - bugfix : war rot_s statt this.cont_s - } - public void setCont(String cont) { - try { - float f = Float.parseFloat(cont); - this.cont = f; - this.cont_s = cont; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** - * Returns the brgt. - * @return float - */ - public float getBrgt() { - return this.brgt; - } - - /** - * Sets the brgt. - * @param brgt The brgt to set - */ - public void setBrgt(float brgt) { - this.brgt = brgt; - this.brgt_s = Float.toString(brgt); - } - public void setBrgt(String brgt) { - try { - float f = Float.parseFloat(brgt); - this.brgt = f; - this.brgt_s = brgt; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** - * @return float[] - */ - public float[] getRgba() { - return this.rgba; - } - - /** - * @return float[] - */ - public float[] getRgbm() { - return this.rgbm; - } - -// lugi - begin - - /** - * @return string property Rgba. - */ - public String getRgba_s() { - if (rgba_s != null) { - return this.rgba_s; - } else { - return ""; - } - } - - /** - * @return string property Rgbm. - */ - public String getRgbm_s() { - if (rgbm_s != null) { - return this.rgbm_s; - } else { - return ""; - } - } - -// lugi - end - - /** - * Sets the rgba. - * @param rgba The rgba to set - */ - public void setRgba(float[] rgba) { - this.rgba = rgba; - this.rgba_s = rgba[0] + "/" + rgba[1] + "/" + rgba[2]; // lugi - bugfix : save string representation was missing - } - public void setRgba(String s) { - try { - String[] sa = s.split("/"); - float[] fa = new float[3]; - for (int i = 0; i < 3; i++) { - float f = Float.parseFloat(sa[i]); - fa[i] = f; - } - this.rgba_s = s; - this.rgba = fa; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** - * Sets the rgbm. - * @param rgbm The rgbm to set - */ - public void setRgbm(float[] rgbm) { - this.rgbm = rgbm; - this.rgbm_s = rgbm[0] + "/" + rgbm[1] + "/" + rgbm[2]; // lugi - bugfix : save string representation was missing - } - public void setRgbm(String s) { - try { - String[] sa = s.split("/"); - float[] fa = new float[3]; - for (int i = 0; i < 3; i++) { - float f = Float.parseFloat(sa[i]); - fa[i] = f; - } - this.rgbm_s = s; - this.rgbm = fa; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property ddpi. - * @return Value of property ddpi. - * - */ - public float getDdpi() { - return ddpi; - } - - /** Setter for property ddpi. - * @param ddpi New value of property ddpi. - * - */ - public void setDdpi(float ddpi) { - this.ddpi = ddpi; - ddpi_s = Float.toString(ddpi); - } - public void setDdpi(String ddpi) { - try { - float f = Float.parseFloat(ddpi); - this.ddpi = f; - this.ddpi_s = ddpi; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property ddpi. - * @return Value of property ddpi. - * - */ - public float getDdpix() { - return ddpix; - } - - /** Setter for property ddpi. - * @param ddpi New value of property ddpi. - * - */ - public void setDdpix(float ddpix) { - this.ddpix = ddpix; - ddpix_s = Float.toString(ddpix); - } - public void setDdpix(String s) { - try { - float f = Float.parseFloat(s); - this.ddpix = f; - this.ddpix_s = s; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property ddpi. - * @return Value of property ddpi. - * - */ - public float getDdpiy() { - return ddpiy; - } - - /** Setter for property ddpi. - * @param ddpi New value of property ddpi. - * - */ - public void setDdpiy(float f) { - this.ddpiy = f; - ddpiy_s = Float.toString(f); - } - public void setDdpiy(String s) { - try { - float f = Float.parseFloat(s); - this.ddpiy = f; - this.ddpiy_s = s; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property ddpi. - * @return Value of property ddpi. - * - */ - public float getOdpi() { - return odpi; - } - - /** Setter for property ddpi. - * @param ddpi New value of property ddpi. - * - */ - public void setOdpi(float f) { - this.odpi = f; - odpi_s = Float.toString(f); - } - public void setOdpi(String s) { - try { - float f = Float.parseFloat(s); - this.odpi = f; - this.odpi_s = s; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property ddpi. - * @return Value of property ddpi. - * - */ - public float getOdpix() { - return odpix; - } - - /** Setter for property ddpi. - * @param ddpi New value of property ddpi. - * - */ - public void setOdpix(float f) { - this.odpix = f; - odpix_s = Float.toString(f); - } - public void setOdpix(String s) { - try { - float f = Float.parseFloat(s); - this.odpix = f; - this.odpix_s = s; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - /** Getter for property ddpi. - * @return Value of property ddpi. - * - */ - public float getOdpiy() { - return odpiy; - } - - /** Setter for property ddpi. - * @param ddpi New value of property ddpi. - * - */ - public void setOdpiy(float f) { - this.odpiy = f; - odpiy_s = Float.toString(f); - } - public void setOdpiy(String s) { - try { - float f = Float.parseFloat(s); - this.odpiy = f; - this.odpiy_s = s; - } catch (Exception e) { - //util.dprintln(4, "trytoGetParam(int) failed on param "+s); - } - } - - - public boolean isRDF(){ - return boolRDF; - } - }
--- a/servlet/src/digilib/servlet/Parameter.java Wed Oct 29 22:45:51 2003 +0100 +++ b/servlet/src/digilib/servlet/Parameter.java Wed Oct 29 22:47:15 2003 +0100 @@ -87,6 +87,7 @@ * @return */ public boolean setValueFromString(String val) { + // no default matches all if (defval == null) { this.value = val; return true; @@ -102,15 +103,18 @@ this.value = new Boolean(val.compareToIgnoreCase("true") == 0); return true; } - // set Integer - if (c == Integer.class) { - this.value = new Integer(Integer.parseInt(val)); - return true; - } - // set Float - if (c == Float.class) { - this.value = new Float(Float.parseFloat(val)); - return true; + try { + // set Integer + if (c == Integer.class) { + this.value = new Integer(Integer.parseInt(val)); + return true; + } + // set Float + if (c == Float.class) { + this.value = new Float(Float.parseFloat(val)); + return true; + } + } catch (NumberFormatException e) { } // then it's unknown return false; @@ -152,7 +156,8 @@ } public String getAsString() { - return (String) getValue(); + Object s = getValue(); + return (s != null) ? s.toString() : ""; } public boolean getAsBoolean() { @@ -160,6 +165,30 @@ return (b != null) ? b.booleanValue() : false; } + public String[] parseAsArray(String separator) { + String s = getAsString(); + String[] sa = s.split(separator); + return sa; + } + + public float[] parseAsFloatArray(String separator) { + String s = getAsString(); + String[] sa = s.split(separator); + float[] fa = null; + try { + int n = sa.length; + fa = new float[n]; + for (int i = 0; i < n; i++) { + float f = Float.parseFloat(sa[i]); + fa[i] = f; + } + } catch (Exception e) { + //System.out.println("ERROR: trytoGetParam(int) failed on param "+name); + } + + return fa; + } + /** Set the value. * * @param value @@ -168,6 +197,22 @@ this.value = value; } + /** Set the value. + * + * @param value + */ + public void setValue(int value) { + this.value = new Integer(value); + } + + /** Set the value. + * + * @param value + */ + public void setValue(float value) { + this.value = new Float(value); + } + /** * @return */
--- a/servlet/src/digilib/servlet/ParameterMap.java Wed Oct 29 22:45:51 2003 +0100 +++ b/servlet/src/digilib/servlet/ParameterMap.java Wed Oct 29 22:47:15 2003 +0100 @@ -58,31 +58,76 @@ return (Parameter) super.get(key); } + /** Get the Parameter with the corresponding key. + * + * Returns null if no element is associated with key. + * + * @param key + * @return + */ public Object getValue(String key) { Parameter p = (Parameter) super.get(key); return (p != null) ? p.getValue() : null; } + /** Get the Parameter with the corresponding key. + * + * Returns null if no element is associated with key. + * + * @param key + * @return + */ public String getAsString(String key) { Parameter p = (Parameter) super.get(key); return (p != null) ? p.getAsString() : null; } + /** Get the Parameter with the corresponding key. + * + * Returns null if no element is associated with key. + * + * @param key + * @return + */ public int getAsInt(String key) { Parameter p = (Parameter) super.get(key); return (p != null) ? p.getAsInt() : 0; } + /** Get the Parameter with the corresponding key. + * + * Returns null if no element is associated with key. + * + * @param key + * @return + */ public float getAsFloat(String key) { Parameter p = (Parameter) super.get(key); return (p != null) ? p.getAsFloat() : 0f; } + /** Get the Parameter with the corresponding key. + * + * Returns null if no element is associated with key. + * + * @param key + * @return + */ public boolean getAsBoolean(String key) { Parameter p = (Parameter) super.get(key); return (p != null) ? p.getAsBoolean() : false; } + /** Returns if the Parameter's value has been set. + * + * @param key + * @return + */ + public boolean hasValue(String key) { + Parameter p = (Parameter) super.get(key); + return (p != null) ? p.hasValue() : false; + } + /** Add the Parameter to the map with a certain key. * * Returns the value that was previously associated with key. @@ -151,4 +196,55 @@ } return false; } + + /** Set the value of an existing parameter. + * + * Sets the value and returns true if the parameter exists. + * + * @param key + * @param val + * @return + */ + public boolean setValue(String key, int val) { + Parameter p = get(key); + if (p != null) { + p.setValue(val); + return true; + } + return false; + } + + /** Set the value of an existing parameter. + * + * Sets the value and returns true if the parameter exists. + * + * @param key + * @param val + * @return + */ + public boolean setValue(String key, float val) { + Parameter p = get(key); + if (p != null) { + p.setValue(val); + return true; + } + return false; + } + + /** Set the value of an existing parameter. + * + * Sets the value and returns true if the parameter exists. + * + * @param key + * @param val + * @return + */ + public boolean setValueFromString(String key, String val) { + Parameter p = get(key); + if (p != null) { + p.setValueFromString(val); + return true; + } + return false; + } }
--- a/servlet/src/digilib/servlet/Scaler.java Wed Oct 29 22:45:51 2003 +0100 +++ b/servlet/src/digilib/servlet/Scaler.java Wed Oct 29 22:47:15 2003 +0100 @@ -51,14 +51,12 @@ //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.16a4"; + public static final String dlVersion = "1.16b2"; // Utils instance with debuglevel Utils util; @@ -92,7 +90,8 @@ // try to enlarge cropping area for "oblique" angles boolean wholeRotArea = false; - /** Initialisation on first run. + /** + * Initialisation on first run. * * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) */ @@ -181,9 +180,7 @@ // output mime/type String mimeType = "image/png"; - /* - * parameters for a session - */ + /* parameters for a session */ // scale the image file to fit window size i.e. respect dw,dh boolean scaleToFit = true; @@ -209,75 +206,74 @@ double origResX = 0; double origResY = 0; - /* - * request parameters - */ + /* request parameters */ DigilibRequest dlRequest = (DigilibRequest) request.getAttribute("digilib.servlet.request"); // destination image width - int paramDW = dlRequest.getDw(); + int paramDW = dlRequest.getAsInt("dw"); // destination image height - int paramDH = dlRequest.getDh(); - // dw and dh shouldn't be empty, if they are, set dw=dh - if (paramDW <= 0) { - paramDW = paramDH; - } - if (paramDH <= 0) { - paramDH = paramDW; - } + int paramDH = dlRequest.getAsInt("dh"); // relative area x_offset (0..1) - double paramWX = dlRequest.getWx(); + double paramWX = dlRequest.getAsFloat("wx"); // relative area y_offset - double paramWY = dlRequest.getWy(); + double paramWY = dlRequest.getAsFloat("wy"); // relative area width (0..1) - double paramWW = dlRequest.getWw(); + double paramWW = dlRequest.getAsFloat("ww"); // relative area height - double paramWH = dlRequest.getWh(); + double paramWH = dlRequest.getAsFloat("wh"); // scale factor (additional to dw/width, dh/height) - double paramWS = dlRequest.getWs(); + double paramWS = dlRequest.getAsFloat("ws"); // rotation angle - double paramROT = dlRequest.getRot(); + double paramROT = dlRequest.getAsFloat("rot"); // contrast enhancement - float paramCONT = dlRequest.getCont(); + float paramCONT = dlRequest.getAsFloat("cont"); // brightness enhancement - float paramBRGT = dlRequest.getBrgt(); + float paramBRGT = dlRequest.getAsFloat("brgt"); // color modification - float[] paramRGBM = dlRequest.getRgbm(); - float[] paramRGBA = dlRequest.getRgba(); + float[] paramRGBM = null; + Parameter p = dlRequest.get("rgbm"); + if (p.hasValue() && (!p.getAsString().equals("0/0/0"))) { + paramRGBM = p.parseAsFloatArray("/"); + } + float[] paramRGBA = null; + p = dlRequest.get("rgba"); + if (p.hasValue() && (!p.getAsString().equals("0/0/0"))) { + paramRGBA = p.parseAsFloatArray("/"); + } // destination resolution (DPI) - float paramDDPIX = dlRequest.getDdpix(); - float paramDDPIY = dlRequest.getDdpiy(); + float paramDDPIX = dlRequest.getAsFloat("ddpix"); + float paramDDPIY = dlRequest.getAsFloat("ddpiy"); if ((paramDDPIX == 0) || (paramDDPIY == 0)) { // if X or Y resolution isn't set, use DDPI - paramDDPIX = dlRequest.getDdpi(); - paramDDPIY = dlRequest.getDdpi(); + paramDDPIX = dlRequest.getAsFloat("ddpi"); + paramDDPIY = paramDDPIX; } - /* operation mode: "fit": always fit to page, - * "clip": send original resolution cropped, "file": send whole file (if - * allowed) + /* + * operation mode: "fit": always fit to page, "clip": send original + * resolution cropped, "file": send whole file (if allowed) */ - if (dlRequest.isOption("clip")) { + if (dlRequest.hasOption("mo", "clip")) { scaleToFit = false; absoluteScale = false; cropToFit = true; sendFile = false; hiresOnly = true; - } else if (dlRequest.isOption("fit")) { + } else if (dlRequest.hasOption("mo", "fit")) { scaleToFit = true; absoluteScale = false; cropToFit = false; sendFile = false; hiresOnly = false; - } else if (dlRequest.isOption("osize")) { + } else if (dlRequest.hasOption("mo", "osize")) { scaleToFit = false; absoluteScale = true; cropToFit = false; sendFile = false; hiresOnly = true; - } else if (dlRequest.isOption("file")) { + } else if (dlRequest.hasOption("mo", "file")) { scaleToFit = false; absoluteScale = false; if (sendFileAllowed) { @@ -290,30 +286,32 @@ } hiresOnly = true; } - // operation mode: "lores": try to use scaled image, "hires": use unscaled image + // operation mode: "lores": try to use scaled image, "hires": use + // unscaled image // "autores": try best fitting resolution - if (dlRequest.isOption("lores")) { + if (dlRequest.hasOption("mo", "lores")) { loresOnly = true; hiresOnly = false; - } else if (dlRequest.isOption("hires")) { + } else if (dlRequest.hasOption("mo", "hires")) { loresOnly = false; hiresOnly = true; - } else if (dlRequest.isOption("autores")) { + } else if (dlRequest.hasOption("mo", "autores")) { loresOnly = false; hiresOnly = false; } - // operation mode: "errtxt": error message in html, "errimg": error image - if (dlRequest.isOption("errtxt")) { + // operation mode: "errtxt": error message in html, "errimg": error + // image + if (dlRequest.hasOption("mo", "errtxt")) { errorMsgHtml = true; - } else if (dlRequest.isOption("errimg")) { + } else if (dlRequest.hasOption("mo", "errimg")) { errorMsgHtml = false; } // operation mode: "q0" - "q2": interpolation quality - if (dlRequest.isOption("q0")) { + if (dlRequest.hasOption("mo", "q0")) { scaleQual = 0; - } else if (dlRequest.isOption("q1")) { + } else if (dlRequest.hasOption("mo", "q1")) { scaleQual = 1; - } else if (dlRequest.isOption("q2")) { + } else if (dlRequest.hasOption("mo", "q2")) { scaleQual = 2; } @@ -326,16 +324,12 @@ // new DocuInfo instance DocuInfo docuInfo = new ImageLoaderImageInfoDocuInfo(); - /* - * find the file to load/send - */ + /* find the file to load/send */ // get PathInfo String loadPathName = dlRequest.getFilePath(); - /* - * check permissions - */ + /* check permissions */ if (useAuthentication) { // get a list of required roles (empty if no restrictions) List rolesRequired = authOp.rolesForPath(loadPathName, request); @@ -363,21 +357,18 @@ fileset = (ImageFileset) dirCache.getFile( loadPathName, - dlRequest.getPn(), + dlRequest.getAsInt("pn"), FileOps.CLASS_IMAGE); if (fileset == null) { throw new FileOpException( "File " + loadPathName + "(" - + dlRequest.getPn() + + dlRequest.getAsInt("pn") + ") not found."); } - - /* - * calculate expected source image size - * - */ + + /* calculate expected source image size */ ImageSize expectedSourceSize = new ImageSize(); if (scaleToFit) { double scale = (1 / Math.min(paramWW, paramWH)) * paramWS; @@ -390,19 +381,17 @@ (int) (paramDH * paramWS)); } - /* - * select a resolution - */ + /* select a resolution */ if (hiresOnly) { // get first element (= highest resolution) - fileToLoad = fileset.get(0); + fileToLoad = fileset.getBiggest(); } else if (loresOnly) { // enforced lores uses next smaller resolution fileToLoad = fileset.getNextSmaller(expectedSourceSize, docuInfo); if (fileToLoad == null) { // this is the smallest we have - fileToLoad = fileset.get(fileset.size() - 1); + fileToLoad = fileset.getSmallest(); } } else { // autores: use next higher resolution @@ -410,7 +399,7 @@ fileset.getNextBigger(expectedSourceSize, docuInfo); if (fileToLoad == null) { // this is the highest we have - fileToLoad = fileset.get(0); + fileToLoad = fileset.getBiggest(); } } util.dprintln(1, "Loading: " + fileToLoad.getFile()); @@ -444,8 +433,8 @@ || mimeType.equals("image/png") || mimeType.equals("image/gif"); boolean imagoOptions = - dlRequest.isOption("hmir") - || dlRequest.isOption("vmir") + dlRequest.hasOption("mo", "hmir") + || dlRequest.hasOption("mo", "vmir") || (paramROT != 0) || (paramRGBM != null) || (paramRGBA != null) @@ -453,11 +442,11 @@ || (paramBRGT != 0); boolean imageSendable = mimetypeSendable && !imagoOptions; - /* if not autoRes and image smaller than requested - * size then send as is. - * if autoRes and image has requested size then send as is. - * if not autoScale and not scaleToFit nor cropToFit - * then send as is (mo=file) + /* + * if not autoRes and image smaller than requested size then send + * as is. if autoRes and image has requested size then send as is. + * if not autoScale and not scaleToFit nor cropToFit then send as + * is (mo=file) */ if ((loresOnly && imageSendable @@ -486,10 +475,16 @@ // set interpolation quality docuImage.setQuality(scaleQual); + + // set missing dw or dh from aspect ratio + double imgAspect = fileToLoad.getAspect(); + if (paramDW == 0) { + paramDW = (int) Math.round(paramDH * imgAspect); + } else if (paramDH == 0) { + paramDH = (int) Math.round(paramDW / imgAspect); + } - /* - * crop and scale the image - */ + /* crop and scale the image */ util.dprintln( 2, @@ -569,13 +564,14 @@ if (wholeRotArea) { if (paramROT != 0) { try { - // rotate user area coordinates around center of user area + // rotate user area coordinates around center of user + // area AffineTransform rotTrafo = AffineTransform.getRotateInstance( Math.toRadians(paramROT), userImgArea.getCenterX(), userImgArea.getCenterY()); - // get bounds from rotated end position + // get bounds from rotated end position innerUserImgArea = rotTrafo .createTransformedShape(userImgArea) @@ -632,9 +628,7 @@ throw new ImageOpException("Invalid scale parameter set!"); } - /* - * crop and scale image - */ + /* crop and scale image */ // use subimage loading if possible if (docuImage.isSubimageSupported()) { @@ -644,7 +638,8 @@ double subsamp = 1d; if (scaleXY < 1) { subf = 1 / scaleXY; - // for higher quality reduce subsample factor by minSubsample + // for higher quality reduce subsample factor by + // minSubsample if (scaleQual > 0) { subsamp = Math.max(Math.floor(subf / minSubsample), 1d); } else { @@ -683,16 +678,17 @@ } // mirror image - // operation mode: "hmir": mirror horizontally, "vmir": mirror vertically - if (dlRequest.isOption("hmir")) { + // operation mode: "hmir": mirror horizontally, "vmir": mirror + // vertically + if (dlRequest.hasOption("mo", "hmir")) { docuImage.mirror(0); } - if (dlRequest.isOption("vmir")) { + if (dlRequest.hasOption("mo", "vmir")) { docuImage.mirror(90); } // rotate image - if (paramROT != 0) { + if (paramROT != 0d) { docuImage.rotate(paramROT); if (wholeRotArea) { // crop to the inner bounding box @@ -719,7 +715,7 @@ // color modification if ((paramRGBM != null) || (paramRGBA != null)) { - // make shure we actually have two arrays + // make shure we actually have two arrays if (paramRGBM == null) { paramRGBM = new float[3]; } @@ -735,7 +731,7 @@ } // contrast and brightness enhancement - if ((paramCONT != 0) || (paramBRGT != 0)) { + if ((paramCONT != 0f) || (paramBRGT != 0f)) { double mult = Math.pow(2, paramCONT); docuImage.enhance((float) mult, (float) paramBRGT); } @@ -744,11 +740,10 @@ 2, "time " + (System.currentTimeMillis() - startTime) + "ms"); - /* - * write the resulting image - */ + /* write the resulting image */ - // setup output -- if source is JPG then dest will be JPG else it's PNG + // setup output -- if source is JPG then dest will be JPG else it's + // PNG if (mimeType.equals("image/jpeg") || mimeType.equals("image/jp2")) { mimeType = "image/jpeg"; @@ -764,9 +759,7 @@ 1, "Done in " + (System.currentTimeMillis() - startTime) + "ms"); - /* - * error handling - */ + /* error handling */ } // end of "big" try catch (IOException e) {
--- a/servlet/src/digilib/servlet/Texter.java Wed Oct 29 22:45:51 2003 +0100 +++ b/servlet/src/digilib/servlet/Texter.java Wed Oct 29 22:47:15 2003 +0100 @@ -1,23 +1,15 @@ -/* 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 - * +/* + * 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; @@ -37,15 +29,17 @@ import digilib.io.FileOps; import digilib.io.TextFile; -/** Servlet for displaying text - * +/** + * Servlet for displaying text + * + * * @author casties - * + * */ public class Texter extends HttpServlet { /** Servlet version */ - public static String tlVersion = "0.1a1"; + public static String tlVersion = "0.1a2"; /** DigilibConfiguration instance */ DigilibConfiguration dlConfig = null; /** Utils instance with debuglevel */ @@ -62,8 +56,8 @@ /** use authentication */ 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); @@ -101,8 +95,9 @@ dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); } - /* (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, @@ -118,8 +113,9 @@ processRequest(request, response); } - /* (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, @@ -135,47 +131,60 @@ 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"); + try { - /* - * request parameters - */ - DigilibRequest dlRequest = - (DigilibRequest) request.getAttribute("digilib.servlet.request"); - try { + /* + * find the file to load/send + */ + if (this.getTextFile(dlRequest, "/txt") != null) { + servletOp.sendFile( + this.getTextFile(dlRequest, "txt").getFile(), + response); + } else if (this.getTextFile(dlRequest, "") != null) { + servletOp.sendFile( + this.getTextFile(dlRequest, "").getFile(), + response); + } else { + ServletOps.htmlMessage("No Text-File!", response); + } - /* - * find the file to load/send - */ - if(this.getTextFile(dlRequest,"/txt") != null) { - servletOp.sendFile(this.getTextFile(dlRequest,"txt").getFile(), response); - } else if(this.getTextFile(dlRequest,"") != null) { - servletOp.sendFile(this.getTextFile(dlRequest,"").getFile(), response); - } else { - ServletOps.htmlMessage("No Text-File!", 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 + } + } - } 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 - } - } - - /** - * Looks for a file in the given subDirectory. - * @param dlRequest The received request which has the file path. - * @param subDirectory 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) { - String loadPathName = dlRequest.getFilePath() + subDirectory; - // find the file(set) - return (TextFile) dirCache.getFile(loadPathName,dlRequest.getPn(),FileOps.CLASS_TEXT); - } + /** + * Looks for a file in the given subDirectory. + * + * @param dlRequest + * The received request which has the file path. + * @param subDirectory + * 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) { + String loadPathName = dlRequest.getFilePath() + subDirectory; + // find the file(set) + return (TextFile) dirCache.getFile( + loadPathName, + dlRequest.getAsInt("pn"), + FileOps.CLASS_TEXT); + } }