Each of these root objects has different APIs. For more detail on this you can refer Alfresco wiki's Template Guide page at http://wiki.alfresco.com/wiki/Template_Guide and see some examples at http://wiki.alfresco.com/wiki/FreeMarker_Template_Cookbook. In this section, we will talk about the FreeMarker APIs available for the AVM repository.
As stated earlier, avm
is the root object for FreeMarker templates; with this root object, you can access the AVM repository. The available APIs for an AVM root node are as follows:
stores:
This returns all store objects in the AVM repositorylookupStore(storeid):
This returns the store object for the specified store IDlookupStoreRoot(storeid):
This returns the root node for the specified store IDlookupNode(path):
This returns a single AVM node based on the given full path including store to the nodewebappsFolderPath(storeid):
This returns the root path to the AVM webapps
folder for the specified store IDgetModifiedItems(storeId, username, webapp):
This returns a sequence of nodes representing modified items for the specified User Sandbox store for a specific webapps folder in the storestagingStore(storeId):
This returns the Staging Sandbox store for the specified store IDavm.userSandboxStore(storeId, username):
This returns the User Sandbox store for the specified user and storewebsiteStagingUrl(storeId):
This returns the preview URL to the Staging Sandbox for the specified store IDwebsiteUserSandboxUrl(storeId, username):
This returns the preview URL to the User's Sandbox for the specified store ID and usernameassetUrl(path):
This returns the preview URL to the specified fully qualified AVM path for the asset nodeassetUrl(storeId, path):
This returns the preview URL to the specified store and asset pathWhen you use any of the AVM APIs mentioned in the previous section, you will get the object of an AVM store. This store object can have the APIs described below:
id:
This returns the internal ID of the storename:
This returns the name of the storecreator:
This returns the user who has created this storecreatedDate:
This returns the date on which the store was createdlookupRoot:
This returns the root node for the storelookupNode(path):
This returns the node for the specified path relative to avm webapps
root folder for the storeluceneSearch(query):
This executes the Lucene Search query against the store and returns the search results as a sequence of nodesFollowing are the APIs for an AVM node:
version:
Returns the node's version, generally it will be -1 (Head revision).path:
Returns fully qualified AVM path to the node.parentPath:
Returns fully qualified AVM path to the parent of the node.isDirectory:
Returns true
if this node is a directory.isFile:
Returns true
if this node is a file.isLocked:
Returns true
if this node is currently locked.isLockOwner:
Returns true
if this node is locked by the current user.hasLockAccess:
Returns true
if this user has the permission to perform operations on the node when locked. This is true if the item is either unlocked, locked by the current user, or locked and the current user has the Content Manager role in the associated web project.rename(name):
This renames the node.Web script response is used to inform the status to the client. It uses HTTP response status code for the following scenarios:
To set this status code, the status root object is available in the web script. And if you are using a Java-backed web script, then overload the API with status
as one of the parameters. In the script, you can use the status code as follows:
status.code = 400; status.message = "Required parameter's value has not been provided."; status.redirect = true;
When you redirect like this, it will render the custom response template for the specified code. Searching of corresponding status templates will be performed in the following order:
<scriptid>.<method>.<format>. <code>.ftl
<scriptid>.<method>.<format>.status.ftl
<format>.<code>.ftl
<format>.status.ftl
<code>.ftl
status.ftl
In this section, we will discuss about the web script controller. Controller is an optional attribute of any web script. If you don't need it, you can omit this section.
This is an optional component of a web script, but generally used when you want to access the repository and perform certain operations. Similar to the role of a controller in the MVC architecture, here also the main objective of the controller is to dictate what to do behind the scenes and what to display in the view. The controller builds a data model that is passed to the FreeMarker response templates and rendered. Web scripts in Alfresco support two types of controllers:
In the following sections, we will talk about these both in detail.
A controller is used in order to perform some business logic, and one of the available controllers is JavaScript, which is also known as execution script. You need to follow the naming convention for a web script execution script, which is:
<serviceId>.<httpMethod>.js
where serviceId
is the web script ID and httpMethod
can be GET, POST, PUT
, or DELETE
.
For example, if we have a web script that is responsible for getting the news, we can have the filename as getNewsHeadline.get.js
.