Mercurial > hg > digilib-old
changeset 151:bc8df0133c04
Servlet version 1.15b1
- information in index.meta works finally for files in subdirectories.
author | robcast |
---|---|
date | Mon, 01 Sep 2003 18:21:27 +0200 |
parents | 84ddd05c95d5 |
children | f4a5cfe37469 |
files | client/digitallibrary/WEB-INF/lib/DigilibServlet.jar servlet/src/digilib/io/Directory.java servlet/src/digilib/io/DocuDirCache.java servlet/src/digilib/io/DocuDirectory.java servlet/src/digilib/io/XMLMetaLoader.java servlet/src/digilib/servlet/Scaler.java |
diffstat | 6 files changed, 172 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/io/Directory.java Tue Aug 26 22:30:02 2003 +0200 +++ b/servlet/src/digilib/io/Directory.java Mon Sep 01 18:21:27 2003 +0200 @@ -1,4 +1,4 @@ -/* Directory -- +/* Directory -- Filesystem directory object Digital Image Library servlet components @@ -30,6 +30,8 @@ public class Directory { // File object pointing to the directory File dir = null; + // parent directory + Directory parent = null; /** Default constructor. * @@ -46,6 +48,15 @@ dir = d; } + /** Constructor taking a File object and a parent. + * + * @param d + */ + public Directory(File dir, Directory parent) { + this.dir = dir; + this.parent = parent; + } + /** Constructor taking a directory name. * * @param d @@ -67,5 +78,20 @@ public void setDir(File dir) { this.dir = dir; } + + /** + * @return + */ + Directory getParent() { + return parent; + } + + /** + * @param parent + */ + void setParent(Directory parent) { + this.parent = parent; + } + }
--- a/servlet/src/digilib/io/DocuDirCache.java Tue Aug 26 22:30:02 2003 +0200 +++ b/servlet/src/digilib/io/DocuDirCache.java Mon Sep 01 18:21:27 2003 +0200 @@ -70,6 +70,27 @@ } } + /** Add a directory to the cache and check its parents. + * + * @param newDir + */ + public void putDir(DocuDirectory newDir) { + put(newDir); + String parent = newDir.getParentDirName(); + if (parent != null) { + // check the parent in the cache + DocuDirectory pd = (DocuDirectory)map.get(parent); + if (pd == null) { + // the parent is unknown + pd = new DocuDirectory(parent, this); + putDir(pd); + } + newDir.setParent(pd); + } + // update dir in the end + newDir.readParentMeta(); + } + /** Returns the DocuFileset with the pathname <code>fn</code> and the * index <code>in</code>. * @@ -92,10 +113,10 @@ // see if it's a directory File f = new File(baseDirNames[0] + fn); if (f.isDirectory()) { - dd = new DocuDirectory(fn, baseDirNames); + dd = new DocuDirectory(fn, this); if (dd.isValid()) { // add to the cache - put(dd); + putDir(dd); } } else { // maybe it's a file @@ -106,10 +127,10 @@ dd = (DocuDirectory) map.get(d); if (dd == null) { // try to read from disk - dd = new DocuDirectory(d, baseDirNames); + dd = new DocuDirectory(d, this); if (dd.isValid()) { // add to the cache - put(dd); + putDir(dd); } else { // invalid path return null; @@ -156,10 +177,10 @@ // see if it's a directory File f = new File(baseDirNames[0] + fn); if (f.isDirectory()) { - dd = new DocuDirectory(fn, baseDirNames); + dd = new DocuDirectory(fn, this); if (dd.isValid()) { // add to the cache - put(dd); + putDir(dd); } } else { // maybe it's a file @@ -168,10 +189,10 @@ dd = (DocuDirectory) map.get(f.getParent()); if (dd == null) { // try to read from disk - dd = new DocuDirectory(f.getParent(), baseDirNames); + dd = new DocuDirectory(f.getParent(), this); if (dd.isValid()) { // add to the cache - put(dd); + putDir(dd); } else { // invalid path return null;
--- a/servlet/src/digilib/io/DocuDirectory.java Tue Aug 26 22:30:02 2003 +0200 +++ b/servlet/src/digilib/io/DocuDirectory.java Mon Sep 01 18:21:27 2003 +0200 @@ -39,16 +39,19 @@ private ArrayList list = null; // directory object is valid (has been read) private boolean isValid = false; - // names of base directories - private String[] baseDirNames = null; + // reference of the parent DocuDirCache + private DocuDirCache cache = null; // directory name (digilib canonical form) private String dirName = null; // directory metadata private HashMap dirMeta = null; + // unresolved file metadata + private HashMap unresolvedFileMeta = null; // time of last access of this object (not the filesystem) private long objectATime = 0; // time the file system directory was last modified private long dirMTime = 0; + /* * constructors @@ -63,34 +66,56 @@ * @param path digilib directory path name * @param bd array of base directory names */ - public DocuDirectory(String path, String[] bd) { - dirName = path; - baseDirNames = bd; + public DocuDirectory(String path, DocuDirCache cache) { + this.dirName = path; + this.cache = cache; readDir(); } /* * other stuff */ + + /** The digilib name of the parent directory. + * + * Returns null if there is no parent. + */ + public String getParentDirName() { + String s = null; + int lastidx = dirName.lastIndexOf("/"); + if (lastidx > 0) { + s = dirName.substring(0, lastidx); + } + return s; + } + /** number of DocuFiles in this directory. + * + */ public int size() { return (list != null) ? list.size() : 0; } + /** Returns the DocuFile at the index. + * + * @param index + * @return + */ public DocuFileset get(int index) { - if ((list == null)||(index >= list.size())) { + if ((list == null) || (index >= list.size())) { return null; - } - return (DocuFileset)list.get(index); + } + return (DocuFileset) list.get(index); } - /** Read the directory and fill this object. + /** Read the filesystem directory and fill this object. * * Clears the List and (re)reads all files. * * @return boolean the directory exists */ public boolean readDir() { + String[] baseDirNames = cache.getBaseDirNames(); // first file extension to try for scaled directories String fext = null; // clear directory first @@ -127,8 +152,7 @@ Arrays.sort(fl); for (int i = 0; i < nf; i++) { String fn = fl[i].getName(); - String fnx = - fn.substring(0, fn.lastIndexOf('.') + 1); + String fnx = fn.substring(0, fn.lastIndexOf('.') + 1); // add the first DocuFile to a new DocuFileset DocuFileset fs = new DocuFileset(nb); fs.add(new DocuFile(fn, fs, this)); @@ -153,13 +177,11 @@ Iterator exts = FileOps.getImageExtensionIterator(); while (exts.hasNext()) { String s = (String) exts.next(); - f = - new File( - dirs[j].getDir(), - fnx + s); + f = new File(dirs[j].getDir(), fnx + s); // if the file exists, add to the DocuFileset if (f.canRead()) { - fs.add(new DocuFile(f.getName(), fs, dirs[j])); + fs.add( + new DocuFile(f.getName(), fs, dirs[j])); fext = s; break; } @@ -210,18 +232,12 @@ return; } // meta for the directory itself is in the "" bin - dirMeta = (HashMap)fileMeta.remove(""); - // is there meta for other files? + dirMeta = (HashMap) fileMeta.remove(""); + // read meta for files in this directory + readFileMeta(fileMeta, null); + // is there meta for other files left? if (fileMeta.size() > 0) { - // iterate through the list of files - for (Iterator i = list.iterator(); i.hasNext();) { - DocuFileset df = (DocuFileset)i.next(); - // look up meta for this file - HashMap meta = (HashMap)fileMeta.get(df.getName()); - if (meta != null) { - df.setFileMeta(meta); - } - } + unresolvedFileMeta = fileMeta; } } catch (SAXException e) { // TODO Auto-generated catch block @@ -230,7 +246,53 @@ // TODO Auto-generated catch block e.printStackTrace(); } + } + readParentMeta(); + } + /** Read metadata from all known parent directories. + * + */ + public void readParentMeta() { + // check the parent directories for additional file meta + Directory dd = parent; + String path = dir.getName() ; + while (dd != null) { + if (((DocuDirectory)dd).hasUnresolvedFileMeta()) { + readFileMeta(((DocuDirectory)dd).unresolvedFileMeta, path); + } + // prepend parent dir path + path = dd.dir.getName() + "/" + path; + // become next parent + dd = dd.parent; + } + } + + /** Read metadata for the files in this directory. + * + * Takes a HashMap with meta-information, adding the relative path + * before the lookup. + * + * @param fileMeta + * @param relPath + */ + public void readFileMeta(HashMap fileMeta, String relPath) { + if (list == null) { + // there are no files + return; + } + String path = (relPath != null) ? (relPath + "/") : ""; + // iterate through the list of files in this directory + for (Iterator i = list.iterator(); i.hasNext();) { + DocuFileset df = (DocuFileset) i.next(); + // prepend path to the filename + String fn = path + df.getName(); + // look up meta for this file and remove from dir + HashMap meta = (HashMap) fileMeta.remove(fn); + if (meta != null) { + // store meta in file + df.setFileMeta(meta); + } } } @@ -323,4 +385,8 @@ this.dirMeta = dirMeta; } + public boolean hasUnresolvedFileMeta() { + return (this.unresolvedFileMeta != null); + } + }
--- a/servlet/src/digilib/io/XMLMetaLoader.java Tue Aug 26 22:30:02 2003 +0200 +++ b/servlet/src/digilib/io/XMLMetaLoader.java Mon Sep 01 18:21:27 2003 +0200 @@ -117,25 +117,25 @@ String localName, String qName) throws SAXException { - + String name = getName(localName, qName); // exit the tag tags.removeLast(); - - // was it a file.name tag? + + // was it a file/name tag? if (name.equals(fileNameTag) && tags.contains(fileTag)) { // save name as filename - if ((content != null)&&(content.length() > 0)) { - fileName = content.toString(); + if ((content != null) && (content.length() > 0)) { + fileName = content.toString().trim(); } return; } - // was it a file.path tag? + // was it a file/path tag? if (name.equals(filePathTag) && tags.contains(fileTag)) { // save path as filepath - if ((content != null)&&(content.length() > 0)) { - filePath = content.toString(); + if ((content != null) && (content.length() > 0)) { + filePath = content.toString().trim(); } return; } @@ -143,13 +143,16 @@ // was it a file tag? if (name.equals(fileTag)) { // is there meta to save? - if ((meta != null)&&(meta.size() > 0)) { - // file name is either file.path or file.name + if ((meta != null) && (meta.size() > 0)) { + // file name is (optional file/path) / file/name String fn = null; - if (filePath != null) { - fn = filePath; - } else if (fileName != null) { - fn = fileName; + + if (fileName != null) { + if (filePath != null) { + fn = filePath + "/" + fileName; + } else { + fn = fileName; + } } else { // no file name, no file return; @@ -163,20 +166,20 @@ // was it a meta tag outside a file tag? if (name.equals(metaTag) && !tags.contains(fileTag)) { // save meta as dir meta - if ((meta != null)&&(meta.size() > 0)) { + if ((meta != null) && (meta.size() > 0)) { files.put("", meta); } return; } - // is this inside an info tag? + // is this inside an info (=img) tag? if (tags.contains(infoTag)) { // then add whatever this is - if ((content != null)&&(content.length() > 0)) { - meta.put(name, content.toString()); + if ((content != null) && (content.length() > 0)) { + meta.put(name, content.toString().trim()); } } - + } }
--- a/servlet/src/digilib/servlet/Scaler.java Tue Aug 26 22:30:02 2003 +0200 +++ b/servlet/src/digilib/servlet/Scaler.java Mon Sep 01 18:21:27 2003 +0200 @@ -58,7 +58,7 @@ public class Scaler extends HttpServlet { // digilib servlet version (for all components) - public static final String dlVersion = "1.14b1"; + public static final String dlVersion = "1.15b1"; // Utils instance with debuglevel Utils util;