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_mg_MGPassesWrapper.h"
|
---|
25 |
|
---|
26 | /* if we need to use java objects, we should initialise their field ids here*/
|
---|
27 | JNIEXPORT void JNICALL
|
---|
28 | Java_org_greenstone_mg_MGPassesWrapper_initIDs(JNIEnv *j_env, jclass j_cls)
|
---|
29 | {
|
---|
30 | return;
|
---|
31 | }
|
---|
32 |
|
---|
33 | JNIEXPORT jboolean JNICALL
|
---|
34 | Java_org_greenstone_mg_MGPassesWrapper_initCSide(JNIEnv *j_env, jobject j_obj)
|
---|
35 | {
|
---|
36 | clear_variables();
|
---|
37 | return 1; /* true - no errors */
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | JNIEXPORT void JNICALL
|
---|
42 | Java_org_greenstone_mg_MGPassesWrapper_addPass(JNIEnv *j_env,
|
---|
43 | jobject j_obj,
|
---|
44 | jchar j_pass_type,
|
---|
45 | jchar j_pass_num)
|
---|
46 | {
|
---|
47 | /* get the level as a c char */
|
---|
48 | const char pass_type = j_pass_type;
|
---|
49 | const char pass_num = j_pass_num;
|
---|
50 | add_pass(pass_type, pass_num);
|
---|
51 |
|
---|
52 | }
|
---|
53 |
|
---|
54 | /* Set the paths */
|
---|
55 | JNIEXPORT void JNICALL
|
---|
56 | Java_org_greenstone_mg_MGPassesWrapper_setPath(JNIEnv *j_env, jobject j_obj,
|
---|
57 | jstring j_filename)
|
---|
58 | {
|
---|
59 | /* Get the filename as a C string */
|
---|
60 | const char* filename = (*j_env)->GetStringUTFChars(j_env, j_filename, NULL);
|
---|
61 |
|
---|
62 | assert(filename != NULL);
|
---|
63 | set_path(filename);
|
---|
64 |
|
---|
65 | /* Release the strings */
|
---|
66 | (*j_env)->ReleaseStringUTFChars(j_env, j_filename, filename);
|
---|
67 |
|
---|
68 | }
|
---|
69 |
|
---|
70 | /* Set the paths */
|
---|
71 | JNIEXPORT void JNICALL
|
---|
72 | Java_org_greenstone_mg_MGPassesWrapper_setPaths(JNIEnv *j_env, jobject j_obj,
|
---|
73 | jstring j_basepath, jstring j_filename)
|
---|
74 | {
|
---|
75 | /* Get the base_path as a C string */
|
---|
76 | const char* basepath = (*j_env)->GetStringUTFChars(j_env, j_basepath, NULL);
|
---|
77 | /* Get the filename as a C string */
|
---|
78 | const char* filename = (*j_env)->GetStringUTFChars(j_env, j_filename, NULL);
|
---|
79 |
|
---|
80 | assert(filename != NULL);
|
---|
81 | assert(basepath != NULL);
|
---|
82 |
|
---|
83 | set_paths(basepath, filename);
|
---|
84 |
|
---|
85 |
|
---|
86 | /* Release the strings */
|
---|
87 | (*j_env)->ReleaseStringUTFChars(j_env, j_basepath, basepath);
|
---|
88 | (*j_env)->ReleaseStringUTFChars(j_env, j_filename, filename);
|
---|
89 |
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | JNIEXPORT void JNICALL
|
---|
94 | Java_org_greenstone_mg_MGPassesWrapper_setInvfLevel(JNIEnv *j_env,
|
---|
95 | jobject j_obj,
|
---|
96 | jchar j_level)
|
---|
97 | {
|
---|
98 | /* get the level as a c char */
|
---|
99 | const char level = j_level;
|
---|
100 | set_invf_level(level);
|
---|
101 |
|
---|
102 | }
|
---|
103 |
|
---|
104 | /* */
|
---|
105 | JNIEXPORT void JNICALL
|
---|
106 | Java_org_greenstone_mg_MGPassesWrapper_setStemOptions(JNIEnv *j_env,
|
---|
107 | jobject j_obj,
|
---|
108 | jstring j_stemmer,
|
---|
109 | jint j_method)
|
---|
110 | {
|
---|
111 |
|
---|
112 | const char* stemmer = (*j_env)->GetStringUTFChars(j_env, j_stemmer, NULL);
|
---|
113 | int method = j_method;
|
---|
114 |
|
---|
115 | assert(stemmer != NULL);
|
---|
116 | set_stem_options(stemmer, method);
|
---|
117 | }
|
---|
118 |
|
---|
119 | JNIEXPORT jboolean JNICALL
|
---|
120 | Java_org_greenstone_mg_MGPassesWrapper_init(JNIEnv *j_env,
|
---|
121 | jobject j_obj) {
|
---|
122 |
|
---|
123 | init_driver();
|
---|
124 | return 1;
|
---|
125 | }
|
---|
126 |
|
---|
127 | JNIEXPORT jboolean JNICALL
|
---|
128 | Java_org_greenstone_mg_MGPassesWrapper_finish(JNIEnv *j_env,
|
---|
129 | jobject j_obj) {
|
---|
130 |
|
---|
131 | finalise_driver();
|
---|
132 | return 1;
|
---|
133 | }
|
---|
134 |
|
---|
135 | JNIEXPORT jboolean JNICALL
|
---|
136 | Java_org_greenstone_mg_MGPassesWrapper_processMGDocument(JNIEnv *j_env,
|
---|
137 | jobject j_obj,
|
---|
138 | jbyteArray j_doc_text) {
|
---|
139 | /* Get the text as a C string */
|
---|
140 | int length = (*j_env)->GetArrayLength(j_env, j_doc_text);
|
---|
141 | u_char * text_buffer = (u_char *)(*j_env)->GetByteArrayElements(j_env, j_doc_text, NULL);
|
---|
142 | process_document(text_buffer, length);
|
---|
143 | /* Release the string */
|
---|
144 | (*j_env)->ReleaseByteArrayElements(j_env, j_doc_text, text_buffer,0);
|
---|
145 | return 1;
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|