Mercurial > hg > digilib-old
changeset 284:c633e97cac12
Servlet version 1.22b1
- more fast searching (hopefully all working now)
- some simple synchronisation
- some reshuffling of methods to eliminate cruft
author | robcast |
---|---|
date | Fri, 15 Oct 2004 16:59:47 +0200 |
parents | b09009d7fcfc |
children | 55e1aba98c15 |
files | servlet/src/digilib/io/ImageFile.java servlet/src/digilib/io/ImageFileset.java servlet/src/digilib/servlet/Scaler.java |
diffstat | 3 files changed, 52 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/io/ImageFile.java Fri Oct 15 16:59:47 2004 +0200 +++ b/servlet/src/digilib/io/ImageFile.java Fri Oct 15 16:59:47 2004 +0200 @@ -99,8 +99,8 @@ * Sets the mimetype. * @param mimetype The mimetype to set */ - public void setMimetype(String mimetype) { - this.mimetype = mimetype; + public void setMimetype(String filetype) { + this.mimetype = filetype; } /**
--- a/servlet/src/digilib/io/ImageFileset.java Fri Oct 15 16:59:47 2004 +0200 +++ b/servlet/src/digilib/io/ImageFileset.java Fri Oct 15 16:59:47 2004 +0200 @@ -25,7 +25,9 @@ import java.util.ListIterator; import java.util.Map; -import digilib.image.DocuInfo; +import org.apache.log4j.Logger; + +import digilib.image.ImageOps; import digilib.image.ImageSize; /** @@ -35,6 +37,9 @@ /** this is an image file */ protected static int fileClass = FileOps.CLASS_IMAGE; + + /** logger for this class */ + private static Logger logger = Logger.getLogger(ImageFileset.class); /** list of files (ImageFile) */ private ArrayList list = null; @@ -71,10 +76,9 @@ int nb = dirs.length; list = new ArrayList(nb); parent = dirs[0]; - fill(dirs, file, hints); + fill(dirs, file, hints); } - - + /** * Adds an ImageFile to this Fileset. * @@ -132,12 +136,12 @@ * @param info * @return */ - public ImageFile getNextSmaller(ImageSize size, DocuInfo info) { + public ImageFile getNextSmaller(ImageSize size) { for (Iterator i = getHiresIterator(); i.hasNext();) { ImageFile f = (ImageFile) i.next(); try { if (!f.isChecked()) { - info.checkFile(f); + ImageOps.checkFile(f); } if (f.getSize().isTotallySmallerThan(size)) { return f; @@ -160,12 +164,12 @@ * @param info * @return */ - public ImageFile getNextBigger(ImageSize size, DocuInfo info) { + public ImageFile getNextBigger(ImageSize size) { for (ListIterator i = getLoresIterator(); i.hasPrevious();) { ImageFile f = (ImageFile) i.previous(); try { if (!f.isChecked()) { - info.checkFile(f); + ImageOps.checkFile(f); } if (f.getSize().isBiggerThan(size)) { return f; @@ -230,7 +234,7 @@ * @param fl * file (from first base dir) * @param hints - * + * */ void fill(Directory[] dirs, File fl, Map hints) { String scalext = (String) hints.get(FileOps.HINT_FILEEXT); @@ -240,44 +244,43 @@ // 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++) { - if (dirs[j] == null) { + for (int dirIdx = 1; dirIdx < nb; dirIdx++) { + if (dirs[dirIdx] == null) { continue; } - // read the directories - if (dirs[j].getFilenames() == null) { - dirs[j].readDir(); + // read the directory + if (dirs[dirIdx].getFilenames() == null) { + dirs[dirIdx].readDir(); } - File f = null; - String[] dirFiles = dirs[j].getFilenames(); - if (scalext != null) { - // use the last extension - int i = Arrays.binarySearch(dirFiles, baseFn + scalext); - if (i >= 0) { - f = new File(dirs[j].getDir(), dirFiles[i]); - } - } else { - // try the same filename as the original - int i = Arrays.binarySearch(dirFiles, fn); - if (i >= 0) { - f = new File(dirs[j].getDir(), dirFiles[i]); + 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 the file doesn't exists, try other file extensions - if (f == null) { - // try other file extensions - for (Iterator exts = FileOps.getImageExtensionIterator(); exts.hasNext();) { - String s = (String) exts.next(); - int i = Arrays.binarySearch(dirFiles, baseFn + s); - if (i >= 0) { - hints.put(FileOps.HINT_FILEEXT, s); - f = new File(dirs[j].getDir(), dirFiles[i]); - break; - } - } - } - if (f != null) { - add(new ImageFile(f.getName(), this, dirs[j])); + if (FileOps.classForFilename(dirFiles[fileIdx]) == FileOps.CLASS_IMAGE) { + logger.debug("adding file " + dirFiles[fileIdx] + + " to Fileset " + this.getName()); + add(new ImageFile(dirFiles[fileIdx], this, dirs[dirIdx])); } } }
--- a/servlet/src/digilib/servlet/Scaler.java Fri Oct 15 16:59:47 2004 +0200 +++ b/servlet/src/digilib/servlet/Scaler.java Fri Oct 15 16:59:47 2004 +0200 @@ -40,9 +40,8 @@ import digilib.auth.AuthOpException; import digilib.auth.AuthOps; import digilib.image.DocuImage; -import digilib.image.DocuInfo; -import digilib.image.ImageLoaderImageInfoDocuInfo; import digilib.image.ImageOpException; +import digilib.image.ImageOps; import digilib.image.ImageSize; import digilib.io.DocuDirCache; import digilib.io.FileOpException; @@ -61,7 +60,7 @@ private static final long serialVersionUID = -325080527268912852L; // digilib servlet version (for all components) - public static final String dlVersion = "1.21b3"; + public static final String dlVersion = "1.22b1"; // logger for accounting requests Logger accountlog = Logger.getLogger("account.request"); @@ -326,9 +325,6 @@ // ImageFileset of the image to load ImageFileset fileset = null; - // new DocuInfo instance - DocuInfo docuInfo = new ImageLoaderImageInfoDocuInfo(); - /* find the file to load/send */ // get PathInfo @@ -393,7 +389,7 @@ } else if (loresOnly) { // enforced lores uses next smaller resolution fileToLoad = - fileset.getNextSmaller(expectedSourceSize, docuInfo); + fileset.getNextSmaller(expectedSourceSize); if (fileToLoad == null) { // this is the smallest we have fileToLoad = fileset.getSmallest(); @@ -401,7 +397,7 @@ } else { // autores: use next higher resolution fileToLoad = - fileset.getNextBigger(expectedSourceSize, docuInfo); + fileset.getNextBigger(expectedSourceSize); if (fileToLoad == null) { // this is the highest we have fileToLoad = fileset.getBiggest(); @@ -447,7 +443,7 @@ // check the source image if (!fileToLoad.isChecked()) { - docuInfo.checkFile(fileToLoad); + ImageOps.checkFile(fileToLoad); } // get the source image type mimeType = fileToLoad.getMimetype();