Document samples

Basics

On most methods you'll see a parameter named "docId". The value of this parameter can be a valid document UUID or path.

Example of docId:

  • Using UUID -> "f123a950-0329-4d62-8328-0ff500fd42db";
  • Using path -> "/okm:root/logo.png"

Methods

createDocument

Description:

MethodReturn valuesDescription

createDocument(Document doc, InputStream is)

Document

Creates a new document and return 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.

Document doc = new Document();
doc.setPath("/okm:root/logo.png");

The other variables of Document ( doc ) will not take any effect on the document creation.

We suggest using the method below createDocumentSimple rather than this one.

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

Description:

MethodReturn valuesDescription

createDocumentSimple(String docPath, InputStream is)

Document

Creates a new document and returns 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 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.createDocumentSimple("/okm:root/logo.png", is);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }	
}

deleteDocument

Description:

MethodReturn valuesDescription

deleteDocument(String docId)

void

Deletes a document.

When a document is deleted it is automatically moved to /okm:trash/userId folder.

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

Description:

MethodReturn valuesDescription

getDocumentProperties(String docId)

Document

Return 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

Description:

MethodReturn valuesDescription

getContent(String docId)

InputStream

Retrieve document content - binary data - of the actual document version.

In case you sent the file across a Servlet response we suggest set the content length with:

Document doc = ws.getDocumentProperties("/okm:root/logo.png");
response.setContentLength(new Long(doc.getActualVersion().getSize()).intValue());

We've found wrong size problems while using:

response.setContentLength(is.available());

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

Description:

MethodReturn valuesDescription

getContentByVersion(String docId,String versionId)

InputStream

Retrieves a document content ( binary data ) from a specific document version.

In case you sent the file across a Servlet response we suggest set the content length with:

Document doc = ws.getDocumentProperties("/okm:root/logo.png");
response.setContentLength(new Long(doc.getActualVersion().getSize()).intValue());

We've found wrong size problems while using:

response.setContentLength(is.available());

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

Description:

MethodReturn valuesDescription

getDocumentChildren(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.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

Description:

MethodReturn valuesDescription

renameDocument(String docId, String newName)

Document

Changes the name of a document.

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.renameDocument("f123a950-0329-4d62-8328-0ff500fd42db", "logo_rename.png");
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }	
}

setProperties

Description:

MethodReturn valuesDescription

 setProperties(Document doc)

void

Changes some document properties.

Variables allowed to be changed:

  • Title
  • Description
  • Language
  • Associated categories
  • Associated keywords

Only not null and not empty variables will be taken in consideration.

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

Description:

MethodReturn valuesDescription

 checkout(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.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

Description:

MethodReturn valuesDescription

cancelCheckout(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.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

Description:

MethodReturn valuesDescription

forceCancelCheckout(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.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

Description:

MethodReturn valuesDescription

isCheckedOut(String docId)

Boolean

Returns a boolean that indicates 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

Description:

MethodReturn valuesDescription

checkin(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.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(); } } }

checkin

Description:

MethodReturn valuesDescription

checkin(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 value of increment variable must be 1 or greater.

The valid values of increment variable depends on the VersionNumberAdapter you  have enabled.

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.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", 1);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }	
}

getVersionHistory

Description:

MethodReturn valuesDescription

getVersionHistory(String docId)

List<Version>

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(); } } }

lock

Description:

MethodReturn valuesDescription

