Previous |
Next
The Files CMIS API exposes the Files application data using the Content Management Interoperability Services (CMIS) standard. CMIS is a standard created with the goal of making application code more portable across various Enterprise Content Management (ECM) systems. In fact, any CMIS-compatible application should work with IBM Connections. This page has a list of existing
CMIS client applications
.
The details of the CMIS standard are outside the scope of this article. For more detailed documentation about the CMIS standard visit the
OASIS CMIS web site
.
To use the Files CMIS API, an application first must retrieve the API service document. This document is available at the following location:
https://server/files/basic/cmis/my/servicedoc. The following is a sample of the beginning of the service document:
<?xml version="1.0" encoding="UTF-8"?>
<app:service xmlns:snx="http://www.ibm.com/xmlns/prod/sn" xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/"
xmlns:cmism="http://docs.oasis-open.org/ns/cmis/messaging/200908/" xmlns:lcmis="http://www.ibm.com/xmlns/prod/sn/cmis"
xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app">
<app:workspace>
<atom:title type="text">Frank Adams</atom:title>
<atom:link href="https://server:443/files/basic/opensocial/container" rel="http://www.ibm.com/xmlns/prod/sn/opensocial" type="application/xrds+xml"/>
<app:collection href="https://server/files/basic/cmis/repository/p%21E514AA26290C91108525688600530CAC/folderc/snx%3Aroot">
<cmisra:collectionType>root</cmisra:collectionType>
<atom:title type="text">Root Children Collection</atom:title>
</app:collection>
<app:collection href="https://server/files/basic/cmis/repository/p%21E514AA26290C91108525688600530CAC/typesc">
<cmisra:collectionType>types</cmisra:collectionType>
<atom:title type="text">Types Children Collection</atom:title>
</app:collection>
<app:collection href="https://server/files/basic/cmis/repository/p%21E514AA26290C91108525688600530CAC/checkedout">
<cmisra:collectionType>checkedout</cmisra:collectionType>
<atom:title type="text">Checkedout Collection</atom:title>
<app:accept>application/atom+xml;type=entry</app:accept>
</app:collection>
<app:collection href="https://server/files/basic/cmis/repository/p%21E514AA26290C91108525688600530CAC/query">
<cmisra:collectionType>query</cmisra:collectionType>
<atom:title type="text">Query Collection</atom:title>
<app:accept>application/cmisquery+xml</app:accept>
</app:collection>
<app:collection href="https://server/files/basic/cmis/repository/p%21E514AA26290C91108525688600530CAC/unfiled">
<cmisra:collectionType>unfiled</cmisra:collectionType>
<atom:title type="text">Unfiled Collection</atom:title>
</app:collection>
<atom:link href="https://server/files/basic/cmis/repository/p%21E514AA26290C91108525688600530CAC/typesd"
rel="http://docs.oasis-open.org/ns/cmis/link/200908/typedescendants" type="application/atom+xml;type=feed"/>
<atom:link href="https://server/files/basic/cmis/nonce" rel="http://www.ibm.com/xmlns/prod/sn/cmis/nonce" type="text/plain"/>
....
Using the service document, an application will then follow the links provided to access the document repository.
The following example uses Apache Abdera to retrieve a list of documents in the My Files collections for a specific user:
Abdera abdera = new Abdera();
Parser parser = abdera.getParser();
AbderaClient client = new AbderaClient(abdera);
AbderaClient.registerTrustManager();
client.addCredentials("https://server", null, null, new UsernamePasswordCredentials("user","password"));
ClientResponse resp = client.get("https://server/files/basic/cmis/my/servicedoc");
Document<Service> service_doc = resp.getDocument();
Service service = service_doc.getRoot();
Collection collection = service.getCollection("Frank Adams","Root Children Collection");
URL myFilesUrl = new URL(collection.getResolvedHref().toASCIIString());
resp = client.get(collection.getResolvedHref().toASCIIString());
Document<Element> document = parser.parse(resp.getInputStream());
Feed feed = (Feed)document.getRoot();
List<Entry> entries = feed.getEntries();
resp = client.get(entries.get(0).getLink("down").getHref().toASCIIString());
document = parser.parse(resp.getInputStream());
feed = (Feed)document.getRoot();
entries = feed.getEntries();
for (Entry entry: entries) {
// Using XPath functions to get file information
XPath xpath = abdera.getXPath();
Map<String,String> ns = new HashMap<String,String>();
ns.put("atom", "http://www.w3.org/2005/Atom");
ns.put("app", "http://www.ibm.com/xmlns/prod/sn");
ns.put("cmisra", "http://docs.oasis-open.org/ns/cmis/restatom/200908/");
ns.put("cmis", "http://docs.oasis-open.org/ns/cmis/core/200908/");
System.out.println("File name: " + xpath.valueOf("cmisra:object/cmis:properties/cmis:propertyString[@queryName='cmis:name']", entry, ns));
System.out.println("File size: " + xpath.valueOf("cmisra:object/cmis:properties/cmis:propertyInteger[@queryName='cmis:contentStreamLength']", entry, ns));
}
When using the Files CMIS API to create or update information in the document repository, the application must first retrieve a nonce token. The nonce token is used to protect against Cross Site RF (CSRF) attacks. The following code example can be used to retrieve the nonce token.
Abdera abdera = new Abdera();
AbderaClient client = new AbderaClient(abdera);
AbderaClient.registerTrustManager();
client.addCredentials("https://server", null, null, new UsernamePasswordCredentials("user","pass"));
String nonceUrl = "https://server/files/basic/cmis/nonce";
resp = client.get(nonceUrl);
StringWriter writer = new StringWriter();
IOUtils.copy(resp.getInputStream(), writer);
String nonce = writer.toString();
// Add the nonce to the request
RequestOptions options = new RequestOptions();
options.addHeader("X-Update-Nonce", nonce);
The code examples in this article and other articles in this wiki used the Apache Abdera libraries when working with the API Atom feeds using Java. If you plan to work heavily in the CMIS API, other libraries such as Apache Chemistry may better serve your needs. For more information about Apache Chemistry, visit the
project website
.
Parent topic:
9.0 Using the API