Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/JDBMWrapper.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/JDBMWrapper.java	(revision 21430)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/JDBMWrapper.java	(revision 21431)
@@ -21,4 +21,19 @@
 import org.apache.log4j.Logger;
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+
+import java.util.Properties;
+import java.util.ArrayList;
+
+import jdbm.RecordManager;
+import jdbm.RecordManagerFactory;
+import jdbm.helper.FastIterator;
+import jdbm.htree.HTree;
+
 public class JDBMWrapper
   implements FlatDatabaseWrapper {
@@ -26,7 +41,71 @@
   static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.JDBMWrapper.class.getName());
 
+    static String TNAME = "greenstone";
+
+    RecordManager  recman_;
+    HTree          hashtable_;
+
+    static private PrintWriter utf8out = null;
+
+    static
+    {
+        try {
+            OutputStreamWriter osw = new OutputStreamWriter(System.out, "UTF-8");
+            utf8out = new PrintWriter(osw, true);
+        }
+        catch (UnsupportedEncodingException e) {
+            System.out.println(e);
+        }
+    }
+
+
   /** open database named filename, using mode */
-  public boolean openDatabase(String filename, int mode) {
-    return false;
+  public boolean openDatabase(String db_filename, int mode) {
+      
+
+      if (db_filename.endsWith(".jdb")) {
+	  // remove file extension as JDBM does not expect it
+	  db_filename = db_filename.substring(0,db_filename.length()-4);
+      }
+
+      // Map the mode value into equivalent JDBM 'must_exist' value
+      // currently this is very simple as there is only READ and WRITE
+      // (no WRITER_CREATE)
+      // => assume the database must exist
+      boolean must_exist = true; // default
+      
+      try {
+	  // create or open a record manager
+	  Properties props = new Properties();
+	  recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
+	  
+	  // load existing table (if exists) otherwise create new one
+	  long recid = recman_.getNamedObject(TNAME);
+	  
+	  if (recid != 0) {
+	      System.err.println("# Loading existing database table '" + TNAME +"' ...");
+	      hashtable_ = HTree.load(recman_, recid);
+	  }
+	  else {
+	      
+	      if (must_exist) {
+		  recman_.close();
+		  System.err.println("Database table '" + TNAME +"' does not exist.");
+		  throw new IOException();
+	      }
+	      else {
+		  System.err.println("# No database table '" + TNAME +"' to set.  Creating new one");
+		    hashtable_ = HTree.createInstance(recman_);
+		    recman_.setNamedObject(TNAME, hashtable_.getRecid());
+		}
+	  }
+      }
+      catch (IOException e) {	  
+	logger.error("couldn't open database "+ db_filename);
+	return false;
+      }
+
+
+      return true;
   }
 
@@ -34,10 +113,28 @@
   /** close the database associated with this wrapper */
   public void closeDatabase() {
-
+      try {
+	  recman_.close();
+      }
+      catch (IOException e) {	  
+	logger.error("Failed to close JDBM database");
+      }
   }
 
   /** returns the value associated with the key */
   public String getValue(String key) {
-    return null;
+
+      String val;
+
+      try {
+	  val = (String) hashtable_.get(key);
+        
+	  recman_.commit();
+      }
+      catch (IOException e) {	  
+	logger.error("Failed get key " + key + "from JDBM database");
+	return null;
+      }
+
+      return val;
   }
 
@@ -45,5 +142,30 @@
    *	printed for debugging purposes*/
   public String displayAllEntries() {
-	return "No entries.";
+
+      StringBuffer keys = new StringBuffer();
+
+      try {
+	  FastIterator   iter = hashtable_.keys();
+	  String         key  = (String) iter.next();
+	  
+	  String nl = System.getProperty("line.separator");
+	  
+	  while (key != null) {
+	      String val = (String) hashtable_.get(key);
+	      keys.append("[" + key + "]" + nl);
+	      keys.append(val + nl);
+	      // 70 hypens
+	      keys.append("----------------------------------------------------------------------" + nl);
+	      key = (String) iter.next();
+	  }
+
+	  recman_.commit();
+      }
+      catch (IOException e) {	  
+	logger.error("Failed get all keys and values from JDBM database");
+	return null;
+      }
+        
+      return keys.toString();
   }
 }
