JavaScript API

From alfrescowiki

Jump to: navigation, search

The JavaScript API is identified for a number of versions.

Versions

  • Next version of Alfresco - not yet diverged from 4.0

Introduction

The Alfresco JavaScript API allows script writers to develop JavaScript (ECMA Script) 1.6 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
  • process WCM Web Projects and AVM objects
  • 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.6 (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.

Personal tools
Download and go
© 2014 Alfresco Software, Inc. All Rights Reserved. Legal | Privacy | Accessibility