changeset 205:6221d688eab6

Servlet version 1.18b9 -- cleanup and bugfixes - fixed bug with slow color JPEGs - better pathname handling - better filehandle cleanup (hopefully)
author robcast
date Fri, 12 Mar 2004 19:52:06 +0100
parents 37a697fd8ec6
children ffbe705d1c3f
files servlet/src/digilib/auth/HashTree.java servlet/src/digilib/image/ImageLoaderImageInfoDocuInfo.java
diffstat 2 files changed, 95 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/auth/HashTree.java	Tue Mar 02 13:43:39 2004 +0100
+++ b/servlet/src/digilib/auth/HashTree.java	Fri Mar 12 19:52:06 2004 +0100
@@ -1,79 +1,110 @@
 /*  HashTree -- Tree in a Hashtable
 
-  Digital Image Library servlet components
+ Digital Image Library servlet components
 
-  Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de)
+ Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de)
 
-  This program is free software; you can redistribute  it and/or modify it
-  under  the terms of  the GNU General  Public License as published by the
-  Free Software Foundation;  either version 2 of the  License, or (at your
-  option) any later version.
-   
-  Please read license.txt for the full details. A copy of the GPL
-  may be found at http://www.gnu.org/copyleft/lgpl.html
+ This program is free software; you can redistribute  it and/or modify it
+ under  the terms of  the GNU General  Public License as published by the
+ Free Software Foundation;  either version 2 of the  License, or (at your
+ option) any later version.
+ 
+ Please read license.txt for the full details. A copy of the GPL
+ may be found at http://www.gnu.org/copyleft/lgpl.html
 
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
-*/
+ */
 
 package digilib.auth;
 
 import java.util.*;
 
+/**
+ * Tree representation wrapper for a HashMap.
+ * 
+ * The HashTree is constructed from a HashMap filled with 'branches' with
+ * 'leaves'. The branches are stored as String keys in the HashMap. The String
+ * values are leaves.
+ * 
+ * Branches are matched in 'twigs' separated by 'twig separator' Strings. The
+ * return values for a match are leaf values separated by 'leaf separator'
+ * Strings.
+ * 
+ * @author casties
+ */
 public class HashTree {
 
-  private HashMap table;
-  private String twigSep = "/";
-  private String leafSep = ",";
+    private HashMap table;
 
-  public HashTree() {
-    table = new HashMap();
-  }
+    private String twigSep = "/";
+
+    private String leafSep = ",";
 
-  public HashTree(HashMap t, String twig_separator, String leaf_separator) {
-    table = t;
-    twigSep = twig_separator;
-    leafSep = leaf_separator;
-    optimizeTable();
-  }
+    /**
+     * Constructor of a HashTree.
+     * 
+     * Creates a HashTree wrapper around a given HashMap, using the given twig
+     * separator and leaf separator.
+     * 
+     * @param t
+     * @param twig_separator
+     * @param leaf_separator
+     */
+    public HashTree(HashMap t, String twig_separator, String leaf_separator) {
+        table = t;
+        twigSep = twig_separator;
+        leafSep = leaf_separator;
+        optimizeTable();
+    }
 
-  void optimizeTable() {
-  }
-
-  List match(String branch) {
-    String b = "";
-    String m;
-    LinkedList matches = new LinkedList();
+    void optimizeTable() {
+    }
 
-    // split branch
-    StringTokenizer twig = new StringTokenizer(branch, twigSep);
-    // walk branch and check with tree
-    while (twig.hasMoreTokens()) {
-      if (b.length() == 0) {
-        b = twig.nextToken();
-      } else {
-        b += twigSep + twig.nextToken();
-      }
-      m = (String)table.get(b);
-      if (m != null) {
-        if (m.indexOf(leafSep) < 0) {
-          // single leaf
-          matches.add(m);
+    /**
+     * Matches the given branch against the HashTree.
+     * 
+     * Returns a LinkedList of all leaves on all matching branches in the tree.
+     * Branches in the tree match if they are substrings starting at the same
+     * root.
+     * 
+     * @param branch
+     * @return
+     */
+    List match(String branch) {
+        String b = "";
+        String m;
+        LinkedList matches = new LinkedList();
+
+        // split branch
+        StringTokenizer twig = new StringTokenizer(branch, twigSep);
+        // walk branch and check with tree
+        while (twig.hasMoreTokens()) {
+            if (b.length() == 0) {
+                b = twig.nextToken();
+            } else {
+                b += twigSep + twig.nextToken();
+            }
+            m = (String) table.get(b);
+            if (m != null) {
+                if (m.indexOf(leafSep) < 0) {
+                    // single leaf
+                    matches.add(m);
+                } else {
+                    // split leaves
+                    StringTokenizer leaf = new StringTokenizer(m, leafSep);
+                    while (leaf.hasMoreTokens()) {
+                        matches.add(leaf.nextToken());
+                    }
+                }
+            }
+        }
+        if (matches.size() > 0) {
+            return matches;
         } else {
-          // split leaves
-          StringTokenizer leaf = new StringTokenizer(m, leafSep);
-          while (leaf.hasMoreTokens()) {
-            matches.add(leaf.nextToken());
-          }
+            return null;
         }
-      }
     }
-    if (matches.size() > 0) {
-      return matches;
-    } else {
-      return null;
-    }
-  }
 }
--- a/servlet/src/digilib/image/ImageLoaderImageInfoDocuInfo.java	Tue Mar 02 13:43:39 2004 +0100
+++ b/servlet/src/digilib/image/ImageLoaderImageInfoDocuInfo.java	Fri Mar 12 19:52:06 2004 +0100
@@ -47,6 +47,7 @@
 
 	/* check image size and type and store in ImageFile f */
 	public boolean checkFile(ImageFile imgf) throws IOException {
+		// fileset to store the information
 		ImageFileset imgfs = imgf.getParent();
 		File f = imgf.getFile();
 		if (f == null) {
@@ -58,6 +59,7 @@
 		iif.setInput(raf);
 		iif.setCollectComments(false);
 		iif.setDetermineImageNumber(false);
+		logger.debug("identifying (ImageInfo) "+f);
 		// try with ImageInfo first
 		if (iif.check()) {
 			ImageSize d =
@@ -69,6 +71,7 @@
 			}
 			raf.close();
 		} else {
+			logger.debug("identifying (ImageIO) "+f);
 			// else use ImageReader
 			ImageInputStream istream = ImageIO.createImageInputStream(raf);
 			Iterator readers = ImageIO.getImageReaders(istream);
@@ -79,9 +82,9 @@
 			}
 			ImageReader reader = (ImageReader) readers.next();
 			/* are there more readers? */
-			logger.debug("this reader: " + reader.getClass());
+			logger.debug("ImageIO: this reader: " + reader.getClass());
 			while (readers.hasNext()) {
-				logger.debug("next reader: " + readers.next().getClass());
+				logger.debug("ImageIO: next reader: " + readers.next().getClass());
 			}
 			reader.setInput(istream);
 			ImageSize d =
@@ -95,6 +98,7 @@
 			}
 			// dispose the reader to free resources
 			reader.dispose();
+			raf.close();
 		}
 		return true;
 	}