# HG changeset patch # User robcast # Date 1294138572 -3600 # Node ID c7034d166a244488ad796f9a361f5823ab97d278 # Parent bb8dfc05674f9e863fb25fc692029a55918c8351 more ripping apart ImageFileSet diff -r bb8dfc05674f -r c7034d166a24 servlet/src/digilib/io/DocuDirectory.java --- a/servlet/src/digilib/io/DocuDirectory.java Thu Dec 23 19:04:57 2010 +0100 +++ b/servlet/src/digilib/io/DocuDirectory.java Tue Jan 04 11:56:12 2011 +0100 @@ -177,8 +177,6 @@ if (!isValid) { return false; } - // first file extension to try for scaled directories - String scalext = null; // read all filenames logger.debug("reading directory " + dir.getPath()); /* @@ -226,14 +224,10 @@ 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); + dirs); // add the file to our list - // logger.debug(f.getName()); - list.get(fileClass.ordinal()).add(f); f.setParent(this); } diff -r bb8dfc05674f -r c7034d166a24 servlet/src/digilib/io/DocuDirent.java --- a/servlet/src/digilib/io/DocuDirent.java Thu Dec 23 19:04:57 2010 +0100 +++ b/servlet/src/digilib/io/DocuDirent.java Tue Jan 04 11:56:12 2011 +0100 @@ -2,7 +2,7 @@ import java.io.File; -public interface DocuDirent extends Comparable{ +public interface DocuDirent extends Comparable { /** * Checks metadata and does something with it. @@ -15,7 +15,7 @@ * * @return */ - public abstract File getInput(); + public abstract File getFile(); /** * Reads meta-data for this Fileset if there is any. diff -r bb8dfc05674f -r c7034d166a24 servlet/src/digilib/io/DocuDirentImpl.java --- a/servlet/src/digilib/io/DocuDirentImpl.java Thu Dec 23 19:04:57 2010 +0100 +++ b/servlet/src/digilib/io/DocuDirentImpl.java Tue Jan 04 11:56:12 2011 +0100 @@ -54,18 +54,18 @@ /* (non-Javadoc) * @see digilib.io.DocuDirent#getInput() */ - public abstract File getInput(); + public abstract File getFile(); /* (non-Javadoc) * @see digilib.io.DocuDirent#readMeta() */ public void readMeta() { - if ((fileMeta != null) || (getInput() == null)) { + if ((fileMeta != null) || (getFile() == null)) { // there is already metadata or there is no file return; } // metadata is in the file {filename}.meta - String fn = getInput().getAbsolutePath(); + String fn = getFile().getAbsolutePath(); File mf = new File(fn + ".meta"); if (mf.canRead()) { XMLMetaLoader ml = new XMLMetaLoader(); @@ -86,7 +86,7 @@ * @see digilib.io.DocuDirent#getName() */ public String getName() { - File f = getInput(); + File f = getFile(); return (f != null) ? f.getName() : null; } diff -r bb8dfc05674f -r c7034d166a24 servlet/src/digilib/io/FileOps.java --- a/servlet/src/digilib/io/FileOps.java Thu Dec 23 19:04:57 2010 +0100 +++ b/servlet/src/digilib/io/FileOps.java Tue Jan 04 11:56:12 2011 +0100 @@ -334,15 +334,15 @@ * * @param fileClass * @param file - * @param hints + * @param baseDirs * optional additional parameters * @return */ - public static DocuDirent fileForClass(FileClass fileClass, File file, Map hints) { + public static DocuDirent fileForClass(FileClass fileClass, File file, Directory[] baseDirs) { // what class of file do we have? if (fileClass == FileClass.IMAGE) { // image file - return new ImageFileSet(file, hints); + return new ImageFileSet(file, baseDirs); } else if (fileClass == FileClass.TEXT) { // text file return new TextFile(file); diff -r bb8dfc05674f -r c7034d166a24 servlet/src/digilib/io/ImageFileSet.java --- a/servlet/src/digilib/io/ImageFileSet.java Thu Dec 23 19:04:57 2010 +0100 +++ b/servlet/src/digilib/io/ImageFileSet.java Tue Jan 04 11:56:12 2011 +0100 @@ -8,6 +8,8 @@ import java.util.Arrays; import java.util.Map; +import org.apache.log4j.Logger; + import digilib.io.FileOps.FileClass; /** @@ -18,8 +20,10 @@ /** this is an image file */ protected static FileClass fileClass = FileClass.IMAGE; + /** the (main) file */ + protected File file = null; /** the file name */ - protected String filename = null; + protected String name = null; /** HashMap with metadata */ protected MetadataMap fileMeta = null; /** Is the Metadata valid */ @@ -33,75 +37,75 @@ * The hints are expected to contain 'basedirs' and 'scaledfilext' keys. * * @param file - * @param hints + * @param baseDirs */ - public ImageFileSet(File file, Map hints) { - Directory[] dirs = (Directory[]) hints.get(FileOps.HINT_BASEDIRS); - int nb = dirs.length; + public ImageFileSet(File file, Directory[] baseDirs) { + int nb = baseDirs.length; list = new ArrayList(nb); - parent = dirs[0]; - fill(dirs, file, hints); + parent = baseDirs[0]; // TODO: is baseDir really our parent? + this.file = file; + this.name = file.getName(); + fill(baseDirs, file); } /* (non-Javadoc) * @see digilib.io.DocuDirent#getName() */ public String getName() { - // TODO Auto-generated method stub - return null; + return this.name; } /* (non-Javadoc) * @see digilib.io.DocuDirent#getParent() */ public Directory getParent() { - // TODO Auto-generated method stub - return null; + return this.parent; } /* (non-Javadoc) * @see digilib.io.DocuDirent#setParent(digilib.io.Directory) */ public void setParent(Directory parent) { - // TODO Auto-generated method stub - + this.parent = parent; } /* (non-Javadoc) * @see digilib.io.DocuDirent#getFileMeta() */ public MetadataMap getFileMeta() { - // TODO Auto-generated method stub - return null; + return this.fileMeta; } /* (non-Javadoc) * @see digilib.io.DocuDirent#setFileMeta(digilib.io.MetadataMap) */ public void setFileMeta(MetadataMap fileMeta) { - // TODO Auto-generated method stub - + this.fileMeta = fileMeta; } /* (non-Javadoc) * @see digilib.io.DocuDirent#isMetaChecked() */ public boolean isMetaChecked() { - // TODO Auto-generated method stub - return false; + return this.metaChecked; } /* (non-Javadoc) * @see digilib.io.DocuDirent#compareTo(java.lang.Object) */ public int compareTo(Object arg0) { - // TODO Auto-generated method stub - return 0; + if (arg0 instanceof DocuDirent) { + return name.compareTo(((DocuDirent) arg0).getName()); + } else { + return getName().compareTo((String) arg0); + } } - public File getInput() { - // TODO Auto-generated method stub - return null; + /* (non-Javadoc) + * @see digilib.io.DocuDirent#getFile() + */ + public File getFile() { + return file; } /** @@ -131,7 +135,7 @@ * @param hints * */ - void fill(Directory[] dirs, File fl, Map hints) { + void fill(Directory[] dirs, File fl) { int nb = dirs.length; String fn = fl.getName(); String baseFn = FileOps.basename(fn); @@ -272,9 +276,31 @@ } } - public void readMeta() { - // FIXME: what to do? - - } + /* (non-Javadoc) + * @see digilib.io.DocuDirent#readMeta() + */ + public void readMeta() { + if ((fileMeta != null) || (file == null)) { + // there is already metadata or there is no file + return; + } + // metadata is in the file {filename}.meta + String fn = file.getAbsolutePath(); + File mf = new File(fn + ".meta"); + if (mf.canRead()) { + XMLMetaLoader ml = new XMLMetaLoader(); + try { + // read meta file + Map meta = ml.loadURL(mf.getAbsolutePath()); + if (meta == null) { + return; + } + fileMeta = meta.get(name); + } catch (Exception e) { + Logger.getLogger(this.getClass()).warn("error reading file .meta", e); + } + } + } + } diff -r bb8dfc05674f -r c7034d166a24 servlet/src/digilib/io/SVGFile.java --- a/servlet/src/digilib/io/SVGFile.java Thu Dec 23 19:04:57 2010 +0100 +++ b/servlet/src/digilib/io/SVGFile.java Tue Jan 04 11:56:12 2011 +0100 @@ -55,7 +55,7 @@ /* (non-Javadoc) * @see digilib.io.DocuDirent#getFile() */ - public File getInput() { + public File getFile() { return file; } diff -r bb8dfc05674f -r c7034d166a24 servlet/src/digilib/io/TextFile.java --- a/servlet/src/digilib/io/TextFile.java Thu Dec 23 19:04:57 2010 +0100 +++ b/servlet/src/digilib/io/TextFile.java Tue Jan 04 11:56:12 2011 +0100 @@ -55,7 +55,7 @@ /* (non-Javadoc) * @see digilib.io.DocuDirent#getFile() */ - public File getInput() { + public File getFile() { return file; } diff -r bb8dfc05674f -r c7034d166a24 servlet/src/digilib/servlet/Texter.java --- a/servlet/src/digilib/servlet/Texter.java Thu Dec 23 19:04:57 2010 +0100 +++ b/servlet/src/digilib/servlet/Texter.java Tue Jan 04 11:56:12 2011 +0100 @@ -142,11 +142,11 @@ */ TextFile f = getTextFile(dlRequest, "/txt"); if (f != null) { - ServletOps.sendFile(f.getInput(), null, null, response, logger); + ServletOps.sendFile(f.getFile(), null, null, response, logger); } else { f = getTextFile(dlRequest, ""); if (f != null) { - ServletOps.sendFile(f.getInput(), null, null, response, logger); + ServletOps.sendFile(f.getFile(), null, null, response, logger); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Text-File not found!"); //ServletOps.htmlMessage("No Text-File!", response);