Mercurial > hg > digilib-old
changeset 576:dad720e9b12b stream
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
author | robcast |
---|---|
date | Wed, 22 Dec 2010 20:19:06 +0100 |
parents | 790cbfb58b52 |
children | 3e3e1b7d659f |
files | servlet/src/digilib/image/ImageJobDescription.java servlet/src/digilib/image/ImageWorker.java servlet/src/digilib/io/DocuDirectory.java servlet/src/digilib/io/DocuDirent.java servlet/src/digilib/io/DocuDirentImpl.java servlet/src/digilib/io/FileOps.java servlet/src/digilib/io/ImageFile.java servlet/src/digilib/io/ImageFileSet.java servlet/src/digilib/io/ImageSet.java servlet/src/digilib/io/SVGFile.java servlet/src/digilib/io/TextFile.java servlet/src/digilib/servlet/DocumentBean.java servlet/src/digilib/servlet/Scaler.java |
diffstat | 13 files changed, 478 insertions(+), 405 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/image/ImageJobDescription.java Wed Dec 22 18:32:06 2010 +0100 +++ b/servlet/src/digilib/image/ImageJobDescription.java Wed Dec 22 20:19:06 2010 +0100 @@ -12,6 +12,7 @@ import digilib.io.FileOps; import digilib.io.FileOps.FileClass; import digilib.io.ImageFile; +import digilib.io.ImageInput; import digilib.io.ImageSet; import digilib.servlet.DigilibConfiguration; import digilib.util.OptionsSet; @@ -36,7 +37,7 @@ DigilibConfiguration dlConfig = null; protected static Logger logger = Logger.getLogger("digilib.servlet"); - ImageFile fileToLoad = null; + ImageInput fileToLoad = null; ImageSet fileset = null; DocuDirectory fileDir = null; String filePath = null; @@ -132,14 +133,14 @@ if (mimeType == null) { fileToLoad = getFileToLoad(); if(! fileToLoad.isChecked()){ - DigilibConfiguration.docuImageIdentify(fileToLoad); + DigilibConfiguration.docuImageIdentify((ImageFile) fileToLoad); //FIXME: cast to file? } mimeType = fileToLoad.getMimetype(); } return mimeType; } - public ImageFile getFileToLoad() throws IOException { + public ImageInput getFileToLoad() throws IOException { if(fileToLoad == null){ fileset = getFileset(); @@ -163,7 +164,7 @@ fileToLoad = fileset.getBiggest(); } } - logger.info("Planning to load: " + fileToLoad.getFile()); + logger.info("Planning to load: " + fileToLoad); } return fileToLoad; @@ -247,9 +248,9 @@ ImageSize hiresSize = null; ImageSet fileset = getFileset(); if (getAbsoluteScale()) { - ImageFile hiresFile = fileset.getBiggest(); + ImageInput hiresFile = fileset.getBiggest(); if (!hiresFile.isChecked()) { - DigilibConfiguration.docuImageIdentify(hiresFile); + DigilibConfiguration.docuImageIdentify((ImageFile) hiresFile); //FIXME: cast to file? } hiresSize = hiresFile.getSize(); }
--- a/servlet/src/digilib/image/ImageWorker.java Wed Dec 22 18:32:06 2010 +0100 +++ b/servlet/src/digilib/image/ImageWorker.java Wed Dec 22 20:19:06 2010 +0100 @@ -10,6 +10,7 @@ import org.apache.log4j.Logger; import digilib.io.FileOpException; +import digilib.io.ImageFile; import digilib.servlet.DigilibConfiguration; /** Worker that renders an image. @@ -70,7 +71,7 @@ + scaleXY); } - docuImage.loadSubimage(jobinfo.getFileToLoad(), loadRect, (int) subsamp); + docuImage.loadSubimage((ImageFile) jobinfo.getFileToLoad(), loadRect, (int) subsamp); //FIXME: cast to file logger.debug("SUBSAMP: " + subsamp + " -> " + docuImage.getSize()); @@ -78,7 +79,7 @@ } else { // else load and crop the whole file - docuImage.loadImage(jobinfo.getFileToLoad()); + docuImage.loadImage((ImageFile) jobinfo.getFileToLoad()); //FIXME: cast to file docuImage.crop((int) loadRect.getX(), (int) loadRect.getY(), (int) loadRect.getWidth(), (int) loadRect.getHeight());
--- a/servlet/src/digilib/io/DocuDirectory.java Wed Dec 22 18:32:06 2010 +0100 +++ b/servlet/src/digilib/io/DocuDirectory.java Wed Dec 22 20:19:06 2010 +0100 @@ -450,8 +450,8 @@ return -1; } - private boolean isBasenameInList(List<DocuDirent> fl, int idx, String fn) { - String dfn = FileOps.basename((fl.get(idx)) + private boolean isBasenameInList(List<DocuDirent> fileList, int idx, String fn) { + String dfn = FileOps.basename((fileList.get(idx)) .getName()); return (dfn.equals(fn)||dfn.equals(FileOps.basename(fn))); }
--- a/servlet/src/digilib/io/DocuDirent.java Wed Dec 22 18:32:06 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,169 +0,0 @@ -/* - * DocuDirent.java -- Abstract directory entry in a DocuDirectory - * - * Digital Image Library servlet components - * - * Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * Please read license.txt for the full details. A copy of the GPL may be found - * at http://www.gnu.org/copyleft/lgpl.html - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA 02111-1307 USA - * - * Created on 15.09.2003 by casties - * - */ -package digilib.io; - -import java.io.File; -import java.util.Map; - -import org.apache.log4j.Logger; - -import digilib.io.FileOps.FileClass; - -/** - * Abstract directory entry in a DocuDirectory. - * - * @author casties - * - */ -public abstract class DocuDirent implements Comparable<Object> { - - /** the file class of this file */ - protected static FileClass fileClass = FileClass.NONE; - /** HashMap with metadata */ - protected MetadataMap fileMeta = null; - /** Is the Metadata valid */ - protected boolean metaChecked = false; - /** the parent directory */ - protected Directory parent = null; - - /** - * Checks metadata and does something with it. - * - */ - public abstract void checkMeta(); - - /** - * gets the (default) File - * - * @return - */ - public abstract File getInput(); - - /** - * Reads meta-data for this Fileset if there is any. - * - */ - public void readMeta() { - if ((fileMeta != null) || (getInput() == null)) { - // there is already metadata or there is no file - return; - } - // metadata is in the file {filename}.meta - String fn = getInput().getAbsolutePath(); - File mf = new File(fn + ".meta"); - if (mf.canRead()) { - XMLMetaLoader ml = new XMLMetaLoader(); - try { - // read meta file - Map<String, MetadataMap> meta = ml.loadURL(mf.getAbsolutePath()); - if (meta == null) { - return; - } - fileMeta = meta.get(getName()); - } catch (Exception e) { - Logger.getLogger(this.getClass()).warn("error reading file .meta", e); - } - } - } - - /** - * The name of the file. - * - * If this is a Fileset, the method returns the name of the default file - * (for image filesets the highest resolution file). - * - * @return - */ - public String getName() { - File f = getInput(); - return (f != null) ? f.getName() : null; - } - - /** - * Returns the parent Directory. - * - * @return DocuDirectory - */ - public Directory getParent() { - return parent; - } - - /** - * Sets the parent Directory. - * - * @param parent - * The parent to set - */ - public void setParent(Directory parent) { - this.parent = parent; - } - - /** - * Returns the meta-data for this file(set). - * - * @return HashMap - */ - public MetadataMap getFileMeta() { - return fileMeta; - } - - /** - * Sets the meta-data for this file(set) . - * - * @param fileMeta - * The fileMeta to set - */ - public void setFileMeta(MetadataMap fileMeta) { - this.fileMeta = fileMeta; - } - - /** - * @return - */ - public boolean isMetaChecked() { - return metaChecked; - } - - /** - * @return - */ - public static FileClass getFileClass() { - return fileClass; - } - - /** Comparator using the file name. - * Compares to a String (for binarySearch) - * or to another DocuDirent (for sort) - * - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - public int compareTo(Object arg0) { - if (arg0 instanceof DocuDirent) { - return getName().compareTo(((DocuDirent) arg0).getName()); - } else { - return getName().compareTo((String) arg0); - } - } - - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/io/DocuDirentImpl.java Wed Dec 22 20:19:06 2010 +0100 @@ -0,0 +1,147 @@ +/* + * DocuDirent.java -- Abstract directory entry in a DocuDirectory + * + * Digital Image Library servlet components + * + * Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * Please read license.txt for the full details. A copy of the GPL may be found + * at http://www.gnu.org/copyleft/lgpl.html + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 15.09.2003 by casties + * + */ +package digilib.io; + +import java.io.File; +import java.util.Map; + +import org.apache.log4j.Logger; + +import digilib.io.FileOps.FileClass; + +/** + * Abstract directory entry in a DocuDirectory. + * + * @author casties + * + */ +public abstract class DocuDirentImpl implements DocuDirent { + + /** the file class of this file */ + protected static FileClass fileClass = FileClass.NONE; + /** HashMap with metadata */ + protected MetadataMap fileMeta = null; + /** Is the Metadata valid */ + protected boolean metaChecked = false; + /** the parent directory */ + protected Directory parent = null; + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#checkMeta() + */ + public abstract void checkMeta(); + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#getInput() + */ + public abstract File getInput(); + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#readMeta() + */ + public void readMeta() { + if ((fileMeta != null) || (getInput() == null)) { + // there is already metadata or there is no file + return; + } + // metadata is in the file {filename}.meta + String fn = getInput().getAbsolutePath(); + File mf = new File(fn + ".meta"); + if (mf.canRead()) { + XMLMetaLoader ml = new XMLMetaLoader(); + try { + // read meta file + Map<String, MetadataMap> meta = ml.loadURL(mf.getAbsolutePath()); + if (meta == null) { + return; + } + fileMeta = meta.get(getName()); + } catch (Exception e) { + Logger.getLogger(this.getClass()).warn("error reading file .meta", e); + } + } + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#getName() + */ + public String getName() { + File f = getInput(); + return (f != null) ? f.getName() : null; + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#getParent() + */ + public Directory getParent() { + return parent; + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#setParent(digilib.io.Directory) + */ + public void setParent(Directory parent) { + this.parent = parent; + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#getFileMeta() + */ + public MetadataMap getFileMeta() { + return fileMeta; + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#setFileMeta(digilib.io.MetadataMap) + */ + public void setFileMeta(MetadataMap fileMeta) { + this.fileMeta = fileMeta; + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#isMetaChecked() + */ + public boolean isMetaChecked() { + return metaChecked; + } + + /** + * @return + */ + public static FileClass getFileClass() { + return fileClass; + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#compareTo(java.lang.Object) + */ + public int compareTo(Object arg0) { + if (arg0 instanceof DocuDirentImpl) { + return getName().compareTo(((DocuDirent) arg0).getName()); + } else { + return getName().compareTo((String) arg0); + } + } + + +}
--- a/servlet/src/digilib/io/FileOps.java Wed Dec 22 18:32:06 2010 +0100 +++ b/servlet/src/digilib/io/FileOps.java Wed Dec 22 20:19:06 2010 +0100 @@ -342,7 +342,7 @@ // what class of file do we have? if (fileClass == FileClass.IMAGE) { // image file - return new ImageSet(file, hints); + return new ImageFileSet(file, hints); } else if (fileClass == FileClass.TEXT) { // text file return new TextFile(file);
--- a/servlet/src/digilib/io/ImageFile.java Wed Dec 22 18:32:06 2010 +0100 +++ b/servlet/src/digilib/io/ImageFile.java Wed Dec 22 20:19:06 2010 +0100 @@ -50,12 +50,6 @@ } - @Override - public boolean hasFile() { - // this is File-based - return true; - } - /** Returns the file name (without path). * * @return @@ -68,7 +62,6 @@ /** * @return File */ - @Override public File getFile() { if (dir == null) { return null; @@ -103,4 +96,18 @@ } } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + // try to use File.toString + File f = getFile(); + if (f != null) { + return f.toString(); + } + return super.toString(); + } + + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/io/ImageFileSet.java Wed Dec 22 20:19:06 2010 +0100 @@ -0,0 +1,283 @@ +/** + * + */ +package digilib.io; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; + +import digilib.io.FileOps.FileClass; + +/** + * @author casties + * + */ +public class ImageFileSet extends ImageSet implements DocuDirent { + + /** this is an image file */ + protected static FileClass fileClass = FileClass.IMAGE; + private Directory parent; + private boolean metaChecked; + private Map fileMeta; + + /** + * Constructor with a file and hints. + * + * The hints are expected to contain 'basedirs' and 'scaledfilext' keys. + * + * @param file + * @param hints + */ + public ImageFileSet(File file, Map<Integer,Object> hints) { + Directory[] dirs = (Directory[]) hints.get(FileOps.HINT_BASEDIRS); + int nb = dirs.length; + list = new ArrayList<ImageInput>(nb); + parent = dirs[0]; + fill(dirs, file, hints); + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#getName() + */ + @Override + public String getName() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#getParent() + */ + @Override + public Directory getParent() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#setParent(digilib.io.Directory) + */ + @Override + public void setParent(Directory parent) { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#getFileMeta() + */ + @Override + public MetadataMap getFileMeta() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#setFileMeta(digilib.io.MetadataMap) + */ + @Override + public void setFileMeta(MetadataMap fileMeta) { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#isMetaChecked() + */ + @Override + public boolean isMetaChecked() { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see digilib.io.DocuDirent#compareTo(java.lang.Object) + */ + @Override + public int compareTo(Object arg0) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public File getInput() { + // TODO Auto-generated method stub + return null; + } + + /** + * Adds an 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". + * + * + * @param f + * file to add + * @return true (always) + */ + public boolean add(ImageFile f) { + f.setParent(this); + return list.add(f); + } + + /** + * Fill the ImageSet with files from different base directories. + * + * + * @param dirs + * list of base directories + * @param fl + * file (from first base dir) + * @param hints + * + */ + void fill(Directory[] dirs, File fl, Map<Integer,Object> hints) { + int nb = dirs.length; + String fn = fl.getName(); + String baseFn = FileOps.basename(fn); + // add the first ImageFile to the ImageSet + add(new ImageFile(fn, this, parent)); + // iterate the remaining base directories + for (int dirIdx = 1; dirIdx < nb; dirIdx++) { + if (dirs[dirIdx] == null) { + continue; + } + // read the directory + if (dirs[dirIdx].getFilenames() == null) { + dirs[dirIdx].readDir(); + } + String[] dirFiles = dirs[dirIdx].getFilenames(); + // try the same filename as the original + int fileIdx = Arrays.binarySearch(dirFiles, fn); + if (fileIdx < 0) { + // try closest matches without extension + fileIdx = -fileIdx - 1; + // try idx + if ((fileIdx < dirFiles.length) + && (FileOps.basename(dirFiles[fileIdx]).equals(baseFn))) { + // idx ok + } else if ((fileIdx > 0) + && (FileOps.basename(dirFiles[fileIdx - 1]) + .equals(baseFn))) { + // idx-1 ok + fileIdx = fileIdx - 1; + } else if ((fileIdx+1 < dirFiles.length) + && (FileOps.basename(dirFiles[fileIdx + 1]) + .equals(baseFn))) { + // idx+1 ok + fileIdx = fileIdx + 1; + } else { + // basename doesn't match + continue; + } + } + if (FileOps.classForFilename(dirFiles[fileIdx]) == fileClass) { + /* logger.debug("adding file " + dirFiles[fileIdx] + + " to Fileset " + this.getName()); */ + add(new ImageFile(dirFiles[fileIdx], this, dirs[dirIdx])); + } + } + } + + /** + * Checks metadata and sets resolution in resX and resY. + * + */ + public void checkMeta() { + if (metaChecked) { + return; + } + if (fileMeta == null) { + // try to read metadata file + readMeta(); + if (fileMeta == null) { + // try directory metadata + ((DocuDirectory) parent).checkMeta(); + if (((DocuDirectory) parent).getDirMeta() != null) { + fileMeta = ((DocuDirectory) parent).getDirMeta(); + } else { + // try parent directory metadata + DocuDirectory gp = (DocuDirectory) parent.getParent(); + if (gp != null) { + gp.checkMeta(); + if (gp.getDirMeta() != null) { + fileMeta = gp.getDirMeta(); + } + } + } + } + } + if (fileMeta == null) { + // no metadata available + metaChecked = true; + return; + } + metaChecked = true; + float dpi = 0; + float dpix = 0; + float dpiy = 0; + float sizex = 0; + float sizey = 0; + float pixx = 0; + float pixy = 0; + // DPI is valid for X and Y + if (fileMeta.containsKey("original-dpi")) { + try { + dpi = Float.parseFloat((String) fileMeta.get("original-dpi")); + } catch (NumberFormatException e) { + } + if (dpi != 0) { + resX = dpi; + resY = dpi; + return; + } + } + // DPI-X and DPI-Y + if (fileMeta.containsKey("original-dpi-x") + && fileMeta.containsKey("original-dpi-y")) { + try { + dpix = Float.parseFloat((String) fileMeta + .get("original-dpi-x")); + dpiy = Float.parseFloat((String) fileMeta + .get("original-dpi-y")); + } catch (NumberFormatException e) { + } + if ((dpix != 0) && (dpiy != 0)) { + resX = dpix; + resY = dpiy; + return; + } + } + // SIZE-X and SIZE-Y and PIXEL-X and PIXEL-Y + if (fileMeta.containsKey("original-size-x") + && fileMeta.containsKey("original-size-y") + && fileMeta.containsKey("original-pixel-x") + && fileMeta.containsKey("original-pixel-y")) { + try { + sizex = Float.parseFloat((String) fileMeta + .get("original-size-x")); + sizey = Float.parseFloat((String) fileMeta + .get("original-size-y")); + pixx = Float.parseFloat((String) fileMeta + .get("original-pixel-x")); + pixy = Float.parseFloat((String) fileMeta + .get("original-pixel-y")); + } catch (NumberFormatException e) { + } + if ((sizex != 0) && (sizey != 0) && (pixx != 0) && (pixy != 0)) { + resX = pixx / (sizex * 100 / 2.54f); + resY = pixy / (sizey * 100 / 2.54f); + return; + } + } + } + + public void readMeta() { + // TODO Auto-generated method stub + + } + +}
--- a/servlet/src/digilib/io/ImageSet.java Wed Dec 22 18:32:06 2010 +0100 +++ b/servlet/src/digilib/io/ImageSet.java Wed Dec 22 20:19:06 2010 +0100 @@ -17,16 +17,12 @@ package digilib.io; -import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.ListIterator; -import java.util.Map; import digilib.image.ImageSize; -import digilib.io.FileOps.FileClass; import digilib.servlet.DigilibConfiguration; /** @@ -34,26 +30,17 @@ */ public class ImageSet { - /** this is an image file */ - protected static FileClass fileClass = FileClass.IMAGE; - /** list of files (ImageFile) */ - private List<ImageInput> list = null; + protected List<ImageInput> list = null; /** aspect ratio (width/height) */ - private float aspect = 0f; + protected float aspect = 0f; /** resolution of the biggest image (DPI) */ - private float resX = 0f; + protected float resX = 0f; /** resolution of the biggest image (DPI) */ - private float resY = 0f; - - private Directory parent; - - private boolean metaChecked; - - private Map fileMeta; + protected float resY = 0f; /** * Creator for empty fileset. @@ -66,38 +53,6 @@ } /** - * Constructor with a file and hints. - * - * The hints are expected to contain 'basedirs' and 'scaledfilext' keys. - * - * @param file - * @param hints - */ - public ImageSet(File file, Map<Integer,Object> hints) { - Directory[] dirs = (Directory[]) hints.get(FileOps.HINT_BASEDIRS); - int nb = dirs.length; - list = new ArrayList<ImageInput>(nb); - parent = dirs[0]; - fill(dirs, file, hints); - } - - /** - * Adds an 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". - * - * - * @param f - * file to add - * @return true (always) - */ - public boolean add(ImageFile f) { - f.setParent(this); - return list.add(f); - } - - /** * The number of image files in this Fileset. * * @@ -108,12 +63,11 @@ } /** - * Gets the default File. + * Gets the default Input. * */ - public ImageInput getInput() { - //return (list != null) ? list.get(0).getFile() : null; - return null; + public ImageInput get() { + return (list != null) ? list.get(0) : null; } /** @@ -144,7 +98,7 @@ ImageInput f = i.next(); try { if (!f.isChecked()) { - DigilibConfiguration.docuImageIdentify((ImageFile) f); + DigilibConfiguration.docuImageIdentify((ImageFile) f); // FIXME: cast to file? } if (f.getSize().isTotallySmallerThan(size)) { return f; @@ -172,7 +126,7 @@ ImageInput f = i.previous(); try { if (!f.isChecked()) { - DigilibConfiguration.docuImageIdentify((ImageFile) f); + DigilibConfiguration.docuImageIdentify((ImageFile) f); // FIXME: cast to file? } if (f.getSize().isBiggerThan(size)) { return f; @@ -229,163 +183,6 @@ } /** - * Fill the ImageSet with files from different base directories. - * - * - * @param dirs - * list of base directories - * @param fl - * file (from first base dir) - * @param hints - * - */ - void fill(Directory[] dirs, File fl, Map<Integer,Object> hints) { - int nb = dirs.length; - String fn = fl.getName(); - String baseFn = FileOps.basename(fn); - // add the first ImageFile to the ImageSet - add(new ImageFile(fn, this, parent)); - // iterate the remaining base directories - for (int dirIdx = 1; dirIdx < nb; dirIdx++) { - if (dirs[dirIdx] == null) { - continue; - } - // read the directory - if (dirs[dirIdx].getFilenames() == null) { - dirs[dirIdx].readDir(); - } - String[] dirFiles = dirs[dirIdx].getFilenames(); - // try the same filename as the original - int fileIdx = Arrays.binarySearch(dirFiles, fn); - if (fileIdx < 0) { - // try closest matches without extension - fileIdx = -fileIdx - 1; - // try idx - if ((fileIdx < dirFiles.length) - && (FileOps.basename(dirFiles[fileIdx]).equals(baseFn))) { - // idx ok - } else if ((fileIdx > 0) - && (FileOps.basename(dirFiles[fileIdx - 1]) - .equals(baseFn))) { - // idx-1 ok - fileIdx = fileIdx - 1; - } else if ((fileIdx+1 < dirFiles.length) - && (FileOps.basename(dirFiles[fileIdx + 1]) - .equals(baseFn))) { - // idx+1 ok - fileIdx = fileIdx + 1; - } else { - // basename doesn't match - continue; - } - } - if (FileOps.classForFilename(dirFiles[fileIdx]) == fileClass) { - /* logger.debug("adding file " + dirFiles[fileIdx] - + " to Fileset " + this.getName()); */ - add(new ImageFile(dirFiles[fileIdx], this, dirs[dirIdx])); - } - } - } - - /** - * Checks metadata and sets resolution in resX and resY. - * - */ - public void checkMeta() { - if (metaChecked) { - return; - } - if (fileMeta == null) { - // try to read metadata file - readMeta(); - if (fileMeta == null) { - // try directory metadata - ((DocuDirectory) parent).checkMeta(); - if (((DocuDirectory) parent).getDirMeta() != null) { - fileMeta = ((DocuDirectory) parent).getDirMeta(); - } else { - // try parent directory metadata - DocuDirectory gp = (DocuDirectory) parent.getParent(); - if (gp != null) { - gp.checkMeta(); - if (gp.getDirMeta() != null) { - fileMeta = gp.getDirMeta(); - } - } - } - } - } - if (fileMeta == null) { - // no metadata available - metaChecked = true; - return; - } - metaChecked = true; - float dpi = 0; - float dpix = 0; - float dpiy = 0; - float sizex = 0; - float sizey = 0; - float pixx = 0; - float pixy = 0; - // DPI is valid for X and Y - if (fileMeta.containsKey("original-dpi")) { - try { - dpi = Float.parseFloat((String) fileMeta.get("original-dpi")); - } catch (NumberFormatException e) { - } - if (dpi != 0) { - resX = dpi; - resY = dpi; - return; - } - } - // DPI-X and DPI-Y - if (fileMeta.containsKey("original-dpi-x") - && fileMeta.containsKey("original-dpi-y")) { - try { - dpix = Float.parseFloat((String) fileMeta - .get("original-dpi-x")); - dpiy = Float.parseFloat((String) fileMeta - .get("original-dpi-y")); - } catch (NumberFormatException e) { - } - if ((dpix != 0) && (dpiy != 0)) { - resX = dpix; - resY = dpiy; - return; - } - } - // SIZE-X and SIZE-Y and PIXEL-X and PIXEL-Y - if (fileMeta.containsKey("original-size-x") - && fileMeta.containsKey("original-size-y") - && fileMeta.containsKey("original-pixel-x") - && fileMeta.containsKey("original-pixel-y")) { - try { - sizex = Float.parseFloat((String) fileMeta - .get("original-size-x")); - sizey = Float.parseFloat((String) fileMeta - .get("original-size-y")); - pixx = Float.parseFloat((String) fileMeta - .get("original-pixel-x")); - pixy = Float.parseFloat((String) fileMeta - .get("original-pixel-y")); - } catch (NumberFormatException e) { - } - if ((sizex != 0) && (sizey != 0) && (pixx != 0) && (pixy != 0)) { - resX = pixx / (sizex * 100 / 2.54f); - resY = pixy / (sizey * 100 / 2.54f); - return; - } - } - } - - private void readMeta() { - // TODO Auto-generated method stub - - } - - /** * @return */ public float getResX() { @@ -422,4 +219,9 @@ return aspect; } + public void checkMeta() { + // TODO Auto-generated method stub + + } + } \ No newline at end of file
--- a/servlet/src/digilib/io/SVGFile.java Wed Dec 22 18:32:06 2010 +0100 +++ b/servlet/src/digilib/io/SVGFile.java Wed Dec 22 20:19:06 2010 +0100 @@ -30,7 +30,7 @@ * @author casties * */ -public class SVGFile extends DocuDirent { +public class SVGFile extends DocuDirentImpl { /** this is a text file */ protected static FileClass fileClass = FileClass.SVG; /** our File instance */
--- a/servlet/src/digilib/io/TextFile.java Wed Dec 22 18:32:06 2010 +0100 +++ b/servlet/src/digilib/io/TextFile.java Wed Dec 22 20:19:06 2010 +0100 @@ -30,7 +30,7 @@ * @author casties * */ -public class TextFile extends DocuDirent { +public class TextFile extends DocuDirentImpl { /** this is a text file */ protected static FileClass fileClass = FileClass.TEXT; /** our File instance */
--- a/servlet/src/digilib/servlet/DocumentBean.java Wed Dec 22 18:32:06 2010 +0100 +++ b/servlet/src/digilib/servlet/DocumentBean.java Wed Dec 22 20:19:06 2010 +0100 @@ -38,6 +38,7 @@ import digilib.io.DocuDirectory; import digilib.io.FileOps.FileClass; import digilib.io.ImageFile; +import digilib.io.ImageInput; import digilib.io.ImageSet; public class DocumentBean { @@ -197,7 +198,7 @@ return; } // add file name - dlRequest.setValue("img.fn", fileset.getName()); + dlRequest.setValue("img.fn", fileset); // add dpi dlRequest.setValue("img.dpix", new Double(fileset.getResX())); dlRequest.setValue("img.dpiy", new Double(fileset.getResY())); @@ -208,11 +209,11 @@ dlRequest.setValue("pt", dd.size()); } // get original pixel size - ImageFile origfile = fileset.getBiggest(); + ImageInput origfile = fileset.getBiggest(); // check image for size if mo=hires if ((! origfile.isChecked())&&dlRequest.hasOption("hires")) { logger.debug("pre-checking image!"); - DigilibConfiguration.docuImageIdentify(origfile); + DigilibConfiguration.docuImageIdentify((ImageFile) origfile); } ImageSize pixsize = origfile.getSize(); if (pixsize != null) {
--- a/servlet/src/digilib/servlet/Scaler.java Wed Dec 22 18:32:06 2010 +0100 +++ b/servlet/src/digilib/servlet/Scaler.java Wed Dec 22 20:19:06 2010 +0100 @@ -195,7 +195,7 @@ /* * check if we can fast-track without scaling */ - ImageFile fileToLoad = jobTicket.getFileToLoad(); + ImageFile fileToLoad = (ImageFile) jobTicket.getFileToLoad(); // check permissions if (useAuthorization) {