changeset 271:d3abaf38fb5f

Servlet version 1.21b3 - searching in directories got faster (real binarySearch now!) - cached file lists get disposed - some code cleaning (Map types instead of HashMap)
author robcast
date Tue, 12 Oct 2004 16:06:43 +0200
parents b21915a3fc24
children 084ef7fbe420
files servlet/src/digilib/io/DocuDirent.java servlet/src/digilib/io/FileOps.java
diffstat 2 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/io/DocuDirent.java	Tue Oct 12 16:06:43 2004 +0200
+++ b/servlet/src/digilib/io/DocuDirent.java	Tue Oct 12 16:06:43 2004 +0200
@@ -23,7 +23,7 @@
 package digilib.io;
 
 import java.io.File;
-import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 
@@ -33,12 +33,12 @@
  * @author casties
  *  
  */
-public abstract class DocuDirent {
+public abstract class DocuDirent implements Comparable {
 
 	/** the file class of this file */
 	protected static int fileClass = FileOps.CLASS_NONE;
 	/** HashMap with metadata */
-	protected HashMap fileMeta = null;
+	protected Map fileMeta = null;
 	/** Is the Metadata valid */
 	protected boolean metaChecked = false;
 	/** the parent directory */
@@ -73,11 +73,11 @@
 			XMLMetaLoader ml = new XMLMetaLoader();
 			try {
 				// read meta file
-				HashMap meta = ml.loadURL(mf.getAbsolutePath());
+				Map meta = ml.loadURL(mf.getAbsolutePath());
 				if (meta == null) {
 					return;
 				}
-				fileMeta = (HashMap) meta.get(getName());
+				fileMeta = (Map) meta.get(getName());
 			} catch (Exception e) {
 				Logger.getLogger(this.getClass()).warn("error reading file .meta", e);
 			}
@@ -121,7 +121,7 @@
 	 * 
 	 * @return HashMap
 	 */
-	public HashMap getFileMeta() {
+	public Map getFileMeta() {
 		return fileMeta;
 	} 
 	
@@ -131,7 +131,7 @@
 	 * @param fileMeta
 	 *            The fileMeta to set
 	 */
-	public void setFileMeta(HashMap fileMeta) {
+	public void setFileMeta(Map fileMeta) {
 		this.fileMeta = fileMeta;
 	} 
 	
@@ -149,4 +149,12 @@
 		return fileClass;
 	}
 
+	/** Comparator using the file name.
+	 * 
+	 * @see java.lang.Comparable#compareTo(java.lang.Object)
+	 */
+	public int compareTo(Object arg0) {
+		return (getName().compareTo(arg0));
+	}
+	
 }
--- a/servlet/src/digilib/io/FileOps.java	Tue Oct 12 16:06:43 2004 +0200
+++ b/servlet/src/digilib/io/FileOps.java	Tue Oct 12 16:06:43 2004 +0200
@@ -75,6 +75,7 @@
 		imageExtensions = new ArrayList();
 		textExtensions = new ArrayList();
 		svgExtensions = new ArrayList();
+		// iterate through file types in ft and fill the Map and Lists
 		for (int i = 0; i < ft.length; i++) {
 			String ext = ft[i][0];
 			String mt = ft[i][1];
@@ -175,6 +176,9 @@
 	 * @return
 	 */
 	public static String basename(String fn) {
+		if (fn == null) {
+			return null;
+		}
 		int i = fn.lastIndexOf('.');
 		if (i > 0) {
 			return fn.substring(0, i);
@@ -193,6 +197,9 @@
 	 * @return
 	 */
 	public static String extname(String fn) {
+		if (fn == null) {
+			return null;
+		}
 		int i = fn.lastIndexOf('.');
 		if (i > 0) {
 			return fn.substring(i + 1);
@@ -211,6 +218,9 @@
 	 * @return
 	 */
 	public static String parent(String fn) {
+		if (fn == null) {
+			return null;
+		}
 		int i = fn.lastIndexOf('/');
 		if (i > 0) {
 			return fn.substring(0, i);
@@ -228,6 +238,9 @@
 	 * @return
 	 */
 	public static String normalName(String pathname) {
+		if (pathname == null) {
+			return null;
+		}
 		// upper-dir references are unwanted
 		if (pathname.indexOf("../") >= 0) {
 			return null;
@@ -366,7 +379,7 @@
 	 * @return
 	 */
 	public static Map newHints(Integer type, Object value) {
-		HashMap m = new HashMap();
+		Map m = new HashMap();
 		if (type != null) {
 			m.put(type, value);
 		}