changeset 88:398d39ee1014

New version 1.8b4. Utility classes use newer Collection classes like HashMap.
author robcast
date Mon, 17 Mar 2003 15:24:55 +0100
parents 5d44cd2481a5
children 6d35c945a5d6
files servlet/src/digilib/auth/HashTree.java servlet/src/digilib/auth/XMLAuthOps.java servlet/src/digilib/io/XMLListLoader.java
diffstat 3 files changed, 135 insertions(+), 104 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/auth/HashTree.java	Mon Mar 17 15:23:17 2003 +0100
+++ b/servlet/src/digilib/auth/HashTree.java	Mon Mar 17 15:24:55 2003 +0100
@@ -24,15 +24,15 @@
 
 public class HashTree {
 
-  private Hashtable table;
+  private HashMap table;
   private String twigSep = "/";
   private String leafSep = ",";
 
   public HashTree() {
-    table = new Hashtable();
+    table = new HashMap();
   }
 
-  public HashTree(Hashtable t, String twig_separator, String leaf_separator) {
+  public HashTree(HashMap t, String twig_separator, String leaf_separator) {
     table = t;
     twigSep = twig_separator;
     leafSep = leaf_separator;
--- a/servlet/src/digilib/auth/XMLAuthOps.java	Mon Mar 17 15:23:17 2003 +0100
+++ b/servlet/src/digilib/auth/XMLAuthOps.java	Mon Mar 17 15:24:55 2003 +0100
@@ -70,8 +70,8 @@
 	 */
 	public void init() throws AuthOpException {
 		util.dprintln(10, "xmlauthops.init (" + configFile + ")");
-		Hashtable pathList = null;
-		Hashtable ipList = null;
+		HashMap pathList = null;
+		HashMap ipList = null;
 		try {
 			// create data loader for auth-path file
 			File confFile = new File(configFile);
--- a/servlet/src/digilib/io/XMLListLoader.java	Mon Mar 17 15:23:17 2003 +0100
+++ b/servlet/src/digilib/io/XMLListLoader.java	Mon Mar 17 15:24:55 2003 +0100
@@ -21,121 +21,152 @@
 package digilib.io;
 
 // JAXP packages
-import javax.xml.parsers.*;
-import org.xml.sax.*;
-import org.xml.sax.helpers.*;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedList;
 
-import java.util.*;
-import java.io.*;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
 
 public class XMLListLoader {
 
-    private String listTag = "list";
-    private String entryTag = "entry";
-    private String keyAtt = "key";
-    private String valueAtt = "value";
+	private String listTag = "list";
+	private String entryTag = "entry";
+	private String keyAtt = "key";
+	private String valueAtt = "value";
 
-    public XMLListLoader() {
-    }
+	public XMLListLoader() {
+	}
 
-    public XMLListLoader(String list_tag, String entry_tag, String key_att, String value_att) {
-      //System.out.println("xmlListLoader("+list_tag+","+entry_tag+","+key_att+","+value_att+")");
-      listTag = list_tag;
-      entryTag = entry_tag;
-      keyAtt = key_att;
-      valueAtt = value_att;
-    }
-
-    /**
-     *  inner class XMLListParser to be called by the parser
-     */
-    private class XMLListParser extends DefaultHandler {
+	public XMLListLoader(
+		String list_tag,
+		String entry_tag,
+		String key_att,
+		String value_att) {
+		//System.out.println("xmlListLoader("+list_tag+","+entry_tag+","+key_att+","+value_att+")");
+		listTag = list_tag;
+		entryTag = entry_tag;
+		keyAtt = key_att;
+		valueAtt = value_att;
+	}
 
-      private Hashtable listData;
-      private Stack nameSpace;
-    
-      public Hashtable getData() {
-        return listData;
-      }
+	/**
+	 *  inner class XMLListParser to be called by the parser
+	 */
+	private class XMLListParser extends DefaultHandler {
+
+		private HashMap listData;
+		private LinkedList nameSpace;
+
+		public HashMap getData() {
+			return listData;
+		}
 
-      // Parser calls this once at the beginning of a document
-      public void startDocument() throws SAXException {
-          listData = new Hashtable();
-          nameSpace = new Stack();
-      }
+		// Parser calls this once at the beginning of a document
+		public void startDocument() throws SAXException {
+			listData = new HashMap();
+			nameSpace = new LinkedList();
+		}
 
-      // Parser calls this for each element in a document
-      public void startElement(String namespaceURI, String localName,
-                               String qName, Attributes atts)
-  	throws SAXException
-      {
-        //System.out.println("<"+qName);
-        // open a new namespace
-        nameSpace.push(qName);
+		// Parser calls this for each element in a document
+		public void startElement(
+			String namespaceURI,
+			String localName,
+			String qName,
+			Attributes atts)
+			throws SAXException {
+			//System.out.println("<"+qName);
+			// open a new namespace
+			nameSpace.addLast(qName);
 
-        // ist it an entry tag?
-        if (qName.equals(entryTag)) {
-          // is it inside a list tag?
-          if ((listTag.length() > 0)&&(nameSpace.search(listTag) < 0)) {
-            System.out.println("BOO: Entry "+entryTag+" not inside list "+listTag);
-            throw new SAXParseException("Entry "+entryTag+" not inside list "+listTag, null);
-          }
-          // get the attributes
-          String key = atts.getValue(keyAtt);
-          String val = atts.getValue(valueAtt);
-          if ((key == null)||(val == null)) {
-            System.out.println("BOO: Entry "+entryTag+" does not have Attributes "+keyAtt+", "+valueAtt);
-            throw new SAXParseException("Entry "+entryTag+" does not have Attributes "+keyAtt+", "+valueAtt, null);
-          }
-          // add the values
-          //System.out.println("DATA: "+key+" = "+val);
-          listData.put(key, val);
-        }
-    }
-
-    public void endElement(String namespaceURI, String localName,
-                             String qName)
-	throws SAXException
-    {
-      // exit the namespace
-      nameSpace.pop();
-    }
-
-    }
-
+			// ist it an entry tag?
+			if (qName.equals(entryTag)) {
+				// is it inside a list tag?
+				if ((listTag.length() > 0) && (!nameSpace.contains(listTag))) {
+					System.out.println(
+						"BOO: Entry "
+							+ entryTag
+							+ " not inside list "
+							+ listTag);
+					throw new SAXParseException(
+						"Entry " + entryTag + " not inside list " + listTag,
+						null);
+				}
+				// get the attributes
+				String key = atts.getValue(keyAtt);
+				String val = atts.getValue(valueAtt);
+				if ((key == null) || (val == null)) {
+					System.out.println(
+						"BOO: Entry "
+							+ entryTag
+							+ " does not have Attributes "
+							+ keyAtt
+							+ ", "
+							+ valueAtt);
+					throw new SAXParseException(
+						"Entry "
+							+ entryTag
+							+ " does not have Attributes "
+							+ keyAtt
+							+ ", "
+							+ valueAtt,
+						null);
+				}
+				// add the values
+				//System.out.println("DATA: "+key+" = "+val);
+				listData.put(key, val);
+			}
+		}
 
-    /**
-     *  load and parse a file (as URL)
-     *    returns Hashtable with list data
-     */
-    public Hashtable loadURL(String path) throws SAXException, IOException {
-        //System.out.println("loadurl ("+path+")");
-        // Create a JAXP SAXParserFactory and configure it
-        SAXParserFactory spf = SAXParserFactory.newInstance();
-        //spf.setNamespaceAware(true);
+		public void endElement(
+			String namespaceURI,
+			String localName,
+			String qName)
+			throws SAXException {
+			// exit the namespace
+			nameSpace.removeLast();
+		}
 
-        XMLReader xmlReader = null;
-        try {
-          // Create a JAXP SAXParser
-          SAXParser saxParser = spf.newSAXParser();
+	}
+
+	/**
+	 *  load and parse a file (as URL)
+	 *    returns HashMap with list data
+	 */
+	public HashMap loadURL(String path) throws SAXException, IOException {
+		//System.out.println("loadurl ("+path+")");
+		// Create a JAXP SAXParserFactory and configure it
+		SAXParserFactory spf = SAXParserFactory.newInstance();
+		//spf.setNamespaceAware(true);
 
-          // Get the encapsulated SAX XMLReader
-          xmlReader = saxParser.getXMLReader();
-        }
-        catch (ParserConfigurationException e) {
-          throw new SAXException(e);
-        }
+		XMLReader xmlReader = null;
+		try {
+			// Create a JAXP SAXParser
+			SAXParser saxParser = spf.newSAXParser();
+
+			// Get the encapsulated SAX XMLReader
+			xmlReader = saxParser.getXMLReader();
+		} catch (ParserConfigurationException e) {
+			throw new SAXException(e);
+		}
 
-        // create a list parser (keeps the data!)
-        XMLListParser listParser = new XMLListParser();
+		// create a list parser (keeps the data!)
+		XMLListParser listParser = new XMLListParser();
 
-        // Set the ContentHandler of the XMLReader
-        xmlReader.setContentHandler(listParser);
+		// Set the ContentHandler of the XMLReader
+		xmlReader.setContentHandler(listParser);
 
-        // Tell the XMLReader to parse the XML document
-        xmlReader.parse(path);
+		// Tell the XMLReader to parse the XML document
+		xmlReader.parse(path);
 
-        return listParser.getData();
-    }
+		return listParser.getData();
+	}
 
 }