OKMDocument
Basics
On almost methods you'll see parameter named "docId". The value of this parameter can be some valid document UUID or path node.
Example of docId:
- Using UUID -> "c41f9ea0-0d6c-45da-bae4-d72b66f42d0f";
- Using path -> "/okm:root/sample.pdf"
About the parameter named "fldId", the value of this parameter can be some valid folder UUID or path or record node.
Example of docId:
- Using UUID -> "c6785440-0d6c-45da-1234-d9874563d0f";
- Using path -> "/okm:root/folder1"
About the parameter named "dstId", the value of this parameter can be some valid folder UUID or path or record node.
Example of dstId:
- Using UUID -> "c4455667-0d6c-45da-1234-d98564323e0";
- Using path -> "/okm:root/folder2"
Also on all methods you'll see parameter named "token". When accessing application across SOAP the login process returns a token, what is used to identify the user on all the exposed methods. 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;
public class Test {
public static void main(String[] args) {
InputStream is = null;
try {
is = new FileInputStream("/home/user/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.getInstance().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;
public class Test {
public static void main(String[] args) {
InputStream is = null;
try {
is = new FileInputStream("/home/user/sample.pdf");
String docPath = "/okm:root/sample.pdf";
Document doc = OKMDocument.getInstance().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;
public class Test {
public static void main(String[] args) {
try {
// Delete document by path
OKMDocument.getInstance().delete(null, "/okm:root/sample.pdf");
// Delete document by uuid
OKMDocument.getInstance().delete(null, "adc048d7-3791-4540-ae32-680629f73875");
} 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;
public class Test {
public static void main(String[] args) {
try {
Document doc = OKMDocument.getInstance().getProperties(null, "adc048d7-3791-4540-ae32-680629f73875");
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;
public class Test {
public static void main(String[] args) {
InputStream is = null;
OutputStream fos = null;
try {
is = OKMDocument.getInstance().getContent(null, "adc048d7-3791-4540-ae32-680629f73875", false);
File tmp = new File("/home/user/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;
public class Test {
public static void main(String[] args) {
InputStream is = null;
OutputStream fos = null;
try {
is = OKMDocument.getInstance().getContentByVersion(null, "adc048d7-3791-4540-ae32-680629f73875", "1.1");
File tmp = new File("/home/user/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;
public class Test {
public static void main(String[] args) {
try {
String indexedText = OKMDocument.getInstance().getExtractedText(null, "adc048d7-3791-4540-ae32-680629f73875");
System.out.println(indexedText);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getChilds
Description:
Method | Return values | Description |
---|---|---|
getChilds(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. This method is deprecated in favour of getChildren method. We encourage do not using it, because on nearly future will be removed. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
import com.openkm.bean.Document;
public class Test {
public static void main(String[] args) {
try {
for (Document doc : OKMDocument.getInstance().getChilds(null, "/okm:root/import")) {;
System.out.println(doc);
}
} 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;
public class Test {
public static void main(String[] args) {
try {
for (Document doc : OKMDocument.getInstance().getChildren(null, "/okm:root/import")) {;
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;
public class Test {
public static void main(String[] args) {
try {
Document doc = OKMDocument.getInstance().rename(null, "/okm:root/samples.pdf","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;
public class Test {
public static void main(String[] args) {
try {
Document doc = OKMDocument.getInstance().getProperties(null, "/okm:root/samples.pdf");
doc.getKeywords().add("key1");
doc.setDescription("some description");
OKMDocument.getInstance().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;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().setLanguage(null, "/okm:root/samples.pdf","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;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().setTitle(null, "/okm:root/samples.pdf","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;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().checkout(null, "/okm:root/samples.pdf");
} 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;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().cancelCheckout(null, "/okm:root/samples.pdf");
} 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;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().forceCancelCheckout(null, "/okm:root/samples.pdf");
} 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;
public class Test {
public static void main(String[] args) {
try {
System.out.println(OKMDocument.getInstance().isCheckedOut(null, "/okm:root/samples.pdf"));
} 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.poi.util.IOUtils;
import com.openkm.api.OKMDocument;
public class Test {
public static void main(String[] args) {
InputStream is = null;
try {
is = new FileInputStream("/home/user/sample.pdf");
OKMDocument.getInstance().checkin(null, "/okm:root/samples.pdf", 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.poi.util.IOUtils;
import com.openkm.api.OKMDocument;
import com.openkm.vernum.VersionNumerationAdapter;
public class Test {
public static void main(String[] args) {
InputStream is = null;
try {
is = new FileInputStream("/home/user/sample.pdf");
OKMDocument.getInstance().checkin(null, "/okm:root/samples.pdf", is, "optional comment", VersionNumerationAdapter.INCREASE_MINOR);
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(is);
}
}
}
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;
public class Test {
public static void main(String[] args) {
try {
System.out.println(OKMDocument.getInstance().isCheckedOut(null, "/okm:root/samples.pdf"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
getVersionHistory
Description:
Method | Return values | Description |
---|---|---|
getVersionHistory(String token, String docId |
List<Version> |
Returns a list of all document versions. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
import com.openkm.bean.Version;
public class Test {
public static void main(String[] args) {
try {
for (Version ver :OKMDocument.getInstance().getVersionHistory(null, "/okm:root/samples.pdf")) {
System.out.println(ver);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
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;
public class Test {
public static void main(String[] args) {
try {
LockInfo lockInfo = OKMDocument.getInstance().lock(null, "/okm:root/samples.pdf"));
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;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().unlock(null, "/okm:root/samples.pdf"));
} 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;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().forceUnlock(null, "/okm:root/samples.pdf"));
} 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;
public class Test {
public static void main(String[] args) {
try {
System.out.println(OKMDocument.getInstance().isLocked(null, "/okm:root/samples.pdf"));
} 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;
public class Test {
public static void main(String[] args) {
try {
LockInfo lockInfo = OKMDocument.getInstance().getLockInfo(null, "/okm:root/samples.pdf"));
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;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().purge(null, "/okm:root/samples.pdf"));
} 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 or path. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().move(null, "/okm:root/samples.pdf", "/okm/root/temp"));
} 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 or path. 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;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().copy(null, "/okm:root/samples.pdf", "/okm/root/temp"));
} 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 or path. 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;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().copy(null, "/okm:root/samples.pdf", "/okm/root/temp", "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 or path. 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;
public class Test {
public static void main(String[] args) {
try {
ExtendedAttributes extAttr = new ExtendedAttributes();
// copy keywords
extAttr.setKeywords(true);
OKMDocument.getInstance().extendedCopy(null, "/okm:root/samples.pdf", "/okm:root/temp", "samples_renamed.pdf", extAttr);
} catch (Exception e) {
e.printStackTrace();
}
}
}
restoreVersion
Description:
Method | Return values | Description |
---|---|---|
restoreVersion(String token, String docId, String versionId) |
void |
Restores previously document version to actual version. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().restoreVersion(null, "/okm:root/samples.pdf", "1.2");
} catch (Exception e) {
e.printStackTrace();
}
}
}
purgeVersionHistory
Description:
Method | Return values | Description |
---|---|---|
purgeVersionHistory(String token, String docId) |
void |
Purges all the previous document versions except the actual version. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().purgeVersionHistory(null, "/okm:root/samples.pdf");
} 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.FormatUtil;
public class Test {
public static void main(String[] args) {
try {
System.out.println(FormatUtil.formatSize(OKMDocument.getInstance().getVersionHistorySize(null, "/okm:root/samples.pdf")));
} 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;
public class Test {
public static void main(String[] args) {
try {
boolean valid = OKMDocument.getInstance().isValid(null, "/okm:root/samples.pdf");
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;
public class Test {
public static void main(String[] args) {
try {
String docPath = OKMDocument.getInstance().getPath(null, "f123a950-0329-4d62-8328-0ff500fd42dbg");
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;
public class Test {
public static void main(String[] args) {
try {
for (String languages : OKMDocument.getInstance().getDetectedLanguages(null)) {
System.out.println(languages);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
createFromTemplate
Description:
Method | Return values | Description |
---|---|---|
createFromTemplate(String token, String docId, String dstPath, List<FormElement> properties, ExtendedAttributes attribute) |
Document |
Creates a new document from template and returns an object Document. |
The dstPath can be a folder or a record path. 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.List;
import com.openkm.api.OKMDocument;
import com.openkm.bean.ExtendedAttributes;
import com.openkm.bean.form.FormElement;
import com.openkm.bean.form.Input;
import com.openkm.bean.form.Option;
import com.openkm.bean.form.Select;
import com.openkm.util.ISO8601;
public class Test {
public static void main(String[] args) {
try {
List<FormElement> formElements = new ArrayList<>();
Input name = new Input();
name.setName("okp:tpl.name");
name.setValue("Some name");
formElements.add(name);
Input birdDate = new Input();
birdDate.setName("okp:tpl.bird_date");
Calendar cal = Calendar.getInstance();
// Value must be converted to String ISO 8601 compliant
birdDate.setValue(ISO8601.formatBasic(cal));
formElements.add(birdDate);
Select language = new Select();
language.setName("okp:tpl.language");
// With selected option is enought
Option option = new Option();
option.setValue("java");
option.setSelected(true);
language.getOptions().add(option);
formElements.add(language);
OKMDocument.getInstance().createFromTemplate(null, "/okm:templates/tpl.pdf", "/okm:root/test", formElements, new ExtendedAttributes());
} catch (Exception e) {
e.printStackTrace();
}
}
}
createFromTemplateSimple
Description:
Method | Return values | Description |
---|---|---|
createFromTemplateSimple(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 path. 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.Calendar;
import java.util.HashMap;
import java.util.Map;
import com.openkm.api.OKMDocument;
import com.openkm.bean.ExtendedAttributes;
import com.openkm.util.ISO8601;
public class Test {
public static void main(String[] args) {
try {
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));
properties.put("okp:tpl.language", "java");
OKMDocument.getInstance().createFromTemplateSimple(null, "/okm:templates/tpl.pdf", "/okm:root/test", properties, new ExtendedAttributes());
} catch (Exception e) {
e.printStackTrace();
}
}
}
updateFromTemplate
Description:
Method | Return values | Description |
---|---|---|
updateFromTemplate(String token, String docId, String dstId, List<FormElement> 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.List;
import com.openkm.api.OKMDocument;
import com.openkm.bean.form.FormElement;
import com.openkm.bean.form.Input;
import com.openkm.bean.form.Option;
import com.openkm.bean.form.Select;
import com.openkm.util.ISO8601;
public class Test {
public static void main(String[] args) {
try {
List<FormElement> formElements = new ArrayList<>();
Input name = new Input();
name.setName("okp:tpl.name");
name.setValue("Some name");
formElements.add(name);
Input birdDate = new Input();
birdDate.setName("okp:tpl.bird_date");
Calendar cal = Calendar.getInstance();
// Value must be converted to String ISO 8601 compliant
birdDate.setValue(ISO8601.formatBasic(cal));
formElements.add(birdDate);
Select language = new Select();
language.setName("okp:tpl.language");
// With selected option is enought
Option option = new Option();
option.setValue("java");
option.setSelected(true);
language.getOptions().add(option);
formElements.add(language);
OKMDocument.getInstance().updateFromTemplate(null, "/okm:templates/tpl.pdf", "/okm:root/test", formElements);
} catch (Exception e) {
e.printStackTrace();
}
}
}
updateFromTemplateSimple
Description:
Method | Return values | Description |
---|---|---|
updateFromTemplateSimple(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.Calendar;
import java.util.HashMap;
import java.util.Map;
import com.openkm.api.OKMDocument;
import com.openkm.util.ISO8601;
public class Test {
public static void main(String[] args) {
try {
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));
properties.put("okp:tpl.language", "java");
OKMDocument.getInstance().updateFromTemplateSimple(null, "/okm:templates/tpl.pdf", "/okm:root/test", 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;
public class Test {
public static void main(String[] args) {
try {
OKMDocument.getInstance().setAnnotations(null, "/okm:root/samples.pdf", "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;
public class Test {
public static void main(String[] args) {
try {
String annotation = OKMDocument.getInstance().getAnnotations(null, "/okm:root/samples.pdf", "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;
public class Test {
public static void main(String[] args) {
try {
for (Document doc : OKMDocument.getInstance().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;
public class Test {
public static void main(String[] args) {
try {
int type = 0; // indicate text stamp definition
long stId = 12; // unique identifier of the stamp definition
OKMDocument.getInstance().stamp(null, "/okm:root/sample.pdf", type, stId);
} catch (Exception e) {
e.printStackTrace();
}
}
}