Alfresco 3 Cookbook
Over 70 recipes for implementing the most important
functionalities of Alfresco
BIRMINGHAM - MUMBAI
Alfresco 3 Cookbook
Copyright © 2011 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its
dealers and distributors will be held liable for any damages caused or alleged to be
caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: July 2011
Production Reference: 1180711
Published by Packt Publishing Ltd.
32 Lincoln Road
Birmingham, B27 6PA, UK.
Cover Image by Duraid Fatouhi (email@example.com)
Adline Swetha Jesuthas
Adline Swetha Jesuthas
About the Author
Snig Bhaumik is the Technical Director at InfoAxon Technologies Ltd, based in India. He
is also the Director of Open Source Innovation and heads the Knowledge Management
Practice at InfoAxon – India's first and pioneer Open Source Integration Company.
A computer engineer by education and developer at heart, Snigdhendu has in total
ten years of experience in various technologies such as Alfresco, Liferay, Pentaho,
and Microsoft .NET. An open source enthusiast and regular community participant,
Snigdhendu was the original contributor of Alfresco Calendar component. He specializes
in Knowledge Management and Business Intelligence domains, and is responsible for
designing and architecting KM and BI solution offerings.
My sweet wife Chaitali was so patient with my late nights, and I want to
thank her for her faithful support while writing this book.
I would also like to thank my mother for everything. She has always been the
guiding force for me.
Writing of this book could not have been possible but for the ungrudging
support from my colleagues at InfoAxon.
Finally, I sincerely thank Packt Publishing for giving me the opportunity to
write this book.
About the Reviewers
Piergiorgio Lucidi is an Open Source Product Specialist and a certified Alfresco Trainer
at Sourcesense. Sourcesense is a European Open Source systems integrator providing
consultancy, support, and services around key open source technologies.
He works as a software engineer and has seven years of experience in the areas of
Enterprise Content Management (ECM), system integrations, and web and mobile
He is an expert in integrating ECM solutions in web and portal applications. He regularly
contributes to the Alfresco Community Forum supporting newbie and expert users.
He is a project leader and committer of the JBoss Community; he contributes to some
of the projects of the JBoss portal platform. He is a speaker at conferences dedicated to
Java, Spring Framework, open source products, and technologies.
He is an author and an affiliate partner at Packt Publishing, he has written the technical
book Alfresco 3 Web Services in collaboration with Ugo Cei. He also writes and publishes
book reviews on his website Open4Dev (http://www.open4dev.com/).
I would like to thank Packt Publishing for this great opportunity to work
again in a very interesting project about Alfresco.
Adit Patel has done his Master's in Computer Applications. He started his career with
CIGNEX Technologies in the year 2004. He has successfully handled complex projects
for enterprise customers for implementing enterprise content management systems. He
has helped many enterprise customers migrate from proprietary content management
systems to more efficient and scalable content management systems – like Alfresco. He
holds in-depth knowledge and experience of Alfresco architecture and implementations.
I would like to thank and dedicate my contribution to this book to my guru
H.D.H. Pramukh Swami Maharaj.
Khazret Sapenov, a 20-year veteran of ICT, is the founder and chief technology
officer of Cloudcor, which serves hundreds of enterprise clients and works closely with
a set of managed partners and independent software vendors. In this role, Sapenov is
responsible for leading overall strategy and technology direction across the United States
and Canada, including employees in IT, partner, marketing, operations, and vertical
Sapenov previously served as the corporate director of research and development at
Enomaly, where he was responsible for growing the company's virtualization solutions
business, including development and service delivery.
Prior to working with Enomaly, Sapenov held positions in technology solutions
development in various Fortune 100 companies where he was responsible for global
network, data centers, and information security, help desk, core IT services, and
enterprise line-of-business applications.
Cloudcor's organizations under Sapenov's leadership have developed into one market
and gained wide recognition as thought leader in cloud computing.
Sapenov founded Cloudcor in 2008. Before that, he was in corporate and academic
research roles, covering oil and gas resources prospecting and development. Sapenov
is a graduate of the University of Karaganda, where he received his Master's degree in
I'd like to thank my parents for giving me life and supporting all my
initiatives, my wife Saule and sons Asan and Aidos for being tactful and
quiet when working on this book.
Snehal Shah has served as the manager and architect of the engineering teams for
seven years in the area of internet applications, system software, and legal applications
for customers in the United States, UK, and India.
He is an expert in Content Management Systems (CMS). At CIGNEX, he has successfully
delivered various CMS applications using various open source technologies. Snehal
earned his Bachelor's degree in Computer Engineering from DDIT, India.
Support files, eBooks, discount offers and more
You might want to visit www.PacktPub.com for support files and downloads related to
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at www.PacktPub.com and
as a print book customer, you are entitled to a discount on the eBook copy. Get in touch
with us at firstname.lastname@example.org for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters and receive exclusive discounts and offers on Packt books
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can access, read and search across Packt's entire library of books.
Fully searchable across every book published by Packt
Copy and paste, print and bookmark content
On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view nine entirely free books. Simply use your login credentials for
Table of Contents
Chapter 1: Getting Started
Setting up a database for Alfresco
Installing Alfresco on Windows
Installing Alfresco on Linux
Running Alfresco for the first time
Chapter 2: Creating and Organizing Contents
Chapter 3: Securing and Searching Contents
Creating a space
Uploading a document
Viewing content details
Tagging a document
Making a document versionable
Adding users into groups
Securing your folders
Securing your files
Searching in Alfresco
Performing normal search
Performing advanced search
Using saved search
Table of Contents
Chapter 4: Rules – the Smart Spaces
Understanding the components of a rule
Creating and applying rules
Understanding possible actions of a rule
Chapter 5: Alfresco Administration Console
Chapter 6: Customizing Alfresco Web Client
Chapter 7: Alfresco Content Model
Managing system users
Managing user groups
Exporting Alfresco content packages
Using the Alfresco Node Browser
Configuring the Alfresco Dashboard
Changing the default view of Items in Space contents
Changing languages in the Login page
Changing textbox length and text area size
Controlling the Date Picker
Controlling the sidebar display
Including custom Icons in your Spaces
Changing the default font and color
Creating new custom content type
Displaying custom Content Type while content uploading
Showing custom properties
Creating custom aspects and associations
Showing custom Aspects and Associations
Displaying custom type in Type Specialization
Customizing Advanced Search to include custom content types
Writing and executing scripts
Add/Change contents of a document
Creating a backup copy of a document
Adding a tag to a document
Assigning permissions to a user
Table of Contents
Chapter 9: FreeMarker Templates
Chapter 10: Web Scripts
Chapter 11: Working with Workflows
Chapter 12: Integrating with MS Outlook and MS Office
Chapter 13: Configuring Alfresco E-Mail and File Servers
Chapter 14: Building Alfresco
Creating a FreeMarker template
Displaying all documents in current space
Displaying all versions of a particular document
Displaying all assigned tasks of the current user
Displaying all spaces and sub-spaces recursively
Writing and deploying Web Scripts
Using the Alfresco Web Script browser
Displaying details of documents
Sending e-mails using a mail template
Invoking a workflow
Creating and deploying custom workflows
Using the Alfresco Workflow Console
Integrating Alfresco with Microsoft Outlook
Integrating Alfresco with MS Outlook
Configuring Alfresco to send e-mails
Configuring Alfresco to receive e-mails
Configure and use Alfresco file servers
Installing Subversion client - TortoiseSVN
Downloading Alfresco's source code
Compiling and building Alfresco
Running Alfresco on your machine
Alfresco is the renowned and multiple award-winning open source Enterprise content
management system which allows you to build, design, and implement your very own
You have read a number of tutorials, blogs, and books on Alfresco. Now you're in the real
world, trying to use Alfresco, but you're running into problems with it. This is the book you
want, packed full of solutions that can be instantly applied to this cookbook with its practicalbased recipes and minimal explanation meets that demand.
This Alfresco 3 Cookbook boasts a comprehensive selection of recipes covering everything from
the basics to the advanced. The book has recipes for quickly installing Alfresco in Windows and
Linux and helping you use custom content model, rules, and search. There is also a collection
of recipes focused on creating Scripts, Freemarker templates, Web Scripts, and new workflow
definitions. Steps to integrate Alfresco with other systems like MS-Office are also included.
You will be able to use Alfresco's File and e-mail servers. Finally, step-by-step recipes are
presented to create an Alfresco build environment and compile the source code. This Alfresco
3 Cookbook is perfect for developers looking to start working on Alfresco quickly, gain complete
understanding, write custom implementations, and achieve expertise very easily.
What this book covers
Chapter 1, Getting Started: It introduces Alfresco with brief demonstration of the Alfresco
Explorer application. Get Alfresco downloaded and installed on your machine, and finally be
acquainted with the default distribution and architecture of Alfresco.
Chapter 2, Creating and Organizing Contents: It explains how to use Alfresco as Content
Management System, how to upload or create contents, how to apply tagging or categorization
of content, understand content metadata, use the document versioning capability of Alfresco.
Chapter 3, Securing and Searching Contents: It is about another important aspect of the
Content Management System – Security. It helps you understand how to secure your contents
and folders. How to create users and user groups – and assign permissions for who can do
what. You will also know about the search capabilities offered by Alfresco, how to search
contents and how search works in Alfresco.
Chapter 4, Rules – the Smart Spaces: It will help you learn how to make your Alfresco
repository dynamic, how to implement your business requirements that works automatically
in the repository. You will understand how to create and apply rules in the repository; you will
also be familiar with different actions that can be performed via a rule.
Chapter 5, Administering Alfresco: It contains recipes for administering Alfresco, demonstrating
how to manage users, user groups, create taxonomies, manage content categories. You will also
be aware of how to use the Alfresco Node Browser to view and search contents stored in the
repository. You will also know how to manage your Alfresco explorer dashboard.
Chapter 6, Customizing Alfresco Web Client: Alfresco offers customization of the Web Client
application via a number of XML configuration files. This chapter elaborates various recipes
for changing the view and appearance of the web client, customizing the application as per
your requirements, and so on.
Chapter 7, Alfresco Content Model: Designing and modeling the content properties and
architecture is one of the most important requirements in a content management system.
Alfresco offers dynamic capabilities for designing the content models. Using these recipes you
will be able to understand the core architecture of Alfresco content models, create your own
custom content models, use your custom models in the Alfresco explorer application.
Several example recipes help you implement various functionalities. You will also learn how to
write, execute, and debug scripts written using the APIs.
Chapter 9, Freemarker Templates: Freemarker Template is the presentation layer technology
used in Alfresco applications. The recipes of this chapter would help you understand the
technologies and model behind the Freemarker templates in Alfresco. Several template
examples are included for commonly-used functions such as displaying folder contents,
showing workflow tasks, showing contents recursively, displaying content properties and
details, and so on.
Chapter 10, Web Scripts : Alfresco Web Scripts provide RESTful APIs of the repository services
and functions. The chapter elaborates all related concepts, knowledge and how-to do it
recipes that would help you write, deploy and debug web scripts. You will also understand the
usage of default web scripts library that come with Alfresco. Several sample web scripts are
included, for example sending e-mails using templates, searching and displaying documents,
and so on.
Chapter 11, Working with Workflows: Workflow implementation is one of the major requirements
in a content management system in a business. This chapter would help you understand
the Alfresco business process engine in detail. You will understand how the workflows are
implemented in Alfresco repository along with various components of the workflow engine.
Several detailed examples and recipes are included to guide you create custom workflows,
custom task models, specific resource bundles, customizing the web client to render the custom
tasks and workflows properly. You will also be able to use the Alfresco workflow console interface
which is useful for debugging the task execution within the BPM engine.
Chapter 12, Integrating with MS Outlook and MS Office : Alfresco can be used from several
other applications and interfaces. Being a content management system, it is quite important
to have the Alfresco repository accessibility from some popular content authoring applications
such as Microsoft Office. This chapter helps you integrate the Alfresco repository with MS
Word, Excel, and PowerPoint. Recipes are also included for communicating with repository
directly from any standard e-mail client application such as MS Outlook.
Chapter 13, Configuring Alfresco E-mail and File Servers: The Alfresco repository can act has
file servers as well and you can expose the repository using several other standard protocols
such as FTP, CIFS, WebDAV, and so on. These recipes are a step-by-step guide to configure
these protocols and using the content repository from different systems. From this chapter,
you will also be able to use Alfresco as e-mail server, and e-mails sent to some specific
address will land directly into the repository.
Chapter 14, Building Alfresco: Until now you have used Alfresco as the binary bundle provided
and downloaded. Now you can compile and build Alfresco source code also. Recipes in this
chapter will guide you to get the source from Alfresco source code repository, compile and
build the source code. You can modify Alfresco source code as your will; of course as per
Alfresco license, you should contribute your changes back to Alfresco community.
What you need for this book
The software list for this book is as follows:
MySQL server, MySQL Workbench, MYSQL GUI Tools, SQLYog
WinZIP or WinRAR
MS Office, MS Outlook
Subversion Client – TortoiseSVN
Who this book is for
If you are a software developer interested in content management systems, who wants to
work with Alfresco or is already experienced in Alfresco, this cookbook will get you up and
running quickly. If you want rapid implementation of Alfresco's most important and effective
features then this is the cookbook for you.
In this book, you will find a number of styles of text that distinguish between different kinds of
information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "We choose our InfoAxon folder for this operation."
A block of code is set as follows:
When we wish to draw your attention to a particular part of a code block, the relevant lines or
items are set in bold:
New terms and important words are shown in bold. Words that you see on the screen, in
menus or dialog boxes for example, appear in the text like this: "Go to Company Home and try
to add a new Content.".
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—
what you liked or may have disliked. Reader feedback is important for us to develop titles that
you really get the most out of.
To send us general feedback, simply send an e-mail to email@example.com, and
mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the
SUGGEST A TITLE form on www.packtpub.com or e-mail firstname.lastname@example.org.
If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to
get the most from your purchase.
Downloading the example code
You can download the example code files for all Packt books you have purchased from your
account at http://www.PacktPub.com. If you purchased this book elsewhere, you can
visit http://www.PacktPub.com/support and register to have the files e-mailed directly
Although we have taken every care to ensure the accuracy of our content, mistakes do happen.
If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be
grateful if you would report this to us. By doing so, you can save other readers from frustration
and help us improve subsequent versions of this book. If you find any errata, please report them
by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata
submission form link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded on our website, or added to any
list of existing errata, under the Errata section of that title. Any existing errata can be viewed by
selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt,
we take the protection of our copyright and licenses very seriously. If you come across any
illegal copies of our works, in any form, on the Internet, please provide us with the location
address or website name immediately so that we can pursue a remedy.
Please contact us at email@example.com with a link to the suspected
We appreciate your help in protecting our authors, and our ability to bring you
You can contact us at firstname.lastname@example.org if you are having a problem with any
aspect of the book, and we will do our best to address it.
In this chapter, we will cover the following:
Setting up a database for Alfresco
Installing Alfresco on Windows
Installing Alfresco on Linux
Running Alfresco for the first time
Using Alfresco explorer
Knowing about Alfresco stores
Understanding default space hierarchy
This chapter will demonstrate how to install Alfresco, introduce Alfresco Explorer – the web
client interface for managing the repository, and the applications that are bundled with
Alfresco standard distribution.
Towards the end, you will understand how Alfresco stores and organizes the uploaded contents.
We will also be acquainted with the default spaces that come with the Alfresco repository.
Today, Alfresco is the leading Open Source alternative to Enterprise Content Management –
alternative to Microsoft SharePoint®, Documentum®, Open Text®, and so on. Alfresco is
developed using best-of-breed Open Source technologies such as Spring, Hibernate, Lucene,
modern standards such as JSR-168, JSR-170, Level 2 Web Services, Java Server Faces,
and so on. Alfresco manages almost all types of content within an enterprise – documents,
records, web pages, images, XML documents, or any other files.
Some of the most important capabilities and features of Alfresco are:
Web content management
Clustered and Federated servers
Web 2.0 collaboration
Browser-based UI and desktop integration
JSR, SOAP, REST interfaces
Content Management Interoperability Services (CMIS)
CIFS, SMB, WebDAV, FTP, and IMAP access channels
MS Office® Integration using MS SharePoint Protocol®
Alfresco offers several integrated products and services in the ECM suite.
The core component in the architecture of Alfresco is the Repository. The Alfresco repository
is a collection of services and components. These interact with the Alfresco storage that
consists of the contents and indexes stored in binary format, the RDBMS to store the
transaction data, tasks and business process information, audit statistics, user and group
records, and so on.
On top of the Repository, the Content Platform serves as the podium of all content
management operations. Alfresco Content Platform is one of the most scalable Java
Content Repository (JCR). The Content Repository API for Java (JCR) is a specification
for Java application APIs to access the repositories in a standard and unified manner. The
REST-based lightweight mash up architecture enables Rapid Application Development and
other applications to integrate with the content repository easily.
REST, stands for Representational State Transfer, it is a software
architecture which client programs and server services can interact with on
any standard protocol such as HTTP.
A RESTful web service or RESTful web API is a collection of resources with
three well-defined aspects.
A base URL of the service.
The Internet media type of the data supported and returned by the service,
such as JSON, XML, HTML, and so on.
The set of operations supported by the service using HTTP methods such as
GET, POST, PUT, DELETE, and so on.
We will explore how Alfresco APIs can be exposed as RESTful services in later chapters.
Using the flexible Content Platform, several products and services have been exposed
such as the Web Client (Alfresco Explorer), Collaboration (Share), and Web Content
Earlier called Alfresco Web Client, this application is developed using Java Server Faces
(JSF). Using Alfresco Explorer, you can explore the full repository of the current installation
of Alfresco and perform most of the activities. In future, this application can be phased out
in favor of Alfresco Share. However, Explorer has very wide capabilities for managing the
repository and can be considered as a system administrator tool.
Java Server Faces (JSF) is an MVC structured web application framework
based on Java. It is created to simplify the development of web-based user
For more information on JSF, please see http://www.oracle.com/
If you are using Alfresco with Tomcat, you can invoke the web client in your web browser by the
URL http://localhost:8080/alfresco, or if you are using Alfresco with JBoss, use the
We are here assuming that the Alfresco server is running in your local machine and the web
server is running on port 8080 – this is the default port where the Tomcat or JBoss servers
run, unless you manually change the ports.
A few operations for which you can use the Alfresco Explorer are:
Browsing the repository
Managing (uploading, creating, updating, deleting) the contents (see Chapter 2)
Managing (creating, updating, deleting) the users and groups (see Chapter 3)
Managing the users' permissions (see Chapter 3)
Setting up rules (see Chapter 4)
Running several actions (see Chapter 4)
Starting or executing a workflow (see Chapter 11)
Performing on a task assigned to you (see Chapter 11)
Managing the content categorization (see Chapter 2)
Managing various scripts and templates in the system
We will be discussing how to install and run Alfresco in the next few sections of this chapter.
Share is the Web 2.0 collaboration-based platform providing content management capabilities
with simple user interfaces. It provides users with tools for searching and browsing the
content, displays thumbnails, and onscreen flash previews of standard documents, enables
collaboration between a community of users by various Web 2.0 collaboration tools such as
Wikis, Blogs, and Discussion Forums.
Share provides highly-collaborative content management-controlled around sites and
activities. End users can easily create collaborative sites for projects, departments, locations,
or organization branches. They can invite users to collaborate and participate on contents,
approve and publish contents using rich content modeling and lifecycle management of the
The Share application is accessible at http://localhost:8080/share.
All users have their private dashboard available in the Share platform. A dashboard is a
collection of dashlets – a dashlet is a miniature view of an application or of functionality or
some information. For example, the Tasks dashlet shows all the pending tasks of the current
users with information and controls to manage each of the tasks.
User's workspaces, sites, and site activities
Share enables a collaborative environment in an organization where the participation and
involvement of the users happens around sites. A site can be viewed as a community or group
of users, a department, a branch, or a location of an organization. The most common usage
of site can be project, for example, when you start a new project, you start a site, invite the
members into the site, collaborate amongst yourselves, and produce knowledge and content.
Share normally offers four types of sites - Collaboration Site, Meeting Workspace, Document
Workspace, and Record Management Site. While Collaborative Site is the default type of site
created in Share, Document Workspace is usually created via MS Office®.
Similar to user dashboard, each site also has a dashboard with dashlets such as:
Site profile and colleagues