# HG changeset patch
# User robcast
# Date 1294235179 -3600
# Node ID 41a8d293b7983f9251168d86a940e2738fbe51d4
# Parent 95417c4615b8b76be4ff2d9f35ab8a5687eb5228# Parent 3af19d51dd7e579c3384d27b24053c2660915d9d
Merge with HEAD
3af19d51dd7e579c3384d27b24053c2660915d9d
diff -r 3af19d51dd7e -r 41a8d293b798 servlet/src/digilib/image/DocuImage.java
--- a/servlet/src/digilib/image/DocuImage.java Wed Jan 05 14:44:19 2011 +0100
+++ b/servlet/src/digilib/image/DocuImage.java Wed Jan 05 14:46:19 2011 +0100
@@ -29,6 +29,7 @@
import digilib.io.ImageFile;
import digilib.io.FileOpException;
+import digilib.io.ImageInput;
/** The basic class for the representation of a digilib image.
*
@@ -46,7 +47,7 @@
*/
public void loadImage(ImageFile f) throws FileOpException;
- /** This DocuImage support the loadSubImage operation.
+ /** This DocuImage supports the loadSubImage operation.
*
* @return boolean
*/
@@ -223,7 +224,7 @@
/**
* Check image size and type and store in ImageFile f
*/
- public ImageFile identify(ImageFile imgf) throws IOException;
+ public ImageInput identify(ImageFile imgf) throws IOException;
/**
* Returns a list of supported image formats
diff -r 3af19d51dd7e -r 41a8d293b798 servlet/src/digilib/image/DocuImageImpl.java
--- a/servlet/src/digilib/image/DocuImageImpl.java Wed Jan 05 14:44:19 2011 +0100
+++ b/servlet/src/digilib/image/DocuImageImpl.java Wed Jan 05 14:46:19 2011 +0100
@@ -34,6 +34,7 @@
import digilib.io.FileOpException;
import digilib.io.ImageFile;
+import digilib.io.ImageInput;
/** Simple abstract implementation of the DocuImage
interface.
*
@@ -106,7 +107,7 @@
/* (non-Javadoc)
* @see digilib.image.DocuImage#identify(digilib.io.ImageFile)
*/
- public ImageFile identify(ImageFile imgf) throws IOException {
+ public ImageInput identify(ImageFile imgf) throws IOException {
// just a do-nothing implementation
return null;
}
diff -r 3af19d51dd7e -r 41a8d293b798 servlet/src/digilib/image/ImageInfoDocuImage.java
--- a/servlet/src/digilib/image/ImageInfoDocuImage.java Wed Jan 05 14:44:19 2011 +0100
+++ b/servlet/src/digilib/image/ImageInfoDocuImage.java Wed Jan 05 14:46:19 2011 +0100
@@ -10,6 +10,7 @@
import org.marcoschmidt.image.ImageInfo;
import digilib.io.ImageFile;
+import digilib.io.ImageInput;
/** Simple abstract implementation of the DocuImage
interface.
* Implements only the identify method using the ImageInfo class.
@@ -19,7 +20,7 @@
public abstract class ImageInfoDocuImage extends DocuImageImpl {
/** Check image size and type and store in ImageFile f */
- public ImageFile identify(ImageFile imgf) throws IOException {
+ public ImageInput identify(ImageFile imgf) throws IOException {
// fileset to store the information
File f = imgf.getFile();
if (f == null) {
diff -r 3af19d51dd7e -r 41a8d293b798 servlet/src/digilib/image/ImageJobDescription.java
--- a/servlet/src/digilib/image/ImageJobDescription.java Wed Jan 05 14:44:19 2011 +0100
+++ b/servlet/src/digilib/image/ImageJobDescription.java Wed Jan 05 14:46:19 2011 +0100
@@ -12,7 +12,8 @@
import digilib.io.FileOps;
import digilib.io.FileOps.FileClass;
import digilib.io.ImageFile;
-import digilib.io.ImageFileset;
+import digilib.io.ImageInput;
+import digilib.io.ImageSet;
import digilib.servlet.DigilibConfiguration;
import digilib.util.OptionsSet;
import digilib.util.Parameter;
@@ -36,8 +37,8 @@
DigilibConfiguration dlConfig = null;
protected static Logger logger = Logger.getLogger("digilib.servlet");
- ImageFile fileToLoad = null;
- ImageFileset fileset = null;
+ ImageInput fileToLoad = null;
+ ImageSet fileset = null;
DocuDirectory fileDir = null;
String filePath = null;
ImageSize expectedSourceSize = null;
@@ -131,15 +132,12 @@
public String getMimeType() throws IOException {
if (mimeType == null) {
fileToLoad = getFileToLoad();
- if(! fileToLoad.isChecked()){
- DigilibConfiguration.docuImageIdentify(fileToLoad);
- }
mimeType = fileToLoad.getMimetype();
}
return mimeType;
}
- public ImageFile getFileToLoad() throws IOException {
+ public ImageInput getFileToLoad() throws IOException {
if(fileToLoad == null){
fileset = getFileset();
@@ -163,7 +161,7 @@
fileToLoad = fileset.getBiggest();
}
}
- logger.info("Planning to load: " + fileToLoad.getFile());
+ logger.info("Planning to load: " + fileToLoad);
}
return fileToLoad;
@@ -182,11 +180,11 @@
return fileDir;
}
- public ImageFileset getFileset() throws FileOpException {
+ public ImageSet getFileset() throws FileOpException {
if(fileset==null){
DocuDirCache dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache");
- fileset = (ImageFileset) dirCache.getFile(getFilePath(), getAsInt("pn"), FileClass.IMAGE);
+ fileset = (ImageSet) dirCache.getFile(getFilePath(), getAsInt("pn"), FileClass.IMAGE);
if (fileset == null) {
throw new FileOpException("File " + getFilePath() + "("
+ getAsInt("pn") + ") not found.");
@@ -245,12 +243,9 @@
logger.debug("get_hiresSize()");
ImageSize hiresSize = null;
- ImageFileset fileset = getFileset();
+ ImageSet fileset = getFileset();
if (getAbsoluteScale()) {
- ImageFile hiresFile = fileset.getBiggest();
- if (!hiresFile.isChecked()) {
- DigilibConfiguration.docuImageIdentify(hiresFile);
- }
+ ImageInput hiresFile = fileset.getBiggest();
hiresSize = hiresFile.getSize();
}
return hiresSize;
diff -r 3af19d51dd7e -r 41a8d293b798 servlet/src/digilib/image/ImageLoaderDocuImage.java
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java Wed Jan 05 14:44:19 2011 +0100
+++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java Wed Jan 05 14:46:19 2011 +0100
@@ -50,7 +50,8 @@
import digilib.io.FileOpException;
import digilib.io.FileOps;
import digilib.io.ImageFile;
-import digilib.io.ImageFileset;
+import digilib.io.ImageSet;
+import digilib.io.ImageInput;
/** Implementation of DocuImage using the ImageLoader API of Java 1.4 and Java2D. */
public class ImageLoaderDocuImage extends ImageInfoDocuImage {
@@ -119,14 +120,14 @@
}
/** Check image size and type and store in ImageFile f */
- public ImageFile identify(ImageFile imageFile) throws IOException {
+ public ImageInput identify(ImageFile imageFile) throws IOException {
// try parent method first
- ImageFile imf = super.identify(imageFile);
+ ImageInput imf = super.identify(imageFile);
if (imf != null) {
return imf;
}
// fileset to store the information
- ImageFileset imgfs = imageFile.getParent();
+ ImageSet imgfs = imageFile.getParent();
File f = imageFile.getFile();
if (f == null) {
throw new IOException("File not found!");
diff -r 3af19d51dd7e -r 41a8d293b798 servlet/src/digilib/image/ImageWorker.java
--- a/servlet/src/digilib/image/ImageWorker.java Wed Jan 05 14:44:19 2011 +0100
+++ b/servlet/src/digilib/image/ImageWorker.java Wed Jan 05 14:46:19 2011 +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());
diff -r 3af19d51dd7e -r 41a8d293b798 servlet/src/digilib/image/JAIDocuImage.java
--- a/servlet/src/digilib/image/JAIDocuImage.java Wed Jan 05 14:44:19 2011 +0100
+++ b/servlet/src/digilib/image/JAIDocuImage.java Wed Jan 05 14:46:19 2011 +0100
@@ -47,7 +47,8 @@
import digilib.io.FileOpException;
import digilib.io.FileOps;
import digilib.io.ImageFile;
-import digilib.io.ImageFileset;
+import digilib.io.ImageSet;
+import digilib.io.ImageInput;
/** A DocuImage implementation using Java Advanced Imaging Library. */
/**
@@ -104,14 +105,14 @@
}
/* Check image size and type and store in ImageFile f */
- public ImageFile identify(ImageFile imageFile) throws IOException {
+ public ImageInput identify(ImageFile imageFile) throws IOException {
// try parent method first
- ImageFile imf = super.identify(imageFile);
+ ImageInput imf = super.identify(imageFile);
if (imf != null) {
return imf;
}
// fileset to store the information
- ImageFileset imgfs = imageFile.getParent();
+ ImageSet imgfs = imageFile.getParent();
File f = imageFile.getFile();
if (f == null) {
throw new IOException("File not found!");
diff -r 3af19d51dd7e -r 41a8d293b798 servlet/src/digilib/io/DigilibInfoReader.java
--- a/servlet/src/digilib/io/DigilibInfoReader.java Wed Jan 05 14:44:19 2011 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-package digilib.io;
-
-/** DigilibInfoReader
- * A class for reading the information from info.xml files used in digilib image directories.
- *
- */
-
-import java.io.File;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.input.SAXBuilder;
-
-
-
-public class DigilibInfoReader {
-
- /** gengeral logger for this class */
- protected static Logger logger = Logger.getLogger("digilib.servlet");
-
- private String filename = null;
- //private static String base_element = "info";
-
- public DigilibInfoReader(String fn){
- filename = fn;
- }
-
- /**
- * Returns the attribute defined by 'attr' as a String.
- *
- * @param attr
- * @return
- */
- @SuppressWarnings("unchecked") // Element.getChildren() returns naked List
- public String getAsString(String attr){
- try{
- SAXBuilder builder = new SAXBuilder();
- Document doc = builder.build(new File(filename));
- Element root = doc.getRootElement();
- List mainElements = root.getChildren();
- // logger.debug("XML mainElements:"+mainElements.toString());
-
- for(int i=0; i> list = null;
- /** default FileClass for unspecified calls */
- public static FileClass defaultFileClass = FileClass.IMAGE;
-
/** directory object is valid (exists on disk) */
private boolean isValid = false;
@@ -52,6 +49,9 @@
/** directory name (digilib canonical form) */
private String dirName = null;
+ /** array of parallel dirs for scaled images */
+ private Directory[] dirs = null;
+
/** directory metadata */
private MetadataMap dirMeta = null;
@@ -111,7 +111,7 @@
*
*/
public int size() {
- return size(defaultFileClass);
+ return ((list != null) && (list.get(0) != null)) ? list.get(0).size() : 0;
}
/**
@@ -121,13 +121,7 @@
* fileClass
*/
public int size(FileClass fc) {
- if (list != null) {
- List l = list.get(fc.ordinal());
- if (l != null) {
- return l.size();
- }
- }
- return 0;
+ return ((list != null) && (list.get(fc.ordinal()) != null)) ? list.get(fc.ordinal()).size() : 0;
}
/**
@@ -136,8 +130,11 @@
* @param index
* @return
*/
- public ImageFileset get(int index) {
- return (ImageFileset) get(index, defaultFileClass);
+ public DocuDirent get(int index) {
+ if ((list == null) || (list.get(0) == null) || (index >= list.get(0).size())) {
+ return null;
+ }
+ return list.get(0).get(index);
}
/**
@@ -177,81 +174,75 @@
*
* @return boolean the directory exists
*/
- public synchronized boolean readDir() {
+ public boolean readDir() {
// check directory first
checkDir();
if (!isValid) {
return false;
}
- // first file extension to try for scaled directories
- String scalext = null;
// read all filenames
logger.debug("reading directory " + dir.getPath());
+ File[] allFiles = null;
/*
* using ReadableFileFilter is safer (we won't get directories with file
* extensions) but slower.
*/
- File[] allFiles = null;
- // allFiles = dir.listFiles(new FileOps.ReadableFileFilter());
+ // allFiles = dir.listFiles(new FileOps.ReadableFileFilter());
allFiles = dir.listFiles();
- //logger.debug(" done");
if (allFiles == null) {
// not a directory
return false;
}
- // list of base dirs from the parent cache
- String[] baseDirNames = cache.getBaseDirNames();
- // number of base dirs
- int nb = baseDirNames.length;
- // array of base dirs
- Directory[] dirs = new Directory[nb];
- // first entry is this directory
- dirs[0] = this;
- // fill array with the remaining directories
- for (int j = 1; j < nb; j++) {
- File d = new File(baseDirNames[j], dirName);
- if (d.isDirectory()) {
- dirs[j] = new Directory(d);
- logger.debug(" reading scaled directory " + d.getPath());
- dirs[j].readDir();
- //logger.debug(" done");
+ // init parallel directories
+ if (dirs == null) {
+ // list of base dirs from the parent cache
+ String[] baseDirNames = cache.getBaseDirNames();
+ // number of base dirs
+ int nb = baseDirNames.length;
+ // array of parallel dirs
+ dirs = new Directory[nb];
+ // first entry is this directory
+ dirs[0] = this;
+ // fill array with the remaining directories
+ for (int j = 1; j < nb; j++) {
+ // add dirName to baseDirName
+ File d = new File(baseDirNames[j], dirName);
+ if (d.isDirectory()) {
+ dirs[j] = new Directory(d);
+ logger.debug(" reading scaled directory " + d.getPath());
+ dirs[j].readDir();
+ }
}
}
// go through all file classes
- //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");
+ for (FileClass fileClass : cache.getFileClasses()) {
+ File[] fileList = FileOps.listFiles(allFiles,
+ FileOps.filterForClass(fileClass));
// number of files in the directory
int numFiles = fileList.length;
if (numFiles > 0) {
// create new list
- list.set(fileClass.ordinal(), new ArrayList(numFiles));
- // sort the file names alphabetically and iterate the list
- // Arrays.sort(fileList); // not needed
- Map hints = FileOps.newHints(FileOps.HINT_BASEDIRS, dirs);
- hints.put(FileOps.HINT_FILEEXT, scalext);
- for (int i = 0; i < numFiles; i++) {
- DocuDirent f = FileOps.fileForClass(fileClass, fileList[i],
- hints);
+ ArrayList dl = new ArrayList(numFiles);
+ list.set(fileClass.ordinal(), dl);
+ for (File f : fileList) {
+ DocuDirent df = FileOps.fileForClass(fileClass, f, dirs);
+ df.setParent(this);
// add the file to our list
- // logger.debug(f.getName());
-
- list.get(fileClass.ordinal()).add(f);
- f.setParent(this);
+ dl.add(df);
}
- // 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.ordinal()));
+ /*
+ * 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(dl);
}
}
// clear the scaled directories
- for (int j = 1; j < nb; j++) {
- if (dirs[j] != null) {
- dirs[j].clearFilenames();
+ for (Directory d: dirs) {
+ if (d != null) {
+ d.clearFilenames();
}
}
// update number of cached files if this was the first time
@@ -456,9 +447,8 @@
return -1;
}
- private boolean isBasenameInList(List fl, int idx, String fn) {
- String dfn = FileOps.basename((fl.get(idx))
- .getName());
+ private boolean isBasenameInList(List fileList, int idx, String fn) {
+ String dfn = FileOps.basename((fileList.get(idx)).getName());
return (dfn.equals(fn)||dfn.equals(FileOps.basename(fn)));
}
@@ -474,7 +464,12 @@
* @return DocuDirent
*/
public DocuDirent find(String fn) {
- return find(fn, defaultFileClass);
+ FileClass fc = FileOps.classForFilename(fn);
+ int i = indexOf(fn, fc);
+ if (i >= 0) {
+ return list.get(0).get(i);
+ }
+ return null;
}
/**
@@ -491,7 +486,7 @@
public DocuDirent find(String fn, FileClass fc) {
int i = indexOf(fn, fc);
if (i >= 0) {
- return (DocuDirent) list.get(fc.ordinal()).get(i);
+ return list.get(fc.ordinal()).get(i);
}
return null;
}
diff -r 3af19d51dd7e -r 41a8d293b798 servlet/src/digilib/io/DocuDirent.java
--- a/servlet/src/digilib/io/DocuDirent.java Wed Jan 05 14:44:19 2011 +0100
+++ b/servlet/src/digilib/io/DocuDirent.java Wed Jan 05 14:46:19 2011 +0100
@@ -1,169 +1,79 @@
-/*
- * 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