Index: /main/trunk/greenstone2/common-src/src/lib/Makefile.in
===================================================================
--- /main/trunk/greenstone2/common-src/src/lib/Makefile.in	(revision 21404)
+++ /main/trunk/greenstone2/common-src/src/lib/Makefile.in	(revision 21405)
@@ -69,4 +69,5 @@
 	fileutil.cpp \
 	gdbmclass.cpp \
+	jdbmnaiveclass.cpp \
 	gsdlsitecfg.cpp \
 	gsdltimes.cpp \
@@ -89,4 +90,5 @@
 	fileutil.o \
 	gdbmclass.o \
+	jdbmnaiveclass.o \
 	gsdlsitecfg.o \
 	gsdltimes.o \
Index: /main/trunk/greenstone2/common-src/src/lib/gdbmclass.cpp
===================================================================
--- /main/trunk/greenstone2/common-src/src/lib/gdbmclass.cpp	(revision 21404)
+++ /main/trunk/greenstone2/common-src/src/lib/gdbmclass.cpp	(revision 21405)
@@ -89,5 +89,6 @@
     }
 
-    // DEPRECATED -- No longer necessary now that the GDBM library reads both little-endian and big-endian files
+    // The following fall-back is less likely to be needed now that GDBM
+    // library reads both little-endian and big-endian files
     if (!file_exists(gdbm_filename))
     {
Index: /main/trunk/greenstone2/common-src/src/lib/gdbmclass.h
===================================================================
--- /main/trunk/greenstone2/common-src/src/lib/gdbmclass.h	(revision 21404)
+++ /main/trunk/greenstone2/common-src/src/lib/gdbmclass.h	(revision 21405)
@@ -85,5 +85,4 @@
   text_t getnextkey (const text_t &key);
 
-  // DEPRECATED -- No longer necessary now that the GDBM library reads both little-endian and big-endian files
   void generate_from_txtgz (text_t filename);
 };
