source: main/trunk/greenstone2/common-src/indexers/mgpp/jni/MGPPRetrieveWrapperImpl.cpp@ 26660

Last change on this file since 26660 was 26660, checked in by davidb, 10 years ago

Support for cross-compilation added. This particular set of changes focus on flags that assist cross-compilation with JNI

File size: 2.8 KB
Line 
1/*
2 * MGPPRetrieveWrapperImpl.c
3 * Copyright (C) 2007 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#ifdef __WIN32__
21#include <win32cfg.h>
22#endif
23
24#include <jni.h>
25
26#ifdef __MINGW32__
27
28/* Cross compiling for Windows
29 Want the type definitions in *win32* version of jni_md.h but
30 this then leads to C-mangled style functions which we *don't*
31 want. The following achieves this */
32
33#undef JNIEXPORT
34#undef JNIIMPORT
35#undef JNICALL
36
37#define JNIEXPORT
38#define JNIIMPORT
39#define JNICALL
40#endif
41
42#include "org_greenstone_mgpp_MGPPRetrieveWrapper.h"
43#include "TextGet.h"
44
45
46//****************************************************
47// retrieve a document
48//****************************************************
49
50/* returns a document from mgpp as a string
51Note: TextData isn't cached - just reloaded each time
52*/
53JNIEXPORT jstring JNICALL
54Java_org_greenstone_mgpp_MGPPRetrieveWrapper_getDocument (JNIEnv *j_env,
55 jobject j_obj, jstring j_text_name, jstring j_level, jlong j_docnum) {
56
57#ifdef __WIN32__
58 const char* base_dir = "";
59#else
60 const char* base_dir = "/";
61#endif
62
63 const char * text_name = j_env->GetStringUTFChars(j_text_name, NULL);
64 if (text_name==NULL) {
65 return NULL;
66 }
67
68 const char * level = j_env->GetStringUTFChars( j_level, NULL);
69 if (level==NULL) {
70 j_env->ReleaseStringUTFChars(j_text_name, text_name);
71 return NULL;
72 }
73
74 // does this work alright? j_docnum is a long (64 bit)
75 mg_u_long docnum = j_docnum;
76 TextData td;
77
78 // cast to char* otherwise complains about const
79 td.LoadData((char *)base_dir, (char *)text_name);
80
81 UCArray mg_level;
82 SetCStr(mg_level, level);
83 UCArray docText;
84 docText.clear();
85 // get the actual text
86 if (!GetDocText(td, mg_level, docnum, docText)) {
87 cerr <<"MGPP JNI: couldn't retrieve doc text"<<endl;
88 }
89
90 td.UnloadData();
91
92 char * doc = GetCStr(docText);
93 jstring result = j_env->NewStringUTF(doc);
94 // release any gets
95 j_env->ReleaseStringUTFChars(j_text_name, text_name);
96 j_env->ReleaseStringUTFChars(j_level, level);
97
98 // free any C++ stuff
99 delete doc;
100
101 return result;
102
103}
Note: See TracBrowser for help on using the repository browser.