www.it-ebooks.info OpenCms Development Extending and customizing OpenCms through its Java API Dan Liliedahl BIRMINGHAM - MUMBAI www.it-ebooks.info OpenCms Development Copyright © 2008 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, Packt Publishing, nor its dealers or 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 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: April 2008 Production Reference: 1160408 Published by Packt Publishing Ltd 32 Lincoln Road Olton Birmingham, B27 6PA, UK ISBN 978-1-847191-05-2 www.packtpub.com Cover Image by Karl Moore (karl.moore@ukonline.co.uk) www.it-ebooks.info Credits Author Project Manager Dan Liliedahl Abhijeet Deobhakta Reviewer Indexer Olli Aro Rekha Nair Senior Acquisition Editor Douglas Paterson Proofreader Angie Butcher Development Editor Production Coordinator Nikhil Bangera Shantanu Zagade Technical Editor Cover Work Himanshu Panchal Shantanu Zagade Editorial Team Leader Mithil Kulkarni www.it-ebooks.info About the Author Dan Liliedahl is the founder and CTO of eFoundry Corporation, a premier consulting company with expertise in selecting, specifying, and delivering Open Source and commercial content management portal and collaboration systems. Since starting eFoundry in 1998, he has architected and developed Web solutions for Fortune 500 companies such as JPMorganChase, Disney, Sirius Satellite Radio, and AMTRAK. Prior to starting eFoundry, Dan was a principal consultant and architect with FutureTense, a start up commercial CMS product vendor, and Open Market, whose products continue to have a strong market presence under a new company name. In addition to his full-time work, Dan frequently donates his marketplace and technical expertise to selected non‑profit organizations. He holds a degree in Electrical Engineering and Computer Science from the University of New Hampshire and has over 20 years of industry experience. In his spare time, he enjoys alpine skiing, ice hockey and coaching his kids' soccer www.it-ebooks.info I would like to thank the people at Packt who have helped me along the way with this book, especially Douglas Paterson, Senior Acquisition Editor for his initial guidance and ongoing support Thanks also to Abhijeet Deobhakta for his patience and for putting up with many delays and missed deadlines Many thanks to Olli Arro and Himanshu Panchal for their time, comments, and helpful suggestions It is great people like these who have made this book enjoyable to write and seem to go by quickly I also would like to thank Alexander Kandzior and his OpenCms team Beside building an outstanding product, they have always been available for questions and help, despite their busy schedules I know their schedules are busy because they came out with four versions of the software before this book was completed! Alex's focus, diligence, obsession with quality, and professionalism has made OpenCms and his company great Special thanks to my wife for her support and encouragement and for keeping me going on those days I didn't want to And of course, to my three children for making me laugh and for tolerating the times I couldn't spend with them www.it-ebooks.info About the Reviewer Olli Aro hails from Finnish Lapland, but is based now in the north of England Olli Aro has over 10 years experience in the area of innovation and development of software and web-based applications In his current role as head of technology and product development for Clicks and Links Ltd, Olli has been responsible for the company's portfolio of Open Source-based solutions He has been involved in the OpenCms project since 2001 (version 4), contributing various open source modules and bug fixes to the project Olli was also involved in reviewing the previous version of the OpenCms book Prior to Clicks and Links, Olli worked for organizations such as Nokia, eMobile Ltd, and CCC Systems Oy In his spare time, he works on his own social networking site, Breakaway Republix www.it-ebooks.info Table of Contents Preface Chapter 1: Overview The Site Design Required Developer Skills 12 OpenCms Application Overview The OpenCms Directory Structure 14 15 OpenCms Architecture Extensibility through Modules The OpenCms Web Request Process OpenCms Web Application Packaging Building a Complete Site with OpenCms Summary 19 20 20 21 21 22 Basic Site Development Sites Requiring Custom Content Types Sites Requiring Custom Features Bespoke Site Development The Real File System Layout The Virtual File System Layout Chapter 2: Developing in OpenCms Developing Basic Site Content Setting Up an Environment for Creating JSP Code Editing Files Using File Synchronization Using WebDAV for Editing Debugging JSP Code in OpenCms Setting Up an Eclipse Environment to Build OpenCms Tools Needed to Build OpenCms in Eclipse Step 1: Checkout the Project Source from CVS Step 2: Setting the Classpath for Compilation Step 3: Using Ant to Build a Distribution Package Building OpenCms outside of Eclipse Using Ant Debugging OpenCms in Eclipse www.it-ebooks.info 12 13 14 14 15 18 23 23 24 26 28 30 33 33 34 40 41 44 45 Table of Contents Setting Up an Eclipse Environment without Building OpenCms Summary Chapter 3: Our First Module Understanding OpenCms Modules Common Module Types Module Events Exporting and Importing Modules Creating a Module Creating a BlogEntry Content Type Registering the Content Type Additional Schema Features Field Mappings Field Validations Default Field Values Localization Content Relationships Content Previewing Creating Content Using a Model User Interface Widgets Nested Content Definitions Editing Configuration Files with Validating Editors Organizing the Content Summary Chapter 4: Developing Templates 46 47 49 50 50 51 51 52 55 59 66 66 67 67 68 68 69 70 70 80 84 87 87 89 Review of the Page Layout Templates in OpenCms Creating the Templates The Homepage Template The Blog Content Loop The Sidebar and Footer Common Code Elements 89 94 94 95 97 99 100 The Supporting Java Bean Class The Blog Template The Content and Template Loading Process Expressions in JSP Templates Using the Tag Library from JSP 106 112 113 115 115 Header Code Search Form Advertisements Blog Archives RSS Client and RSS Feeds Footer Section [ ii ] www.it-ebooks.info 101 102 102 103 105 106 Table of Contents Combining Expressions with JSTL Accelerating Template Development Using WebDAV Install the Eclipse WebDAV Plug-in Create a Site Within Eclipse for the Server Import Content into the Project Summary 116 117 118 120 122 124 Chapter 5: Adding Site Search 125 Chapter 6: Adding User Registration and Comment Support 153 Chapter 7: Providing Site Customization Features 185 A Quick Overview of Lucene Search Indexes Search Queries Configuring OpenCms Search Field Configurations Creating a Field Configuration Creating an Index Source Additional Search Settings Introducing Luke – a Visual Index Tool Writing the Search Code A Simple Search Example Subclassing the CmsSearch Bean The Search.jsp Template Summary Understanding OpenCms Security User, Groups, Roles, and Permissions Organizational Units Setting up Security for Our Site Organization Unit and Group Setup Adding the Users Resource Permissions User Login and Registration Code Adding Comment Support Adding the Comments to the XML Content Publishing the Comments Summary What is RSS? Creating the Module The RSS Client Code Displaying the RSS Feed in the Template Adding User Preferences to Accounts [ iii ] www.it-ebooks.info 125 125 127 127 128 130 133 136 137 140 140 143 145 151 153 154 157 158 159 163 166 169 178 181 183 184 185 186 187 189 190 ... Summary Chapter 4: Developing Templates 46 47 49 50 50 51 51 52 55 59 66 66 67 67 68 68 69 70 70 80 84 87 87 89 Review of the Page Layout Templates in OpenCms Creating the Templates The Homepage... Accounts [ iii ] www.it-ebooks.info 125 125 1 27 1 27 128 130 133 136 1 37 140 140 143 145 151 153 154 1 57 158 159 163 166 169 178 181 183 184 185 186 1 87 189 190 Table of Contents Updating the Java.. .OpenCms Development Extending and customizing OpenCms through its Java API Dan Liliedahl BIRMINGHAM - MUMBAI www.it-ebooks.info OpenCms Development Copyright © 2008