Mercurial > hg > digilib-old
changeset 563:686086d6e6d6 digilibPDF
more refactoring and rearranging
more enums
pdf and image generation still works
line wrap: on
line diff
--- a/servlet/src/digilib/image/ImageJobDescription.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/image/ImageJobDescription.java Fri Dec 17 20:42:25 2010 +0100 @@ -12,6 +12,7 @@ import digilib.io.DocuDirectory; import digilib.io.FileOpException; import digilib.io.FileOps; +import digilib.io.FileOps.FileClass; import digilib.io.ImageFile; import digilib.io.ImageFileset; import digilib.servlet.DigilibConfiguration; @@ -135,7 +136,7 @@ if (mimeType == null) { fileToLoad = getFileToLoad(); if(! fileToLoad.isChecked()){ - dlConfig.docuImageIdentify(fileToLoad); + DigilibConfiguration.docuImageIdentify(fileToLoad); } mimeType = fileToLoad.getMimetype(); } @@ -189,7 +190,7 @@ if(fileset==null){ DocuDirCache dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); - fileset = (ImageFileset) dirCache.getFile(getFilePath(), getAsInt("pn"), FileOps.CLASS_IMAGE); + fileset = (ImageFileset) dirCache.getFile(getFilePath(), getAsInt("pn"), FileClass.IMAGE); if (fileset == null) { throw new FileOpException("File " + getFilePath() + "(" + getAsInt("pn") + ") not found."); @@ -252,7 +253,7 @@ if (getAbsoluteScale()) { ImageFile hiresFile = fileset.getBiggest(); if (!hiresFile.isChecked()) { - dlConfig.docuImageIdentify(hiresFile); + DigilibConfiguration.docuImageIdentify(hiresFile); } hiresSize = hiresFile.getSize(); } @@ -428,15 +429,6 @@ } - public int getForceType(){ - if(hasOption("jpg")) - return ImageOps.TYPE_JPEG; - if(hasOption("png")) - return ImageOps.TYPE_PNG; - - return ImageOps.TYPE_AUTO; - } - public float[] getRGBM(){ float[] paramRGBM = null;//{0f,0f,0f}; Parameter p = params.get("rgbm");
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java Fri Dec 17 20:42:25 2010 +0100 @@ -123,14 +123,15 @@ } /** Check image size and type and store in ImageFile f */ - public boolean identify(ImageFile imgf) throws IOException { + public ImageFile identify(ImageFile imageFile) throws IOException { // try parent method first - if (super.identify(imgf)) { - return true; + ImageFile imf = super.identify(imageFile); + if (imf != null) { + return imf; } // fileset to store the information - ImageFileset imgfs = imgf.getParent(); - File f = imgf.getFile(); + ImageFileset imgfs = imageFile.getParent(); + File f = imageFile.getFile(); if (f == null) { throw new IOException("File not found!"); } @@ -152,15 +153,15 @@ try { reader.setInput(istream); ImageSize d = new ImageSize(reader.getWidth(0), reader.getHeight(0)); - imgf.setSize(d); + imageFile.setSize(d); //String t = reader.getFormatName(); String t = FileOps.mimeForFile(f); - imgf.setMimetype(t); + imageFile.setMimetype(t); //logger.debug(" format:"+t); if (imgfs != null) { imgfs.setAspect(d); } - return true; + return imageFile; } finally { // dispose the reader to free resources reader.dispose();
--- a/servlet/src/digilib/image/ImageOps.java Fri Dec 17 16:24:03 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* ImageOps -- convenience methods for images - - Digital Image Library servlet components - - Copyright (C) 2004 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 13.10.2004 - */ -package digilib.image; - -import java.io.IOException; - -import digilib.io.ImageFile; - -/** - * convenience methods for images - * - * @author casties - */ -public class ImageOps { - - public static final int TYPE_AUTO = 0; - public static final int TYPE_JPEG = 1; - public static final int TYPE_PNG = 2; - - private static DocuImage docuImg; - - public static ImageFile checkFile(ImageFile imgf) throws IOException { - return docuImg.identify(imgf); - } - - public static void setDocuImage(DocuImage di) { - docuImg = di; - } - - public static DocuImage getDocuImage() { - return docuImg; - } -}
--- a/servlet/src/digilib/image/JAIDocuImage.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/image/JAIDocuImage.java Fri Dec 17 20:42:25 2010 +0100 @@ -20,7 +20,6 @@ package digilib.image; -import java.awt.Image; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.image.RenderedImage; @@ -100,14 +99,15 @@ } /* Check image size and type and store in ImageFile f */ - public boolean identify(ImageFile imgf) throws IOException { - // try parent method first - if (super.identify(imgf)) { - return true; + public ImageFile identify(ImageFile imageFile) throws IOException { + // try parent method first + ImageFile imf = super.identify(imageFile); + if (imf != null) { + return imf; } // fileset to store the information - ImageFileset imgfs = imgf.getParent(); - File f = imgf.getFile(); + ImageFileset imgfs = imageFile.getParent(); + File f = imageFile.getFile(); if (f == null) { throw new IOException("File not found!"); } @@ -118,15 +118,15 @@ try { RenderedOp img = JAI.create("fileload", f.getAbsolutePath()); ImageSize d = new ImageSize(img.getWidth(), img.getHeight()); - imgf.setSize(d); + imageFile.setSize(d); String t = FileOps.mimeForFile(f); - imgf.setMimetype(t); + imageFile.setMimetype(t); // logger.debug(" format:"+t); if (imgfs != null) { imgfs.setAspect(d); } - logger.debug("image size: " + imgf.getSize()); - return true; + logger.debug("image size: " + imageFile.getSize()); + return imageFile; } catch (Exception e) { throw new FileOpException("ERROR: unknown image file format!"); } @@ -332,11 +332,6 @@ logger.debug("CROP: " + x_off + "," + y_off + ", " + width + "," + height + " ->" + croppedImg.getWidth() + "x" + croppedImg.getHeight()); - // DEBUG - - if (croppedImg == null) { - throw new ImageOpException("Unable to crop"); - } img = croppedImg; } @@ -386,11 +381,6 @@ logger.debug("ROTATE: " + x + "," + y + ", " + angle + " (" + rangle + ")" + " ->" + rotImg.getWidth() + "x" + rotImg.getHeight()); - // DEBUG - - if (rotImg == null) { - throw new ImageOpException("Unable to rotate"); - } img = rotImg; } @@ -444,10 +434,6 @@ logger.debug("ENHANCE: *" + mult + ", +" + add + " ->" + enhImg.getWidth() + "x" + enhImg.getHeight()); // DEBUG - - if (enhImg == null) { - throw new ImageOpException("Unable to enhance"); - } img = enhImg; } @@ -474,11 +460,6 @@ logger.debug("ENHANCE_RGB: *" + rgbm + ", +" + rgba + " ->" + enhImg.getWidth() + "x" + enhImg.getHeight()); - // DEBUG - - if (enhImg == null) { - throw new ImageOpException("Unable to enhanceRGB"); - } img = enhImg; }
--- a/servlet/src/digilib/io/AliasingDocuDirCache.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/io/AliasingDocuDirCache.java Fri Dec 17 20:42:25 2010 +0100 @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Map.Entry; +import digilib.io.FileOps.FileClass; import digilib.servlet.DigilibConfiguration; /** @@ -36,15 +37,15 @@ /** * @param baseDirs - * @param fileClasses + * @param fcs * @param confFileName * @throws FileOpException */ - public AliasingDocuDirCache(String[] baseDirs, int[] fileClasses, + public AliasingDocuDirCache(String[] baseDirs, FileClass[] fcs, File confFile, DigilibConfiguration dlConfig) throws FileOpException { // create standard DocuDirCache - super(baseDirs, fileClasses, dlConfig); + super(baseDirs, fcs, dlConfig); Map<String,String> pathMap = null; // read alias config file try {
--- a/servlet/src/digilib/io/DocuDirCache.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/io/DocuDirCache.java Fri Dec 17 20:42:25 2010 +0100 @@ -30,6 +30,7 @@ import org.apache.log4j.Logger; +import digilib.io.FileOps.FileClass; import digilib.servlet.DigilibConfiguration; /** @@ -47,7 +48,7 @@ String[] baseDirNames = null; /** array of allowed file classes (image/text) */ - private int[] fileClasses = null; + private FileClass[] fileClasses = null; /** number of files in the whole cache (approximate) */ long numFiles = 0; @@ -67,11 +68,11 @@ * @param bd * base directory names */ - public DocuDirCache(String[] bd, int[] fileClasses, + public DocuDirCache(String[] bd, FileClass[] fcs, DigilibConfiguration dlConfig) { baseDirNames = bd; map = new HashMap<String, DocuDirectory>(); - this.fileClasses = fileClasses; + this.fileClasses = fcs; } /** @@ -84,8 +85,7 @@ baseDirNames = bd; map = new HashMap<String, DocuDirectory>(); // default file class is CLASS_IMAGE - fileClasses = new int[1]; - fileClasses[0] = FileOps.CLASS_IMAGE; + fileClasses = new FileClass[] { FileClass.IMAGE }; } /** @@ -122,7 +122,7 @@ String parent = FileOps.parent(newDir.getDirName()); if (parent != "") { // check the parent in the cache - DocuDirectory pd = (DocuDirectory) map.get(parent); + DocuDirectory pd = map.get(parent); if (pd == null) { // the parent is unknown pd = new DocuDirectory(parent, this); @@ -175,12 +175,12 @@ * file class * @return */ - public DocuDirent getFile(String fn, int in, int fc) { + public DocuDirent getFile(String fn, int in, FileClass fc) { DocuDirectory dd; // file number is 1-based, vector index is 0-based int n = in - 1; // first, assume fn is a directory and look in the cache - dd = (DocuDirectory) map.get(fn); + dd = map.get(fn); // logger.debug("fn: " + fn); // logger.debug("dd: " + dd); if (dd == null) { @@ -206,7 +206,7 @@ String d = FileOps.parent(fn); // try it in the cache // logger.debug(fn + " is a file in dir " + d); - dd = (DocuDirectory) map.get(d); + dd = map.get(d); if (dd == null) { // try to read from disk dd = new DocuDirectory(d, this); @@ -255,7 +255,7 @@ public DocuDirectory getDirectory(String fn) { DocuDirectory dd; // first, assume fn is a directory and look in the cache - dd = (DocuDirectory) map.get(fn); + dd = map.get(fn); if (dd == null) { // cache miss misses++; @@ -271,7 +271,7 @@ // maybe it's a file if (f.canRead()) { // try the parent directory in the cache - dd = (DocuDirectory) map.get(f.getParent()); + dd = map.get(f.getParent()); if (dd == null) { // try to read from disk dd = new DocuDirectory(f.getParent(), this); @@ -343,14 +343,14 @@ /** * @return */ - public int[] getFileClasses() { + public FileClass[] getFileClasses() { return fileClasses; } /** * @param fileClasses */ - public void setFileClasses(int[] fileClasses) { + public void setFileClasses(FileClass[] fileClasses) { this.fileClasses = fileClasses; }
--- a/servlet/src/digilib/io/DocuDirectory.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/io/DocuDirectory.java Fri Dec 17 20:42:25 2010 +0100 @@ -30,6 +30,8 @@ import org.xml.sax.SAXException; +import digilib.io.FileOps.FileClass; + /** * @author casties */ @@ -88,12 +90,11 @@ */ protected void initDir() { String baseDirName = cache.getBaseDirNames()[0]; - // clear directory first - //list = new ArrayList[FileOps.NUM_CLASSES]; - - list = new ArrayList<List<DocuDirent>>(FileOps.NUM_CLASSES); - // create empty list - for (int i=0; i < FileOps.NUM_CLASSES; ++i) { + // clear directory list + FileClass[] fcs = FileClass.values(); + list = new ArrayList<List<DocuDirent>>(fcs.length); + // create empty list for all classes + for (@SuppressWarnings("unused") FileClass fc: fcs) { list.add(null); } isValid = false; @@ -116,12 +117,12 @@ * @param fc * fileClass */ - public int size(int fc) { - return ((list != null) && (list.get(fc) != null)) ? list.get(fc).size() : 0; + public int size(FileClass fc) { + return ((list != null) && (list.get(fc.ordinal()) != null)) ? list.get(fc.ordinal()).size() : 0; } /** - * Returns the ImageFile at the index. + * Returns the ImageFileSet at the index. * * @param index * @return @@ -141,11 +142,11 @@ * fileClass * @return */ - public DocuDirent get(int index, int fc) { - if ((list == null) || (list.get(fc) == null) || (index >= list.get(fc).size())) { + public DocuDirent get(int index, FileClass fc) { + if ((list == null) || (list.get(fc.ordinal()) == null) || (index >= list.get(fc.ordinal()).size())) { return null; } - return (DocuDirent) list.get(fc).get(index); + return (DocuDirent) list.get(fc.ordinal()).get(index); } /** @@ -212,10 +213,9 @@ } // go through all file classes - for (int classIdx = 0; classIdx < FileOps.NUM_CLASSES; classIdx++) { - int fileClass = cache.getFileClasses()[classIdx]; - //logger.debug("filtering directory "+dir.getPath()+" for class - // "+fc); + //for (int classIdx = 0; classIdx < FileOps.NUM_CLASSES; classIdx++) { + for (FileClass fileClass: cache.getFileClasses()) { + //fileClass = cache.getFileClasses()[classIdx]; File[] fileList = FileOps.listFiles(allFiles, FileOps .filterForClass(fileClass)); //logger.debug(" done"); @@ -223,7 +223,7 @@ int numFiles = fileList.length; if (numFiles > 0) { // create new list - list.set(fileClass, new ArrayList<DocuDirent>(numFiles)); + list.set(fileClass.ordinal(), new ArrayList<DocuDirent>(numFiles)); // sort the file names alphabetically and iterate the list // Arrays.sort(fileList); // not needed <hertzhaft> Map<Integer, Object> hints = FileOps.newHints(FileOps.HINT_BASEDIRS, dirs); @@ -234,12 +234,12 @@ // add the file to our list // logger.debug(f.getName()); - list.get(fileClass).add(f); + list.get(fileClass.ordinal()).add(f); f.setParent(this); } // we sort the inner ArrayList (the list of files not the list of file types) // for binarySearch to work (DocuDirent's natural sort order is by filename) - Collections.sort(list.get(fileClass)); + Collections.sort(list.get(fileClass.ordinal())); } } // clear the scaled directories @@ -344,13 +344,12 @@ } String path = (relPath != null) ? (relPath + "/") : ""; // go through all file classes - for (int nc = 0; nc < list.size(); nc++) { - int fc = cache.getFileClasses()[nc]; - if (list.get(fc) == null) { + for (FileClass fc: FileClass.values()) { + if (list.get(fc.ordinal()) == null) { continue; } // iterate through the list of files in this directory - for (DocuDirent f: list.get(fc)) { + for (DocuDirent f: list.get(fc.ordinal())) { // prepend path to the filename String fn = path + f.getName(); // look up meta for this file and remove from dir @@ -397,7 +396,7 @@ * @return int index of file <code>fn</code> */ public int indexOf(String fn) { - int fc = FileOps.classForFilename(fn); + FileClass fc = FileOps.classForFilename(fn); return indexOf(fn, fc); } @@ -411,14 +410,14 @@ * filename * @return int index of file <code>fn</code> */ - public int indexOf(String fn, int fc) { + public int indexOf(String fn, FileClass fc) { if (!isRead()) { // read directory now if (!readDir()) { return -1; } } - List<DocuDirent> fileList = list.get(fc); + List<DocuDirent> fileList = list.get(fc.ordinal()); // empty directory? if (fileList == null) { return -1; @@ -434,15 +433,15 @@ // try closest matches without extension idx = -idx - 1; if ((idx < fileList.size()) - && isBaseInList(fileList, idx, fn)) { + && isBasenameInList(fileList, idx, fn)) { // idx matches return idx; } else if ((idx > 0) - && isBaseInList(fileList, idx-1, fn)) { + && isBasenameInList(fileList, idx-1, fn)) { // idx-1 matches return idx - 1; } else if ((idx + 1 < fileList.size()) - && isBaseInList(fileList, idx+1, fn)) { + && isBasenameInList(fileList, idx+1, fn)) { // idx+1 matches return idx + 1; } @@ -451,7 +450,7 @@ return -1; } - private boolean isBaseInList(List<DocuDirent> fl, int idx, String fn) { + private boolean isBasenameInList(List<DocuDirent> fl, int idx, String fn) { String dfn = FileOps.basename((fl.get(idx)) .getName()); return (dfn.equals(fn)||dfn.equals(FileOps.basename(fn))); @@ -469,7 +468,7 @@ * @return DocuDirent */ public DocuDirent find(String fn) { - int fc = FileOps.classForFilename(fn); + FileClass fc = FileOps.classForFilename(fn); int i = indexOf(fn, fc); if (i >= 0) { return (DocuDirent) list.get(0).get(i); @@ -488,10 +487,10 @@ * filename * @return DocuDirent */ - public DocuDirent find(String fn, int fc) { + public DocuDirent find(String fn, FileClass fc) { int i = indexOf(fn, fc); if (i >= 0) { - return (DocuDirent) list.get(fc).get(i); + return (DocuDirent) list.get(fc.ordinal()).get(i); } return null; }
--- a/servlet/src/digilib/io/DocuDirent.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/io/DocuDirent.java Fri Dec 17 20:42:25 2010 +0100 @@ -27,6 +27,8 @@ import org.apache.log4j.Logger; +import digilib.io.FileOps.FileClass; + /** * Abstract directory entry in a DocuDirectory. * @@ -36,7 +38,7 @@ public abstract class DocuDirent implements Comparable<Object> { /** the file class of this file */ - protected static int fileClass = FileOps.CLASS_NONE; + protected static FileClass fileClass = FileClass.NONE; /** HashMap with metadata */ protected MetadataMap fileMeta = null; /** Is the Metadata valid */ @@ -145,7 +147,7 @@ /** * @return */ - public static int getFileClass() { + public static FileClass getFileClass() { return fileClass; }
--- a/servlet/src/digilib/io/FileOps.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/io/FileOps.java Fri Dec 17 20:42:25 2010 +0100 @@ -52,15 +52,7 @@ public static List<String> svgExtensions; - public static final int CLASS_NONE = -1; - - public static final int CLASS_IMAGE = 0; - - public static final int CLASS_TEXT = 1; - - public static final int CLASS_SVG = 2; - - public static final int NUM_CLASSES = 3; + public static enum FileClass {NONE, IMAGE, TEXT, SVG} public static final Integer HINT_BASEDIRS = new Integer(1); @@ -81,11 +73,11 @@ String ext = ft[i][0]; String mt = ft[i][1]; fileTypes.put(ext, mt); - if (classForMimetype(mt) == CLASS_IMAGE) { + if (classForMimetype(mt) == FileClass.IMAGE) { imageExtensions.add(ext); - } else if (classForMimetype(mt) == CLASS_TEXT) { + } else if (classForMimetype(mt) == FileClass.TEXT) { textExtensions.add(ext); - } else if (classForMimetype(mt) == CLASS_SVG) { + } else if (classForMimetype(mt) == FileClass.SVG) { svgExtensions.add(ext); } } @@ -97,18 +89,18 @@ * @param mt * @return */ - public static int classForMimetype(String mt) { + public static FileClass classForMimetype(String mt) { if (mt == null) { - return CLASS_NONE; + return FileClass.NONE; } if (mt.startsWith("image/svg")) { - return CLASS_SVG; + return FileClass.SVG; } else if (mt.startsWith("image")) { - return CLASS_IMAGE; + return FileClass.IMAGE; } else if (mt.startsWith("text")) { - return CLASS_TEXT; + return FileClass.TEXT; } - return CLASS_NONE; + return FileClass.NONE; } /** @@ -124,7 +116,7 @@ * @param fn * @return */ - public static int classForFilename(String fn) { + public static FileClass classForFilename(String fn) { String mt = (String) fileTypes.get(extname(fn).toLowerCase()); return classForMimetype(mt); } @@ -290,7 +282,7 @@ static class ImageFileFilter implements FileFilter { public boolean accept(File f) { - return (classForFilename(f.getName()) == CLASS_IMAGE); + return (classForFilename(f.getName()) == FileClass.IMAGE); } } @@ -300,7 +292,7 @@ static class TextFileFilter implements FileFilter { public boolean accept(File f) { - return (classForFilename(f.getName()) == CLASS_TEXT); + return (classForFilename(f.getName()) == FileClass.TEXT); } } @@ -311,7 +303,7 @@ static class SVGFileFilter implements FileFilter { public boolean accept(File f) { - return (classForFilename(f.getName()) == CLASS_SVG); + return (classForFilename(f.getName()) == FileClass.SVG); } } @@ -321,14 +313,14 @@ * @param fileClass * @return */ - public static FileFilter filterForClass(int fileClass) { - if (fileClass == CLASS_IMAGE) { + public static FileFilter filterForClass(FileClass fileClass) { + if (fileClass == FileClass.IMAGE) { return new ImageFileFilter(); } - if (fileClass == CLASS_TEXT) { + if (fileClass == FileClass.TEXT) { return new TextFileFilter(); } - if (fileClass == CLASS_SVG) { + if (fileClass == FileClass.SVG) { return new SVGFileFilter(); } return null; @@ -346,15 +338,15 @@ * optional additional parameters * @return */ - public static DocuDirent fileForClass(int fileClass, File file, Map<Integer,Object> hints) { + public static DocuDirent fileForClass(FileClass fileClass, File file, Map<Integer,Object> hints) { // what class of file do we have? - if (fileClass == CLASS_IMAGE) { + if (fileClass == FileClass.IMAGE) { // image file return new ImageFileset(file, hints); - } else if (fileClass == CLASS_TEXT) { + } else if (fileClass == FileClass.TEXT) { // text file return new TextFile(file); - } else if (fileClass == CLASS_SVG) { + } else if (fileClass == FileClass.SVG) { // text file return new SVGFile(file); }
--- a/servlet/src/digilib/io/ImageFileset.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/io/ImageFileset.java Fri Dec 17 20:42:25 2010 +0100 @@ -26,8 +26,9 @@ import java.util.ListIterator; import java.util.Map; -import digilib.image.ImageOps; import digilib.image.ImageSize; +import digilib.io.FileOps.FileClass; +import digilib.servlet.DigilibConfiguration; /** * @author casties @@ -35,7 +36,7 @@ public class ImageFileset extends DocuDirent { /** this is an image file */ - protected static int fileClass = FileOps.CLASS_IMAGE; + protected static FileClass fileClass = FileClass.IMAGE; /** list of files (ImageFile) */ private List<ImageFile> list = null; @@ -137,7 +138,7 @@ ImageFile f = i.next(); try { if (!f.isChecked()) { - ImageOps.checkFile(f); + DigilibConfiguration.docuImageIdentify(f); } if (f.getSize().isTotallySmallerThan(size)) { return f; @@ -165,7 +166,7 @@ ImageFile f = i.previous(); try { if (!f.isChecked()) { - ImageOps.checkFile(f); + DigilibConfiguration.docuImageIdentify(f); } if (f.getSize().isBiggerThan(size)) { return f; @@ -272,7 +273,7 @@ continue; } } - if (FileOps.classForFilename(dirFiles[fileIdx]) == FileOps.CLASS_IMAGE) { + if (FileOps.classForFilename(dirFiles[fileIdx]) == fileClass) { /* logger.debug("adding file " + dirFiles[fileIdx] + " to Fileset " + this.getName()); */ add(new ImageFile(dirFiles[fileIdx], this, dirs[dirIdx]));
--- a/servlet/src/digilib/io/SVGFile.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/io/SVGFile.java Fri Dec 17 20:42:25 2010 +0100 @@ -23,6 +23,8 @@ import java.io.File; +import digilib.io.FileOps.FileClass; + /** Class for SVG files. * * @author casties @@ -30,7 +32,7 @@ */ public class SVGFile extends DocuDirent { /** this is a text file */ - protected static int fileClass = FileOps.CLASS_SVG; + protected static FileClass fileClass = FileClass.SVG; /** our File instance */ protected File file = null;
--- a/servlet/src/digilib/io/TextFile.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/io/TextFile.java Fri Dec 17 20:42:25 2010 +0100 @@ -23,6 +23,8 @@ import java.io.File; +import digilib.io.FileOps.FileClass; + /** Class for text files. * * @author casties @@ -30,7 +32,7 @@ */ public class TextFile extends DocuDirent { /** this is a text file */ - protected static int fileClass = FileOps.CLASS_TEXT; + protected static FileClass fileClass = FileClass.TEXT; /** our File instance */ protected File file = null;
--- a/servlet/src/digilib/servlet/DigilibConfiguration.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/servlet/DigilibConfiguration.java Fri Dec 17 20:42:25 2010 +0100 @@ -58,7 +58,7 @@ private Class<DocuImageImpl> docuImageClass = null; /** DocuImage instance */ - private DocuImage docuImage = null; + private static DocuImage docuImage = null; /** Log4J logger */ private Logger logger = Logger.getLogger("digilib.config"); @@ -192,6 +192,7 @@ /** * read parameter list from the XML file in init parameter "config-file" + * or file digilib-config.xml */ public void readConfig(ServletConfig c) throws Exception { @@ -245,14 +246,14 @@ p.setValue(sa); } } - } } else { // parameter unknown -- just add newParameter(confEntry.getKey(), null, confEntry.getValue(), 'f'); } } - + // initialise static DocuImage instance + DigilibConfiguration.docuImage = getDocuImageInstance(); } /** @@ -275,10 +276,14 @@ return di; } - public ImageFile docuImageIdentify(ImageFile imgf) throws IOException { - if (docuImage == null) { - docuImage = (DocuImageImpl) getDocuImageInstance(); - } + /** + * Check image size and type and store in ImageFile imgf + * + * @param imgf + * @return + * @throws IOException + */ + public static ImageFile docuImageIdentify(ImageFile imgf) throws IOException { return docuImage.identify(imgf); }
--- a/servlet/src/digilib/servlet/DocumentBean.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/servlet/DocumentBean.java Fri Dec 17 20:42:25 2010 +0100 @@ -33,11 +33,11 @@ import digilib.auth.AuthOpException; import digilib.auth.AuthOps; -import digilib.image.ImageOps; import digilib.image.ImageSize; import digilib.io.DocuDirCache; import digilib.io.DocuDirectory; import digilib.io.FileOps; +import digilib.io.FileOps.FileClass; import digilib.io.ImageFile; import digilib.io.ImageFileset; @@ -193,7 +193,7 @@ String fn = dlRequest.getFilePath(); // get information about the file ImageFileset fileset = (ImageFileset) dirCache.getFile(fn, dlRequest - .getAsInt("pn"), FileOps.CLASS_IMAGE); + .getAsInt("pn"), FileClass.IMAGE); if (fileset == null) { return; } @@ -213,7 +213,7 @@ // check image for size if mo=hires if ((! origfile.isChecked())&&dlRequest.hasOption("hires")) { logger.debug("pre-checking image!"); - ImageOps.checkFile(origfile); + DigilibConfiguration.docuImageIdentify(origfile); } ImageSize pixsize = origfile.getSize(); if (pixsize != null) { @@ -238,15 +238,22 @@ return getNumPages(dlRequest); } + /** + * get the number of image pages/files in the directory + */ + public int getNumPages(DigilibRequest request) throws Exception { + return getNumPages(request, FileClass.IMAGE); + } + /** - * get the number of pages/files in the directory + * get the number of pages/files of type fc in the directory */ - public int getNumPages(DigilibRequest request) throws Exception { + public int getNumPages(DigilibRequest request, FileClass fc) throws Exception { logger.debug("getNumPages"); DocuDirectory dd = (dirCache != null) ? dirCache.getDirectory(request .getFilePath()) : null; if (dd != null) { - return dd.size(); + return dd.size(fc); } return 0; }
--- a/servlet/src/digilib/servlet/Initialiser.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/servlet/Initialiser.java Fri Dec 17 20:42:25 2010 +0100 @@ -35,10 +35,10 @@ import digilib.auth.AuthOps; import digilib.auth.XMLAuthOps; import digilib.image.DocuImage; -import digilib.image.ImageOps; import digilib.io.AliasingDocuDirCache; import digilib.io.DocuDirCache; import digilib.io.FileOps; +import digilib.io.FileOps.FileClass; import digilib.util.DigilibJobCenter; /** @@ -51,7 +51,7 @@ public class Initialiser extends HttpServlet { /** servlet version */ - public static final String iniVersion = "0.2"; + public static final String version = "0.2"; /** gengeral logger for this class */ private static Logger logger = Logger.getLogger("digilib.init"); @@ -81,7 +81,7 @@ System.out .println("***** Digital Image Library Initialisation Servlet (version " - + iniVersion + ") *****"); + + version + ") *****"); // get our ServletContext ServletContext context = config.getServletContext(); @@ -104,11 +104,10 @@ // say hello in the log file logger .info("***** Digital Image Library Initialisation Servlet (version " - + iniVersion + ") *****"); + + version + ") *****"); // directory cache String[] bd = (String[]) dlConfig.getValue("basedir-list"); - int[] fcs = { FileOps.CLASS_IMAGE, FileOps.CLASS_TEXT, - FileOps.CLASS_SVG }; + FileClass[] fcs = { FileClass.IMAGE, FileClass.TEXT }; if (dlConfig.getAsBoolean("use-mapping")) { // with mapping file File mapConf = ServletOps.getConfigFile((File) dlConfig @@ -135,21 +134,20 @@ // DocuImage class DocuImage di = dlConfig.getDocuImageInstance(); dlConfig.setValue("servlet.docuimage.class", di.getClass().getName()); - ImageOps.setDocuImage(di); // digilib worker threads int nt = dlConfig.getAsInt("worker-threads"); int mt = dlConfig.getAsInt("max-waiting-threads"); - imageEx = new DigilibJobCenter<DocuImage>(nt, mt, true); + imageEx = new DigilibJobCenter<DocuImage>(nt, mt, true, "servlet.worker.imageexecutor"); dlConfig.setValue("servlet.worker.imageexecutor", imageEx); // PDF worker threads int pnt = dlConfig.getAsInt("pdf-worker-threads"); int pmt = dlConfig.getAsInt("pdf-max-waiting-threads"); - pdfEx = new DigilibJobCenter<OutputStream>(pnt, pmt, true); + pdfEx = new DigilibJobCenter<OutputStream>(pnt, pmt, true, "servlet.worker.pdfexecutor"); dlConfig.setValue("servlet.worker.pdfexecutor", pdfEx); // PDF image worker threads int pint = dlConfig.getAsInt("pdf-image-worker-threads"); int pimt = dlConfig.getAsInt("pdf-image-max-waiting-threads"); - pdfImageEx = new DigilibJobCenter<DocuImage>(pint, pimt, true); + pdfImageEx = new DigilibJobCenter<DocuImage>(pint, pimt, true, "servlet.worker.pdfimageexecutor"); dlConfig.setValue("servlet.worker.pdfimageexecutor", pdfImageEx); // set as the servlets main config context.setAttribute("digilib.servlet.configuration", dlConfig); @@ -161,7 +159,7 @@ // say hello in the log file logger .info("***** Digital Image Library Initialisation Servlet (version " - + iniVersion + ") *****"); + + version + ") *****"); logger.warn("Already initialised!"); } }
--- a/servlet/src/digilib/servlet/PDFRequest.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/servlet/PDFRequest.java Fri Dec 17 20:42:25 2010 +0100 @@ -10,7 +10,7 @@ import digilib.image.ImageJobDescription; import digilib.io.DocuDirectory; import digilib.io.FileOpException; -import digilib.io.FileOps; +import digilib.io.FileOps.FileClass; import digilib.util.NumRange; import digilib.util.OptionsSet; import digilib.util.ParameterMap; @@ -93,7 +93,7 @@ pages = new NumRange(getAsString("pgs")); ImageJobDescription ij = ImageJobDescription.getInstance(this, dlConfig); DocuDirectory dir = ij.getFileDirectory(); - int dirsize = dir.size(FileOps.CLASS_IMAGE); + int dirsize = dir.size(FileClass.IMAGE); pages.setMaxnum(dirsize); }
--- a/servlet/src/digilib/servlet/Scaler.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/servlet/Scaler.java Fri Dec 17 20:42:25 2010 +0100 @@ -23,7 +23,7 @@ import digilib.io.DocuDirCache; import digilib.io.DocuDirectory; import digilib.io.DocuDirent; -import digilib.io.FileOps; +import digilib.io.FileOps.FileClass; import digilib.io.ImageFile; import digilib.util.DigilibJobCenter; @@ -31,7 +31,7 @@ public class Scaler extends HttpServlet { /** digilib servlet version (for all components) */ - public static final String dlVersion = "1.9.0a"; + public static final String version = "1.9.0a"; /** servlet error codes */ public static enum Error {UNKNOWN, AUTH, FILE, IMAGE}; @@ -87,10 +87,10 @@ System.out .println("***** Digital Image Library Image Scaler Servlet (version " - + dlVersion + ") *****"); + + version + ") *****"); // say hello in the log file logger.info("***** Digital Image Library Image Scaler Servlet (version " - + dlVersion + ") *****"); + + version + ") *****"); // get our ServletContext ServletContext context = config.getServletContext(); @@ -133,7 +133,7 @@ DigilibRequest dlReq = new DigilibRequest(request); // find the file(set) DocuDirent f = dirCache.getFile(dlReq.getFilePath(), - dlReq.getAsInt("pn"), FileOps.CLASS_IMAGE); + dlReq.getAsInt("pn"), FileClass.IMAGE); // find the requested file if (f != null) { DocuDirectory dd = (DocuDirectory) f.getParent(); @@ -313,7 +313,7 @@ } public static String getVersion() { - return dlVersion; + return version; } }
--- a/servlet/src/digilib/servlet/Texter.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/servlet/Texter.java Fri Dec 17 20:42:25 2010 +0100 @@ -31,6 +31,7 @@ import digilib.io.DocuDirCache; import digilib.io.FileOpException; import digilib.io.FileOps; +import digilib.io.FileOps.FileClass; import digilib.io.TextFile; /** @@ -174,6 +175,6 @@ String loadPathName = dlRequest.getFilePath() + subDirectory; // find the file(set) return (TextFile) dirCache.getFile(loadPathName, dlRequest - .getAsInt("pn"), FileOps.CLASS_TEXT); + .getAsInt("pn"), FileClass.TEXT); } } \ No newline at end of file
--- a/servlet/src/digilib/util/DigilibJobCenter.java Fri Dec 17 16:24:03 2010 +0100 +++ b/servlet/src/digilib/util/DigilibJobCenter.java Fri Dec 17 20:42:25 2010 +0100 @@ -29,20 +29,24 @@ private int maxThreads = 1; /** max number of waiting threads */ private int maxQueueLen = 50; + /** label for this job center */ + private String label = ""; /** * @param maxThreads + * @param label TODO * @param maxQueueLength */ - public DigilibJobCenter(int maxThreads, int maxQueueLen, boolean prestart) { + public DigilibJobCenter(int maxThreads, int maxQueueLen, boolean prestart, String label) { super(); + this.label = (label != null) ? label : ""; this.maxThreads = maxThreads; this.maxQueueLen = maxQueueLen; executor = Executors.newFixedThreadPool(maxThreads); if (prestart) { // prestart threads so Tomcat's leak protection doesn't complain int st = ((ThreadPoolExecutor)executor).prestartAllCoreThreads(); - logger.debug("prestarting threads: "+st); + logger.debug(label+" prestarting threads: "+st); } } @@ -62,7 +66,7 @@ public boolean canRun() { int jql = getWaitingJobs(); int jrl = getRunningJobs(); - logger.debug("canRun: waiting jobs="+jql+" running jobs="+jrl); + logger.debug(label+" canRun: waiting jobs="+jql+" running jobs="+jrl); return (jql <= maxQueueLen); } @@ -73,7 +77,7 @@ public boolean isBusy() { int jql = getWaitingJobs(); int jrl = getRunningJobs(); - logger.debug("isBusy: waiting jobs="+jql+" running jobs="+jrl); + logger.debug(label+" isBusy: waiting jobs="+jql+" running jobs="+jrl); return (jql > maxQueueLen); }