# HG changeset patch # User hertzhaft # Date 1144435147 -7200 # Node ID f8ca069517a2ac0373ecd20151c232778c9d99e4 # Parent d623c6fee3c9a9e461351d4f3948298395df4a90 Bugfix for images not found in dir: added sorting for ArrayLists of ImageFilesets diff -r d623c6fee3c9 -r f8ca069517a2 servlet/src/digilib/io/DocuDirCache.java --- a/servlet/src/digilib/io/DocuDirCache.java Wed Feb 15 00:09:50 2006 +0100 +++ b/servlet/src/digilib/io/DocuDirCache.java Fri Apr 07 20:39:07 2006 +0200 @@ -188,6 +188,8 @@ int n = in - 1; // first, assume fn is a directory and look in the cache dd = (DocuDirectory) map.get(fn); + // logger.debug("fn: " + fn); + // logger.debug("dd: " + dd); if (dd == null) { // cache miss misses++; @@ -196,6 +198,7 @@ */ File f = new File(baseDirNames[0], fn); if (f.isDirectory()) { + // logger.debug(fn + " is a dir"); dd = new DocuDirectory(fn, this); if (dd.isValid()) { // add to the cache @@ -209,12 +212,14 @@ // cache) String d = FileOps.parent(fn); // try it in the cache + // logger.debug(fn + " is a file in dir " + d); dd = (DocuDirectory) map.get(d); if (dd == null) { // try to read from disk dd = new DocuDirectory(d, this); if (dd.isValid()) { // add to the cache + // logger.debug(dd + " is valid"); putDir(dd); } else { // invalid path @@ -226,16 +231,20 @@ } // get the file's index n = dd.indexOf(f.getName(), fc); + // logger.debug(f.getName() + ", index is " + n + ", fc = " + fc); } } else { // cache hit hits++; } dd.refresh(); + // logger.debug(dd + " refreshed"); if (dd.isValid()) { try { + // logger.debug(dd + " is valid"); return dd.get(n, fc); } catch (IndexOutOfBoundsException e) { + logger.debug(fn + ": index out of bounds"); } } return null; diff -r d623c6fee3c9 -r f8ca069517a2 servlet/src/digilib/io/DocuDirectory.java --- a/servlet/src/digilib/io/DocuDirectory.java Wed Feb 15 00:09:50 2006 +0100 +++ b/servlet/src/digilib/io/DocuDirectory.java Fri Apr 07 20:39:07 2006 +0200 @@ -30,6 +30,8 @@ import java.util.List; import java.util.Map; +import org.apache.log4j.Logger; + import org.xml.sax.SAXException; /** @@ -175,7 +177,7 @@ // first file extension to try for scaled directories String scalext = null; // read all filenames - //logger.debug("reading directory " + dir.getPath()); + logger.debug("reading directory " + dir.getPath()); /* * using ReadableFileFilter is safer (we won't get directories with file * extensions) but slower. @@ -204,7 +206,7 @@ File d = new File(baseDirNames[j], dirName); if (d.isDirectory()) { dirs[j] = new Directory(d); - //logger.debug(" reading scaled directory " + d.getPath()); + logger.debug(" reading scaled directory " + d.getPath()); dirs[j].readDir(); //logger.debug(" done"); } @@ -224,16 +226,20 @@ // create new list list[fileClass] = new ArrayList(numFiles); // sort the file names alphabetically and iterate the list - Arrays.sort(fileList); + // 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); // add the file to our list + // logger.debug(f.getName()); + list[fileClass].add(f); f.setParent(this); } + // we need to sort the ArrayList, not the Array, for binarysearch to work + Collections.sort(list[fileClass]); } } // clear the scaled directories @@ -418,11 +424,14 @@ if (fileList == null) { return -1; } + // search for exact match + // OBS: fileList needs to be sorted first (see )! int idx = Collections.binarySearch(fileList, fn); if (idx >= 0) { return idx; } else { + logger.debug(fn + " not found by binarysearch"); // try closest matches without extension idx = -idx - 1; if ((idx < fileList.size()) diff -r d623c6fee3c9 -r f8ca069517a2 servlet/src/digilib/io/ImageFileset.java --- a/servlet/src/digilib/io/ImageFileset.java Wed Feb 15 00:09:50 2006 +0100 +++ b/servlet/src/digilib/io/ImageFileset.java Fri Apr 07 20:39:07 2006 +0200 @@ -109,6 +109,16 @@ } /** + * Compares to a String (for binarySearch) + * or to another ImageFileset (for sort) + */ + public int compareTo(Object arg0) { + return (arg0 instanceof ImageFileset) + ? getName().compareTo(((ImageFileset) arg0).getName()) + : getName().compareTo((String) arg0); + } + + /** * Get the ImageFile at the index. * *