In Part One we covered the default installation of Alfresco and in Part Two we covered a JBoss installation. Now we’re going to look at how you would handle linking up your own web application with Alfresco web client.

The structure of the Alfresco repository is similar to that of nested folders or nodes. You start with a root folder and then add sub folders that can contain content or more folders. In Alfresco these folders are called spaces. Each space or piece of content has its own node reference.

In our scenario you have a standalone web application and want to be able to link to Alfresco’s Web Client from it. Alfresco will then handle all the content management functionality. You have objects in your web application for which you want a corresponding workspace in Alfresco to contain any content for that object. The functionality you need to add to your web application is:

1. When an object is created, create a corresponding workspace for that object in Alfresoc and retrieve the node reference for that workspace.
2. Store the objects and matching node references (you will need to do this yourself).
3. Select an object in your web application, get the node reference for the workspace in Alfresco, and open a new tab/window to view/update that workspace in Alfresco.
4. You also want to bypass the Alfresco login page / authentication in all these scenarios so the user doesn’t have to enter login details.

At a minimum you will need the following jars in your web application:

(jaxrpc.jar should already be available in a jboss application)

Depending on the jar files already included in your application you may need to add some more jars.

We’ll start with authenticating a web service call that will create a new space. To use a web service api you need to authenticate your session.

Authentication for web service API:

// Start the session
AuthenticationUtils.startSession(“admin”, “admin”);

try {
// Make your web service call in here
catch (Throwable e) {
finally {
// End the session

To create a workspace called “child” in the “parent” workspace using a web service call:

// The default workspace store is SpacesStore
Store storeRefence = new Store(Constants.WORKSPACE_STORE, “SpacesStore”);

// We want to create a new folder or workspace called child in the parent folder under company home
// Create parent reference to the parent space in company home
ParentReference parentReference = new ParentReference(storeReference, null, “/app:company_home/cm:parent”,
Constants.ASSOC_CONTAINS, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, “sample_folder”));

// Create the child folder
NamedValue[] properties = new NamedValue[] { Utils.createNamedValue(Constants.PROP_NAME, “Child Folder”) };
CMLCreate create = new CMLCreate(“1”, parentReference, null, null, null, Constants.TYPE_FOLDER, properties);
CML cml = new CML();
cml.setCreate(new CMLCreate[] { create });
UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml);

// From the result of the web service call we want to retrieve the node reference for the child folder so we can access it later
String childReference = results[0].getDestination().getUuid();
System.out.println(“Created a new workspace, node is: ” + childReference);

In Part Four we will handle generating a url to access the space we have just created and bypassing the login page when accessing the url.