lock(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.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

Description:

MethodReturn valuesDescription

unlock(String docId)

void

Unlocks a locked document.

Only the user who locked the document is allowed to unlock.

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

Description:

MethodReturn valuesDescription

forceUnlock(String docId)

void

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.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

Description:

MethodReturn valuesDescription

isLocked(String docId)

Boolean

Returns a boolean that indicates 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

Description:

MethodReturn valuesDescription

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

Description:

MethodReturn valuesDescription

purgeDocument(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.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

Description:

MethodReturn valuesDescription

moveDocument(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.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

Description:

MethodReturn valuesDescription

copyDocument(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 "extendedDocumentCopy" method for this feature.

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","new_logo.png");         } catch (Exception e) {             e.printStackTrace();         }     } }

restoreVersion

Description:

MethodReturn valuesDescription

restoreVersion(String docId, String versionId)

void

Restores previously 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

Description:

MethodReturn valuesDescription

purgeVersionHistory(String docId)

void

Purges all the previous document versions except the actual version.

This action compacts the version history of a document.

This action cannot be reverted.

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

Description:

MethodReturn valuesDescription

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

Description:

MethodReturn valuesDescription

isValidDocument(String docId)

Boolean

Returns a boolean that indicates 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

Description:

MethodReturn valuesDescription

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

Description:

MethodReturn valuesDescription

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.

By default only the binary data and the security grants, the metadata, keywords, etc. of the document are not copied.

Additional:

  • When the category parameter is true the original values of the categories will be copied.
  • When the keywords parameter is true the original values of the keywords will be copied.
  • When the propertyGroups parameter is true the original values of the metadata groups will be copied.
  • When the notes parameter is true the original value of the notes will be copied.
  • When wiki parameter is true the original value of the wiki will be copied.

  

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();         }     } }

getExtractedText

Description:

MethodReturn valuesDescription

getExtractedText(String docId)

String

Returns an String with the extracted text by text extractor process.

When a document is uploaded to OpenKM, it goes into text extraction queue. There's a crontab tab that periodically process this queue and extract document contents.

Unfortunately there is not a direct way to know if a document has been processed or not from the API, because this information is only stored at database level.

Althoughthis restriction, from API - only administrators users - can do database queries to retrieve this information. Check Repository samples for accessing database level.

More information at Statistics.

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 {             String text = ws.getExtractedText("/okm:root/document.doc");             System.out.println(text);         } catch (Exception e) {             e.printStackTrace();         }     } }

getThumbnail

Description:

MethodReturn valuesDescription

 getThumbnail(String docId, ThumbnailType type)

InputStream

Returns thumbnail image data.

Available types:

  • ThumbnailType.THUMBNAIL_PROPERTIES ( shown in properties view )
  • ThumbnailType.THUMBNAIL_LIGHTBOX ( shown in light box )
  • ThumbnailType.THUMBNAIL_SEARCH ( shown in search view )

Each thumbnail type has its own image dimensions.

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;
import com.openkm.sdk4j.bean.ThumbnailType;

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/thumbnail.png");             InputStream is = ws.getThumbnail("/okm:root/document.doc", ThumbnailType.THUMBNAIL_LIGHTBOX);             IOUtils.copy(is, fos);             IOUtils.closeQuietly(is);             IOUtils.closeQuietly(fos);         } catch (Exception e) {             e.printStackTrace();         }     } }

setLanguage

Description:

MethodReturn valuesDescription

setLanguage(String docId, String lang)

void

Sets the document language.

The parameter lang must be ISO 691-1 compliant.

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.setLanguage("/okm:root/document.doc", "es");         } catch (Exception e) {             e.printStackTrace();         }     } }

setDocumentTitle

Description:

MethodReturn valuesDescription

setDocumentTitle(String docId, String title)

void

Sets the document title.

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.setTitle("/okm:root/document.doc", "Some title here");         } catch (Exception e) {             e.printStackTrace();         }     } }

createFromTemplate

Description:

MethodReturn valuesDescription