Index: /main/trunk/greenstone2/common-src/src/lib/jdbmnaiveclass.cpp
===================================================================
--- /main/trunk/greenstone2/common-src/src/lib/jdbmnaiveclass.cpp	(revision 21405)
+++ /main/trunk/greenstone2/common-src/src/lib/jdbmnaiveclass.cpp	(revision 21405)
@@ -0,0 +1,297 @@
+/**********************************************************************
+ *
+ * jdbmnaiveclass.cpp -- 
+ * Copyright (C) 1999-2010  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * 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.
+ *
+ *********************************************************************/
+
+#include "jdbmnaiveclass.h"
+#include "gsdltools.h"
+#include "gsdlunicode.h"
+#include "fileutil.h"
+#include "stdlib.h"
+#include <cstring>
+
+
+jdbmnaiveclass::jdbmnaiveclass(const text_t& gsdlhome)
+  : dbclass()
+{
+  gsdlhome_ = gsdlhome;
+
+  text_t jdbm_jar = filename_cat(gsdlhome_,"lib","java","jdbm-1.0.jar");
+
+  text_t jdbm_wrapper_jar = filename_cat(gsdlhome_,"bin","java","JDBMWrapper.jar");
+
+  classpath_ = pathname_cat(jdbm_wrapper_jar,jdbm_jar);
+  classpath_cstr_ = to_utf8(classpath_).getcstr();
+}
+
+jdbmnaiveclass::~jdbmnaiveclass()
+{
+  delete [] classpath_cstr_;
+}
+
+
+// returns true if opened
+bool jdbmnaiveclass::opendatabase (const text_t &filename, int mode, int num_retrys, 
+#ifdef __WIN32__
+			      bool need_filelock
+#else
+                              bool
+#endif
+			      )
+{
+  if (openfile_ == filename) {
+    return true;
+  }
+
+  if (logout == NULL) {
+    logout = &cerr;
+  }
+
+  // Map the DB mode value into equivalent JDBM 'must_exist' value
+  bool must_exist = true; // default
+
+  if (mode == DB_WRITER_CREATE) {
+    must_exist = false;
+  }
+
+  if (must_exist) {    
+    // test that jdbm file exists
+
+    if (!file_exists(filename)) {
+      outconvertclass text_t2ascii;
+      (*logout) << text_t2ascii 
+		<< "Error: JDBM filename " << filename << "does not exist\n";
+      return false;   
+    }
+  }    
+
+  openfile_ = filename;
+
+  // In naive implementation, no connection to database to open, so
+  // nothing else to do at this stage
+  
+  return true;
+}
+
+
+void jdbmnaiveclass::closedatabase ()
+{
+  // nothing to do in naive implementation
+}
+
+// returns file extension string
+text_t jdbmnaiveclass::getfileextension ()
+{
+  return ".jdb";
+}
+
+
+void jdbmnaiveclass::deletekey (const text_t &key)
+{
+  if (openfile_.empty()) return;
+
+  if (logout == NULL) {
+    logout = &cerr;
+  }
+
+  // get a utf-8 encoded c string of the unicode key
+  char* key_cstr = (to_utf8(key)).getcstr();
+  if (key_cstr == NULL) {
+    (*logout) << "jdbmnaiveclass: out of memory" << endl;
+    return;
+  }
+
+  
+  // delete the key<
+  char* openfile_cstr = (to_utf8(openfile_)).getcstr();
+
+  char cmd[512];
+  sprintf(cmd,"java -cp %s JdbDel %s %s",classpath_cstr_,
+	  openfile_cstr,key_cstr);
+
+  delete [] openfile_cstr;
+
+  int status = system(cmd);
+  if (status != 0 ) {
+    (*logout) << "jdbmnaiveclass: failed to run cmd: " << cmd << endl;
+  }
+
+  // free up the key memory
+  delete [] key_cstr;
+}
+
+
+
+// returns true on success
+bool jdbmnaiveclass::getkeydata (const text_t& key, text_t &data)
+{
+  if (openfile_.empty()) return false;
+  
+  if (logout == NULL) {
+    logout = &cerr;
+  }
+
+  // get a utf-8 encoded c string of the unicode key
+  char* key_cstr = (to_utf8(key)).getcstr();
+  if (key_cstr == NULL) {
+    (*logout) << "jdbmnaiveclass: out of memory" << endl;
+
+    return false;
+  }
+  
+  // fetch the result
+  char* openfile_cstr = (to_utf8(openfile_)).getcstr();
+
+  char cmd[512];
+  sprintf(cmd,"java -cp %s JdbGet %s %s",classpath_cstr_,
+	  openfile_cstr,key_cstr);
+
+  delete [] openfile_cstr;
+
+  FILE* PIN = popen(cmd,"r");
+
+  if (PIN == NULL) {
+    (*logout) << "jdbmnaiveclass: failed to run cmd: " << cmd << endl;
+  }
+  else {
+    while (!feof(PIN)) {
+      char buf[256];
+      fgets(buf,256,PIN);
+
+      cerr << "**## buf = " << buf << endl;
+
+      cerr << "**## buf: ";
+
+      int blen = strlen(buf);
+      for (int i=0; i< blen; i++) {
+	cerr << "(" << buf[i] << "," << (int)buf[i] << ") ";
+      }
+      cerr << endl;
+
+
+      data.append(buf);
+    }
+
+  }
+
+  delete [] key_cstr;
+  
+  cerr << "**** data before to_unicode = " << data << endl;
+
+  data = to_uni(data);  // convert to unicode
+
+  return true;
+}
+
+
+// returns array of keys
+text_tarray jdbmnaiveclass::getkeys ()
+{
+  text_tarray keys;
+
+  if (openfile_.empty()) return keys;
+
+  if (logout == NULL) {
+    logout = &cerr;
+  }
+
+  char* openfile_cstr = (to_utf8(openfile_)).getcstr();
+
+  char cmd[512];
+  sprintf(cmd,"java -cp %s JdbKeys %s",classpath_cstr_,
+	  openfile_cstr);
+
+  delete [] openfile_cstr;
+
+  FILE* PIN = popen(cmd,"r");
+
+  if (PIN == NULL) {
+    (*logout) << "jdbmnaiveclass: failed to run cmd: " << cmd << endl;
+  }
+  else {
+    text_t key = "";
+
+    while (!feof(PIN)) {
+
+      char buf[256];
+      fgets(buf,256,PIN);
+      key.append(buf);
+
+      keys.push_back(key);
+      
+    }
+  }
+
+  pclose(PIN);
+
+  return keys;
+}
+
+
+// returns true on success
+bool jdbmnaiveclass::setkeydata (const text_t &key, const text_t &data)
+{
+  if (openfile_.empty()) return false;
+  
+  if (logout == NULL) {
+    logout = &cerr;
+  }
+
+  // get a utf-8 encoded c string of the unicode key
+  char* key_cstr = (to_utf8(key)).getcstr();
+
+  if (key_cstr == NULL) {
+    (*logout) << "jdbmnaiveclass: out of memory" << endl;
+
+    return false;
+  }
+
+  char* data_cstr = (to_utf8(data)).getcstr();
+  if (data_cstr == NULL) {
+    (*logout) << "jdbmnaiveclass: out of memory" << endl;
+
+    delete [] key_cstr;
+    return false;
+  }
+  int data_len = strlen(data_cstr);
+
+  char* openfile_cstr = (to_utf8(openfile_)).getcstr();
+
+  char cmd[512];
+  sprintf(cmd,"java -cp %s JdbSet %s %s %s",
+	  classpath_cstr_,openfile_cstr,key_cstr,data_cstr);
+
+  delete [] openfile_cstr;
+
+  int status = system(cmd);
+  if (status != 0) {
+    (*logout) << "jdbmnaiveclass: failed to run cmd:" 
+	      << cmd << endl;
+  }
+
+  delete [] key_cstr;
+  delete [] data_cstr;
+
+  return (status == 0);
+}
+
Index: /main/trunk/greenstone2/common-src/src/lib/jdbmnaiveclass.h
===================================================================
--- /main/trunk/greenstone2/common-src/src/lib/jdbmnaiveclass.h	(revision 21405)
+++ /main/trunk/greenstone2/common-src/src/lib/jdbmnaiveclass.h	(revision 21405)
@@ -0,0 +1,90 @@
+/**********************************************************************
+ *
+ * jdbmnaiveclass.h -- 
+ * Copyright (C) 1999-2010  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * 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.
+ *
+ *********************************************************************/
+
+#ifndef JDBMNAIVECLASS_H
+#define JDBMNAIVECLASS_H
+
+// This implementation is simple but potentially inefficient (hence 'naive')
+// For each operation is runs a separate "java -cp ... " command
+// A more efficient implementation would open a connection to
+// JdbmAPI and then use a bi-directional pipe for issuing commands and
+// (in the case of Get) reading back the answer.
+//
+// While there is off-the-shelf code for a bi-directional pipe for Unix
+// (see gsdl-music) this has not yet been implemented for Windows (would need
+// to make use of Windows native calls to CreatePipe and CreateProcess)
+
+#include "gsdlconf.h"
+#include "dbclass.h"
+
+#ifdef __WIN32__
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+// Check to see if these are still needed // *****
+#include "autoconf.h"
+#include "systems.h"
+#ifdef __cplusplus
+  }
+#endif
+
+#endif
+
+
+class jdbmnaiveclass : public dbclass
+{
+public:
+  jdbmnaiveclass(const text_t& gsdlhome);
+  ~jdbmnaiveclass();
+
+  // returns true if opened
+  bool opendatabase (const text_t &filename, int mode, int num_retrys, bool need_filelock);
+
+  void closedatabase ();
+
+  void deletekey (const text_t &key);
+
+  // returns file extension string
+  text_t getfileextension ();
+
+  // returns true on success
+  bool getkeydata (const text_t& key, text_t &data);
+
+  // returns array of keys
+  text_tarray getkeys ();
+
+  // returns true on success
+  bool setkeydata (const text_t &key, const text_t &data);
+
+protected:
+  text_t openfile_;
+  text_t classpath_;
+  char*  classpath_cstr_;
+  text_t gsdlhome_;
+};
+
+
+#endif
