mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Add JNI code for CDocBuilder
This commit is contained in:
@ -0,0 +1,43 @@
|
||||
package docbuilder;
|
||||
|
||||
public class CDocBuilder {
|
||||
|
||||
private long c_internal = 0;
|
||||
|
||||
// NATIVE METHODS:
|
||||
private static native long c_Create();
|
||||
private static native void c_Destroy(long self);
|
||||
|
||||
private static native int c_OpenFile(long self, String path, String params);
|
||||
private static native boolean c_CreateFileByType(long self, int type);
|
||||
private static native boolean c_CreateFileByExtension(long self, String extension);
|
||||
|
||||
private static native void c_SetTmpFolder(long self, String folder);
|
||||
|
||||
private static native int c_SaveFileByType(long self, int type, String path);
|
||||
private static native int c_SaveFileByTypeWithParams(long self, int type, String path, String params);
|
||||
private static native int c_SaveFileByExtension(long self, String extension, String path);
|
||||
private static native int c_SaveFileByExtensionWithParams(long self, String extension, String path, String params);
|
||||
|
||||
private static native void c_CloseFile(long self);
|
||||
|
||||
private static native boolean c_ExecuteCommand(long self, String command);
|
||||
private static native boolean c_ExecuteCommandWithRetValue(long self, String command, long retValue);
|
||||
|
||||
private static native boolean c_Run(long self, String path);
|
||||
private static native boolean c_RunText(long self, String commands);
|
||||
|
||||
private static native void c_SetProperty(long self, String param, String value);
|
||||
|
||||
private static native void c_WriteData(long self, String path, String value, boolean append);
|
||||
|
||||
private static native boolean c_IsSaveWithDoctrendererMode(long self);
|
||||
|
||||
private static native String c_GetVersion(long self);
|
||||
|
||||
private static native long c_GetContext(long self);
|
||||
|
||||
private static native void c_Initialize();
|
||||
private static native void c_InitializeWithDirectory(String directory);
|
||||
private static native void c_Dispose();
|
||||
}
|
||||
@ -0,0 +1,179 @@
|
||||
#include "docbuilder_CDocBuilder.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "docbuilder.h"
|
||||
// for wchar_t <=> char conversion
|
||||
#include "../../../../common/File.h"
|
||||
|
||||
using namespace NSDoctRenderer;
|
||||
|
||||
static std::wstring wstringFromJavaString(JNIEnv* env, jstring jstr)
|
||||
{
|
||||
const char* strUtf = env->GetStringUTFChars(jstr, nullptr);
|
||||
std::wstring wstr = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)strUtf, (LONG)strlen(strUtf));
|
||||
env->ReleaseStringUTFChars(jstr, strUtf);
|
||||
return wstr;
|
||||
}
|
||||
|
||||
jlong Java_docbuilder_CDocBuilder_c_1Create(JNIEnv* env, jclass cls)
|
||||
{
|
||||
return reinterpret_cast<jlong>(new CDocBuilder());
|
||||
}
|
||||
|
||||
void Java_docbuilder_CDocBuilder_c_1Destroy(JNIEnv* env, jclass cls, jlong self)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
delete pSelf;
|
||||
}
|
||||
|
||||
jint Java_docbuilder_CDocBuilder_c_1OpenFile(JNIEnv* env, jclass cls, jlong self, jstring path, jstring params)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
std::wstring strPath = wstringFromJavaString(env, path);
|
||||
std::wstring strParams = wstringFromJavaString(env, params);
|
||||
return (jint)pSelf->OpenFile(strPath.c_str(), strParams.c_str());
|
||||
}
|
||||
|
||||
jboolean Java_docbuilder_CDocBuilder_c_1CreateFileByType(JNIEnv* env, jclass cls, jlong self, jint type)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
return (jboolean)pSelf->CreateFile((int)type);
|
||||
}
|
||||
|
||||
jboolean Java_docbuilder_CDocBuilder_c_1CreateFileByExtension(JNIEnv* env, jclass cls, jlong self, jstring extension)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
std::wstring strExtension = wstringFromJavaString(env, extension);
|
||||
return (jboolean)pSelf->CreateFile(strExtension.c_str());
|
||||
}
|
||||
|
||||
void Java_docbuilder_CDocBuilder_c_1SetTmpFolder(JNIEnv* env, jclass cls, jlong self, jstring folder)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
std::wstring strFolder = wstringFromJavaString(env, folder);
|
||||
pSelf->SetTmpFolder(strFolder.c_str());
|
||||
}
|
||||
|
||||
jint Java_docbuilder_CDocBuilder_c_1SaveFileByType(JNIEnv* env, jclass cls, jlong self, jint type, jstring path)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
std::wstring strPath = wstringFromJavaString(env, path);
|
||||
return (jint)pSelf->SaveFile((int)type, strPath.c_str());
|
||||
}
|
||||
|
||||
jint Java_docbuilder_CDocBuilder_c_1SaveFileByTypeWithParams(JNIEnv* env, jclass cls, jlong self, jint type, jstring path, jstring params)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
std::wstring strPath = wstringFromJavaString(env, path);
|
||||
std::wstring strParams = wstringFromJavaString(env, params);
|
||||
return (jint)pSelf->SaveFile((int)type, strPath.c_str(), strParams.c_str());
|
||||
}
|
||||
|
||||
jint Java_docbuilder_CDocBuilder_c_1SaveFileByExtension(JNIEnv* env, jclass cls, jlong self, jstring extension, jstring path)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
std::wstring strExtension = wstringFromJavaString(env, extension);
|
||||
std::wstring strPath = wstringFromJavaString(env, path);
|
||||
return (jint)pSelf->SaveFile(strExtension.c_str(), strPath.c_str());
|
||||
}
|
||||
|
||||
jint Java_docbuilder_CDocBuilder_c_1SaveFileByExtensionWithParams(JNIEnv* env, jclass cls, jlong self, jstring extension, jstring path, jstring params)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
std::wstring strExtension = wstringFromJavaString(env, extension);
|
||||
std::wstring strPath = wstringFromJavaString(env, path);
|
||||
std::wstring strParams = wstringFromJavaString(env, params);
|
||||
return (jint)pSelf->SaveFile(strExtension.c_str(), strPath.c_str(), strParams.c_str());
|
||||
}
|
||||
|
||||
void Java_docbuilder_CDocBuilder_c_1CloseFile(JNIEnv* env, jclass cls, jlong self)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
pSelf->CloseFile();
|
||||
}
|
||||
|
||||
jboolean Java_docbuilder_CDocBuilder_c_1ExecuteCommand(JNIEnv* env, jclass cls, jlong self, jstring command)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
std::wstring strCommand = wstringFromJavaString(env, command);
|
||||
return (jboolean)pSelf->ExecuteCommand(strCommand.c_str());
|
||||
}
|
||||
|
||||
jboolean Java_docbuilder_CDocBuilder_c_1ExecuteCommandWithRetValue(JNIEnv* env, jclass cls, jlong self, jstring command, jlong retValue)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
std::wstring strCommand = wstringFromJavaString(env, command);
|
||||
CDocBuilderValue* pRetValue = reinterpret_cast<CDocBuilderValue*>(retValue);
|
||||
return (jboolean)pSelf->ExecuteCommand(strCommand.c_str(), pRetValue);
|
||||
}
|
||||
|
||||
jboolean Java_docbuilder_CDocBuilder_c_1Run(JNIEnv* env, jclass cls, jlong self, jstring path)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
std::wstring strPath = wstringFromJavaString(env, path);
|
||||
return (jboolean)pSelf->Run(strPath.c_str());
|
||||
}
|
||||
|
||||
jboolean Java_docbuilder_CDocBuilder_c_1RunText(JNIEnv* env, jclass cls, jlong self, jstring commands)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
const char* strUtfCommands = env->GetStringUTFChars(commands, nullptr);
|
||||
jboolean result = (jboolean)pSelf->RunTextA(strUtfCommands);
|
||||
env->ReleaseStringUTFChars(commands, strUtfCommands);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Java_docbuilder_CDocBuilder_c_1SetProperty(JNIEnv* env, jclass cls, jlong self, jstring param, jstring value)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
const char* strUtfParam = env->GetStringUTFChars(param, nullptr);
|
||||
std::wstring strValue = wstringFromJavaString(env, value);
|
||||
pSelf->SetProperty(strUtfParam, strValue.c_str());
|
||||
env->ReleaseStringUTFChars(param, strUtfParam);
|
||||
}
|
||||
|
||||
void Java_docbuilder_CDocBuilder_c_1WriteData(JNIEnv* env, jclass cls, jlong self, jstring path, jstring data, jboolean append)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
std::wstring strPath = wstringFromJavaString(env, path);
|
||||
std::wstring strData = wstringFromJavaString(env, data);
|
||||
pSelf->WriteData(strPath.c_str(), strData.c_str(), (bool)append);
|
||||
}
|
||||
|
||||
jboolean Java_docbuilder_CDocBuilder_c_1IsSaveWithDoctrendererMode(JNIEnv* env, jclass cls, jlong self)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
return (jboolean)pSelf->IsSaveWithDoctrendererMode();
|
||||
}
|
||||
|
||||
jstring Java_docbuilder_CDocBuilder_c_1GetVersion(JNIEnv* env, jclass cls, jlong self)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
char* strUtfVersion = pSelf->GetVersion();
|
||||
jstring jstrVersion = env->NewStringUTF(strUtfVersion);
|
||||
delete[] strUtfVersion;
|
||||
return jstrVersion;
|
||||
}
|
||||
|
||||
jlong Java_docbuilder_CDocBuilder_c_1GetContext(JNIEnv* env, jclass cls, jlong self)
|
||||
{
|
||||
CDocBuilder* pSelf = reinterpret_cast<CDocBuilder*>(self);
|
||||
return reinterpret_cast<jlong>(new CDocBuilderContext(pSelf->GetContext()));
|
||||
}
|
||||
|
||||
void Java_docbuilder_CDocBuilder_c_1Initialize(JNIEnv* env, jclass cls)
|
||||
{
|
||||
CDocBuilder::Initialize();
|
||||
}
|
||||
|
||||
void Java_docbuilder_CDocBuilder_c_1InitializeWithDirectory(JNIEnv* env, jclass cls, jstring directory)
|
||||
{
|
||||
std::wstring strDirectory = wstringFromJavaString(env, directory);
|
||||
CDocBuilder::Initialize(strDirectory.c_str());
|
||||
}
|
||||
|
||||
void Java_docbuilder_CDocBuilder_c_1Dispose(JNIEnv* env, jclass cls)
|
||||
{
|
||||
CDocBuilder::Dispose();
|
||||
}
|
||||
@ -0,0 +1,197 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class docbuilder_CDocBuilder */
|
||||
|
||||
#ifndef _Included_docbuilder_CDocBuilder
|
||||
#define _Included_docbuilder_CDocBuilder
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_Create
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_docbuilder_CDocBuilder_c_1Create
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_Destroy
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_docbuilder_CDocBuilder_c_1Destroy
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_OpenFile
|
||||
* Signature: (JLjava/lang/String;Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_docbuilder_CDocBuilder_c_1OpenFile
|
||||
(JNIEnv *, jclass, jlong, jstring, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_CreateFileByType
|
||||
* Signature: (JI)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_docbuilder_CDocBuilder_c_1CreateFileByType
|
||||
(JNIEnv *, jclass, jlong, jint);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_CreateFileByExtension
|
||||
* Signature: (JLjava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_docbuilder_CDocBuilder_c_1CreateFileByExtension
|
||||
(JNIEnv *, jclass, jlong, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_SetTmpFolder
|
||||
* Signature: (JLjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_docbuilder_CDocBuilder_c_1SetTmpFolder
|
||||
(JNIEnv *, jclass, jlong, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_SaveFileByType
|
||||
* Signature: (JILjava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_docbuilder_CDocBuilder_c_1SaveFileByType
|
||||
(JNIEnv *, jclass, jlong, jint, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_SaveFileByTypeWithParams
|
||||
* Signature: (JILjava/lang/String;Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_docbuilder_CDocBuilder_c_1SaveFileByTypeWithParams
|
||||
(JNIEnv *, jclass, jlong, jint, jstring, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_SaveFileByExtension
|
||||
* Signature: (JLjava/lang/String;Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_docbuilder_CDocBuilder_c_1SaveFileByExtension
|
||||
(JNIEnv *, jclass, jlong, jstring, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_SaveFileByExtensionWithParams
|
||||
* Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_docbuilder_CDocBuilder_c_1SaveFileByExtensionWithParams
|
||||
(JNIEnv *, jclass, jlong, jstring, jstring, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_CloseFile
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_docbuilder_CDocBuilder_c_1CloseFile
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_ExecuteCommand
|
||||
* Signature: (JLjava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_docbuilder_CDocBuilder_c_1ExecuteCommand
|
||||
(JNIEnv *, jclass, jlong, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_ExecuteCommandWithRetValue
|
||||
* Signature: (JLjava/lang/String;J)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_docbuilder_CDocBuilder_c_1ExecuteCommandWithRetValue
|
||||
(JNIEnv *, jclass, jlong, jstring, jlong);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_Run
|
||||
* Signature: (JLjava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_docbuilder_CDocBuilder_c_1Run
|
||||
(JNIEnv *, jclass, jlong, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_RunText
|
||||
* Signature: (JLjava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_docbuilder_CDocBuilder_c_1RunText
|
||||
(JNIEnv *, jclass, jlong, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_SetProperty
|
||||
* Signature: (JLjava/lang/String;Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_docbuilder_CDocBuilder_c_1SetProperty
|
||||
(JNIEnv *, jclass, jlong, jstring, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_WriteData
|
||||
* Signature: (JLjava/lang/String;Ljava/lang/String;Z)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_docbuilder_CDocBuilder_c_1WriteData
|
||||
(JNIEnv *, jclass, jlong, jstring, jstring, jboolean);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_IsSaveWithDoctrendererMode
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_docbuilder_CDocBuilder_c_1IsSaveWithDoctrendererMode
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_GetVersion
|
||||
* Signature: (J)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_docbuilder_CDocBuilder_c_1GetVersion
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_GetContext
|
||||
* Signature: (J)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_docbuilder_CDocBuilder_c_1GetContext
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_Initialize
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_docbuilder_CDocBuilder_c_1Initialize
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_InitializeWithDirectory
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_docbuilder_CDocBuilder_c_1InitializeWithDirectory
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: docbuilder_CDocBuilder
|
||||
* Method: c_Dispose
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_docbuilder_CDocBuilder_c_1Dispose
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@ -29,10 +29,10 @@ core_mac:JAVA_ARCH = darwin
|
||||
|
||||
INCLUDEPATH += $$JDK_PATH/include/$$JAVA_ARCH
|
||||
|
||||
|
||||
|
||||
SOURCES += \
|
||||
docbuilder_CDocBuilderValue.cpp
|
||||
docbuilder_CDocBuilderValue.cpp \
|
||||
docbuilder_CDocBuilder.cpp
|
||||
|
||||
HEADERS += \
|
||||
docbuilder_CDocBuilderValue.h
|
||||
docbuilder_CDocBuilderValue.h \
|
||||
docbuilder_CDocBuilder.h
|
||||
|
||||
Reference in New Issue
Block a user