Document createFromTemplate(String docId, String dstPath, String language, boolean categories, boolean keywords,
            boolean propertyGroups, boolean notes, boolean wiki, List<FormElement> properties)

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:

  • When category parameter is true the original values of the categories will be copied.
  • When keywords parameter is true the original values of the keywords will be copied.
  • When propertyGroups parameter is true the original values of the metadata groups will be copied.
  • When notes parameter is true the original values of the notes will be copied.
  • When wiki parameter is true the original values of the wiki will be copied.

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.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.form.FormElement;
import com.openkm.sdk4j.bean.form.Input;
import com.openkm.sdk4j.bean.form.Option;
import com.openkm.sdk4j.bean.form.Select;
import com.openkm.sdk4j.util.ISO8601;

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 {             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);                          ws.createFromTemplate("/okm:templates/tpl.pdf", "/okm:root/test", null, false, false, true, false, false, formElements);         } catch (Exception e) {             e.printStackTrace();         }     } }

createFromTemplateSimple

Description:

MethodReturn valuesDescription

Document createFromTemplateSimple(String docId, String dstPath, String language, boolean categories,
            boolean keywords, boolean propertyGroups, boolean notes, boolean wiki, Map<String, String> properties)

Document

Creates a new document from the template and returns an object Document.

The dstPath can be a folder or a record path.

The parameter language is optional.

When the template usea metadata groups to fill in fields, then these values are mandatory and must be set into properties parameter. 

For more information about Templates and metadata check: Creating templates Creating templates.

Additional:

  • When category parameter is true the original values of the categories will be copied.
  • When keywords parameter is true the original values of the keywords will be copied.
  • When property Groups parameter is true the original values of the metadata groups will be copied.
  • When notes parameter is true the original values of the notes will be copied.
  • When wiki parameter is true the original values of the wiki will be copied.

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.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.util.ISO8601;

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 {             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");                          ws.createFromTemplateSimple("/okm:templates/tpl.pdf", "/okm:root/test", null, false, false, true, false, false, properties);         } catch (Exception e) {             e.printStackTrace();         }     } }

updateFromTemplate

Description:

MethodReturn valuesDescription

Document updateFromTemplate(String docId, String dstId, List<FormElement> properties)

Document

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.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.form.FormElement;
import com.openkm.sdk4j.bean.form.Input;
import com.openkm.sdk4j.bean.form.Option;
import com.openkm.sdk4j.bean.form.Select;
import com.openkm.sdk4j.util.ISO8601;

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 {             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);                          ws.updateFromTemplate("/okm:templates/tpl.pdf", "/okm:root/test", formElements);         } catch (Exception e) {             e.printStackTrace();         }     } }

 

updateFromTemplateSimple

Description:

MethodReturn valuesDescription

updateFromTemplateSimple(String docId, String dstId, Map<String, String> properties) 

Document

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 in fields.

For more information about Templates and metadata take a look at 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.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.util.ISO8601;

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 {             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");                          ws.updateFromTemplateSimple("/okm:templates/tpl.pdf", "/okm:root/test", properties);         } catch (Exception e) {             e.printStackTrace();         }     } }

getDetectedLanguages

Description:

MethodReturn valuesDescription

getDetectedLanguages()

List<String>

Return a list of available document languages what OpenKM can identify.

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 {
            for (String lang : ws.getDetectedLanguages()) {
                System.out.println(lang);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }   
}

getAnnotations

Description:

MethodReturn valuesDescription

getAnnotations(String docId, String verName)  

String

Return the document annotations of some document 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 {
            System.out.println(ws.getAnnotations("b46f8df5-0920-4550-9046-21aba7e57e6d", "1.0"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getDifferences

Description:

MethodReturn valuesDescription

getDifferences(String docId, String v1, String v2)

InputStream

Return a PDF document with the differences between two document versions.

Example:

package com.openkm;

import java.io.FileOutputStream;
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 = ws.getDifferences("b46f8df5-0920-4550-9046-21aba7e57e6d", "1.0", "1.1");
            FileOutputStream fos = new FileOutputStream("/home/files/out.pdf");
            IOUtils.copy(is, fos);
            is.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getCheckedOut

Description:

MethodReturn valuesDescription

getCheckedOut()

List<Document>

Return a list of documents checkout by the user.

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.getCheckedOut()) {
                System.out.println(doc);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}