changeset 582:c7034d166a24 stream

more ripping apart ImageFileSet
author robcast
date Tue, 04 Jan 2011 11:56:12 +0100
parents bb8dfc05674f
children 7357ad8f9f42
files servlet/src/digilib/io/DocuDirectory.java servlet/src/digilib/io/DocuDirent.java servlet/src/digilib/io/DocuDirentImpl.java servlet/src/digilib/io/FileOps.java servlet/src/digilib/io/ImageFileSet.java servlet/src/digilib/io/SVGFile.java servlet/src/digilib/io/TextFile.java servlet/src/digilib/servlet/Texter.java
diffstat 8 files changed, 69 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- 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<DocuDirent>(numFiles));
 				// sort the file names alphabetically and iterate the list
 				// Arrays.sort(fileList); // not needed <hertzhaft>
-				Map<Integer, Object> 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);
 				}
--- 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<Object>{
+public interface DocuDirent extends Comparable<Object> {
 
     /**
      * 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.
--- 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;
 	} 
 	
--- 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<Integer,Object> 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);
--- 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<Integer,Object> 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<ImageInput>(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<Integer,Object> 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<String, MetadataMap> 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);
+			}
+		}
+	}
+
 
 }
--- 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;
 	}
 
--- 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;
 	}
 
--- 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);