Document samples
Esta página aún no está disponible en tu idioma.
Basics
Section titled “Basics”On most methods you’ll see parameter named “docId”. The value of this parameter can be some valid document UUID or path.
Methods
Section titled “Methods”createDocument
Section titled “createDocument”Description:
| Method | Return values | Description |
|---|---|---|
| createDocument(Document doc, InputStream is) | Document | Creates a new document and returns as a result an object Document with the properties of the created document. |
- The variable path into the parameter doc, must be initializated. It indicates where the document must be stored into OpenKM.
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.Document;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { InputStream is = new FileInputStream("/home/files/logo.png"); Document doc = new Document(); doc.setPath("/okm:root/logo.png"); ws.createDocument(doc, is); IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); } }}createDocumentSimple
Section titled “createDocumentSimple”Description:
| Method | Return values | Description |
|---|---|---|
| createDocumentSimple(String docPath, InputStream is) | Document | Creates a new document and return as a result an object Document with the properties of the created document. |
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { InputStream is = new FileInputStream("/home/files/logo.png"); ws.createDocumentSimple("/okm:root/logo.png", is); IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); } }}deleteDocument
Section titled “deleteDocument”Description:
| Method | Return values | Description |
|---|---|---|
| deleteDocument(String docId) | void | Delete a document. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { ws.deleteDocument("/okm:root/logo.png"); } catch (Exception e) { e.printStackTrace(); } }}getDocumentProperties
Section titled “getDocumentProperties”Description:
| Method | Return values | Description |
|---|---|---|
| getDocumentProperties(String docId) | Document | Returns the document properties. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { System.out.println(ws.getDocumentProperties("/okm:root/logo.png")); } catch (Exception e) { e.printStackTrace(); } }}getContent
Section titled “getContent”Description:
| Method | Return values | Description |
|---|---|---|
| getContent(String docId) | InputStream | Retrieves the document content - binary data - of the actual document version. |
Example:
package com.openkm;
import java.io.FileOutputStream;import java.io.InputStream;import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { OutputStream fos = new FileOutputStream("/home/files/logo.png"); InputStream is = ws.getContent("/okm:root/logo.png"); IOUtils.copy(is, fos); IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); } catch (Exception e) { e.printStackTrace(); } }}getContentByVersion
Section titled “getContentByVersion”Description:
| Method | Return values | Description |
|---|---|---|
| getContentByVersion(String docId, String versionId) | InputStream | Retrieves document content ( binary data ) of some specific document version. |
Example:
package com.openkm;
import java.io.FileOutputStream;import java.io.InputStream;import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { OutputStream fos = new FileOutputStream("/home/files/logo.png"); InputStream is = ws.getContentByVersion("/okm:root/logo.png","1.1"); IOUtils.copy(is, fos); IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); } catch (Exception e) { e.printStackTrace(); } }}getDocumentChildren
Section titled “getDocumentChildren”Description:
| Method | Return values | Description |
|---|---|---|
| getDocumentChildren(String fldId) | List |
Returns a list of all documents which their parent is fldId. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.Document;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { for (Document doc : ws.getDocumentChildren("/okm:root")) { System.out.println(doc); } } catch (Exception e) { e.printStackTrace(); } }}renameDocument
Section titled “renameDocument”Description:
| Method | Return values | Description |
|---|---|---|
| renameDocument(String docId, String newName) | void | Change the name of a document. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { ws.renameDocument("f123a950-0329-4d62-8328-0ff500fd42db", "logo_rename.png"); } catch (Exception e) { e.printStackTrace(); } }}setProperties
Section titled “setProperties”Description:
| Method | Return values | Description |
|---|---|---|
| setProperties(Document doc) | void | Change some document properties. |
- Variables allowed to be changed:
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.Document;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { Document doc = ws.getDocumentProperties("f123a950-0329-4d62-8328-0ff500fd42db"); doc.setDescription("some description"); doc.getKeywords().add("test"); ws.setProperties(doc); } catch (Exception e) { e.printStackTrace(); } }}checkout
Section titled “checkout”Description:
| Method | Return values | Description |
|---|---|---|
| checkout(String docId) | void | Marks the document for edition. |
- Only one user can modify a document at the same time.
- Before starting edition must do a checkout action that lock the edition process for other users and allows only to the user who has executed the action.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { ws.checkout("/okm:root/logo.png"); // At this point the document is locked for other users except for the user who executed the action } catch (Exception e) { e.printStackTrace(); } }}cancelCheckout
Section titled “cancelCheckout”Description:
| Method | Return values | Description |
|---|---|---|
| cancelCheckout(String docId) | void | Cancel a document edition. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { // At this point the document is locked for other users except for the user who executed the action ws.cancelCheckout("/okm:root/logo.png"); // At this point other users are allowed to execute a checkout and modify the document } catch (Exception e) { e.printStackTrace(); } }}forceCancelCheckout
Section titled “forceCancelCheckout”Description:
| Method | Return values | Description |
|---|---|---|
| forceCancelCheckout(String docId) | void | Cancel a document edition. |
- This method allows to cancel edition of any document.
- It is not mandatory to execute this action by the same user who previously executed the checkout action.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { // At this point the document is locked for other users except for the user who executed the action ws.forceCancelCheckout("/okm:root/logo.png"); // At this point other users are allowed to execute a checkout and modify the document } catch (Exception e) { e.printStackTrace(); } }}isCheckedOut
Section titled “isCheckedOut”Description:
| Method | Return values | Description |
|---|---|---|
| isCheckedOut(String docId) | Boolean | Returns a boolean that indicate if the document is on edition or not. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { System.out.println("Is the document checkout:"+ws.isCheckedOut("/okm:root/logo.png")); } catch (Exception e) { e.printStackTrace(); } }}checkin
Section titled “checkin”Description:
| Method | Return values | Description |
|---|---|---|
| checkin(String docId, InputStream is, String comment) | Version | Updates a document with new version and return an object with new Version values. |
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { InputStream is = new FileInputStream("/home/files/logo.png"); ws.checkin("/okm:root/logo.png", is, "optional some comment"); IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); } }}getVersionHistory
Section titled “getVersionHistory”Description:
| Method | Return values | Description |
|---|---|---|
| getVersionHistory(String docId) | List |
Returns a list of all document versions. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.Version;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { for (Version version : ws.getVersionHistory("/okm:root/logo.png")) { System.out.println(version); } } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| lock(String docId) | LockInfo | Locks a document and return an object with the Lock information. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { ws.lock("/okm:root/logo.png"); } catch (Exception e) { e.printStackTrace(); } }}unlock
Section titled “unlock”Description:
| Method | Return values | Description |
|---|---|---|
| unlock(String docId) | void | Unlocks a locked document. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { ws.unlock("/okm:root/logo.png"); } catch (Exception e) { e.printStackTrace(); } }}forceUnlock
Section titled “forceUnlock”Description:
| Method | Return values | Description |
|---|---|---|
| forceUnlock(String docId) | void | Unlocks a locked document. |
- This method allows to unlcok any locked document.
- It is not mandatory execute this action by the same user who previously executed the checkout lock action.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { ws.forceUnlock("/okm:root/logo.png"); } catch (Exception e) { e.printStackTrace(); } }}isLocked
Section titled “isLocked”Description:
| Method | Return values | Description |
|---|---|---|
| isLocked(String docId) | Boolean | Returns a boolean that indicate if the document is locked or not. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { System.out.println("Is document locked:"+ws.isLocked("/okm:root/logo.png")); } catch (Exception e) { e.printStackTrace(); } }}getLockInfo
Section titled “getLockInfo”Description:
| Method | Return values | Description |
|---|---|---|
| getLockInfo(String docId) | LockInfo | Returns an object with the Lock information |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { System.out.println(ws.getLockInfo("/okm:root/logo.png")); } catch (Exception e) { e.printStackTrace(); } }}purgeDocument
Section titled “purgeDocument”Description:
| Method | Return values | Description |
|---|---|---|
| purgeDocument(String docId) | void | 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.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { ws.purgeDocument("/okm:trash/okmAdmin/logo.png"); } catch (Exception e) { e.printStackTrace(); } }}moveDocument
Section titled “moveDocument”Description:
| Method | Return values | Description |
|---|---|---|
| moveDocument(String docId, String dstId) | void | Moves a document into some folder or record. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { ws.moveDocument("/okm:root/logo.png","/okm:root/temp"); } catch (Exception e) { e.printStackTrace(); } }}copyDocument
Section titled “copyDocument”Description:
| Method | Return values | Description |
|---|---|---|
| copyDocument(String docId, String dstId) | void | Copies a 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.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { ws.copyDocument("/okm:root/logo.png","/okm:root/temp"); } catch (Exception e) { e.printStackTrace(); } }}restoreVersion
Section titled “restoreVersion”Description:
| Method | Return values | Description |
|---|---|---|
| restoreVersion(String docId, String versionId) | void | Promotes a previous document version to actual version. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { // Actual version is 1.2 ws.restoreVersion("/okm:root/logo.png","1.1"); // Actual version is 1.1 } catch (Exception e) { e.printStackTrace(); } }}purgeVersionHistory
Section titled “purgeVersionHistory”Description:
| Method | Return values | Description |
|---|---|---|
| purgeVersionHistory(String docId) | void | Purges all documents version except the actual version. |
- This action compact the version history of a document.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { // Version history has version 1.3,1.2,1.1 and 1.0 ws.purgeVersionHistory("/okm:root/logo.png"); // Version history has only version 1.3 } catch (Exception e) { e.printStackTrace(); } }}getVersionHistorySize
Section titled “getVersionHistorySize”Description:
| Method | Return values | Description |
|---|---|---|
| getVersionHistorySize(String docId) | long | Returns the sum in bytes of all documents into documents history. |
Example:
package com.openkm;
import java.util.Locale;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { String[] UNITS = new String[] { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; long bytes = ws.getVersionHistorySize("/okm:root/logo.png"); String value = ""; for (int i = 6; i > 0; i--) { double step = Math.pow(1024, i); if (bytes > step) value = String.format(Locale.ROOT, "%3.1f %s", bytes / step, UNITS[i]); }
if (value.isEmpty()) { value = Long.toString(bytes) + " " + UNITS[0]; } System.out.println(value); } catch (Exception e) { e.printStackTrace(); } }}isValidDocument
Section titled “isValidDocument”Description:
| Method | Return values | Description |
|---|---|---|
| isValidDocument(String docId) | Boolean | Returns a boolean that indicate if the node is a document or not. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { // Return true ws.isValidDocument("/okm:root/logo.png"); // Return false ws.isValidDocument("/okm:root"); } catch (Exception e) { e.printStackTrace(); } }}getDocumentPath
Section titled “getDocumentPath”Description:
| Method | Return values | Description |
|---|---|---|
| getDocumentPath(String uuid) | String | Converts a document UUID to document path. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { System.out.println(ws.getDocumentPath("f123a950-0329-4d62-8328-0ff500fd42dbg")); } catch (Exception e) { e.printStackTrace(); } }}extendedDocumentCopy
Section titled “extendedDocumentCopy”Description:
| Method | Return values | Description |
|---|---|---|
| extendedDocumentCopy(String docId, String dstId, String name, boolean categories, boolean keywords, boolean propertyGroups, boolean notes, boolean wiki) | 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 newName value is null, the document will preserve the same name.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { ws.extendedDocumentCopy("/okm:root/logo.png", "/okm:root/tmp", null, true, true, true, true, true); } catch (Exception e) { e.printStackTrace(); } }}createFromTemplate
Section titled “createFromTemplate”Description:
| Method | Return values | Description |
|---|---|---|
| Document createFromTemplate(String docId, String dstPath, boolean categories, boolean keywords, boolean propertyGroups, boolean notes, boolean wiki, Map<String, String> properties) | Document | Creates a new document from the template and returns a Document. |
- The dstPath must be a folder.
- When the template use metadata groups to fill in fields, then these values are mandatory and must be set into properties parameter.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.Document;import com.openkm.sdk4j.util.ISO8601;
import java.util.Calendar;import java.util.HashMap;import java.util.Map;
public class Test {
public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { // createFromTemplate Map<String, String> properties = new HashMap<>(); // okg:tpl properties.put("okp:tpl.name", "sdk 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");
// Property okg:technology properties.put("okp:technology.comment", "sdk name");
Document document = ws.createFromTemplate("fc638b93-0072-49ac-ad88-d4eeb098fd5a", "/okm:root/sdk/template.pdf", true, true, true, true, true, properties); System.out.println(document); } catch (Exception e) { e.printStackTrace(); } }}