Index: trunk/indexers/mgpp/java/org/greenstone/mgpp/MGPPPassesWrapper.java
===================================================================
--- trunk/indexers/mgpp/java/org/greenstone/mgpp/MGPPPassesWrapper.java	(revision 8950)
+++ trunk/indexers/mgpp/java/org/greenstone/mgpp/MGPPPassesWrapper.java	(revision 8950)
@@ -0,0 +1,146 @@
+/*
+ *    MGPassesWrapper.java
+ *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
+ *
+ *    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.
+ */
+package org.greenstone.mgpp;
+
+
+/** java wrapper class for access to gs3_mgpp_passes in C
+ *
+ * the native side implemented in MGPPPassesWrapperImpl.c
+ */
+
+public class MGPPPassesWrapper
+{
+    static {
+	System.loadLibrary("mgpppassjni");
+	initIDs();
+    }
+    
+    //static final public char INVF_LEVEL_1 = '1';
+    //static final public char INVF_LEVEL_2 = '2';
+    //static final public char INVF_LEVEL_3 = '3';
+    
+    static final public int TEXT_PASS_1 = 0;
+    static final public int TEXT_PASS_2 = 1;
+    static final public int INDEX_PASS_1 = 2;
+    static final public int INDEX_PASS_2 = 3;
+    static final public int SPECIAL_PASS = 4;
+
+    //static final public int NO_STEM_OR_CASE = 0;
+    //static final public int CASE_ONLY = 1;
+    //static final public int STEM_ONLY = 2;
+    //static final public int STEM_AND_CASE = 3;
+
+    //static final public String STEMMER_ENGLISH = "english";
+    //static final public String STEMMER_FRENCH = "french";
+    //static final public String STEMMER_LOVIN = "lovin";
+    //static final public String STEMMER_SIMPLE_FRENCH = "simple-french";
+
+    //static final private char END_OF_DOCUMENT = (char) 2;
+
+    public MGPPPassesWrapper() {
+	initCSide();
+    }
+
+    /** initialise the pass through the documents */
+    public native boolean init();
+    
+    /** add a pass declaration */
+    public void addPass(int pass) {
+	switch (pass) {
+	case TEXT_PASS_1:
+	    addPass('T','1');
+	    break;
+	case TEXT_PASS_2:
+	    addPass('T','2');	    
+	    break;
+	case INDEX_PASS_1:
+	    addPass('I','1');
+	    break;
+	case INDEX_PASS_2:
+	    addPass('I','2');
+	    break;
+	case SPECIAL_PASS:
+	    addPass('S','1');
+	    break;
+	}
+    }
+    /** set the base path */
+    public native void setBasePath(String basepath);
+    /** set the file name */
+    public native void setFileName(String filename);
+
+    /** set the Document tag */
+    public native void setDocumentTag(String tag);
+
+    /** add a level tag */
+    public native void addLevelTag(String tag);
+
+    /** set the index level (default word level) */
+    public native void setIndexLevel(String tag);
+    
+    /** Maximum amount of memory to use for  the index  pass-2  file
+	inversion  in  megabytes.
+    */
+    public native void setInversionMemLimit(int limit);
+
+    /** process one or more MGPP documents */
+    public boolean processDocument(String doc_text) {
+	try {
+	    processMGPPDocument(doc_text.getBytes("UTF-8"));
+	} catch (Exception e) {
+	    e.printStackTrace();
+	    return false;
+	}
+	return true;
+    }
+   
+    /** finalise the pass through the documents */
+    public native boolean finish();
+
+    /** get the exit value once finished */
+    public native int exitValue();
+
+    /** initialises field and method IDs for java side to enable access on C side */
+    private static native void initIDs();
+
+    /** initialises any C side stuff */
+    private native boolean initCSide();
+
+    private native void addPass(char pass_type, char pass_num);
+
+    /** process a MGPP document */
+    private native boolean processMGPPDocument(byte[] text);
+
+    public static void main(String []args) {
+
+	String doc = "<Document>hello there kath<Title>this is a title</Title></Document><Document>my name is helen</Document>";
+
+	MGPPPassesWrapper wrapper = new MGPPPassesWrapper();
+	wrapper.addPass(TEXT_PASS_1);
+	wrapper.addPass(TEXT_PASS_2);
+	wrapper.setDocumentTag("Document");
+	wrapper.setBasePath("/tmp/kjdon/index");
+	wrapper.setFileName("idx");
+
+	wrapper.init();
+	wrapper.processDocument(doc);
+	wrapper.finish();
+
+    }
+}
Index: trunk/indexers/mgpp/jni/MGPPPassesWrapperImpl.cpp
===================================================================
--- trunk/indexers/mgpp/jni/MGPPPassesWrapperImpl.cpp	(revision 8950)
+++ trunk/indexers/mgpp/jni/MGPPPassesWrapperImpl.cpp	(revision 8950)
@@ -0,0 +1,190 @@
+/*
+ *    MGPassesWrapperImpl.c
+ *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
+ *
+ *    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 <jni.h>
+#include <assert.h>
+#include "sysfuncs.h"
+#include "org_greenstone_mgpp_MGPPPassesWrapper.h"
+
+#include "mgpp_passes_4jni.h"
+#include "mg_files.h"
+
+/* if we need to use java objects, we should initialise their field ids here*/
+JNIEXPORT void JNICALL
+Java_org_greenstone_mgpp_MGPPPassesWrapper_initIDs(JNIEnv *j_env, jclass j_cls)
+{
+  return;
+}
+
+JNIEXPORT jboolean JNICALL
+Java_org_greenstone_mgpp_MGPPPassesWrapper_initCSide(JNIEnv *j_env, jobject j_obj)
+{
+  clear_variables();
+  return true;  
+}  
+
+/* add a pass type T1, T2, I1, I2, S */
+JNIEXPORT void JNICALL
+Java_org_greenstone_mgpp_MGPPPassesWrapper_addPass(JNIEnv *j_env, 
+					       jobject j_obj, 
+					       jchar j_pass_type,
+					       jchar j_pass_num)
+{
+  /* get the level as a c char */
+  const char pass_type = j_pass_type;
+  const char pass_num = j_pass_num;
+  add_pass(pass_type, pass_num);
+  
+}
+
+/* Set the filename */
+JNIEXPORT void JNICALL
+Java_org_greenstone_mgpp_MGPPPassesWrapper_setFileName(JNIEnv *j_env, 
+						   jobject j_obj,
+						   jstring j_filename)
+{
+  /* Get the filename as a C string */
+  const char* filename = j_env->GetStringUTFChars(j_filename, NULL);
+ 
+  assert(filename != NULL);
+  set_filename(filename);
+  
+  /* Release the string */
+ j_env->ReleaseStringUTFChars(j_filename, filename);
+
+}
+
+/* Set the base path */
+JNIEXPORT void JNICALL
+Java_org_greenstone_mgpp_MGPPPassesWrapper_setBasePath(JNIEnv *j_env, 
+						   jobject j_obj,
+						   jstring j_basepath)
+{
+  /* Get the base_path as a C string */
+  const char* basepath = j_env->GetStringUTFChars(j_basepath, NULL);
+  assert(basepath != NULL);
+ 
+  set_basepath(basepath);
+  
+  /* Release the string */
+  j_env->ReleaseStringUTFChars(j_basepath, basepath);
+
+}
+
+/* set the Document tag */
+JNIEXPORT void JNICALL
+Java_org_greenstone_mgpp_MGPPPassesWrapper_setDocumentTag(JNIEnv *j_env, 
+						      jobject j_obj,
+						      jstring j_tag)
+{
+  const char* tag = j_env->GetStringUTFChars(j_tag, NULL);
+
+  set_document_tag(tag);
+  /* Release the string */
+  j_env->ReleaseStringUTFChars(j_tag, tag);
+
+
+}
+
+/* add a level tag */
+JNIEXPORT void JNICALL
+Java_org_greenstone_mgpp_MGPPPassesWrapper_addLevelTag(JNIEnv *j_env, 
+						   jobject j_obj,
+						   jstring j_tag)
+{
+  const char* tag = j_env->GetStringUTFChars(j_tag, NULL);
+  add_level_tag(tag);
+
+  /* Release the string */
+  j_env->ReleaseStringUTFChars(j_tag, tag);
+
+}
+
+/* set the index level (default word level) */
+JNIEXPORT void JNICALL
+Java_org_greenstone_mgpp_MGPPPassesWrapper_setIndexLevel(JNIEnv *j_env, 
+						     jobject j_obj,
+						     jstring j_tag)
+{
+  const char* tag = j_env->GetStringUTFChars(j_tag, NULL);
+  set_index_level(tag);
+
+  /* Release the string */
+  j_env->ReleaseStringUTFChars(j_tag, tag);
+
+  
+}
+
+
+/** Maximum amount of memory to use for  the index  pass-2  file
+    inversion  in  megabytes.
+*/
+JNIEXPORT void JNICALL
+Java_org_greenstone_mgpp_MGPPPassesWrapper_setInversionMemLimit(JNIEnv *j_env, 
+							    jobject j_obj, 
+							    jint j_limit) {
+  int limit = j_limit;
+  set_inversion_limit(limit);
+}
+
+
+/* initialise the pass through the documents. must be called after all
+   the set methods 
+*/
+JNIEXPORT jboolean JNICALL 
+Java_org_greenstone_mgpp_MGPPPassesWrapper_init(JNIEnv *j_env, 
+					    jobject j_obj) {
+
+  init_driver();
+  return true;
+}
+
+
+/* process one or more documents */
+JNIEXPORT jboolean JNICALL 
+Java_org_greenstone_mgpp_MGPPPassesWrapper_processMGPPDocument(JNIEnv *j_env, 
+						       jobject j_obj,
+						       jbyteArray j_doc_text) {
+  /* Get the text as a C string */
+  int length = j_env->GetArrayLength(j_doc_text);
+  u_char * text_buffer = (u_char *)j_env->GetByteArrayElements(j_doc_text, NULL);
+  process_document(text_buffer, length);
+  /* Release the string */
+  // why doesn't this work in c++ when it works in C?????
+  //j_env->ReleaseByteArrayElements(j_doc_text, text_buffer, 0);
+  return true;
+}
+
+/* finalise the pass through the documents */
+JNIEXPORT jboolean JNICALL 
+Java_org_greenstone_mgpp_MGPPPassesWrapper_finish(JNIEnv *j_env, 
+					    jobject j_obj) {
+  
+  finalise_driver();
+  return true;
+}
+
+/** get the exit value once finished */
+JNIEXPORT jint JNICALL 
+Java_org_greenstone_mgpp_MGPPPassesWrapper_exitValue(JNIEnv *j_env, 
+					    jobject j_obj) {
+
+  return get_exit_value();
+}
Index: trunk/indexers/mgpp/jni/org_greenstone_mgpp_MGPPPassesWrapper.h
===================================================================
--- trunk/indexers/mgpp/jni/org_greenstone_mgpp_MGPPPassesWrapper.h	(revision 8950)
+++ trunk/indexers/mgpp/jni/org_greenstone_mgpp_MGPPPassesWrapper.h	(revision 8950)
@@ -0,0 +1,127 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_greenstone_mgpp_MGPPPassesWrapper */
+
+#ifndef _Included_org_greenstone_mgpp_MGPPPassesWrapper
+#define _Included_org_greenstone_mgpp_MGPPPassesWrapper
+#ifdef __cplusplus
+extern "C" {
+#endif
+#undef org_greenstone_mgpp_MGPPPassesWrapper_TEXT_PASS_1
+#define org_greenstone_mgpp_MGPPPassesWrapper_TEXT_PASS_1 0L
+#undef org_greenstone_mgpp_MGPPPassesWrapper_TEXT_PASS_2
+#define org_greenstone_mgpp_MGPPPassesWrapper_TEXT_PASS_2 1L
+#undef org_greenstone_mgpp_MGPPPassesWrapper_INDEX_PASS_1
+#define org_greenstone_mgpp_MGPPPassesWrapper_INDEX_PASS_1 2L
+#undef org_greenstone_mgpp_MGPPPassesWrapper_INDEX_PASS_2
+#define org_greenstone_mgpp_MGPPPassesWrapper_INDEX_PASS_2 3L
+#undef org_greenstone_mgpp_MGPPPassesWrapper_SPECIAL_PASS
+#define org_greenstone_mgpp_MGPPPassesWrapper_SPECIAL_PASS 4L
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    init
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_init
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    setBasePath
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_setBasePath
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    setFileName
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_setFileName
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    setDocumentTag
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_setDocumentTag
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    addLevelTag
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_addLevelTag
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    setIndexLevel
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_setIndexLevel
+  (JNIEnv *, jobject, jstring);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    setInversionMemLimit
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_setInversionMemLimit
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    finish
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_finish
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    exitValue
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_exitValue
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    initIDs
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_initIDs
+  (JNIEnv *, jclass);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    initCSide
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_initCSide
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    addPass
+ * Signature: (CC)V
+ */
+JNIEXPORT void JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_addPass
+  (JNIEnv *, jobject, jchar, jchar);
+
+/*
+ * Class:     org_greenstone_mgpp_MGPPPassesWrapper
+ * Method:    processMGPPDocument
+ * Signature: ([B)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_greenstone_mgpp_MGPPPassesWrapper_processMGPPDocument
+  (JNIEnv *, jobject, jbyteArray);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
