Through an email Jeff Potts commented on my recent post Processing CMIS with Freemarker. In his email Jeff suggested to have a look at the ‘cmis’ root object that is available in Alfresco Community 4.0. I assume it will also be available in the upcoming Alfresco Enterprise 4.0.
Note: Jeff warned that the cmis root object appears to be broken in the current Community release 4c, but it might be fixed in the upcoming release 4d.
Basic Example
To test it in my Alfresco Community 4b release I created a new Web Script in Alfresco Share similar to the one I used to test the approach described in the Freemarker related tutorial. It retrieves a file by path and displays the properties.
The first step is to create the Web Script descriptor. Create a file called ‘sample-opencmis.get.desc.xml’ with the following contents:
<webscript>
<shortname>Open CMIS example</shortname>
<description>Open CMIS Example</description>
<url>/sample/opencmis</url>
</webscript>
The next step is to create the controller. We start with a simple example to test the root object. It simply retrieves the root folder and adds it to the model. Create a file called ‘sample-opencmis.get.js’ with the following contents:
var cmisConnection = cmis.getConnection();
var cmisSession = cmisConnection.getSession();
folder = cmisSession.getRootFolder();
model.folder = folder;
Finally create the view by adding a file called ‘sample-opencmis.get.ftl’ with the following contents:
<h2>${folder.name}</h2>
Now when you refresh your Web Scripts at http://localhost:8080/share/service/index.html you should see a new Web Script called ‘sample/opencmis’. When you run this script using the URL http://localhost:8080/share/page/sample/opencmis, you should see a page similar to this:

Retrieving a Document
You can also use the cmis root object to retrieve content by path or to execute queries. For example to get a file ‘sample.txt’ located in the Company Home folder, you can add the following lines to the JavaScript controller:
doc = cmisSession.getObjectByPath("/sample.txt");
model.doc = doc;
You can then use the document in your view, for example to print the name and list the properties:
<h2>${doc.name}</h2>
<ul>
<#list doc.properties as p>
<li>${p.definition.displayName}: ${p.valuesAsString}</li>
</#list>
</ul>
This will output the following information:

You can for example also access a number of properties directly like the creationDate, createdBy or versionLabel. To access a property by queryName or id, you can use the following method:
${doc.getPropertyValue("cmis:objectTypeId")}
Next Steps
Within the next couple of days I hope to find some time to further explore the features and limitations of the cmis root object, for example how to execute queries, how to set up a remote connection, or even how to create or update content, folders, properties and aspects.
References
The cmis root object does not seem to be extensively documented in the alfresco documentation. Exploring the documentation of the Alfresco OpenCMIS Extension can be very helpful to lookup the available objects and methods. You can adjust them to meet the conventions of either the JavaScript controller or the Freemarker view.
Updates
- February 2, 2012: added accessing properties by name.
References
-
together12up likes this
-
keynotetis8 likes this
-
bpeters posted this