OKMDocument
Basics
On almost methods you'll see parameter named "docId". The value of this parameter can be some valid document UUID node.
Example of docId:
- Using UUID -> "c41f9ea0-0d6c-45da-bae4-d72b66f42d0f";
About the parameter named "fldId", the value of this parameter can be some valid folder UUID or record node.
Example of fldId:
- Using UUID -> "c6785440-0d6c-45da-1234-d9874563d0f";
About the parameter named "dstId", the value of this parameter can be some valid folder UUID or record node.
Example of dstId:
- Using UUID -> "c4455667-0d6c-45da-1234-d98564323e0";
Also on all methods you'll see parameter named "token". Because the Cron Task are executed in background without authentication, the methods used in this scenario might use the token parameter. From default application execution context you must use "null" value what indicates to the application must use the "user session".
On special cases you might be "promoted as Administrator" using the "administrator token".
String systemToken = DbSessionManager.getInstance().getSystemToken();
Methods
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 into the repository. Optionally you can also set keywords and title values. The other parameteres are not taken in consideration for document creation. |
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);
}
}
}
createSimple
Description:
Method | Return values | Description |
---|---|---|
createSimple(String token, String docPath, InputStream is) |
Document |
Create a new document. |
The parameter docPath must be initialized with the OpenKM path value into the repository. |
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
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
Description:
Method | Return values | Description |
---|---|---|
getProperties(String token, String docId) |
Document |
Return a document 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
Description:
Method | Return values | Description |
---|---|---|
getContent(String token, String docId, boolean checkout) |
InputStream |
Return the document content. |
When paramer checkout is true, the document is marked for edition. |
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
Description:
Method | Return values | Description |
---|---|---|
getContentByVersion(String token, String docId, String versionId) |
InputStream |
Return the document content by version. |
The parameter versionIs 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
Description:
Method | Return values | Description |
---|---|---|
getExtractedText(String token, String docId) |
String |
Return the extracted text of the document. |
When document is upload to OpenKM goes into search engine queue to be processed. Until the process be finished this method will return an empty string. From Database query view you can execute a query to verify is a document has yet been processed: SELECT NDC_TEXT_EXTRACTED FROM OKM_NODE_DOCUMENT where NBS_UUID='1048eb46-2f32-4011-90e4-e084d838a592' NBS_UUID value is the document UUID value. You can get it from properties tab in desktop 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);
String indexedText = okmDocument.getExtractedText(null, "f3a977f7-abfc-4f58-a033-988903b31473");
System.out.println(indexedText);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getChildren
Descripcion:
Method | Return values | Description |
---|---|---|
getChildren(String token, String fldId) |
List<Document> |
Returns a list of all documents which their 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
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
Description:
Method | Return values | Description |
---|---|---|
setProperties(String token, Document doc) |
void |
Changes some document properties. |
Variables allowed to be changed:
Only not null and not empty variables will be taken in consideration. |
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
Description:
Method | Return values | Description |
---|---|---|
setLanguage(String token, String docId, String lang) |
void |
Sets the document language. |
The parameter lang must be ISO 691-1 compliant. More information at: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes. |
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
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
Description:
Method | Return values | Description |
---|---|---|
checkout(String token, String docId) |
void |
Marks the document for edition. |
Only one user can modify a document at a time. Before starting edition you must do a checkout action that locks the edition process for other users and allows edition only to the user who has 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
Description:
Method | Return values | Description |
---|---|---|
cancelCheckout(String token, String docId) |
void |
Cancels a document edition. |
This action can only be done by the 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.cancelCheckout(null, "f3a977f7-abfc-4f58-a033-988903b31473");
} catch (Exception e) {
e.printStackTrace();
}
}
}
forceCancelCheckout
Description:
Method | Return values | Description |
---|---|---|
forceCancelCheckout(String token, String docId) |
void |
Cancels a document edition. |
This method allows to cancel edition on any document. It is not mandatory to execute this action by the same user who previously executed the checkout action. This action can only be done by a super user ( user with ROLE_ADMIN ). |
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
Description:
Method | Return values | Description |
---|---|---|
isCheckedOut(String token, String docId) |
void |
Returns a boolean that indicates if the document is on edition 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
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 new Version values. |
Only the user who started the edition - checkout - is allowed to update the 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.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
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 VersionNumeration implementation. Common values are:
More information about VersionNumeration at Creating your own Version Number Adapter. Only the user who started the edition - checkout - is allowed to update the 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.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);
}
}
}
lock
Description:
Method | Return values | Description |
---|---|---|
lock(String token, String docId) |
LockInfo |
Locks a document and returns an object with the Lock information. |
Only the user who locked the document is allowed to unlock. A locked document cannot be modified by other users.
|
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
Description:
Method | Return values | Description |
---|---|---|
unlock(String token, String docId) |
LockInfo |
Unlocks a locked document. |
Only the user who locked the document is allowed to unlock. |
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
Description:
Method | Return values | Description |
---|---|---|
forceUnlock(String token, String docId) |
LockInfo |
Unlocks a locked document. |
This method allows to unlock any locked document. It is not mandatory execute this action by the same user who previously executed the checkout lock action. This action can only be done by a super user ( user with ROLE_ADMIN ). |
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
Description:
Method | Return values | Description |
---|---|---|
isLocked(String token, String docId) |
void |
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
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();
}
}
}
purge
Description:
Method | Return values | Description |
---|---|---|
purge(String token, String docId) |
void |
The document is definitely removed from repository. |
Usually you will purge documents into /okm:trash/userId - the personal trash user locations - but is possible to directly purge any document from the whole repository. When a document is purged only will be able to be restored from a previously repository backup. The purge action removes the document definitely from the 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();
}
}
}
move
Description:
Method | Return values | Description |
---|---|---|
move(String token, String docId, String dstId) |
void |
Move document into some 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.move(null, "f3a977f7-abfc-4f58-a033-988903b31473", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474");
} catch (Exception e) {
e.printStackTrace();
}
}
}
copy
Description:
Method | Return values | Description |
---|---|---|
copy(String token, String docId, String dstId) |
void |
Copy a document into some folder or record. |
The values of the dstId parameter should be a folder or record UUID. Only the binary data and the security grants are copied to destination, the metadata, keywords, etc. of the document are not copied. See "extendedCopy" method for this feature. |
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();
}
}
}
copy
Description:
Method | Return values | Description |
---|---|---|
copy(String token, String docId, String dstId, String newName) |
void |
Copy a document into some folder or record. |
The values of the dstId parameter should be a folder or record UUID. When the parameter newName value is null,the document will preservate the same name. Only the binary data and the security grants are copied to destination, the metadata, keywords, etc. of the document are not copied. See "extendedCopy" method for this feature. |
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
Description:
Method | Return values | Description |
---|---|---|
extendedCopy(String token, String docId, String dstId, String docName, ExtendedAttributes extAttr) |
void |
Copies a document with associated data into 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. By default only the binary data and the security grants, the metadata, keywords, etc. of the document are not copied. Additional:
|
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
Description:
Method | Return values | Description |
---|---|---|
getVersionHistorySize(String token, String docId) |
long |
Returns the sum in bytes of all documents into documents 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
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
Description:
Method | Return values | Description |
---|---|---|
getPath(String token, String uuid) |
String |
Converts a document UUID to 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
Description:
Method | Return values | Description |
---|---|---|
getDetectedLanguages(String token) |
List<String> |
Return a list of available document languages what 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
Description:
Method | Return values | Description |
---|---|---|
createFromTemplate(String token, String docId, String dstPath, Map<String, String> properties, ExtendedAttributes attributes) |
Document |
Creates a new document from template and returns an object Document. |
The dstPath can be a folder or a record UUID. The parameter language is optional. When the template uses metadata groups to fill fields into, then these values are mandatory and must be set into properties parameter. For more information about Templates and metadata check: Creating templates. Additional attribute parameters:
|
Example:
The example below is based on Creating PDF template sample.
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
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 and returns an object Document. |
This method only has sense when the template uses metadata groups to fill fields in. For more information about Templates and metadata check: Creating templates . |
Example:
The example below is based on Creating PDF template sample.
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
Description:
Method | Return values | Description |
---|---|---|
setAnnotations(String token, String docId, String verName, String annotation) |
void |
Set document annotations of some 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
Description:
Method | Return values | Description |
---|---|---|
getAnnotations(String token, String docId, String verName) |
String |
Return the document annotations of some 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
Description:
Method | Return values | Description |
---|---|---|
getCheckedOut(String token) |
List<Document> |
Return the list of all documents checkout 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();
}
}
}
stamp
Description:
Method | Return values | Description |
---|---|---|
stamp(String token, String docId, int type, long stId) |
void |
Stamp a document. |
The parameter type indicates stamp type:
The parameter stId is the unique identifier value 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
Description:
Method | Return values | Description | ||||
---|---|---|---|---|---|---|
stampText(String token, String docId, long stId, String range, String exprX, String exprY, String text) |
void |
Stamp in a document with a custom text. |
||||
The id is the id of an image stamp which is created in the administrator. The exprX is the expression to set the position in X coordinates. The exprY is the expression to set the position in Y coordinates. In Expr. X and Expr. Y input fields you can put more than a simple number. Currently, the following macros are defined:
So to center a stamp in the page you can use:
|
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
import com.openkm.util.ContextWrapper;
import java.io.FileInputStream;
import java.io.InputStream;
public class Test {
public static void main(String[] args) {
try {
long stampTextId = 1;
String text = "OpenKM";
String exprX = "PAGE_CENTER";
String exprY = "PAGE_MIDDLE";
InputStream is = new FileInputStream("/home/gnujavasergio/okm/logo.png");
OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class);
okmDocument.stampText(null, "05b14eee5-2e57-4d1d-925a-c9bc3f526e24", stampTextId, "", exprX, exprY, text);
} catch (Exception e) {
e.printStackTrace();
}
}
}
stampImage
Description:
Method | Return values | Description | ||||
---|---|---|---|---|---|---|
stampImage(String token, String docId, long stId, String range, String exprX, String exprY, InputStream is) |
void |
Stamp in a document with a custom image. |
||||
The id is the id of an image stamp which is created in the administrator. The exprX is the expression to set the position in X coordinates. The exprY is the expression to set the position in Y coordinates. In Expr. X and Expr. Y input fields you can put more than a simple number. Currently, the following macros are defined:
So to center a stamp in the page you can use:
|
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
import com.openkm.util.ContextWrapper;
import java.io.FileInputStream;
import java.io.InputStream;
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");
OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class);
okmDocument.stampImage(null, "055b5206-35d0-4351-ba92-c304bbba7ddf", id, "", exprX, exprY, is);
} catch (Exception e) {
e.printStackTrace();
}
}
}
setDescription
Description:
Method | Return values | Description |
---|---|---|
setDescription(String token, String docId, String description) |
void |
Set 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
Description:
Method | Return values | Description |
---|---|---|
setNodeClass(String token, String docId, long ncId) |
void |
Set 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
Description:
Method | Return values | Description |
---|---|---|
setDispositionStage(String token, String docId, long stage) |
void |
Set 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
Description:
Method | Return values | Description |
---|---|---|
createWizard(String token, String docPath, long nodeClass, InputStream is) |
WizardNode |
Create a new document with wizard. |
The parameters docPath should be any valid folder or record PATH. The WizardNode contains a list of pending actions what should be done to complete the process of document creation. These might be:
|
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
Description:
Method | Return values | Description |
---|---|---|
getNumberOfPages(String token, String uuid) |
int |
Get the number of pages of 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
Description:
Method | Return values | Description |
---|---|---|
getPageAsImage(String token, String uuid, int pageNumber, int maxWidth, int maxHeight) |
String |
Return specific page as an image encoded as a String in B64. |
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
Description:
Method | Return values | Description |
---|---|---|
isConvertibleToPDF(String docId) |
Boolean |
Returns a boolean that indicates if the node is convertible to PDF or not. |
In case of a node of type PDF file will be returned a false value.
|
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("9ed5c7b1-9314-4479-8f80-fd8e2b47f55e"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
setIndexable
Description:
Method | Return values | Description |
---|---|---|
setIndexable(String uuid, boolean enabled) |
void |
Sets the document indexable. |
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.setIndexable("19938640-fd34-421c-90c8-6b435e4b7d79", true);
Document document = okmDocument.getDocumentProperties("19938640-fd34-421c-90c8-6b435e4b7d79");
System.out.println("Document indexable:" + document.isIndexable());
} catch (Exception e) {
e.printStackTrace();
}
}
}
mergePdf
Description:
Method | Return values | Description |
---|---|---|
mergePdf(String token, String destinationPath, String docName, List<String> paths) |
void |
Merge two or more PDF files. |
The parameters destinationPath should be any 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();
}
}
}