CYAN MAGENTA YELLOW BLACK PANTONE 123 C Books for professionals by professionals ® The EXPERT’s VOIce ® in Open Source Companion eBook Available Java -based Portal Applications Development ™ Dear Reader, Author of Pro Apache XML Business Process Execution Language for Web Services SOA Approach to Integration Congratulations! You are holding a comprehensive guide to the world’s most popular open source portal—Liferay In spite of its growing popularity, Liferay does not come with very much documentation With Practical Liferay, I aim to bridge the gap in understanding between Liferay and its potential users The book describes, in detail, how to develop a practical portal using Liferay It takes you through all the Liferay applications, from chat and messaging to blogs, calendars, wikis, and discussion forums You will learn the purpose of each application; how to install, configure, and manage it; and how to put it to good practical use There are also plenty of helpful tips on content management, user management, and security Liferay application configuration is nontrivial for the first-time user, but this book gives you the answers you need By following the step-by-step instructions provided for each application, you will quickly understand how to configure it to meet your needs Once you have read the book and followed its detailed examples, you will have no difficulty setting up and managing an entire portal consisting of several Liferay applications As you read on, each chapter will help you add features to your portal and tailor them to your own precise requirements After the introductory chapters, you can read each chapter independently of the others This can save you a lot of time in getting your portal up and running as quickly as possible If you would like to evaluate the suitability of Liferay for your next portal development project, you will find Practical Liferay a valuable resource If, on the other hand, you are already using Liferay, it will come in handy as a ready reference on the various Liferay commands and applications And if you are developing a training course on Liferay, you will find it a wealth of useful information Practical Liferay Practical Liferay Liferay Java -based Portal Applications Development ™ A down-to-earth, practical approach to developing full-featured Java™-based web portals with blogs, wikis, and more Poornachandra Sarang Companion eBook Practical Related Titles See last page for details on $10 eBook version www.apress.com 90000 Sarang ISBN 978-1-4302-1847-0 Poornachandra Sarang, Ph.D Shelve in Java Programming User level: Beginner–Intermediate 781430 218470 this print for content only—size & color not accurate spine = 0.885" 384 page count Practical Liferay Java -based Portal Applications Development ™ Poornachandra Sarang, Ph.D Practical Liferay: Java™-based Portal Applications Development Copyright © 2009 by Poornachandra Sarang, Ph.D All rights reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher ISBN-13 (pbk): 978-1-4302-1847-0 ISBN-13 (electronic): 978-1-4302-1848-7 Printed and bound in the United States of America Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark Java™ and all Java™-based marks are trademarks or registered trademarks of Sun Microsystems, Inc., in the United States and other countries Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was written without endorsement from Sun Microsystems, Inc Lead Editor: Steve Anglin Development Editor: Tom Welsh Technical Reviewer: Alexander Wallace Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Project Manager: Richard Dal Porto Copy Editor: Nina Goldschlager Perry Associate Production Director: Kari Brooks-Copony Production Editor: Laura Esterman Compositor: Linda Weidemann, Wolf Creek Publishing Services Proofreader: Dan Shaw Indexer: Ron Strauss Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013 Phone 1-800-SPRINGER, fax 201-348-4505, e‑mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705 Phone 510-549-5930, fax 510-549-5939, e‑mail info@apress.com, or visit http://www apress.com Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use eBook versions and licenses are also available for most titles For more information, reference our Special Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales The information in this book is distributed on an “as is” basis, without warranty Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work To my wife, Nita Contents at a Glance About the Author xix About the Technical Reviewer xxi Acknowledgments xxiii Introduction xxv chapter Introducing and Installing Liferay CHAPTER Creating Portal Pages 31 CHAPTER Managing Portal Users 67 CHAPTER Creating Discussion Forums 99 CHAPTER Facilitating Collaboration 127 CHAPTER Incorporating Blogs 149 Chapter Establishing a Wiki 175 Chapter Implementing a Shared Calendar 205 Chapter Managing Content 229 Chapter 10 Publishing Dynamic Content 261 Chapter 11 Enhancing Your Portal 299 CHAPTER 12 Doing Portal Administration 325 index 345 v Contents About the Author xix About the Technical Reviewer xxi Acknowledgments xxiii Introduction xxv chapter Introducing and Installing Liferay What Is a Portal? Example Portal: Yahoo! Example Portal: Google Kinds of Portals 14 Personal Portals 15 Academic Portals 15 Regional Web Portals 16 Government Web Portals 16 Corporate Web Portals 16 Domain-Specific Portals 16 Sports Portals 17 Portal Advantages 17 Creating a Portal with Liferay 18 Liferay Features 19 Ease of Use 20 Support for a Wide Variety of Applications 20 Liberal Licensing and Open Source Code 20 Extensibility 20 Scalability 20 Internationalization Support 20 Integration with Other Tools 21 Adherence to Industry Standards 21 vii viii ■CO NTENT S Under the Hood 22 Page Internal Structure 22 Page Creation Process 23 Request Handling 24 Installing Liferay 26 Downloading Liferay 27 Setting Up J2SE 27 Setting Up Liferay 27 Testing the Liferay Installation 28 Summary 29 CHAPTER Creating Portal Pages 31 Defining the Securities Portal 31 Access to Critical and Timely Data 32 Timely News Updates 33 Trade Data from Stock Exchanges 33 Expert Analysis 33 Peer-to-Peer Collaboration 34 Creating the Securities Portal 34 Adding a Page 35 Deleting a Page 35 Changing the Page Name 36 Adding Multiple Pages 36 Adding Child Pages 37 Changing the Page’s Display Order 40 Editing a Page 41 Applying Themes 42 Individual Page Themes 44 Installing New Themes 44 Downloading Community Themes 49 Installing Community Themes 50 About the Technical Reviewer Alexander Wallace was born in the city of Saltillo, Coahuila, Mexico, where he went to college and graduated with honors in 1995 as an industrial engineer In 1997 he moved to Austin, Texas, where he worked for multiple companies developing software, architecting enterprise applications, and leading software-development teams In 2006 he moved back to his hometown, where he now owns an enterprise and web software-development company with clients in the United States and Mexico, specializing in the Liferay Portal framework and many other leading Java™ technologies You can reach him at aw@siiesa.com.mx xxi Acknowledgments I would like to acknowledge the efforts of Vijay Jadhav, who provided valuable help in testing the portal developed in this book, validating the setup and configuration procedures described in each chapter, and helping format the manuscript I express my gratitude to the technical reviewer, Alexander Wallace, who did an extremely thorough review of the entire manuscript and provided invaluable comments throughout the editorial process to improve the book’s content I would like to thank Nina G Perry for her efforts in improving the overall quality of the book by doing an excellent job of copy editing the manuscript Finally, I would like to thank the entire Apress editorial team, without whose efforts this book would not have been possible I would especially like to mention Steve Anglin (lead editor), Tom Welsh (development editor), Richard Dal Porto (project manager), and Laura Esterman (production editor), whose constant support made this book possible in a short period of time xxiii Introduction L iferay is a popular open source framework that you can use to create attractive web portals A web portal can consist of a wide variety of applications such as blogs, document management apps, wikis, discussion forums, and shared calendars Liferay lets you offer these kinds of features on your portal by providing a runtime environment for hosting Java™-based portal applications, also known as portlets It offers a container where you assemble the portlets, configure them, and set their look and feel In addition to the portlets offered by Liferay, you have access to third-party portlets created by user communities To create a successful portal based on Liferay, you need a definitive guide that can take you through the various Liferay applications and teach you how to put together a portal quickly and easily Who This Book Is For You are probably reading this book because you are interested in creating your own portal based on Liferay, or because you want to maintain or enhance your existing Liferay portal Either way, this book meets your requirements by covering Liferay and its various applications in depth You’ll get a thorough introduction to the operation and function of a number of Life ray applications, including step-by-step instructions on how to install and use them on your own portal How This Book Is Structured This book is a comprehensive guide to Liferay It deals with every aspect of obtaining, installing, configuring, and maintaining it • Chapter 1, “Introducing and Installing Liferay”: This chapter defines what a portal is, describes the various types of portals, explains their advantages, and gives a brief overview of the various tools available to create them Finally, it introduces Liferay itself You’ll get an introduction to Liferay’s important features and its internal architecture, after which you’ll learn to install and test Liferay on your machine • Chapter 2, “Creating Portal Pages”: This chapter describes the basics for setting up a portal, using a case study that will serve as the example portal throughout the book You will learn to create a portal, define portal pages, set page layouts and themes, and download and install third-party plugins xxv xxvi ■INT ROD UC TION • Chapter 3, “Managing Portal Users”: A portal is used by a number of people, quite likely in a distributed organization But simply creating users is not enough to run a portal efficiently; you need to give your portal an organizational structure, manage user accounts, establish access policies, and more You can also create communities of users who share common interests, e‑mail those communities, send them event reminders, and so on This chapter covers user management in depth • Chapter 4, “Creating Discussion Forums”: This chapter shows you how to set up discussion forums for your users As a portal creator, you can create discussion categories according to the users’ areas of interest You can enable users to create their own discussion threads, to read posts made by others, to comment on existing posts, and to post replies As a discussion-forum facilitator, you can publish a list of recent posts, provide portal statistics, ban and unban users, tag contents, and so on This chapter will help you master all these techniques • Chapter 5, “Facilitating Collaboration”: Using discussion forums is one way to allow user collaboration, but you can also facilitate several other kinds of collaboration in your portal For example, this chapter explains how to let users receive and send e‑mail without leaving the portal You can also allow users to send SMS messages, chat with other online users, and locate users to create their own discussion groups • Chapter 6, “Incorporating Blogs”: This chapter introduces you to Liferay’s application that facilitates blogging You will learn how to set rights and permissions to blog entries and replies, and you’ll discover how to publish a list of recent bloggers and display blog aggregations • Chapter 7, “Establishing a Wiki”: Wikis offer another fashionable way of publishing your knowledge for the benefit of other users In this chapter, you will learn to set up a wiki on your portal You’ll find out how to create nodes, add pages and subpages, set up the pages’ look and feel, assign permissions, manage page hierarchies, track modified pages, get rid of orphan pages, and so on • Chapter 8, “Implementing a Shared Calendar”: As a portal administrator, you might organize events for your portal’s user communities Using shared calendars, you can define and announce such events on your portal You will be able to create single events as well as recurring events And if you move your entire portal from one server to another, you will be able to move the entire event database to a new server • Chapter 9, “Managing Content”: Any large site should be able to accommodate the publication of important documents for its user communities This chapter covers Liferay’s tools for managing documents and images You will learn to set up document libraries, create hierarchies, upload documents, set user permissions, publish a list of recently added documents, create archives, and more ■I N T R O D U C T I O N • Chapter 10, “Publishing Dynamic Content”: This chapter focuses on publishing content that changes periodically, such as news and announcements You’ll find out how to publish and manage such items on your portal • Chapter 11, “Enhancing Your Portal”: As the other chapters have described, Liferay provides a number of applications that you can use to give your portal its core functionality But Liferay has become so popular that many Liferay users have developed useful tools that can help you enhance your portal even further You’ll learn to integrate these external tools into your portal, including applications that other developers have built using the Java Portlet Specification and Google’s Gadgets API • Chapter 12, “Doing Portal Administration”: Any portal requires proper administration And as the number of users grows, administrative tasks become more demanding Fortunately, Liferay provides tools for managing a portal and controlling its activities to ensure user satisfaction In this chapter, you will see how to perform several administrative tasks using Liferay’s admin tools Prerequisites A web developer who creates and maintains web sites will easily be able to create a sophisticated web portal after reading this book Contacting the Author Dr Sarang is a founder and director of ABCOM Information Systems, a firm specializing in IT consulting and training (http://www.abcom.com) You can reach him at drsarang@abcom com for consulting and training assignments Dr Sarang is also associated with the University of Mumbai as a post-graduate faculty member and advisor for Ph.D students For academicrelated work, you can reach him at profsarang@gmail.com xxvii chap ter Introducing and Installing Liferay W eb portals have become commonplace in today’s online world While surfing the Internet, you often open web portals without even realizing it So what’s a portal, anyway? Why are portals so important? How you create your own portal? Are there any frameworks and tools that are suitable for creating portals? What kind of management is required to maintain a portal? How you administer a portal? You will find answers to these and many other questions in this book, which walks you through an example of creating and managing a typical web portal In this chapter, you’ll first learn what a portal is You will then be introduced to Liferay, a popular open source framework for creating portals You’ll learn to install Liferay on your machine and create a portal of your own as you read through the book This chapter comprises the following sections: • What Is a Portal? • Kinds of Portals • Portal Advantages • Creating a Portal with Liferay • Liferay Features • Under the Hood • Installing Liferay • Testing the Liferay Installation What Is a Portal? You have already encountered a web portal if you’ve used Yahoo!—one of the world’s bestknown and most-used portals Yahoo! Sports, Yahoo! Finance, Yahoo! Movies, and Yahoo! Music each aggregate the contents provided by their partners This is exactly what a portal does: it provides a single point of entry to widely distributed information on the web, and it offers a unified way to access that diverse information Some portals allow users to decide what they want to display on their portal pages In many of these cases, the portal designer will customize the user’s page contents and generate Ch apt er 1 ■ I NTRO D UC I N G A N D I N STA L L I NG L I FERA Y them dynamically Regardless of whether the customization is done by the portal designer or the user, portals provide an easy way to configure desired content on a personal web page Plus, portals provide a consistent look and feel Users can take advantage of diverse applications in the same manner, making it easy for them to access information from various sources Now let’s look at the formal definition of a “portal.” If you search for “portal definition” on Google, you’ll pull up several definitions that all convey the same meaning Wikipedia (http://en.wikipedia.org/wiki/Web_portal), the popular free encyclopedia, provides the following definition: A web portal is a site that provides a single function via a web page or site Web portals often function as a point of access to information on the World Wide Web Portals pres‑ ent information from diverse sources in a unified way Apart from the search engine standard, web portals offer other services such as e‑mail, news, stock prices, infotain‑ ment, and other features Portals provide a way for enterprises to provide a consistent look and feel with access control and procedures for multiple applications, which other‑ wise would have been different entities altogether The Wikipedia definition is probably the most comprehensive one As it states, a web portal gives a user access to contents generated by diverse applications in a unified way Here’s another definition from Sun Microsystems, which defines “portal” in its Java Portlet Specifications (JSR 286) as follows: A portal is a web-based application that commonly provides personalization, authen‑ tication, [and] content aggregation from different sources and hosts the presentation layer of information systems This definition states that a portal is a kind of web application that aggregates content from different sources—web sites or web applications The content generated by these web sites can be static or dynamic For example, a sports-related portal might generate a web page that aggregates and presents information from several sports web sites If a user decides to gather further information from one of the displayed web sites, she can simply visit that web site by navigating to it from the portal page After doing that, she can return to the portal page with ease and continue navigating to the other web sites if desired Some of the displayed web sites might require the user to sign on, in which case a portal can offer the capability of single sign-on Single sign-on means that once the portal authenticates the user, it applies the same credentials to all the applications displayed on the portal page so that the user can access them In some cases, a portal simply communicates to an aggregated application that the user is authenticated, and the application trusts that As stated in the Sun Microsystems definition, a portal provides personalization, whereby the user can decide what applications should be initially displayed on the personal portal page The user can configure this page any time by adding and removing different applications Different web sites offer several other definitions, all of which describe portals as usercustomizable web sites that serve as gateways to diversified content arising from various sources However, these definitions neglect to describe an important feature of today’s portals: C h a p t e r ■ I NTR O D U C I N G A N D I N S TAL L I N G L I FERAY they provide collaboration among their users Most of the Web 2.0 features such as wikis, blogs, video sharing, and even social networking are available on today’s portals Generally, these new types of portals give users tools and applications to create sites for social networking and collaboration I’ll describe one such portal, uPortal, later in this chapter The Liferay portal that we’ll explore also falls into this new category of portals Now that I’ve defined what a web portal is, I’ll discuss two real-life examples: Yahoo! and Google Example Portal: Yahoo! To understand what a portal is and how to customize its contents, look at what Yahoo! provides to a user When you open the Yahoo! web site, you see a screen similar to the one shown in Figure 1-1, assuming that you are in the United States (http://us.yahoo.com) n Note The Yahoo! pages shown in this section vary by region Depending on your location in the world, the menus and their locations appear in different places So not get alarmed if the menus discussed here not appear in the shown location You will need to locate the appropriate menu to proceed further Figure 1-1 Yahoo! home page Ch apt er 1 ■ I NTRO D UC I N G A N D I N STA L L I NG L I FERA Y On the right-hand side, you will see the Page Options drop-down menu One of the options in the drop-down list is Try My Yahoo!, which allows you to customize your Yahoo! page (see Figure 1-2) Figure 1-2 My Yahoo! portal page Aggregating Contents At the top of the page, you will find a toolbar that allows you to add content to the page and change its appearance When you click the Add Content menu option, you will see a list of options as shown in Figure 1-3 C h a p t e r ■ I NTR O D U C I N G A N D I N S TAL L I N G L I FERAY Figure 1-3 Content-selection menu option Click the desired item in the displayed list to add it to your page Before adding an item, you can preview it by hovering the mouse over it and clicking the Show Preview link that’s displayed You can add multiple items to the page Once you’ve added an item, you can relocate it on the page simply by selecting it and dragging it to the desired position You can remove any of the added or existing items from the page by clicking the “x” symbol shown in the top-right corner of each After deleting the undesired items, you can relocate the remaining items to your liking Once you’ve finished adding items to your page, click the I’m Done button to return to full-page view You’ve just configured the entry-point page that provides easy, uniform access to several distributed applications on the web Now, you’ll change the page’s appearance—its look and feel Ch apt er 1 ■ I NTRO D UC I N G A N D I N STA L L I NG L I FERA Y Changing Look and Feel Clicking the Change Appearance menu option opens the screen shown in Figure 1-4 Figure 1-4 Changing the look and feel of a page Here, you will find options for changing the color, layout, font size, and search-box size Select the color of your choice from the displayed colors You can also select textures, environments, and so on from the displayed menu choices To change the layout, click the Change Layout option and select the size and number of columns from the choices offered After selecting a different column layout, you might want to rearrange the display items to your liking Likewise, you can configure font size and search-box size by clicking the respective menu choices Try out the other configuration options If you want your changes to persist, you should sign on before making them You’ve used a portal that lets the user aggregate desired home-page content and you’ve set the page’s look and feel Now consider Google, another popular portal in the market ... Practical Liferay Java -based Portal Applications Development ™ Poornachandra Sarang, Ph.D Practical Liferay: Java? ? ?-based Portal Applications Development Copyright ©... 11 5 Managing Message Boards 11 6 My Posts 11 7 My Subscriptions 11 8... portal • Chapter 11 , “Enhancing Your Portal? ??: As the other chapters have described, Liferay provides a number of applications that you can use to give your portal its core functionality But Liferay