OKMDocument
Basics
Section titled “Basics”In most methods you’ll see a parameter named “docId”. The value of this parameter can be a valid document UUID node.
About the parameter named “fldId”, the value of this parameter can be a valid folder UUID or a record node.
About the parameter named “dstId”, the value of this parameter can be a valid folder UUID or a record node.
Also, in all methods you’ll see a parameter named “token”. Because Cron tasks are executed in the background without authentication, the methods used in this scenario might use the token parameter. In the default application execution context, you must use the “null” value, which indicates the application must use the “user session”.
Methods
Section titled “Methods”create
Section titled “create”Description:
| Method | Return values | Description |
|---|---|---|
| create(String token, Document doc, InputStream is) | Document | Create a new document. |
- The parameter doc must be initialized with the OpenKM path value in the repository. Optionally, you can also set keywords and title values.
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { InputStream is = null; try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); is = new FileInputStream("/home/openkm/sample.pdf"); Document doc = new Document(); doc.setPath("/okm:root/sample.pdf"); // Optional doc.setTitle("sample document"); doc.getKeywords().add("key1"); doc.getKeywords().add("key2"); // Create document doc = okmDocument.create(null, doc, is); System.out.println(doc); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}createWithPropertyGroup
Section titled “createWithPropertyGroup”Description:
| Method | Return values | Description |
|---|---|---|
| createWithPropertyGroup(String token, Document doc, InputStream is, String grpName, Map<String, String> properties) | Document | Same as create(), but also sets a metadata group’s properties on the document’s first version in the same call, instead of a create() followed by a separate OKMPropertyGroup.addGroup() call. |
- The parameter doc must be initialized with the OpenKM path value in the repository, same as create(). The grpName should be a valid Metadata group name, and only the properties belonging to that group are applied - any other keys present in the properties map are ignored.
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;import java.util.HashMap;import java.util.Map;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { InputStream is = null; try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); is = new FileInputStream("/home/openkm/sample.pdf"); Document doc = new Document(); doc.setPath("/okm:root/sample.pdf");
Map<String, String> properties = new HashMap<>(); properties.put("okp:invoice.number", "INV-000");
// Create document with metadata in a single atomic call doc = okmDocument.createWithPropertyGroup(null, doc, is, "okg:invoice", properties); System.out.println(doc); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}createSimple
Section titled “createSimple”Description:
| Method | Return values | Description |
|---|---|---|
| createSimple(String token, String docPath, InputStream is) | Document | Create a new document. |
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { InputStream is = null; try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class);
is = new FileInputStream("/home/openkm/sample.pdf"); String docPath = "/okm:root/sample.pdf"; Document doc = okmDocument.createSimple(null, docPath, is); System.out.println(doc); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}delete
Section titled “delete”Description:
| Method | Return values | Description |
|---|---|---|
| delete(String token, String docId) | void | Delete a document. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.delete(null, "d50133e3-dbfa-4d01-a109-28785cd48f40"); } catch (Exception e) { e.printStackTrace(); } }}getProperties
Section titled “getProperties”Description:
| Method | Return values | Description |
|---|---|---|
| getProperties(String token, String docId) | Document | Returns a document’s properties. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); Document doc = okmDocument.getProperties(null, "3887ae75-dd67-4019-b4d1-2f6962815403"); System.out.println(doc); } catch (Exception e) { e.printStackTrace(); } }}getContent
Section titled “getContent”Description:
| Method | Return values | Description |
|---|---|---|
| getContent(String token, String docId, boolean checkout) | InputStream | Returns the document content. |
- When the parameter checkout is true, the document is marked for editing.
Example:
package com.openkm;
import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { InputStream is = null; OutputStream fos = null; try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); is = okmDocument.getContent(null, "3887ae75-dd67-4019-b4d1-2f6962815403", false); File tmp = new File("/home/openkm/sample.pdf"); fos = new FileOutputStream(tmp); IOUtils.copy(is, fos); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); } }}getContentByVersion
Section titled “getContentByVersion”Description:
| Method | Return values | Description |
|---|---|---|
| getContentByVersion(String token, String docId, String versionId) | InputStream | Returns the document content for a specific version. |
- The parameter versionId is the name of the document version.
Example:
package com.openkm;
import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { InputStream is = null; OutputStream fos = null; try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); is = okmDocument.getContentByVersion(null, "f3a977f7-abfc-4f58-a033-988903b31473", "1.1"); File tmp = new File("/home/openkm/sample.pdf"); fos = new FileOutputStream(tmp); IOUtils.copy(is, fos); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); } }}getExtractedText
Section titled “getExtractedText”Description:
| Method | Return values | Description |
|---|---|---|
| getExtractedText(String token, String docId) | String | Returns the extracted text of the document. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); String indexedText = okmDocument.getExtractedText(null, "f3a977f7-abfc-4f58-a033-988903b31473"); System.out.println(indexedText); } catch (Exception e) { e.printStackTrace(); } }}getChildren
Section titled “getChildren”Description:
| Method | Return values | Description |
|---|---|---|
| getChildren(String token, String fldId) | List |
Returns a list of all documents whose parent is fldId. |
- The parameter fldId can be a folder or a record node.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); for (Document doc : okmDocument.getChildren(null, "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474")) { System.out.println(doc); } } catch (Exception e) { e.printStackTrace(); } }}rename
Section titled “rename”Description:
| Method | Return values | Description |
|---|---|---|
| rename(String token, String docId, String newName) | Document | Changes the name of a document. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); Document doc = okmDocument.rename(null, "f3a977f7-abfc-4f58-a033-988903b31473", "samples_renamed.pdf"); System.out.println(doc); } catch (Exception e) { e.printStackTrace(); } }}setProperties
Section titled “setProperties”Description:
| Method | Return values | Description |
|---|---|---|
| setProperties(String token, Document doc) | void | Changes some document properties. |
- Variables allowed to be changed:
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); Document doc = okmDocument.getProperties(null, "f3a977f7-abfc-4f58-a033-988903b31473"); doc.getKeywords().add("key1"); doc.setDescription("some description"); okmDocument.setProperties(null, doc); } catch (Exception e) { e.printStackTrace(); } }}setLanguage
Section titled “setLanguage”Description:
| Method | Return values | Description |
|---|---|---|
| setLanguage(String token, String docId, String lang) | void | Sets the document language. |
- The parameter lang must be ISO 639-1 compliant.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.setLanguage(null, "f3a977f7-abfc-4f58-a033-988903b31473", "en"); } catch (Exception e) { e.printStackTrace(); } }}setTitle
Section titled “setTitle”Description:
| Method | Return values | Description |
|---|---|---|
| setTitle(String token, String docId, String title) | void | Sets the document title. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.setTitle(null, "f3a977f7-abfc-4f58-a033-988903b31473", "Document title"); } catch (Exception e) { e.printStackTrace(); } }}checkout
Section titled “checkout”Description:
| Method | Return values | Description |
|---|---|---|
| checkout(String token, String docId) | void | Marks the document for editing. |
- Only one user can modify a document at a time.
- Before starting editing, you must perform a checkout action that locks the editing process for other users and allows editing only to the user who executed the action.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.checkout(null, "f3a977f7-abfc-4f58-a033-988903b31473"); } catch (Exception e) { e.printStackTrace(); } }}cancelCheckout
Section titled “cancelCheckout”Description:
| Method | Return values | Description |
|---|---|---|
| cancelCheckout(String token, String docId) | void | Cancels document editing. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.cancelCheckout(null, "f3a977f7-abfc-4f58-a033-988903b31473"); } catch (Exception e) { e.printStackTrace(); } }}forceCancelCheckout
Section titled “forceCancelCheckout”Description:
| Method | Return values | Description |
|---|---|---|
| forceCancelCheckout(String token, String docId) | void | Cancels document editing. |
- This method allows cancelling editing on any document.
- It is not mandatory to execute this action as the same user who previously executed the checkout action.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.forceCancelCheckout(null, "f3a977f7-abfc-4f58-a033-988903b31473"); } catch (Exception e) { e.printStackTrace(); } }}isCheckedOut
Section titled “isCheckedOut”Description:
| Method | Return values | Description |
|---|---|---|
| isCheckedOut(String token, String docId) | boolean | Returns a boolean that indicates whether the document is being edited or not. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); System.out.println(okmDocument.isCheckedOut(null, "f3a977f7-abfc-4f58-a033-988903b31473")); } catch (Exception e) { e.printStackTrace(); } }}checkin
Section titled “checkin”Description:
| Method | Return values | Description |
|---|---|---|
| checkin(String token, String docId, InputStream is, String comment) | Version | Updates a document with a new version and returns an object with the new Version values. |
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { InputStream is = null; try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); is = new FileInputStream("/home/openkm/sample.pdf"); okmDocument.checkin(null, "f3a977f7-abfc-4f58-a033-988903b31473", is, "optional comment"); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}checkin
Section titled “checkin”Description:
| Method | Return values | Description |
|---|---|---|
| checkin(String token, String docId, InputStream is, String comment, int increment) | Version | Updates a document with a new version and returns an object with new Version values. |
- The increment value depends on the VersionNumeration implementation. Common values are:
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.plugin.vernum.VersionNumerationAdapter;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { InputStream is = null; try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); is = new FileInputStream("/home/openkm/sample.pdf"); okmDocument.checkin(null, "f3a977f7-abfc-4f58-a033-988903b31473", is, "optional comment", VersionNumerationAdapter.INCREASE_MINOR); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}checkinWithPropertyGroup
Section titled “checkinWithPropertyGroup”Description:
| Method | Return values | Description |
|---|---|---|
| checkinWithPropertyGroup(String token, String docId, InputStream is, String comment, int increment, String grpName, Map<String, String> properties) | Version | Same as checkin(), but also applies a metadata group’s properties change onto the same new version, instead of a checkin() followed by a separate OKMPropertyGroup.setProperties() call. |
- The grpName must already be assigned to the document (see OKMPropertyGroup.addGroup()); only the properties belonging to that group are applied.
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;import java.util.HashMap;import java.util.Map;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { InputStream is = null; try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); is = new FileInputStream("/home/openkm/sample.pdf");
Map<String, String> properties = new HashMap<>(); properties.put("okp:invoice.number", "INV-001");
// Checkin + metadata update as a single atomic call okmDocument.checkinWithPropertyGroup(null, "f3a977f7-abfc-4f58-a033-988903b31473", is, "optional comment", 0, "okg:invoice", properties); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}Description:
| Method | Return values | Description |
|---|---|---|
| lock(String token, String docId) | LockInfo | Locks a document and returns an object with the Lock information. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.LockInfo;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); LockInfo lockInfo = okmDocument.lock(null, "f3a977f7-abfc-4f58-a033-988903b31473"); System.out.println(lockInfo); } catch (Exception e) { e.printStackTrace(); } }}unlock
Section titled “unlock”Description:
| Method | Return values | Description |
|---|---|---|
| unlock(String token, String docId) | LockInfo | Unlocks a locked document. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.unlock(null, "f3a977f7-abfc-4f58-a033-988903b31473"); } catch (Exception e) { e.printStackTrace(); } }}forceUnlock
Section titled “forceUnlock”Description:
| Method | Return values | Description |
|---|---|---|
| forceUnlock(String token, String docId) | LockInfo | Unlocks a locked document. |
- This method allows you to unlock any locked document.
- It is not mandatory to execute this action as the same user who previously executed the checkout lock action.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.forceUnlock(null, "f3a977f7-abfc-4f58-a033-988903b31473"); } catch (Exception e) { e.printStackTrace(); } }}isLocked
Section titled “isLocked”Description:
| Method | Return values | Description |
|---|---|---|
| isLocked(String token, String docId) | boolean | Returns a boolean that indicates if the document is locked or not. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); System.out.println(okmDocument.isLocked(null, "f3a977f7-abfc-4f58-a033-988903b31473")); } catch (Exception e) { e.printStackTrace(); } }}getLockInfo
Section titled “getLockInfo”Description:
| Method | Return values | Description |
|---|---|---|
| getLockInfo(String token, String docId) | LockInfo | Returns an object with the Lock information. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.LockInfo;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); LockInfo lockInfo = okmDocument.getLockInfo(null, "f3a977f7-abfc-4f58-a033-988903b31473"); System.out.println(lockInfo); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| purge(String token, String docId) | void | The document is permanently removed from the repository. |
- Usually you will purge documents to /okm:trash/userId - the personal trash user location - but it is possible to directly purge any document from the whole repository.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.purge(null, "f3a977f7-abfc-4f58-a033-988903b31473"); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| move(String token, String docId, String dstId) | void | Move a document to a folder or record. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.move(null, "f3a977f7-abfc-4f58-a033-988903b31473", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474"); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| copy(String token, String docId, String dstId) | Document | Copy a document to a folder or record. |
- The values of the dstId parameter should be a folder or record UUID.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.copy(null, "f3a977f7-abfc-4f58-a033-988903b31473", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474"); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| copy(String token, String docId, String dstId, String newName) | Document | Copy a document to some folder or record. |
- The values of the dstId parameter should be a folder or record UUID.
- When the parameter newName is null, the document will preserve the same name.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.copy(null, "f3a977f7-abfc-4f58-a033-988903b31473", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474", "samples_renamed.pdf"); } catch (Exception e) { e.printStackTrace(); } }}extendedCopy
Section titled “extendedCopy”Description:
| Method | Return values | Description |
|---|---|---|
| extendedCopy(String token, String docId, String dstId, String docName, ExtendedAttributes extAttr) | Document | Copies a document with associated data to some folder or record. |
- The values of the dstId parameter should be a folder or a record UUID.
- When the parameter docName value is null, the document will preserve the same name.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.ExtendedAttributes;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); ExtendedAttributes extAttr = new ExtendedAttributes(); // copy keywords extAttr.setKeywords(true); extAttr.setCategories(true); extAttr.setNotes(true); extAttr.setPropertyGroups(true);
okmDocument.extendedCopy(null, "f3a977f7-abfc-4f58-a033-988903b31473", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474", "samples_renamed.pdf", extAttr); } catch (Exception e) { e.printStackTrace(); } }}getVersionHistorySize
Section titled “getVersionHistorySize”Description:
| Method | Return values | Description |
|---|---|---|
| getVersionHistorySize(String token, String docId) | long | Returns the sum in bytes of all documents in the document’s history. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;import com.openkm.util.FormatUtil;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); System.out.println(FormatUtil.formatSize(okmDocument.getVersionHistorySize(null, "f3a977f7-abfc-4f58-a033-988903b31473"))); } catch (Exception e) { e.printStackTrace(); } }}isValid
Section titled “isValid”Description:
| Method | Return values | Description |
|---|---|---|
| isValid(String token, String docId) | boolean | Returns a boolean that indicates if the node is a document or not. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); boolean valid = okmDocument.isValid(null, "f3a977f7-abfc-4f58-a033-988903b31473"); System.out.println(valid); } catch (Exception e) { e.printStackTrace(); } }}getPath
Section titled “getPath”Description:
| Method | Return values | Description |
|---|---|---|
| getPath(String token, String uuid) | String | Converts a document UUID to a document path. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); String docPath = okmDocument.getPath(null, "f3a977f7-abfc-4f58-a033-988903b31473"); System.out.println(docPath); } catch (Exception e) { e.printStackTrace(); } }}getDetectedLanguages
Section titled “getDetectedLanguages”Description:
| Method | Return values | Description |
|---|---|---|
| getDetectedLanguages(String token) | List |
Returns a list of available document languages that OpenKM can identify. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); for (String languages : okmDocument.getDetectedLanguages(null)) { System.out.println(languages); } } catch (Exception e) { e.printStackTrace(); } }}createFromTemplate
Section titled “createFromTemplate”Description:
| Method | Return values | Description |
|---|---|---|
| createFromTemplate(String token, String docId, String dstPath, Map<String, String> properties, ExtendedAttributes attributes) | Document | Creates a new document from a template and returns a Document object. |
- The dstPath can be a folder or a record UUID.
- The parameter language is optional.
- When the template uses metadata groups to fill fields, then these values are mandatory and must be set in the properties parameter.
Example:
package com.openkm;
import java.util.ArrayList;import java.util.Calendar;import java.util.HashMap;import java.util.Map;import java.util.List;
import com.google.gson.Gson;import com.openkm.api.OKMDocument;import com.openkm.bean.ExtendedAttributes;import com.openkm.util.ContextWrapper;import com.openkm.util.ISO8601;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); Map<String, String> properties = new HashMap<>(); properties.put("okp:tpl.name", "Some name"); Calendar cal = Calendar.getInstance(); // Value must be converted to String ISO 8601 compliant properties.put("okp:tpl.bird_date", ISO8601.formatBasic(cal));
List<String> list = new ArrayList<>(); list.add("java"); properties.put("okp:tpl.language", new Gson().toJson(list).toString());
okmDocument.createFromTemplate(null, "86633fe8-1b0d-48ac-a716-7685022adad8", "/okm:root/templates.pdf", properties, new ExtendedAttributes()); } catch (Exception e) { e.printStackTrace(); } }}updateFromTemplate
Section titled “updateFromTemplate”Description:
| Method | Return values | Description |
|---|---|---|
| updateFromTemplate(String token, String docId, String dstId, Map<String, String> properties) | void | Updates a document previously created from the template. |
- This method only makes sense when the template uses metadata groups to fill fields in.
Example:
package com.openkm;
import java.util.ArrayList;import java.util.Calendar;import java.util.HashMap;import java.util.List;import java.util.Map;
import com.google.gson.Gson;import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;import com.openkm.util.ISO8601;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); Map<String, String> properties = new HashMap<>(); properties.put("okp:tpl.name", "Some name"); Calendar cal = Calendar.getInstance(); // Value must be converted to String ISO 8601 compliant properties.put("okp:tpl.bird_date", ISO8601.formatBasic(cal));
List<String> list = new ArrayList<>(); list.add("java"); properties.put("okp:tpl.language", new Gson().toJson(list).toString());
okmDocument.updateFromTemplate(null, "86633fe8-1b0d-48ac-a716-7685022adad8", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474", properties); } catch (Exception e) { e.printStackTrace(); } }}setAnnotations
Section titled “setAnnotations”Description:
| Method | Return values | Description |
|---|---|---|
| setAnnotations(String token, String docId, String verName, String annotation) | void | Sets annotations for a document version. |
Example:
package com.openkm;import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.setAnnotations(null, "3887ae75-dd67-4019-b4d1-2f6962815403", "1.1", "The annotation text."); } catch (Exception e) { e.printStackTrace(); } }}getAnnotations
Section titled “getAnnotations”Description:
| Method | Return values | Description |
|---|---|---|
| getAnnotations(String token, String docId, String verName) | String | Returns the document annotations for a document version. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); String annotation = okmDocument.getAnnotations(null, "3887ae75-dd67-4019-b4d1-2f6962815403", "1.1"); System.out.println(annotation); } catch (Exception e) { e.printStackTrace(); } }}getCheckedOut
Section titled “getCheckedOut”Description:
| Method | Return values | Description |
|---|---|---|
| getCheckedOut(String token) | List |
Returns the list of all checked-out documents in the repository. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); for (Document doc : okmDocument.getCheckedOut(null)) { System.out.println(doc); } } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| stamp(String token, String docId, int type, long stId) | void | Stamps a document. |
- The parameter type indicates stamp type:
- The parameter stId is the unique identifier of the stamp definition. You can get it from Administration > Stamp view.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); int type = 0; // indicate text stamp definition long stId = 1; // unique identifier of the stamp definition okmDocument.stamp(null, "3887ae75-dd67-4019-b4d1-2f6962815403", type, stId); } catch (Exception e) { e.printStackTrace(); } }}stampText
Section titled “stampText”Description:
| Method | Return values | Description |
|---|---|---|
| stampText(String token, String docId, long stId, String range, String exprX, String exprY, String text) | void | Stamps a document with custom text. |
In Expr. X and Expr. Y input fields, you can enter more than a simple number. Currently, the following macros are defined:
- IMAGE_WIDTH
- IMAGE_HEIGHT
- PAGE_WIDTH
- PAGE_HEIGHT
- PAGE_CENTER
- PAGE_MIDDLE
To center a stamp on the page, you can use:
| Expr. X | PAGE_CENTER |
| Expr. Y | PAGE_MIDDLE |
| ::: |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
import java.io.FileInputStream;import java.io.InputStream;import org.apache.commons.io.IOUtils;
public class Test {
public static void main(String[] args) { try { long id = 1; String exprX = "PAGE_CENTER - IMAGE_WIDTH / 2"; String exprY = "PAGE_MIDDLE - IMAGE_HEIGHT / 2"; InputStream is = new FileInputStream("/home/gnujavasergio/okm/logo.png"); byte[] image = IOUtils.toByteArray(is); OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.stampImage(null, "055b5206-35d0-4351-ba92-c304bbba7ddf", id, "", exprX, exprY, image); } catch (Exception e) { e.printStackTrace(); } }}setDescription
Section titled “setDescription”Description:
| Method | Return values | Description |
|---|---|---|
| setDescription(String token, String docId, String description) | void | Sets a description. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.setDescription(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", "some description"); } catch (Exception e) { e.printStackTrace(); } }}setNodeClass
Section titled “setNodeClass”Description:
| Method | Return values | Description |
|---|---|---|
| setNodeClass(String token, String docId, long ncId) | void | Sets the NodeClass. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); long ncId = 2; okmDocument.setNodeClass(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", ncId); } catch (Exception e) { e.printStackTrace(); } }}setDispositionStage
Section titled “setDispositionStage”Description:
| Method | Return values | Description |
|---|---|---|
| setDispositionStage(String token, String docId, long stage) | void | Sets the disposition stage |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); long stage = 1; okmDocument.setDispositionStage(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", stage); } catch (Exception e) { e.printStackTrace(); } }}createWizard
Section titled “createWizard”Description:
| Method | Return values | Description |
|---|---|---|
| createWizard(String token, String docPath, long nodeClass, InputStream is) | WizardNode | Create a new document with a wizard. |
The WizardNode contains a list of pending actions that should be done to complete the document creation process. These might be:
- Add keyword
- Add Categories
- Add Metadata
- The parameter docPath should be a valid folder or record PATH.
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.bean.WizardNode;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); InputStream is = new FileInputStream("/home/gnujavasergio/okm/logo.png"); WizardNode wn = okmDocument.createWizard(null, "/okm:root/test/logo.png", 0, is); System.out.print(wn); IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); } }}getNumberOfPages
Section titled “getNumberOfPages”Description:
| Method | Return values | Description |
|---|---|---|
| getNumberOfPages(String token, String uuid) | int | Get the number of pages in a document. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); System.out.println("The number of pages is : " + okmDocument.getNumberOfPages(null, "b2f88679-e3fd-4f97-bf0e-abf76f9ec499")); } catch (Exception e) { e.printStackTrace(); } }}getPageAsImage
Section titled “getPageAsImage”Description:
| Method | Return values | Description |
|---|---|---|
| getPageAsImage(String token, String uuid, int pageNumber, int maxWidth, int maxHeight) | String | Returns a specific page as an image encoded as a Base64 string. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); System.out.println(okmDocument.getPageAsImage(null, "3fe350e2-69e8-4681-a97c-6ac4ba6c1524", 1, 150, 150)); } catch (Exception e) { e.printStackTrace(); } }}isConvertibleToPDF
Section titled “isConvertibleToPDF”Description:
| Method | Return values | Description |
|---|---|---|
| isConvertibleToPdf(String token, String docId) | boolean | Returns a boolean that indicates whether the node is convertible to PDF. |
In the case of a node of type PDF file, a false value will be returned.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); System.out.println(okmDocument.isConvertibleToPdf(null, "9ed5c7b1-9314-4479-8f80-fd8e2b47f55e")); } catch (Exception e) { e.printStackTrace(); } }}setIndexable
Section titled “setIndexable”Description:
| Method | Return values | Description |
|---|---|---|
| setIndexable(String token, String uuid, boolean enabled) | void | Sets whether the document is indexable. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); okmDocument.setIndexable(null, "19938640-fd34-421c-90c8-6b435e4b7d79", true); Document document = okmDocument.getProperties(null, "19938640-fd34-421c-90c8-6b435e4b7d79"); System.out.println("Document indexable:" + document.isIndexable()); } catch (Exception e) { e.printStackTrace(); } }}mergePdf
Section titled “mergePdf”Description:
| Method | Return values | Description |
|---|---|---|
| mergePdf(String token, String destinationPath, String docName, List |
void | Merge two or more PDF files. |
- The parameter destinationPath should be a valid folder or record PATH.
Example:
package com.openkm;
import java.util.ArrayList;import java.util.List;
import com.openkm.api.OKMDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class); List<String> uuids = new ArrayList<>(); uuids.add("/okm:root/test/document.pdf"); uuids.add("/okm:root/test/document1.pdf"); String fldUuid = "/okm:root/mergue"; okmDocument.mergePdf(null, fldUuid, "MergePdf.pdf", uuids); } catch (Exception e) { e.printStackTrace(); } }}