Index: /main/trunk/greenstone2/common-src/src/jdbmedit/Jdb2Txt.java
===================================================================
--- /main/trunk/greenstone2/common-src/src/jdbmedit/Jdb2Txt.java	(revision 21395)
+++ /main/trunk/greenstone2/common-src/src/jdbmedit/Jdb2Txt.java	(revision 21395)
@@ -0,0 +1,109 @@
+/**********************************************************************
+ *
+ * Jdb2Txt.java -- 
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the 
+ * University of Waikato, New Zealand.
+ *
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ * 
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ **********************************************************************/
+
+import jdbm.RecordManager;
+import jdbm.RecordManagerFactory;
+import jdbm.helper.FastIterator;
+import jdbm.htree.HTree;
+
+import java.io.IOException;
+import java.util.Properties;
+
+
+public class Jdb2Txt
+{
+    static String TNAME = "greenstone";
+
+    RecordManager  recman_;
+    HTree          hashtable_;
+
+
+    public Jdb2Txt(String db_filename)
+	throws IOException
+    {
+        // create or open a record manager
+        Properties props = new Properties();
+        recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
+
+        // create or load table
+        long recid = recman_.getNamedObject(TNAME);
+        if (recid != 0) {
+            hashtable_ = HTree.load(recman_, recid);
+        } 
+	else {
+            System.err.println("Failed to find database table '" + TNAME +"' ...");
+	    System.exit(-1);
+        }
+    }
+
+
+    public void db2txt()
+        throws IOException
+    {
+	FastIterator   iter;
+	String         key;
+	String         val;
+
+        iter = hashtable_.keys();
+        key = (String) iter.next();
+        while (key != null) {
+            val = (String) hashtable_.get(key);
+            System.out.println("[" + key + "]");
+            System.out.println(val);
+	    // 70 hypens
+	    System.out.println("----------------------------------------------------------------------");
+            key = (String) iter.next();
+        }
+        
+        recman_.close();
+    }
+
+
+    public static void print_usage()
+    {
+	System.err.println("Usage: java Jdb2Txt database-name");
+	System.exit(-1);
+    }
+
+   
+    public static void main(String[] args)
+    {
+	if (args.length != 1) {
+	    print_usage();
+	}
+
+	String dbname = args[0];
+
+        try {
+
+            Jdb2Txt table = new Jdb2Txt(dbname);
+            table.db2txt();
+        } 
+	catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+}
Index: /main/trunk/greenstone2/common-src/src/jdbmedit/JdbDel.java
===================================================================
--- /main/trunk/greenstone2/common-src/src/jdbmedit/JdbDel.java	(revision 21395)
+++ /main/trunk/greenstone2/common-src/src/jdbmedit/JdbDel.java	(revision 21395)
@@ -0,0 +1,107 @@
+/**********************************************************************
+ *
+ * JdbDel.java -- 
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the 
+ * University of Waikato, New Zealand.
+ *
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ * 
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ **********************************************************************/
+
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+
+import jdbm.RecordManager;
+import jdbm.RecordManagerFactory;
+import jdbm.helper.FastIterator;
+import jdbm.htree.HTree;
+
+import java.io.IOException;
+import java.util.Properties;
+
+
+public class JdbDel
+{
+    static String TNAME = "greenstone";
+
+    RecordManager  recman_;
+    HTree          hashtable_;
+
+    public JdbDel(String db_filename)
+	throws IOException
+    {
+        // create or open a record manager
+        Properties props = new Properties();
+        recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
+
+        // load existing table (if exists) otherwise report error
+        long recid = recman_.getNamedObject(TNAME);
+
+	if (recid != 0) {
+	    System.out.println("Loading existing database table '" + TNAME +"' ...");
+	    hashtable_ = HTree.load(recman_, recid);
+	}
+	else {
+	    recman_.close();
+	    System.out.println("No database table '" + TNAME +"' to delete key from.");
+	    System.exit(-1);
+	}
+    }
+    
+
+    public void del(String key)
+	throws IOException
+    {
+	hashtable_.remove(key);
+	recman_.close();
+    }
+    
+
+    public static void print_usage()
+    {
+	System.err.println("Usage: java JdbDel database-name key");
+	System.exit(-1);
+    }
+
+    
+    public static void main(String[] args)
+    {
+	int argc = args.length;
+
+	// sanity check
+	if (argc!=2) {
+	    print_usage();
+	}
+
+	try {
+	    String dbname = args[0];
+	    JdbDel table = new JdbDel(dbname);
+	    
+	    String key = args[1];
+	    table.del(key);
+	}
+
+	catch (IOException e) {
+	    e.printStackTrace();
+	}
+		
+    }
+
+}
+
+
Index: /main/trunk/greenstone2/common-src/src/jdbmedit/JdbGet.java
===================================================================
--- /main/trunk/greenstone2/common-src/src/jdbmedit/JdbGet.java	(revision 21395)
+++ /main/trunk/greenstone2/common-src/src/jdbmedit/JdbGet.java	(revision 21395)
@@ -0,0 +1,101 @@
+/**********************************************************************
+ *
+ * JdbGet.java -- 
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the 
+ * University of Waikato, New Zealand.
+ *
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ * 
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ **********************************************************************/
+
+import jdbm.RecordManager;
+import jdbm.RecordManagerFactory;
+import jdbm.helper.FastIterator;
+import jdbm.htree.HTree;
+
+import java.io.IOException;
+import java.util.Properties;
+
+
+public class JdbGet
+{
+    static String TNAME = "greenstone";
+
+    RecordManager  recman_;
+    HTree          hashtable_;
+
+
+    public JdbGet(String db_filename)
+	throws IOException
+    {
+        // create or open a record manager
+        Properties props = new Properties();
+        recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
+
+        // create or load table
+        long recid = recman_.getNamedObject(TNAME);
+        if (recid != 0) {
+            hashtable_ = HTree.load(recman_, recid);
+        } 
+	else {
+            System.err.println("Failed to find database table '" + TNAME +"' ...");
+	    System.exit(-1);
+        }
+    }
+
+
+    public void get(String key)
+        throws IOException
+    {
+	FastIterator   iter;
+	String         val;
+
+	val = (String) hashtable_.get(key);
+	System.out.println(val);
+        
+        recman_.close();
+    }
+
+
+    public static void print_usage()
+    {
+	System.err.println("Usage: java JdbGet database-name key");
+	System.exit(-1);
+    }
+
+    public static void main(String[] args)
+    {
+
+	if (args.length != 2) {
+	    print_usage();
+	}
+
+	String dbname = args[0];
+	String key    = args[1];
+
+        try {
+
+            JdbGet table = new JdbGet(dbname);
+            table.get(key);
+        } 
+	catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+}
Index: /main/trunk/greenstone2/common-src/src/jdbmedit/JdbKeys.java
===================================================================
--- /main/trunk/greenstone2/common-src/src/jdbmedit/JdbKeys.java	(revision 21395)
+++ /main/trunk/greenstone2/common-src/src/jdbmedit/JdbKeys.java	(revision 21395)
@@ -0,0 +1,105 @@
+/**********************************************************************
+ *
+ * JdbKeys.java -- 
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the 
+ * University of Waikato, New Zealand.
+ *
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ * 
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ **********************************************************************/
+
+import jdbm.RecordManager;
+import jdbm.RecordManagerFactory;
+import jdbm.helper.FastIterator;
+import jdbm.htree.HTree;
+
+import java.io.IOException;
+import java.util.Properties;
+
+
+public class JdbKeys
+{
+    static String TNAME = "greenstone";
+
+    RecordManager  recman_;
+    HTree          hashtable_;
+
+
+    public JdbKeys(String db_filename)
+	throws IOException
+    {
+        // create or open a record manager
+        Properties props = new Properties();
+        recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
+
+        // create or load table
+        long recid = recman_.getNamedObject(TNAME);
+        if (recid != 0) {
+            hashtable_ = HTree.load(recman_, recid);
+        } 
+	else {
+            System.err.println("Failed to find database table '" + TNAME +"' ...");
+	    System.exit(-1);
+        }
+    }
+
+
+    public void get_keys()
+        throws IOException
+    {
+	FastIterator   iter;
+	String         key;
+	String         val;
+
+        iter = hashtable_.keys();
+        key = (String) iter.next();
+        while (key != null) {
+            System.out.println(key);
+            key = (String) iter.next();
+        }
+        
+        recman_.close();
+    }
+
+
+    public static void print_usage()
+    {
+	System.err.println("Usage: java JdbKeys database-name");
+	System.exit(-1);
+    }
+
+   
+    public static void main(String[] args)
+    {
+	if (args.length != 1) {
+	    print_usage();
+	}
+
+	String dbname = args[0];
+
+        try {
+
+            JdbKeys table = new JdbKeys(dbname);
+            table.get_keys();
+        } 
+	catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+}
Index: /main/trunk/greenstone2/common-src/src/jdbmedit/JdbSet.java
===================================================================
--- /main/trunk/greenstone2/common-src/src/jdbmedit/JdbSet.java	(revision 21395)
+++ /main/trunk/greenstone2/common-src/src/jdbmedit/JdbSet.java	(revision 21395)
@@ -0,0 +1,148 @@
+/**********************************************************************
+ *
+ * JdbSet.java -- 
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the 
+ * University of Waikato, New Zealand.
+ *
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ * 
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ **********************************************************************/
+
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+
+import jdbm.RecordManager;
+import jdbm.RecordManagerFactory;
+import jdbm.helper.FastIterator;
+import jdbm.htree.HTree;
+
+import java.io.IOException;
+import java.util.Properties;
+
+
+public class JdbSet
+{
+    static String TNAME = "greenstone";
+
+    RecordManager  recman_;
+    HTree          hashtable_;
+
+    public JdbSet(String db_filename)
+	throws IOException
+    {
+        // 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.out.println("Loading existing database table '" + TNAME +"' ...");
+	    hashtable_ = HTree.load(recman_, recid);
+	}
+	else {
+	    System.out.println("No database table '" + TNAME +"' to set.  Creating new one");
+	    hashtable_ = HTree.createInstance(recman_);
+	    recman_.setNamedObject(TNAME, hashtable_.getRecid());
+	}
+    }
+    
+    public void append(String key, String val)
+	throws IOException
+    {
+    	    
+	String orig_val = (String)hashtable_.get(key);           
+	String new_val = orig_val + val;
+
+	hashtable_.put(key,new_val);
+	recman_.close();
+    }
+
+    public void set(String key, String val)
+	throws IOException
+	       
+    {
+	hashtable_.put(key,val);
+	recman_.close();
+    }
+
+    public void del(String key)
+	throws IOException
+    {
+	hashtable_.remove(key);
+	recman_.close();
+    }
+    
+
+    public static void print_usage()
+    {
+	System.err.println("Usage: java JdbSet database-name key [value] [append]");
+	System.err.println("\t- if no value is given then the lexicon indicated by the key is removed");
+	System.err.println("\t- if a value is given followed by 'append' then the value is ");
+	System.err.println("\t  added to the existing entry rather than overwriting it");
+	System.exit(-1);
+    }
+
+    
+    public static void main(String[] args)
+    {
+	int argc = args.length;
+
+	// sanity check
+	if ((argc < 2) || (argc>4)) {
+	    print_usage();
+	}
+
+	try {
+	    String dbname = args[0];
+	    JdbSet table = new JdbSet(dbname);
+	    
+	    if (argc == 4) {
+		
+		if (args[3].equals("append")) {
+		    String key = args[1];
+		    String val = args[2];
+		    
+		    table.append(key,val);
+		}
+		else {
+		    System.err.println("Error: Unrecognised option " + args[3]);
+		    print_usage();
+		}
+	    }
+	    else if (argc == 3) {
+		String key = args[1];
+		String val = args[2];
+		table.set(key,val);
+	    }
+	    else {
+		String key = args[1];
+		table.del(key);
+	    }
+	}
+
+	catch (IOException e) {
+	    e.printStackTrace();
+	}
+		
+    }
+
+}
+
+
Index: /main/trunk/greenstone2/common-src/src/jdbmedit/JdbmGet.java
===================================================================
--- /main/trunk/greenstone2/common-src/src/jdbmedit/JdbmGet.java	(revision 21395)
+++ /main/trunk/greenstone2/common-src/src/jdbmedit/JdbmGet.java	(revision 21395)
@@ -0,0 +1,121 @@
+import jdbm.RecordManager;
+import jdbm.RecordManagerFactory;
+import jdbm.helper.FastIterator;
+import jdbm.htree.HTree;
+
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * Sample JDBM application to demonstrate the use of basic JDBM operations.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: Jdbm2Txt.java,v 1.3 2003/08/06 20:10:15 boisvert Exp $
+ */
+public class Jdbm2Txt
+{
+    RecordManager  recman;
+    HTree          hashtable;
+    FastIterator   iter;
+    String         fruit;
+    String         color;
+
+
+    public Jdbm2Txt()
+        throws IOException
+    {
+        // create or open fruits record manager
+        Properties props = new Properties();
+        recman = RecordManagerFactory.createRecordManager( "fruits", props );
+
+        // create or load fruit basket (hashtable of fruits)
+        long recid = recman.getNamedObject( "basket" );
+        if ( recid != 0 ) {
+            System.out.println( "Reloading existing fruit basket..." );
+            hashtable = HTree.load( recman, recid );
+            showBasket();
+        } else {
+            System.out.println( "Creating new fruit basket..." );
+            hashtable = HTree.createInstance( recman );
+            recman.setNamedObject( "basket", hashtable.getRecid() );
+        }
+    }
+
+
+    public void runDemo()
+        throws IOException
+    {
+        // insert keys and values
+        System.out.println();
+        System.out.println( "Adding fruits to the basket..." );
+        hashtable.put( "bananas", "yellow" );
+        hashtable.put( "strawberries", "red" );
+        hashtable.put( "kiwis", "green" );
+
+        showBasket();
+
+
+        // display color of a specific fruit
+        System.out.println();
+        System.out.println( "Get the color of bananas..." );
+        String bananasColor = (String) hashtable.get( "bananas" );
+        System.out.println( "bananas are " + bananasColor );
+        
+        recman.commit();
+        
+        try {
+            // Thread.sleep( 10 * 1000 );
+        } catch ( Exception except ) {
+            // ignore
+        }
+
+        // remove a specific fruit from hashtable
+        System.out.println();
+        System.out.print( "Removing bananas from the basket..." );
+        hashtable.remove( "bananas" );
+        recman.commit();
+        System.out.println( " done." );
+
+        // iterate over remaining objects
+        System.out.println();
+        System.out.println( "Remaining fruit colors:" );
+        iter = hashtable.keys();
+        fruit = (String) iter.next();
+        while ( fruit != null ) {
+            color = (String) hashtable.get( fruit );
+            System.out.println( fruit + " are " + color );
+            fruit = (String) iter.next();
+        }
+        
+        // cleanup
+        recman.close();
+    }
+
+
+    public void showBasket() 
+        throws IOException
+    {
+        // Display content of fruit basket
+        System.out.println();
+        System.out.print( "Fruit basket contains: " );
+        iter = hashtable.keys();
+        fruit = (String) iter.next();
+        while ( fruit != null ) {
+            System.out.print( " " + fruit );
+            fruit = (String) iter.next();
+        }
+        System.out.println();
+    }
+    
+    
+    public static void main( String[] args )
+    {
+        try {
+            Jdbm2Txt basket = new Jdbm2Txt();
+            basket.runDemo();
+        } catch ( IOException ioe ) {
+            ioe.printStackTrace();
+        }
+    }
+
+}
Index: /main/trunk/greenstone2/common-src/src/jdbmedit/JdbmSet.java
===================================================================
--- /main/trunk/greenstone2/common-src/src/jdbmedit/JdbmSet.java	(revision 21395)
+++ /main/trunk/greenstone2/common-src/src/jdbmedit/JdbmSet.java	(revision 21395)
@@ -0,0 +1,121 @@
+import jdbm.RecordManager;
+import jdbm.RecordManagerFactory;
+import jdbm.helper.FastIterator;
+import jdbm.htree.HTree;
+
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * Sample JDBM application to demonstrate the use of basic JDBM operations.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ * @version $Id: Jdbm2Txt.java,v 1.3 2003/08/06 20:10:15 boisvert Exp $
+ */
+public class Jdbm2Txt
+{
+    RecordManager  recman;
+    HTree          hashtable;
+    FastIterator   iter;
+    String         fruit;
+    String         color;
+
+
+    public Jdbm2Txt()
+        throws IOException
+    {
+        // create or open fruits record manager
+        Properties props = new Properties();
+        recman = RecordManagerFactory.createRecordManager( "fruits", props );
+
+        // create or load fruit basket (hashtable of fruits)
+        long recid = recman.getNamedObject( "basket" );
+        if ( recid != 0 ) {
+            System.out.println( "Reloading existing fruit basket..." );
+            hashtable = HTree.load( recman, recid );
+            showBasket();
+        } else {
+            System.out.println( "Creating new fruit basket..." );
+            hashtable = HTree.createInstance( recman );
+            recman.setNamedObject( "basket", hashtable.getRecid() );
+        }
+    }
+
+
+    public void runDemo()
+        throws IOException
+    {
+        // insert keys and values
+        System.out.println();
+        System.out.println( "Adding fruits to the basket..." );
+        hashtable.put( "bananas", "yellow" );
+        hashtable.put( "strawberries", "red" );
+        hashtable.put( "kiwis", "green" );
+
+        showBasket();
+
+
+        // display color of a specific fruit
+        System.out.println();
+        System.out.println( "Get the color of bananas..." );
+        String bananasColor = (String) hashtable.get( "bananas" );
+        System.out.println( "bananas are " + bananasColor );
+        
+        recman.commit();
+        
+        try {
+            // Thread.sleep( 10 * 1000 );
+        } catch ( Exception except ) {
+            // ignore
+        }
+
+        // remove a specific fruit from hashtable
+        System.out.println();
+        System.out.print( "Removing bananas from the basket..." );
+        hashtable.remove( "bananas" );
+        recman.commit();
+        System.out.println( " done." );
+
+        // iterate over remaining objects
+        System.out.println();
+        System.out.println( "Remaining fruit colors:" );
+        iter = hashtable.keys();
+        fruit = (String) iter.next();
+        while ( fruit != null ) {
+            color = (String) hashtable.get( fruit );
+            System.out.println( fruit + " are " + color );
+            fruit = (String) iter.next();
+        }
+        
+        // cleanup
+        recman.close();
+    }
+
+
+    public void showBasket() 
+        throws IOException
+    {
+        // Display content of fruit basket
+        System.out.println();
+        System.out.print( "Fruit basket contains: " );
+        iter = hashtable.keys();
+        fruit = (String) iter.next();
+        while ( fruit != null ) {
+            System.out.print( " " + fruit );
+            fruit = (String) iter.next();
+        }
+        System.out.println();
+    }
+    
+    
+    public static void main( String[] args )
+    {
+        try {
+            Jdbm2Txt basket = new Jdbm2Txt();
+            basket.runDemo();
+        } catch ( IOException ioe ) {
+            ioe.printStackTrace();
+        }
+    }
+
+}
Index: /main/trunk/greenstone2/common-src/src/jdbmedit/Makefile
===================================================================
--- /main/trunk/greenstone2/common-src/src/jdbmedit/Makefile	(revision 21395)
+++ /main/trunk/greenstone2/common-src/src/jdbmedit/Makefile	(revision 21395)
@@ -0,0 +1,16 @@
+
+OBJECTS = Jdb2Txt.class Txt2Jdb.class JdbGet.class \
+  JdbSet.class JdbDel.class JdbKeys.class
+
+all: JDBWrapper.jar
+	@echo "Done"
+
+JDBWrapper.jar: $(OBJECTS)
+	jar cvf JDBWrapper.jar $(OBJECTS)
+
+%.class: %.java
+	javac -cp lib/jdbm-1.0.jar:. $<
+
+
+clean:
+	/bin/rm -f *.class
Index: /main/trunk/greenstone2/common-src/src/jdbmedit/Txt2Jdb.java
===================================================================
--- /main/trunk/greenstone2/common-src/src/jdbmedit/Txt2Jdb.java	(revision 21395)
+++ /main/trunk/greenstone2/common-src/src/jdbmedit/Txt2Jdb.java	(revision 21395)
@@ -0,0 +1,242 @@
+/**********************************************************************
+ *
+ * Txt2Jdb.java -- 
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the 
+ * University of Waikato, New Zealand.
+ *
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ * 
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ **********************************************************************/
+
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+
+import jdbm.RecordManager;
+import jdbm.RecordManagerFactory;
+import jdbm.helper.FastIterator;
+import jdbm.htree.HTree;
+
+import java.io.IOException;
+import java.util.Properties;
+
+
+public class Txt2Jdb
+{
+    static String TNAME = "greenstone";
+
+    RecordManager  recman_;
+    HTree          hashtable_;
+
+
+    public Txt2Jdb(String db_filename, boolean append)
+	throws IOException
+    {
+        // create or open a record manager
+        Properties props = new Properties();
+        recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
+
+        // create new table or (if append) load existing table
+        long recid = recman_.getNamedObject(TNAME);
+        if (append) {
+	    if (recid != 0) {
+		System.out.println("Appending to existing database table '" + TNAME +"' ...");
+		hashtable_ = HTree.load(recman_, recid);
+	    }
+	    else {
+		System.out.println("No database table '" + TNAME +"' to append to.  Creating new one");
+		hashtable_ = HTree.createInstance(recman_);
+		recman_.setNamedObject(TNAME, hashtable_.getRecid());
+	    }
+        } 
+	else {
+            System.out.println("Creating new database table '" + TNAME +"' ...");
+            hashtable_ = HTree.createInstance(recman_);
+            recman_.setNamedObject(TNAME, hashtable_.getRecid());
+        }
+    }
+
+
+    // Helper function to fill in for C++ equivalent
+    // Assumes InputStream is a file or standard-in  
+    // (no some other form of IO mapped device)
+    public boolean eof(InputStream is) 
+	throws IOException
+    {
+	return (is.available() == 0);
+    }
+
+    public void txt2db()
+        throws IOException
+    {
+
+	// Port of main txt2db code (originally written in C++)
+	// Note: might not be most efficient way to do things in Java
+
+	StringBuffer key;
+	StringBuffer value;
+	StringBuffer tmp;
+	int num_dashes = 0;
+
+	boolean delkey = false;
+
+	BufferedInputStream bis = new BufferedInputStream(System.in);
+	
+	int c = bis.read();
+	while (!eof(bis)) {
+	    num_dashes = 0;
+	    key = new StringBuffer();
+	    value = new StringBuffer();
+	    
+	    // Parse out 'key' from [key]\n
+	    
+	    // scan for first occurrence of [
+	    while (!eof(bis) && c != '[') {
+		c = bis.read();
+	    }
+
+	    
+	    if (!eof(bis)) {
+		c = bis.read(); // skip [
+	    }
+
+	    
+	    // now look for closing ], building up 'key' as we go
+	    while (!eof(bis) && c != ']') {
+		key.append ((char)c);
+		c = bis.read();
+	    }
+	    
+	    if (!eof(bis)) {
+		// most likely an eol char, but if '-', then signifies record
+		// is to be deleted, not added
+		c = bis.read();
+		if (c == '-') {	
+		    delkey = true;
+		}
+		else {
+		    delkey = false;
+		}
+	    }
+
+	    while (!eof(bis) && (c == '\n' || c == '\r')) {
+		c = bis.read();
+	    }
+	    
+	    // look for 70 dashes
+	    tmp = new StringBuffer();
+	    while (!eof(bis) && (num_dashes < 70)) {
+		if (c == '\n') {
+		    tmp.append((char)c);
+		    num_dashes = 0;	
+		    
+		} else if (c == '\r') { 
+		    // Here we are able to process both Windows-specific
+		    // text files (containing carriage-return, newline) and
+		    // Linux text files (containing only newline
+		    // characters) by ignoring the Windows' carriage-return
+		    // altogether so that we produce a uniform database
+		    // file from either system's type of text file.
+		    //
+		    // If we don't ignore the carriage return here, txt.gz
+		    // files produced on Windows cause a GS library running
+		    // on Linux to break.
+		    num_dashes = 0;
+		    
+		} else if (c == '-') {
+		    tmp.append((char)c);
+		    ++num_dashes;
+		    
+		} else {
+		    value.append(tmp);
+		    value.append((char)c);
+		    tmp = new StringBuffer();
+		    num_dashes = 0;
+		}
+		c = bis.read();
+	    }
+	    
+	    // if the key is not an empty string store this key-value pair
+	    if (key.length()>0) {
+		String key_str = key.toString();
+
+		if (delkey) {
+		    // delete the given key
+		    hashtable_.remove(key_str);
+		}
+		else {		    
+		    // add/append
+		    String value_str = value.toString();
+		    hashtable_.put(key_str,value_str); 
+		    recman_.commit();
+		}
+	    }
+	}	
+
+        recman_.close();
+    }
+
+
+    
+    public static void print_usage()
+    {
+	System.err.println("Usage: java Txt2Jdb [-append] database-name");
+	System.exit(-1);
+    }
+
+    
+    public static void main(String[] args)
+    {
+	int argc = args.length;
+
+	// sanity check
+	if (argc != 1 && argc != 2) {
+	    print_usage();
+	}
+	
+	String dbname;
+	boolean append = false;
+	boolean delkey = false;
+	
+	if (argc == 2) {
+	    dbname = args[1];
+	    if (args[0].equals("-append")) {
+		append = true;
+	    } else {
+		System.err.println(args[0] + " is not a valid option.");
+		print_usage();
+	    }
+	} else {
+	    dbname = args[0];
+	}
+
+	try {
+
+            Txt2Jdb table = new Txt2Jdb(dbname,append);
+            table.txt2db();
+        } 
+	catch (IOException e) {
+            e.printStackTrace();
+        }
+
+
+
+    }
+
+}
+
+
