FreeMarker methods for the AVM repository

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.

AVM API

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 repository
  • lookupStore(storeid): This returns the store object for the specified store ID
  • lookupStoreRoot(storeid): This returns the root node for the specified store ID
  • lookupNode(path): This returns a single AVM node based on the given full path including store to the node
  • webappsFolderPath(storeid): This returns the root path to the AVM webapps folder for the specified store ID
  • getModifiedItems(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 store
  • stagingStore(storeId): This returns the Staging Sandbox store for the specified store ID
  • avm.userSandboxStore(storeId, username): This returns the User Sandbox store for the specified user and store
  • websiteStagingUrl(storeId): This returns the preview URL to the Staging Sandbox for the specified store ID
  • websiteUserSandboxUrl(storeId, username): This returns the preview URL to the User's Sandbox for the specified store ID and username
  • assetUrl(path): This returns the preview URL to the specified fully qualified AVM path for the asset node
  • assetUrl(storeId, path): This returns the preview URL to the specified store and asset path

AVM store API

When 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 store
  • name: This returns the name of the store
  • creator: This returns the user who has created this store
  • createdDate: This returns the date on which the store was created
  • lookupRoot: This returns the root node for the store
  • lookupNode(path): This returns the node for the specified path relative to avm webapps root folder for the store
  • luceneSearch(query): This executes the Lucene Search query against the store and returns the search results as a sequence of nodes

AVM node API

Following 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.

Response status

Web script response is used to inform the status to the client. It uses HTTP response status code for the following scenarios:

  • To inform the client about the cause of an error
  • To inform the client about the occurrence of an event
  • To instruct a client to perform a follow-up request
  • To inform a client about the success of a web script

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:

  • Web script-specific template named<scriptid>.<method>.<format>. <code>.ftl
  • Web script-specific template named<scriptid>.<method>.<format>.status.ftl
  • Package-level template named<format>.<code>.ftl
  • Package-level template named<format>.status.ftl
  • Default template named<code>.ftl
  • Default template named status.ftl

Web script controller

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.

Objectives of a controller

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:

  • JavaScript controller
  • Java-backed controller

In the following sections, we will talk about these both in detail.

JavaScript controller

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset