The following examples of the CMIS usage may be useful for developers who need to access a repository. CMIS access code snippets are built using Apache HTTP Client for Java, or using Google gadgets (gadgets.io) for JavaScript examples. For the cURL examples, look at http://code.google.com/p/xcmis/wiki/xCMISusesWithCurl.

There are several methods to get the documents lists, such as getChildren(), getFolderTree() and getDescentants(), their usage will be described below. The difference between them is the usage of different URL segments to get data ("/children" for getChildren(), "/foldertree" for getFolderTree(), "/descendants" for getDescentants()), and a different kind of results (getChildren() returns a flat structure, while a getFolderTree() and getDescentants() have a tree of items in response).

Reading the Document properties and content stream are two separate operations. Getting the content stream is possible after the properties set have been read and the content stream ID was extracted from it.

Get document properties.

Get document content-stream.

To get the Document's content stream, an URL must contain "/file" part, object ID, and optionally the content stream ID, which can be used, for example, to obtain renditions. If no stream ID is specified, the default stream will be returned.

CMIS supports SQL queries for more handful content search. Query service can handle both GET and POST requests. URL for query consists of repository name and method name "/query". The GET request must contain query as a parameter named "q", in case of POST request query must be located in a request body.

For more detailed instructions how to construct queries, refer to the Query examples chapter.

The command of property update uses PUT method. The URL is the same as the one for reading properties, the difference is only in the HTTP method used. The body of the request must be an Atom document with specified properties (see spec. 2.2.4.12 for detailed constructing document).

Sending of content stream can be executed via PUT or POST requests. Content-type of the request must be an "multipart/form-data".

Update properties:



 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.StringRequestEntity;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.RequestEntity; 
 String url = "http://localhost:8080/rest/private/cmisatom/";
 url += repository;
 url += "/object/";
 url += obj_id;
 HttpClient client = new HttpClient();
 client.getHttpConnectionManager().
 getParams().setConnectionTimeout(10000);
String atomDoc = "<?xml version='1.0' encoding='utf-8'?>"
         + "<entry xmlns='http://www.w3.org/2005/Atom'"
         + " xmlns:cmis='http://docs.oasis-open.org/ns/cmis/core/200908/'"
         + " xmlns:cmisra='http://docs.oasis-open.org/ns/cmis/restatom/200908/'>"
         + "<cmisra:object><cmis:properties>"
         + "<cmis:propertyString queryName='cmis:name' localName='cmis:name' propertyDefinitionId='cmis:name'>"
         + "<cmis:value>newName</cmis:value>"
         + "</cmis:propertyString>"
         + "</cmis:properties></cmisra:object>"
         + "</entry>";
 PutMethod put = new PutMethod(url);
 RequestEntity entity = new StringRequestEntity(atomDoc, "text/xml", "utf-8");
 put.setRequestEntity(entity); 
 try { 
   int result = client.executeMethod(put);
   final String strResponse = put.getResponseBodyAsString(); 
 } finally {
   put.releaseConnection();
 }

Set content stream:

Update properties:

Set content stream: