jquery-cmisHere's a handy tip:

When developing web applications on top of the Alfresco platform, use jQuery and the built-inCMIS API to query nodes in the repository.

CMIS, which stands for Content Management Interoperability Services, is a standard that describes what you can do with items in a content management system. This includes actions like searching, querying metadata, updating or deleting content, and so on. It's an extension to AtomPub, meaning you perform these operations by posting XML-based requests to HTTP endpoints, which Alfresco provides via webscripts in versions 3.3 and higher.

jQuery is my favorite JavaScript library for performing asynchronous HTTP requests and has been steadily improving its XML support over the past two years. In the software development world, XML responses are notoriously wordy and CMIS responses are no exception. jQuery's powerful Selector notation can be used to find the elements you're looking for and makes working with CMIS a breeze.

To find any node property, for instance, query the "api/node" GET webscript. Say you have a string JavaScript variable called "nodeRef" that looks something like "workspace://SpacesStore/01234567-89ab-...". The following shows how to retrieve the "cm:name" property ("cmis:name", in CMIS terminology) from that node using jQuery and CMIS:

$.ajax({ dataType: "xml", url: Alfresco.constants.PROXY_URI + "api/node/" + nodeRef.replace("://","/"), success: function(doc) { var name = $(doc).find("propertyString[queryName='cmis:name']").text(); console.log("node name: " + name); } });

Likewise, to find the parent of a node, append "/parent" to the previous URL, like so :

$.ajax({ dataType: "xml", url: Alfresco.constants.PROXY_URI + "/api/node/" + nodeRef.replace("://", "/") + "/parent", success: function(data) { var parentNodeRef = $(data).find('[propertyDefinitionId="cmis:objectId"]').text(); console.log("parent nodeRef: " + parentNodeRef); } });

While this may be overkill for many apps and not ideal for situations where bandwidth is a limited resource, it's great for prototypes and one-off situations where you need to query a property here and there.

To find out more about the types of CMIS operations and queries you can do using Alfresco, check your server's webscript console at:

http://<server>:<port>/alfresco/service/index http://<server>:<port>/alfresco/service/index/family/CMIS

Extended information is provided for each service endpoint. For example, the "api/node" GET webscript can be viewed at:

http://<server>:<port>/alfresco/service/script/org/alfresco/cmis/item.get

Happy querying!


Loading Conversation