source: gsdl/trunk/trunk/mgpp/jni/MGPPPassesWrapperImpl.cpp@ 16583

Last change on this file since 16583 was 16583, checked in by davidb, 13 years ago

Undoing change commited in r16582

  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/*
2 * MGPassesWrapperImpl.c
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20
21#include <jni.h>
22#include <assert.h>
23#include "sysfuncs.h"
24#include "org_greenstone_mgpp_MGPPPassesWrapper.h"
25
26#include "mgpp_passes_4jni.h"
27#include "mg_files.h"
28
29/* if we need to use java objects, we should initialise their field ids here*/
30JNIEXPORT void JNICALL
31Java_org_greenstone_mgpp_MGPPPassesWrapper_initIDs(JNIEnv *j_env, jclass j_cls)
32{
33 return;
34}
35
36JNIEXPORT jboolean JNICALL
37Java_org_greenstone_mgpp_MGPPPassesWrapper_initCSide(JNIEnv *j_env, jobject j_obj)
38{
39 clear_variables();
40 return true;
41}
42
43/* add a pass type T1, T2, I1, I2, S */
44JNIEXPORT void JNICALL
45Java_org_greenstone_mgpp_MGPPPassesWrapper_addPass(JNIEnv *j_env,
46 jobject j_obj,
47 jchar j_pass_type,
48 jchar j_pass_num)
49{
50 /* get the level as a c char */
51 const char pass_type = j_pass_type;
52 const char pass_num = j_pass_num;
53 add_pass(pass_type, pass_num);
54
55}
56
57/* Set the filename */
58JNIEXPORT void JNICALL
59Java_org_greenstone_mgpp_MGPPPassesWrapper_setFileName(JNIEnv *j_env,
60 jobject j_obj,
61 jstring j_filename)
62{
63 /* Get the filename as a C string */
64 const char* filename = j_env->GetStringUTFChars(j_filename, NULL);
65
66 assert(filename != NULL);
67 set_filename(filename);
68
69 /* Release the string */
70 j_env->ReleaseStringUTFChars(j_filename, filename);
71
72}
73
74/* Set the base path */
75JNIEXPORT void JNICALL
76Java_org_greenstone_mgpp_MGPPPassesWrapper_setBasePath(JNIEnv *j_env,
77 jobject j_obj,
78 jstring j_basepath)
79{
80 /* Get the base_path as a C string */
81 const char* basepath = j_env->GetStringUTFChars(j_basepath, NULL);
82 assert(basepath != NULL);
83
84 set_basepath(basepath);
85
86 /* Release the string */
87 j_env->ReleaseStringUTFChars(j_basepath, basepath);
88
89}
90
91/* set the Document tag */
92JNIEXPORT void JNICALL
93Java_org_greenstone_mgpp_MGPPPassesWrapper_setDocumentTag(JNIEnv *j_env,
94 jobject j_obj,
95 jstring j_tag)
96{
97 const char* tag = j_env->GetStringUTFChars(j_tag, NULL);
98
99 set_document_tag(tag);
100 /* Release the string */
101 j_env->ReleaseStringUTFChars(j_tag, tag);
102
103
104}
105
106/* add a level tag */
107JNIEXPORT void JNICALL
108Java_org_greenstone_mgpp_MGPPPassesWrapper_addLevelTag(JNIEnv *j_env,
109 jobject j_obj,
110 jstring j_tag)
111{
112 const char* tag = j_env->GetStringUTFChars(j_tag, NULL);
113 add_level_tag(tag);
114
115 /* Release the string */
116 j_env->ReleaseStringUTFChars(j_tag, tag);
117
118}
119
120/* set the index level (default word level) */
121JNIEXPORT void JNICALL
122Java_org_greenstone_mgpp_MGPPPassesWrapper_setIndexLevel(JNIEnv *j_env,
123 jobject j_obj,
124 jstring j_tag)
125{
126 const char* tag = j_env->GetStringUTFChars(j_tag, NULL);
127 set_index_level(tag);
128
129 /* Release the string */
130 j_env->ReleaseStringUTFChars(j_tag, tag);
131
132
133}
134
135
136/** Maximum amount of memory to use for the index pass-2 file
137 inversion in megabytes.
138*/
139JNIEXPORT void JNICALL
140Java_org_greenstone_mgpp_MGPPPassesWrapper_setInversionMemLimit(JNIEnv *j_env,
141 jobject j_obj,
142 jint j_limit) {
143 int limit = j_limit;
144 set_inversion_limit(limit);
145}
146
147
148/* initialise the pass through the documents. must be called after all
149 the set methods
150*/
151JNIEXPORT jboolean JNICALL
152Java_org_greenstone_mgpp_MGPPPassesWrapper_init(JNIEnv *j_env,
153 jobject j_obj) {
154
155 init_driver();
156 return true;
157}
158
159
160/* process one or more documents */
161JNIEXPORT jboolean JNICALL
162Java_org_greenstone_mgpp_MGPPPassesWrapper_processMGPPDocument(JNIEnv *j_env,
163 jobject j_obj,
164 jbyteArray j_doc_text) {
165 /* Get the text as a C string */
166 int length = j_env->GetArrayLength(j_doc_text);
167 u_char * text_buffer = (u_char *)j_env->GetByteArrayElements(j_doc_text, NULL);
168 process_document(text_buffer, length);
169 /* Release the string */
170 // why doesn't this work in c++ when it works in C?????
171 //j_env->ReleaseByteArrayElements(j_doc_text, text_buffer, 0);
172 return true;
173}
174
175/* finalise the pass through the documents */
176JNIEXPORT jboolean JNICALL
177Java_org_greenstone_mgpp_MGPPPassesWrapper_finish(JNIEnv *j_env,
178 jobject j_obj) {
179
180 finalise_driver();
181 return true;
182}
183
184/** get the exit value once finished */
185JNIEXPORT jint JNICALL
186Java_org_greenstone_mgpp_MGPPPassesWrapper_exitValue(JNIEnv *j_env,
187 jobject j_obj) {
188
189 return get_exit_value();
190}
Note: See TracBrowser for help on using the repository browser.