A few weeks ago when I was working on setting up an Alfresco Community Edition v4.2.c, I came across a problem that took me quite some time. What I will talk about today is the customization of the actions provided by the interface of Alfresco Share. This action was tested on all sub-versions of Alfresco Community Edition 4.2 (a, b, c and d).

Unfortunately, Alfresco Share does not provide function to archive content. To meet this need, I was led to develop an action using the Java-Backed Web Script. This technology is very similar to Web Scripts except that the desired action is written in Java.

This article contains the changes made to the core of Alfresco for the implementation of this action. In an article that will be available soon, I will discuss the changes to do to Alfresco Share to add this new action and make it work. Please also note that in this second article, I will join a zip file containing all the files needed to create the two AMPs and therefore the action.

1. Description of the action

We Assume that your repository is structured as follows:

  • Company Home
    • 00_FirstLevel
      • 001_SecondLevel
    • 01_FirstLevel
    • 99_Archives

The only requirement is to have a folder named 99_Archives. You can change the name of this folder in the Java code.

With this structure, the purpose of the archive action will be to move an element (a file or a folder containing other elements) to the folder named 99_Archives.

In order to do something useful, we can also add other features such as:

  • Each time a user will execute the archive action, a folder named YYYYMMDD (current date) will be created if it does not exist
  • In order to maintain the integrity of the repository, each archived item must keep their own rights
  • All the elements entering into the 99_Archives folder should no longer be editable

2. Operation

The use of Java-Backed Web Script for the creation of actions in Alfresco Share is very useful because it allows access to the entire Java API provided by Alfresco. This allows you to easily develop actions that will be very powerful.

When a user clicks the archive action from the interface of Alfresco Share, a JavaScript file is called. This file is used to record the action that has been requested and tries to process the request. It also uses a generic module provided by Alfresco that allows the execution of a Web Script from its URL. This module then starts the execution of the Web Script which is, in our case, a Java code. Depending on the success or failure of the Java code, the JavaScript file will send to the user a message with the state of the action.

3. Extension of Alfresco

For the development of the archive action, start from the assumption that you already have an Eclipse project (or other IDE) which allow you to create some AMPs (Alfresco Module Packages) for Alfresco and Alfresco Share. It means that you have two project with the following files: build.xml, file-mapping.properties, module.properties and jars to compress JavaScript. If I get a few requests, I could make a new blog about setting up an Eclipse project to completely customize Alfresco or Alfresco Share.

Note these two projects as follows: AlfrescoAMP and AlfrescoShareAMP. ALF_AMP_HOME and SHARE_AMP_HOME references the location of the projects (for example C:/AlfrescoEclipseProjects/AlfrescoAMP).

The first thing to do is to write the Java code. To do this, just created the file:


  • Notice that in the code, there are several methods “setXXX” that will be called automatically by Alfresco to initialize variables that are defined and have the same name
  • As you can see in the Java code, I’ve previously been led to create customized groups (“dbi_read”, “dbi_write”, etc…). It is important to note that to prevent edition of elements in the folder 99_Archives, I created other groups completely equivalent except that I remove the terms “AddChildren”, “Write” and “CheckOut”. All of these groups have been created in ALF_AMP_HOME/config/alfresco/model/permissionDefinitions.xml. There are other ways to do this but this is the one that best suited our needs.

Then you need to tell Spring that we have a new Java class:

This file allows you to set several other context files (e.g. one for each action) in order to separate actions but this is not mandatory.

The definition of the action is in the following file:

Note that each variable that needs to be initialized by Alfresco at the execution of the archive action must be declared in this file.

The last step in the extension of the core of Alfresco is the declaration of the Java-Backed Web Script. As I stated previously, this is done in the same way as the declaration of a classic Web Script:


This concludes the first part of this blog about the modification to bring to the core of Alfresco. The other part of this post will be available soon!