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.
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:
<shortname>Open CMIS example</shortname>
<description>Open CMIS Example</description>
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:
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
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:
<#list doc.properties as p>
This will output the following information:
You can for example also access a number of properties directly like the
versionLabel. To access a property by
queryName or id, you can use the following method:
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.
- February 2, 2012: added accessing properties by name.