Professional Documents
Culture Documents
DZone
#126
Get More Refcardz! Visit refcardz.com brought to you by...
Liferay Essentials
CONTENTS INCLUDE:
n
Introduction
n
Web Content Management
n
Workflow
n
n
Liferay Administration
Develop for Liferay
A Definitive Guide for Enterprise Portal Development
Hot Tips and more...
By James Falkner
n
diagram illustrates only users and their collections. Permissions Text Area (HTML) $textarea.data
do not flow through all of these collections; permissions can be Checkbox $checkbox.data
assigned to roles only.
Selectbox $selectbox.data
Repeatable $el.siblings
Communities that have a common interest. company The current company object. This represents the portal instance on
which the user is currently navigating.
• Within Organizations and Communities, users can belong companyId The current company ID.
to Teams, which are groupings of users for specific functions
groupId ID of the group in which this web content is published.
within a community or organization.
locale The current user's locale, as defined by Java.
• Users, Organizations and Communities have two separate
randomNamespace A randomized string. It is very useful for creating IDs that are
collections of Pages called Public and Private Pages. Each guaranteed to be unique.
page can have as many applications (portlets) as desired. The browserSniffer Dynamic browser capabilities. e.g.$browserSniffer.isMobile()
page administrator can lay out these applications into zones portal Current portal instance
defined by a default or customized layout template.
portletURLFactory Creates portlet URLs (action URLs, etc)
Liferay’s Web Content Management (WCM) is a system which renderRequest* Standard Portlet RenderRequest object
allows non-technical users to publish content to the Web without renderResponse* Standard Portlet RenderResponse object
having advanced knowledge of Web technology or programming themeDisplay* Contains many useful items, such as the logged in user, the layout,
logo information, paths, and much more.
of any sort. Liferay Content Management System (CMS)
empowers you to publish your content with a simple point-and- user* The User object representing the current user.
click interface, and it helps you to keep your site fresh. layoutSet* The set of pages to which the user has currently navigated. Generally,
communities and organizations have two: a public set and a private set.
You can use WCM to author both structured and unstructured scopeGroupId* groupId that is used to identify the scope where the data of the
content. Unstructured content is authored using an HTML-based current portlet is stored and retrieved. The scope can represent a
community, organization, user, the global scope, or a scope tied to a
WYSIWYG editor. Structured content is authored and displayed by specific page.
combining Web Content Structures, Web Content Templates, and timeZone* The current user's time zone, as defined by Java.
Web Contents. Structures and Templates are defined individually viewMode e.g. “print” when clicked print icon
using a text editor or through the Liferay WCM UI.
fullTemplatesPath* Path to all templates used.
other template languages such as FreeMarker, XSL, or CSS have prefsPropsUtil Access to portal settings that were set from the Control Panel or
through the portal.properties configuration file.
similar constructs). The variable name defined in the structure are
permissionChecker An object which can determine given a particular resource whether or
denoted in bold and will be different depending on the name not the current user has a particular permission for that resource.
assigned in the structure. [css|images|javascrip Full path to various theme files
Element Type Velocity Template Accessors t|templates]_folder*
Example Task
WORKFLOW <task>
<name>MyTask</name>
<due-date-duration>12</due-date-duration>
<due-date-scale>day</due-date-scale>
A Liferay Workflow is a predetermined sequence of connected <actions>
steps. In Liferay, workflow is designed to manage the creation, <notification>
<name>A Notification</name>
modification, and publication of all supported web content <execution-type>onAssignment</execution-type>
<template>You have a new task</template>
types (including Web Content, Blogs, Wikis, Message Boards, <template-language>text</template-language>
Documents, and other user-generated content). Liferay ships <notification-type>email</notification-type>
</notification>
with a default workflow engine called Kaleo. It can generate and </actions>
<assignments>
reference roles scoped for Organizations, Communities, and for <roles>
<role>
the entire Portal. This engine is deeply integrated with Liferay, <role-type>community</role-type>
but can be replaced with an external engine, such as jBPM. <name>Community Administrator</name>
</role>
</roles>
Kaleo Workflow Definitions </assignments>
<transitions>
Liferay comes with a default Kaleo workflow definition called <transition>
“Single Approver” that means that a single approval is needed <name>Transition1</name>
<target>state1</target>
before content is published. You can create custom workflow <default>true</default>
</transition>
definitions by using the APIs and workflow definition format <transition>
provided. An example skeleton of a simple workflow is shown <name>Transition2</name>
<target>state2</target>
below: <default>false</default>
</transition>
<workflow-definition> </transitions>
<name>MyName</name> </task>
<version>1</version>
<state>
</state> Notable Elements Options
<state>
</state> <due-date-duration> Defines when the task is due
<task>
</task> <due-date-scale> second, minute, hour, day, week, month, year
<task>
</task> <roles> Users who have this role can be assigned this task
</workflow-definition>
<role-type> regular, community, organization
To use a particular database, you must set the following four Logging Configuration
properties in your portal-ext.properties. Liferay uses Log4j for its logging operations. When debugging an
issue, it is useful to be able to increase verbosity of certain areas
MySQL Example:
of Liferay to diagnose an issue. There are two ways to do this:
1. jdbc.default.driverClassName=com.mysql.jdbc.Driver
2. jdbc.default.url=jdbc:mysql://localhost/lportal?
useUnicode=true&characterEncoding=UTF- Interactively
8&useFastDateParsing=false
3. jdbc.default.username=
Interactively changing the log levels will only persist until the
4. jdbc.default.password= next system restart, when the log level settings will revert to
their previous values. This is done through the Control Panel->
Oracle Example:
Server Administration -> Log Levels user interface.
jdbc.default.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.default.url=jdbc:oracle:thin:@localhost:1521:xe
jdbc.default.username=lportal
Config File
jdbc.default.password=lportal To make a more permanent change, copy Liferay’s default META-
INF/portal-log4j.xml file from the portal-impl.jar, rename to
It’s also possible to delegate this configuration to the application
portal-log4j-ext.xml, make any edits, and place the file
server through a DataSource by using the following property:
somewhere along the servers classpath. For example, if you
jdbc.default.jndi.name=NameOfDataSource
were using Tomcat, one could create
${TOMCAT_DIR}/lib/META-INF/portal-log4j-ext.xml.
App Server Configuration
Liferay is supported on the following app servers or servlet For example, to enable debug logging for Hibernate, add this
containers: Geronimo, GlassFish, JBoss, Jetty, JOnAS, to your portal-log4j-ext.xml file:
Oracle, Resin, Tomcat, WebLogic, and WebSphere. Consult
<category name=”org.hibernate”>
your app server documentation for details on configuration. <priority value=”DEBUG” />
</category>
The following table lists common files that are involved in
configuring your app server.
Tomcat 6.x Location JBoss includes its own Log4j configuration that may
Global Libraries ${TOMCAT_DIR}/lib/ext Hot override Liferay’s configuration. The JBoss Log4j
Portal Libraries ${TOMCAT_DIR}/webapps/ROOT/WEB-INF/lib
Tip configuration file can be found in $JBOSS/server/default/
conf/log4j.xml. Read the JBoss documentation for details.
Primary Configuration ${TOMCAT_DIR}/conf/server.xml
Primary Configuration ${GLASSFISH_DOMAIN_DIR}/config/domain.xml liferay.home Specifies the root of Liferay’s working directory /
Default: Depends on App Server configuration. Example: /var/lr-home
Primary Log Files ${GLASSFISH_DOMAIN_DIR}/logs/server.log
portal.ctx Specifies the path of the portal servlet context. If you
JBoss 5.x Location Default: / change this, you must also change the setting in web.xml
Example: /mysite
Default Instance Directory ${JBOSS_DIR}/server/default
jdbc.default.jndi.name Set the JNDI name to lookup the JDBC data source. If
Global Libraries ${JBOSS_INSTANCE_DIR}/lib
Default: Not Set none is set, then Liferay will attempt to create the JDBC
Portal Libraries ${JBOSS_INSTANCE_DIR}/deploy/ROOT.war/WEB-INF/lib data source based on the properties prefixed with jdbc.
default. Example: jdbc/LiferayPool
Primary Configuration ${JBOSS_INSTANCE_DIR}/conf/jboss-service.xml
jdbc.default.driverClassName Database configuration options for creating the Liferay
Primary Log Files ${JBOSS_INSTANCE_DIR}/log/server.log ${JBOSS_INSTANCE_
jdbc.default.url Database connection pool
DIR}/log/boot.log
jdbc.default.username
jdbc.default.password
Troubleshooting and Debugging Defaults: settings for HSQL
The following items should be checked when troubleshooting company.default.web.id Default Web ID. Omni administrators must belong to this
a problem. Default: liferay.com company. Example: mycompany.com
Item Notes
Log Files Log files for several app servers are listed above. These should be checked for DEVELOPING FOR LIFERAY
warnings, errors, Java stack traces, etc.
Log Settings Liferay uses the Apache Log4j library to perform all of its logging operations.
See below on how to configure log settings. You can develop many things both for and in Liferay: portlets,
JMX Liferay provides out-of-the-box JMX MBeans, which allow introspection into
hooks, themes, layout templates, services, and more.
the runtime, for example to identify and isolate problematic behavior such as
poor cache performance or slow portlet rendering.
Plugins SDK
The Plugins SDK is both a project generator and a location
Debug To attach a Java debugger to Liferay, you must start the JVM with special
properties. Some servers have done this for you. For example, to start Tomcat where your projects are stored. Download the Plugins SDK
under a debugger, run “bin/catalina.sh jpda start” from liferay.com/downloads/liferay-portal/additional-files.
Other servers may need the JVM properties added manually. A typical set of
properties is: Do not forget to create a build.username.properties file (where
-Xdebug username is your OS username). Set the app.server.dir
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
property to point at an extracted Liferay/App Server bundle.
For example, app.server.dir=${user.home}/lr-6.0.5.
Building projects in the Plugins SDK requires that you have Ant Services
1.7.0 or higher installed on your machine. Download the latest By wrapping services it’s possible to extend any core Liferay
version of Ant from http://ant.apache.org/. service method to perform additional operations or even to
replace the default operations.
Creating and Deploying New “Hello World” Plugins
<hook>
Use the “create” script for creating new portlet, theme, hook, <service>
layout, or Web plugins: <service-type>
com.liferay.portal.service.UserLocalService
</service-type>
$ cd portlets; ./create.sh hello-world “Hello World Portlet”
<service-impl>
$ ant deploy
com.liferay.test.hook.service.impl.MyUserLocalServiceImpl
</service-impl>
Other ANT targets include: </service>
</hook>
Clean: removes build artifacts.
War: creates distributable .war file. Liferay Themes
Compile: compiles source code. Themes are plugins, and are therefore hot-deployable just like
uild-service: invokes Liferay’s Service Builder to create and
b portlet plugins. You can use the Plugins to build your themes
build service source code. automatically so that they can be deployed to any Liferay
instance. The Plugins SDK packages a theme into a .war file
Anatomy of a Portlet Project
just like a portlet, and this .war file can then be hot-deployed
Several directories and files are created when you use the
to Liferay.
create.sh tool.
Folder Description Anatomy of a Theme
docroot This folder is the “root” of your application. Path within Theme Description
WEB-INF Standard WEB-INF folder for Web applications. Also contains Liferay- /css/base.css, custom.css, … Defines many aspects of Liferay’s UI. To override, create your
specific descriptors. own _diffs/css/custom.css within your theme source code
WEB-INF/src Portlet source code. /images/ Static image resources references from CSS, JS, VM, etc.
build.xml ANT build script controlling building and deploying your plugin. /javascript/main.js Defines stub functions that fire at certain points of page
loading when using theme. Override using custom main.js
liferay-display.xml Describes what category the portlet should appear under in the Liferay UI.
/templates/ Various Velocity Macro Templates that are executed during
liferay-plugin- Describes properties used by Liferay’s hot-deploy mechanism. page rendering
package.properties
init-custom.vm Allows you to add your own custom Velocity variables
liferay-portlet.xml Describes Liferay-specific portlet enhancements (akin to portlet.xml for
generic portlets). There are many settings here to customize your portlet. init.vm Sets many Velocity variables that correspond to Liferay
Java objects. See the section on Web Content for common
portlet.xml Standard JSR-168 or JSR-286 portlet descriptor
variables available from your custom theme code.
web.xml Standard Web Application descriptor
navigation.vm Implements the page navigation within the theme
Liferay Hooks portal_normal.vm The overall template for all pages the theme implements. This
file includes the other files.
Hooks are the best way to extend or modify Liferay’s behavior.
They allow you to override parts of core Liferay with custom portal_pop_up.vm The overall template for any portlets which implement pop-
up windows.
implementations. You specify what you wish to hook into in
portlet.vm The template for portlet windows within the theme.
your liferay-hook.xml file. Within this file, you can customize:
Portal Properties
Service Builder
<hook>
<portal-properties>my.custom.portal.properties</portal-properties> Service Builder is a source code
</hook>
generation tool built by Liferay to
Within custom properties files, add startup action: automate the creation of interfaces
and classes for database persistence,
application.startup.events=org.mypkg.MyStartupEventClass
local and remote services. This is useful
Add Model Listener for Blogs: when developing data-driven applications
value.object.listener.com.liferay.portlet.blogs.model.BlogsEntry=org.mypkg.
that make frequent calls to the underlying
BlogEntryAction database.
Language Properties
<hook>
A “service” in Liferay is simply a class or set of classes
<language-properties>content/Language_fr.properties</language-properties> designed to handle retrieving and storing data classes. A
</hook>
Hot local service is used by code running in the local instance
JSP File Override Tip of Liferay, while a remote service can be accessed from
Allows overriding of any JSP from the core of Liferay by using anywhere over the internet or your local network. Remote
the same paths as Liferay uses within the specified directory. services support SOAP, JSON, and Java RMI.
Use with care:
Sample Service
<hook>
<custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir> Services are defined by creating a service.xml file. Once
</hook>
defined, source code can be generated for the persistence and
Then create custom JSPs: data access/transfer layers of your Data-driven app. An example:
/META-INF/custom_jsps/html/portlet/blogs/view.jsp
/META-INF/custom_jsps/html/portlet/calendar/week.jsp
<service-builder package-path=”com.sample.portlet.library”> plid A Portal Layout ID. This is a unique identifier for any page that exists in
<namespace>Library</namespace> the portal, across all portal instances.
<entity name=”Book” local-service=”true” remote-service=”true”>
<!-- PK fields --> layoutTypePortlet This object can be used to programmatically add or remove portlets
<column name=”bookId” type=”long” primary=”true” /> from a page.
<!-- Group instance -->
<column name=”groupId” type=”long” /> scopeGroupId A unique scope identifier for custom scopes, such as the page scope
<!-- Audit fields -->
that was introduced in Liferay Portal 5.2.
<column name=”companyId” type=”long” />
<column name=”userId” type=”long” />
permissionChecker An object that can determine, given a particular resource, whether or
<column name=”userName” type=”String” />
<column name=”createDate” type=”Date” /> not the current user has a particular permission for that resource.
<column name=”modifiedDate” type=”Date” />
<!-- Other fields --> locale The current user's locale, as defined by Java.
<column name=”title” type=”String” />
</entity> timeZone The current user's time zone, as defined by Java.
</service-builder>
theme An object representing the current theme that is being rendered by
the portal.
Generating the Code
colorScheme An object representing the current color scheme in the theme that is
$ ant build-service being rendered by the portal.
JSP Variable Reference portletDisplay An object that gives the programmer access to many attributes of the
current portlet, including the portlet name, the portlet mode, the ID of
To get access to Liferay contextual objects when writing a JSP: the column on the layout in which it resides, and more
<liferay-theme:defineObjects />
Social Tools and Activity Streams
Then, the following variables are available to your JSP: Liferay’s portal, content, and collaboration frameworks are tied
Variable Name Description
together using a rich suite of social features. For developers,
plugging social software into Liferay can be achieved in many
themeDisplay A runtime object which contains many useful items, such as the logged-
in user, the layout, logo information, paths, and much more. ways. For example, using the native Social Relationship API for
company The current company object. This represents the portal instance on
managing relationships between users (via the com.liferay.portlet.
which the user is currently navigating. social package), interacting with the Activity Stream (via the
account The user's account object. This object maps to the Account table in the SocialActivity model), calculating and visualizing Social Equity
Liferay database. participation and contribution values, or dropping OpenSocial
user The User object representing the current user. gadgets onto a page and managing via Liferay’s Control Panel.
realUser When an administrator is impersonating a user, this variable tracks the
administrator's user object. More Information
contact The user's Contact object. This object maps to the Contacts table in the For up-to-date and in-depth information, please refer to the
Liferay database.
official documentation for Liferay at http://www.liferay.com/
layout The set of pages to which the user has currently navigated. Generally, documentation.
communities and organizations have two: a public set and a private set.
#82
Browse our collection of more than 100 Free Cheat Sheets
Get More Refcardz! Visit refcardz.com
CONTENTS INCLUDE:
■
■
About Cloud Computing
Usage Scenarios Getting Started with
Aldon Cloud#64Computing
■
Underlying Concepts
Cost
by...
■
Upcoming Refcardz
youTechnologies ®
■
Data
t toTier
brough Comply.
borate.
Platform Management and more...
■
Chan
ge. Colla By Daniel Rubio
on:
dz. com
grati s
also minimizes the need to make design changes to support
CON
ABOUT CLOUD COMPUTING one time events. TEN TS
INC
s Inte -Patternvall
■
HTML LUD E:
Basics
Automated growthHTM
ref car
Windows Phone 7
Usef
ContiPatterns an
■
However, the demands and technology used on such servers faced by web applications.Structure Tools
Core
Key ■
Structur Elem
has changed substantially in recent years, especially with al Elem ents
n
ratio the entrance of service providers like Amazon, Google and Large scale growth scenarios involvingents
specialized
and mor equipment
rdz !
HTML
Change Microsoft. e chang
es e... away by
(e.g. load balancers and clusters) are all but abstracted
to isolat
erns space relying on a cloud computing platform’s technology.
CSS3
n
Re fca
riptio e Work
These companies Desc have a Privat
are in long deployed trol repos
itory
webmana applications
ge HTM
lop softw n-con to L BAS
that adapt and scale
Deve
les toto large user
a versio ing and making them
bases, In addition, several cloud computing ICSplatforms support data
rn ize merg
Patte it all fi minim HTM
more... ine to le
e Work knowledgeable in amany
space Comm
mainl aspects related tos multip
cloud computing. tier technologies that Lexceedand XHT the precedent set by Relational
re
Repo
This Refcard active
will introduce are within
to you to cloud riente computing, with an
ION d units etc. Some platforms ram support large grapRDBMS deployments. The src
dy Ha
softw
EGRAT e ine loping task-o it and Java s written in hical on of
all attribute
softwar emphasis onDeve es by
Mainl
INT these ines providers, so youComm can better understand
also rece JavaScri user interfac web develop and the rris
REST
UOUS
codel chang desc
ding e code Task Level as the
www.dzone.com
JPA 2.0
-patter particu s cies Pay only what you consume
tagge or Amazon’s cloud
the curr you cho platform
computing becisome
heavily based moron very little fine. b></ ed insid
xplained ) and anti “fi x” the are solution duce e imp a></
For each (e.g. WAR
ent stan ose to writ
nden t
es more e
not lega each othe
b> is
text
al Depeapplication deployment
Web ge until
nden a few years
t librari agonmen
t enviro was similar that will software
industry standard and virtualization apparen ortant, the
e HTM technology.
used
to
tterns to pro Minim packa
dard HTM r. Tags
ular con
targe
can rity all depe that all simp s will L t. l, but
es Ant i-pa they
tend
es, but to most phone services:
y Integ alize plans with late alloted resources,
file
ts with an and XHT lify all help or XHTML, Reg ardless L VS XH <a><
etim Centr
end,
Binar
es som cess. practic enting incurred cost
nt
whether
temp
e a single based on
nmen
MLaare your you prov
to be understand of
TML b></
the pro Creatsuchareresources were consumed orthenot.
geme
, in the rily bad
t enviro Virtualization
muchallows physical othe
piece ofr hardware HTML
implem
cy Mana nt targe es to actually web cod ide a solid
d with eficial, but necessa of the ing has
nden rties
d to Depe er
prope into differe itting
chang
utilized by multiple operating
function systems.simplerThis allows ing.resourcesfoundati job adm been arou
pare te builds commo
ben are not Fortuna
late Verifi e comm than on
ality be allocated nd for
o be n com Cloud computing asRun it’sremo
known etoday has changed this. expecte irably, that
befor
They they
etc.
(e.g. bandwidth, elem CPU) tohas
nmemory, exclusively totely
Temp
job has some time
Build
lts whe
ually,
mov used
effects. ed resu The various resourcesPerfo rm a
consumed
Privat
by webperio y, contin
applications
dicall (e.g. nt team Every
page system
individual operating entsinstances. ed to CSS to be, HTML Brow d. Earl . Whi
gration exp
d Builds opme bec y
tend sitory Build r to devel common (HTM . ause ser HTM anded le it
ous Inte web dev manufacture L had very far mor has done
Stage Repo
ce unin bandwidth, memory, CPU) areIntegtallied
ration on a per-unit CI serve basis L or XHT
Continu Refcard
e Build rm an ack from extensio .) All are
e.com
DZone, Inc.
e the to to rate devel
s
efer of CI Gene
ion
Cloud Computing
not
on the
pands
ISBN-13: 978-1-936502-05-9
140 Preston Executive Dr. ISBN-10: 1-936502-05-4
Suite 100
50795
Cary, NC 27513