JavaScript API

cancel
Showing results for 
Search instead for 
Did you mean: 

JavaScript API

resplin
Intermediate
0 0 10.5K

{{Obsolete}}

Note: This topic has been added to the official documentation, and so this page is no longer maintained. The official documentation for the Alfresco APIs is here:
http://docs.alfresco.com/5.0/concepts/API-intro.html




The JavaScript API is improved and enhanced in each version of Alfresco.


Specific API documentation for versions older than 4.0 JavaScript_API_Old_Pages.


Introduction


The Alfresco JavaScript API allows script writers to develop JavaScript (ECMA Script) 1.7 compatible files that access, modify, and create Alfresco repository objects. It provides a clean and simple object-oriented API to well known Alfresco concepts such as Nodes, Properties, Associations, and Aspects. The API is similar to the Alfresco Template API - with a significant difference in that it allows modification and creation of nodes, aspects, and properties.

Using the API script writers can:


  • find nodes (via XPath and directly via NodeRef or path)
  • perform searches (including Lucene full-text searches, with sorted results)
  • walk node hierarchies
  • examine and modify the value of properties, aspects and associations
  • transform and manipulate content
  • create Groups, People and modify permissions

In addition, scripts can create new files, folders, or nodes of any type, copy/move/delete nodes and create/modify/remove child and target associations between nodes. All the usual Alfresco security and ACL permissions apply.

Scripts can also include (or 'import') other scripts. The developer can build libraries of scripts that are included at runtime to reduce copy/paste between script files.

As JavaScript is a standards based language (also known as ECMA Script) there are many web resources, online tutorials and books to help developers in writing JavaScript files. It is suggested that potential script writers read up on JavaScript resources before attempting to script the Alfresco repository.

A good general JavaScript reference can be found on the Mozilla site.

The integrated JavaScript engine in Alfresco utilises the Mozilla Rhino JavaScript Engine for Java. This allows JavaScript 1.7 (ECMA Script) files to access Alfresco Java objects using a simple bean-style notation and interpreted mode execution without compiling to external class files.

A mechanism for adding and configuring additional scripting engines exists. It is possible to completely replace or augment the existing script engines with others such as PHP or Ruby. The correct scripting implementation will be automatically selected by the ScriptService when executing a script file based on the file extension of the script being executed. If it cannot resolve the engine to use, then the developer can specify it explicitly when calling the ScriptService. By default only JavaScript is available and this is the API documented here. However a Java-based PHP scripting engine is also provided as an additional AMP download.

Note: There are many example scripts illustrating the API in the JavaScript API Cookbook.

Please see the links at the top of the page for the appropriate API page for your Alfresco version.