1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 package org
.libreoffice
.kit
;
12 import java
.nio
.ByteBuffer
;
15 private ByteBuffer handle
;
16 private MessageCallback messageCallback
= null;
18 public Office(ByteBuffer handle
) {
20 bindMessageCallback();
24 * Bind the signal callback in LOK.
26 private native void bindMessageCallback();
28 public native String
getError();
30 private native ByteBuffer
documentLoadNative(String url
);
32 public Document
documentLoad(String url
) {
33 ByteBuffer documentHandle
= documentLoadNative(url
);
34 Document document
= null;
35 if (documentHandle
!= null) {
36 document
= new Document(documentHandle
);
41 public native void destroy();
42 public native void destroyAndExit();
43 public native void setDocumentPassword(String url
, String pwd
);
44 public native void setOptionalFeatures(long options
);
46 public void setMessageCallback(MessageCallback messageCallback
) {
47 this.messageCallback
= messageCallback
;
51 * Callback triggered through JNI to indicate that a new signal
52 * from LibreOfficeKit was retrieved.
54 private void messageRetrievedLOKit(int signalNumber
, String payload
) {
55 if (messageCallback
!= null) {
56 messageCallback
.messageRetrieved(signalNumber
, payload
);
62 * Callback to retrieve messages from LOK
64 public interface MessageCallback
{
66 * Invoked when a message is retrieved from LOK
67 * @param signalNumber - signal type / number
68 * @param payload - retrieved for the signal
70 void messageRetrieved(int signalNumber
, String payload
);