CQ5 4DevGuide
CQ5 4DevGuide
Exercise Guide
CQ 5.4 Developer Training
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 www.adobe.com
We grant you limited license to use materials solely for eduction purposes. You acknowledge that all right, title and interest (including IP rights) in and to the materials remains in Adobe.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 www.adobe.com
Understanding the Technology and Architecture ! EXERCISE - Install & Start an Author Instance ! EXERCISE - Create and Edit a CQ5 Page ! EXERCISE - Browse Related Application/Server Interfaces ! EXERCISE - Create an Application/Project! EXERCISE - Create a Template ! EXERCISE - Create a "Page-rendering" Component! EXERCISE - Create Pages & Web Site Structure ! EXERCISE - Install & Start CRXDE! EXERCISE - Utilize CRXDE!
6 11 16 22 27 32 38 41 45 47
EXERCISE - Include the "global.jsp" in the Page Component! 52 EXERCISE - Display Basic Page Content ! 55
EXERCISE - Create Multiple Scripts/Renderers for the "Page" Component! 58 EXERCISE - Breakout/Modularize the "Page" Component! EXERCISE - Initialize the WCM! EXERCISE - Extend the Foundation "Page" Component ! EXERCISE - Extend the Script Structure of the "Page" Component! EXERCISE - Create and Assign a New Design ! EXERCISE - Create a Navigation Component! EXERCISE - Add a Log Message !
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 www.adobe.com
67 70 72 78 82 89 95
3
99 104
Extra Credit EXERCISE - Create a List Children Component! 111 EXERCISE - Create a Logo Component ! 113
EXERCISE - Include the Foundation Breadcrumb Component1 ! 21 Extra Credit EXERCISE - Modify the Foundation Breadcrumb component ! 124 Extra Credit EXERCISE - Modify your topnav component! EXERCISE - Include the Foundation Paragraph System Component! EXERCISE - Create a Title Image Component! EXERCISE - Content Finder and Drag-and-Drop ! EXERCISE - Create a Complex Component ! EXERCISE - Include Multiple Foundation Components ! EXERCISE - Create a Search Component! EXERCISE - Apply i18n to a Component! EXERCISE - Create & Register a Widget! EXERCISE - Create and Consume an OSGi Bundle ! EXERCISE - Examine the Workow Console ! EXERCISE - Create a Workow Implementation Step! EXERCISE - Create & Download a CQ Package ! EXERCISE - Find Slow Responses !
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 www.adobe.com
125 126 132 141 147 159 163 168 173 181 189 196 204 210
4
Appendix B!
220
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 www.adobe.com
The best example of a REST-ful architecture is the web, where "resources" have URIs and the "uniform interface" is HTTP. For most cases, a framework like HTTP (addressable resources + "verbs" + standard ways to transmit metadata) is all you need to build a distributed application. HTTP is actually a very rich application protocol which gives us things like content negotiation and distributed caching. REST-ful web applications try to leverage HTTP in its entirety using specific architectural principles. 1. 2. Resource-oriented. Any piece of information (content object), for example a news entry or product description or photo is a resource. Addressable Resources. With REST over HTTP, every object will have its own specific URI. From the URI, we know how to communicate with the object, as well as where it is in the network and its identity on the server where it resides. A Uniform, Constrained Interface. When using REST over HTTP, stick to the methods provided by the protocol. This means following the meaning of GET, POST, PUT, and DELETE as defined with no additional methods/ services. Representation oriented. You interact with services using representations of that service. An object referenced by one URI can have different formats/renderings available. Different clients need different formats. AJAX may need JSON. A Java application may need XML. A browser my need HTML. A human may need a print-friendly rendering. Communicate statelessly. REST as implemented in HTTP tends to be stateless; for example, it doesn't use cookies and clients need to reauthenticate on every request. No client session data is stored on the server. Session-specific is held and maintained by the client and transferred to the server on each request, as needed. Stateless applications are easier to scale.
3.
4.
5.
Apache Sling
Apache Sling is a web framework that uses a Java Content Repository, such as Apache Jackrabbit or Adobe CRX to store and manage content. Sling applications use either scripts or Java servlets, selected based on simple name conventions, to process HTTP requests in a RESTful way. The Sling application is built as a series of OSGi bundles and makes heavy use of a number of OSGi core and compendium services. The embedded Apache
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 www.adobe.com 8
Felix OSGi framework and console provide a dynamic runtime environment, where code and content bundles can be loaded, unloaded and reconfigured at runtime. As the first web framework dedicated to JSR-283 Java Content Repositories, Sling makes it very simple to implement simple applications, while providing an enterprise-level framework for more complex applications. Being a REST framework, Sling is oriented around resources, which usually map into JCR nodes. Unlike traditional web applications that select a processing script, based on the URL, and then attempt to load data to render a result, Apache Sling request processing takes what, at first might seem like an insideout approach to handling requests in that a request URL is first resolved to a resource, then based on the resource (and only the resource) it selects the actual servlet or script to handle the request. Everything is a Resource The Resource is one of the central parts of Sling. Extending from JCR's Everything is Content, Sling assumes that Everything is a Resource. A resource is Apache Slings abstraction of the object addressed by the URI. Sling resources usually map to a JCR node. Servlets and Scripts are handled uniformly in that they are represented as resources themselves and are accessible by a resource path. This means, that every script, servlet, filter, error handler, etc. is available from the ResourceResolver just like normal content providing data to be rendered upon requests. Sling Script Resolution Using Sling, the type of content to be rendered is not the first processing consideration. Instead the main consideration is whether the URL resolves to a content object for which a script can then be found to perform the rendering. This provides excellent support for Web content authors to build Pages which are easily customized to their requirements. The advantages of this flexibility are apparent in applications with a wide range of different content elements, or when you need Pages that can be easily customized/viewed differently.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 www.adobe.com
In Sling, and therefore also CQ5, processing is driven by the URL of the HTTP request. This defines the content to be displayed by the appropriate scripts. To do this, information is extracted from the URL.30 When the appropriate resource (content node) is located, the resource type
is extracted from the resource properties. The sling:resourceType property is a path, which locates the script to be used for rendering the content.
Sling and MVC Some Java developers, especially those familiar with Struts/Spring may not recognize Sling as MVC. However, as stated by Alexander Klimetschek of Day Software (now Adobe Systems): Sling is *totally* MVC:
model = JCR repository controller = Sling engine (url processing, resource + script resolution) view = custom rendering scripts/servlets, both for read and write (GET + POST)...
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
10 www.adobe.com
An Author instance is the CQ5 installation content authors will login to and manage pages. This includes: 1) creating, 2) editing, 3) deleting, 4) moving, 5) etc. In addition, it is the installation you will be developing against as you can easily observe both Author and Publish views. What will we install? The CQ5 quickstart jar file is a self-extracting jar that will install:
CQSE - Days Servlet engine CRX - Day Software implementation of JSR 283, a Java Content Repository CQ5 WCM Product Documentation Reference Web site - Geometrixx
"
(Any servlet engine supporting the Java servlet API 2.4 can be used)
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
11 www.adobe.com
How to install an Author instance: 1. Create a folder structure on your file system where you will store, install, and start CQ5 (e.g. C:/day/cq5/author). WARNING
MS Windows users, please do not use spaces in your newly created folder structure (e.g. C:/this is bad/cq5/author). This will cause CQ5 to error.
2. Copy the CQ5 quickstart JAR and license.properties file from <USB>/ distribution/cq5_wcm into the newly created folder structure.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
12 www.adobe.com
If no port number is provided in the file name, CQ5 will select the first available port from the following list: 1) 4502, 2) 8080, 3) 8081, 4) 8082, 5) 8083, 6) 8084, 7) 8085, 8) 8888, 9) 9362, 10) random.
NOTE You can also install/start CQ5 from the command line while increasing the Java heap size, which will improve performance. Please see image below.
Once CQ5 has started successfully, the dialog will change to something similar to the following:
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 13 www.adobe.com
Logging into CQ5 1. Enter the default administrator "Username" (admin) and "Password" (admin) in the CQ5 login screen after your favorite Web browser pops-up then select OK.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
14 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
15 www.adobe.com
CQ uses a web-based graphical user interface, so you need a web browser to access CQ. The graphical user interface is divided into various web-based consoles where you can access all of the CQ functionality:
To Edit a page: 1. Click on the Websites button on the Welcome Screen. This will take you to the Websites Administrator Console (Site Admin screen).
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 16 www.adobe.com
2.Open the Press Releases page.# You can open a page to be edited by one of several methods:
! ! ! From Websites tab, you can double-click the page title to open it for editing. From Websites tab, you can right-click the page item, then select Open from the menu After you have opened a page, you can navigate to other pages within the site to edit them by clicking the links.
To insert a new paragraph, double-click the area labeled Drag components or assets here... or drag a component from the floating toolbar (called sidekick) to insert a new paragraph. This area appears wherever new content can be added, such as at the end of the list if other paragraphs exist or at the end of a column. 3.Drag the Text & Image icon from the sidekick to the center of the dotted rectangle and drop it in.# The green check mark will tell you that the drag-anddrop is allowed.
5. Double-click the thumbnail placeholder for the component to open the dialog box. 6. Click the Image tab to open the Image pane of the dialog box. Drag-and-drop an image from the Content Finder to the dialog box.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
18 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
19 www.adobe.com
To Create a new page: 1. On the Site Admin screen, Select English in the Geometrixx Web Site. Click New..New Page on the right-hand toolbar.
" "
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
20 www.adobe.com
4. Put content on your new page, as you learned above. Congratulations! You have successfully created a CQ5 page and filled it with content!!
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
21 www.adobe.com
A typical CQ5 installation consists of a Java servlet engine (CQSE), a Java Content Repository (CRX), and a Launchpad (Felix/Sling) application. They each have their own Web interface allowing you to perform expected administrative/ configuration tasks. How to browse the CQSE interface: 1. Enter the URL http://localhost:4502/admin in your favorite Web browsers address bar. 2. Enter the default administrator "User name" (admin) and "Password" (admin) in the dialog then select OK.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
22 www.adobe.com
Congratulations! You have successfully logged into the CQSE Java servlet engine. Typically, tasks available through this interface will be handled by the system administrator.
How to browse the CRX interface: 1. Enter the URL http://localhost:4502/crx in your favorite Web browsers address bar then select Log In after the CRX interface appears. 2. If you are not already logged in, enter the default administrator "User" (admin) and "Password" (admin) in the CRX login screen, while continuing to use the crx.default "Workspace" then select Submit Query.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
23 www.adobe.com
Congratulations! You have successfully logged into the CRX application and have browsed a portion of the node (Web site) structure. To be a successful developer in CQ5, you need to be able to easily explore/edit nodes and properties at the CRX level.
How to browse the Apache Felix interface: 1. Enter the URL http://localhost:4502/system/console in your favorite Web browsers address bar. 2. Enter the default administrator "User name" (admin) and "Password" (admin) in the dialog then select OK.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
25 www.adobe.com
Congratulations! You have successfully logged into the Felix application and have removed recent requests from the displayed list. You can use this request information to investigate the internal workings of CQ5.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
26 www.adobe.com
CRXDE Lite is embedded into CQ5/CRX and enables you to perform standard development tasks in a Web browser. With CRXDE Lite, you can create and edit files (e.g. JSP, Java, HTML, etc.), folders, Templates, Components, Dialogs, nodes, properties, and bundles; all while logging and integrating with SVN. CRXDE Lite is recommended when you do not have direct access to the CQ5/ CRX server, when you develop an application by extending or modifying the out-of-the-box Components and Java bundles, or when you do not need a dedicated debugger, code completion and syntax highlighting. How to use CRXDE Lite: 1. Enter the URL http://localhost:4502/crx/de/ in your favorite Web browsers address bar. 2. Check the username in the upper right hand corner. If you are not logged in as the default administrator, select Login then enter the default administrator "Name" (admin) and "Password" (admin) in the dialog, while continuing to use the crx.default "Workspace" then select OK.
3. Navigate to the folder /apps/geometrixx/components to view the custom components created for the Geometrixx Web site/project.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
28 www.adobe.com
What is an application/project?
An application/project is where you will store CQ5 elements such as Templates, Components, OSGi bundles, and static files. In order to start a new application/ project, it is necessary to define a location for these elements. Typically, they are defined as a subfolder of the /apps folder. Day recommends that you create the following structure for your application/project:
Structure
/apps/<application name> /apps/<application name>/ components /apps/<application name>/ components/page /apps/<application name>/ components/global /apps/<application name>/src /apps/<application name>/install
Description
The application container The Components container The Page Components container A location for global component files
/apps/<application name>/templates The Templates container The OSGi bundles container The compiled OSGi bundles container
How to create a project using CRXDE Lite: 1. Right-click the folder under which you want to create the new folder then select Create , Create Folder ...
2. Enter the folder Name (training) you wish to create in the dialog then select OK.
3. Repeat this process until you have created Days recommended application/ project structure then click Save All. Make sure you Save All before going on to the next exercise.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
30 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
31 www.adobe.com
What is a Template?
A Template is used to create a Page and defines which components can be used within the selected scope. A Template is a hierarchy of nodes that has the same structure as the page to be created, but without any actual content. Each Template will present you with a selection of components available for use. Templates are built up of Components. Components use, and allow access to, Widgets, which are used to author/render content. A Template is the basis of a Page. To create a Page, the Template's content must be copied (/apps/<application name>/templates/<template name>) to the corresponding position in the site-tree (this occurs automatically if page is created using CQ5). This copy action also gives the Page its initial content and the property sling:resourceType, the path to the "Page" Component that is used to render the page.
How to create a Template: 1. Right-click /apps/<application name>/templates then select Create, Create Template
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 32 www.adobe.com
NOTE
The property sling:resourceType will be created on the Template's jcr:content node. In addition, the Component may not yet exist. This is because you have not yet created it.
Ranking (property ranking) = the order (ascending) in which this Template will appear in relation to other Templates. Setting the Rank to 1, will ensure that our Template appears first in the list. ! 1
33 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
3. Select Next for Allowed Paths#. Allowed Paths will define paths where this template may be used to create pages.
5.# Click Next for Allowed Parents then select OK on Allowed Children.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
34 www.adobe.com
NOTE
Dont forget to click Save All to persist your changes in the repository.
Congratulations! You have successfully created a Template in CQ5. To make you more aware of the structure associated with CQ5 objects, it is a good idea to view the nodes and properties that were created in the repository (CRX). Please see the image below.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
35 www.adobe.com
Even though you do not yet have a component to render pages based on your new template, you can test the values you set in the Create Template dialog. 5.Open the Site Admin Console and Select Websites.
7.You should see your template in the list of available templates in the Create Page Dialog. It will be thin, as it doesnt have a thumbnail, but it should be 1st in the list.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
37 www.adobe.com
Components are modular, re-usable units that implement specific functionality/logic to render the content of your Web site. They have no hidden configuration files, can include other Components, and can run anywhere within CQ5 or in isolation (e.g. portal). A Component could be described as a collection of scripts (e.g. JSPs, Java servlets, etc.) that completely realize a specific function. More specific, a "Page" Component is typically referenced by a Template. How to create a Page-rendering Component using CRXDE Lite: 1. Right-click /apps/<application name>/components/page then select Create, Create Component 2. Enter the desired Component Label, Title, and Description in the dialog then select Next.
! ! Label = the name of the Component/node that will be created ! ! contentpage Training Contentpage Title (property jcr:title) = the title that will be assigned to the Component
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
38 www.adobe.com
Description (property jcr:description) = the description that will be assigned to the Component ! NA
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
39 www.adobe.com
A Component could be described as a collection of scripts (e.g. JSPs, Java servlets, etc.) that completely realize a specific function. In order to realize this specific functionality, it is your responsibility to create any necessary scripts that will do so. Typically, a Component ("Page" or otherwise) will have at least one default script, identical to the name of the Component (e.g. contentpage.jsp).# Notice that the creation of the component results in the creation of the default contentpage.jsp script. 4. Open the script by double-clicking the script object in the left pane.# The script contains some sample code that may have to be adjusted or deleted, depending on what the component will do. 5. Enter some HTML code, similar to below then select Save All. contentpage.jsp
<html> <head> <title>Hello World !!!</title> </head> <body> <h1>Hello World !!!</h1> <h2>Welcome to a new Day</h2> </body> </html>
NOTE
Dont forget to click Save All to persist your changes in the repository.
Congratulations! You have successfully created a Page Component in CQ5. You can now create a script that will render content based on your requirements. In addition, you will perform a similar process when creating Content Components in the future.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
40 www.adobe.com
What is a Page?
A Page is where content authors will create and edit content that will most likely be published and viewed by site visitors. It is an exact copy of the Template from which it was created. How to create a Page: 1. Select Websites in the CQ5 Siteadmin tool then select New , New Page
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
41 www.adobe.com
2. Enter and select the desired Page Title, Name and Template on which to base this Page on then click Create.
! ! Title (property jcr:title) = the title that will be assigned to the Page Name = the name of the Page/node that will be created
3. Open the newly created Training Site page by double-clicking it in the right pane then view its output to ensure it meets your expectations.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
42 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
43 www.adobe.com
NOTE
Since all Pages will be created using the same Template (i.e. Training Contentpage) and implement the same rendering script, every Page will look identical for now.
Congratulations! You have successfully created Pages and Web site structure in CQ5. This is the type of behavior you can expect from content authors when building out their Web site structure.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
44 www.adobe.com
What is CRXDE?
CRXDE is a pre-packaged stand-alone Eclipse application. CRXDE is custombuilt specifically for CQ and CRX and thus enables you to efficiently develop your project. CRXDE gives you a broad set of tools to easily create and manage files, folders, Templates, Components, Dialogs, nodes, properties, scripts and OSGi bundles while logging, debugging and integrating with SVN. CRXDE is built on the Eclipse Rich Client Platform (RCP), leveraging the Eclipse File System (EFS) API. How to install and start CRXDE: 1. Create/identify a folder structure on your file system where you will store, install, and start CRXDE (e.g. C:/day/cq5). 2. Copy the appropriate CRXDE package from <USB>/distribution/crxde into the folder structure. 3. Extract the package. 4. Double-click the executable in the CRXDE folder. 5. Enter the URL (http://localhost:4502), default administrator User Name (admin) and Password (admin) in the dialog then click OK.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
45 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
46 www.adobe.com
As stated earlier, CRXDE Lite is recommended when you do not have direct access to the CQ5/CRX server, when you develop an application by extending or modifying the out-of-the-box Components and Java bundles, or when you do not need a dedicated debugger, code completion and syntax highlighting. CRXDE is recommended when you are developing complex applications by creating new components and Java bundles. Again, CRXDE hides some of the complexity of the development process by allowing you to work directly with the repository without the need to synchronize the repository with the file system. How to use CRXDE: 1. Navigate to and open, by double-clicking, the contentpage.jsp script you created earlier for the Training Contentpage Page Component (e.g. /apps/ training/components/page/contentpage).
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
47 www.adobe.com
3. In the CQ5 Siteadmin tool, navigate to and open any page that is based off of this Page Component to view your changes.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
48 www.adobe.com
Congratulations! You have successfully modified a script using CRXDE. For the rest of this training, you will use CRXDE to accomplish more complex development tasks.
You will notice that the tree browser in CRXDE includes only /apps, /etc, and / libs. If you want to see additional branches of the repository, similar to CRXDE Lite, you can use the CRX Content Explorer or CRXDE Lite to export the additional nodes to CRXDE. How to modify the set of repository paths exported to CRXDE using the CRX Content Explorer: 1. Navigate to http://localhost:4502/crx. 2. Login if you have not already logged in. 3. Select the Content Explorer. 4. In the Content Explorer, navigate to /etc/crxde/profiles/default 5. Modify the crxde:paths property by adding desired paths. (e.g., /content)
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
49 www.adobe.com
You can also add Java API documentation, for CQ5 APIs and your own APIs, to CRXDE. Simply define the location of the javadocs to CRXDE using the Package Explorer pane. How to add java API documentation to the CRXDE: 1. In CRXDE, switch the view from Navigator to Package Explorer. 2. Expand the localhost_4502 folder and then expand the Reference Libraries folder. 3. Right-click cq-wcm-api-5.4.0.jar and select Properties from the context menu.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
50 www.adobe.com
4. Select Javadoc Location. 5. Use the browse button to navigate to and select the location of the unpacked API documentation. (e.g, <cq-install-dir>/crx-quickstart/docs
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
51 www.adobe.com
When you develop the JSP script of a CQ5 component, it is recommended to include the following code at the top of the script: <%@include file="/libs/foundation/global.jsp"%> The Day provided global.jsp declares the Sling, CQ and JSTL taglibs and exposes the regularly used scripting objects defined by the <cq:defineObjects /> tag. This shortens and simplifies the JSP code of your component. The <cq:defineObjects> tag exposes the following, regularly used, scripting objects which can be referenced by the developer. It also exposes the objects defined by the <sling:defineObjects> tag.
! componentContext ! ! the current component context object of the request (com.day.cq.wcm.api.components.ComponentContext interface). component
52 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
! !
the current CQ5 component object of the current resource (com.day.cq.wcm.api.components.Component interface).
currentDesign ! the current design object of the current page (com.day.cq.wcm.api.designer.Design interface).
! ! !
currentPage ! ! ! the current CQ WCM page object (com.day.cq.wcm.api.Page interface). the current JCR node object (javax.jcr.Node interface). the current style object of the current cell (com.day.cq.wcm.api.designer.Style interface). currentNode currentStyle
designer ! the designer object used to access design information (com.day.cq.wcm.api.designer.Designer interface).
editContext ! the edit context object of the CQ5 component (com.day.cq.wcm.api.components.EditContext interface).
pageManager ! the page manager object for page level operations (com.day.cq.wcm.api.PageManager interface).
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
How to include the global.jsp script in your Training Page Component: 1. Open the contentpage.jsp script by double-clicking it. 2. Enter the include statement in your JSP, similar to below then Save. contentpage.jsp
<%@include file="/libs/foundation/global.jsp"%> <html> <head> <title>Hello World !!!</title> </head> <body> <h1>Hello World !!!</h1> <h2>Welcome to a new Day</h2> <h3>Look at me, I am using CRXDE</h3> </body> </html>
3. Test your script by requesting a Page in CQ5 Siteadmin that implements this Page Component.
! If successful, you should not notice any difference in the way the Page is rendered
Congratulations! You have successfully included the global.jsp, allowing you access to numerous Sling, CQ, and Java objects to aid you in your development efforts.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
54 www.adobe.com
After inclusion of the global.jsp in whatever script you are working on, there are generally three ways to access content in CQ5:
! Via the properties object ! The properties object is an instance of the ValueMap (see Sling API) class and contains all properties of the current resource. For example:
...
! Via currentNode object ! The currentNode object is an instance of the Node (see JCR API) class, which provides access to content via the getProperty() method. For example:
NOTE
Day does not recommend using the JCR API directly in CQ5 unless necessary. Since CQ5 is a Sling application, you should deal with resources and not JCR nodes.
How to dynamically display basic Page content in your Training Page Component: 1. Open the contentpage.jsp script. 2. Enter some JSP and HTML code, similar to below then Save. contentpage.jsp
<%@include file="/libs/foundation/global.jsp"%> <html> <head> <title><%= currentPage.getTitle() == null ? currentPage.getName() : currentPage.getTitle() %></title> </head> <body> <h2>properties</h2> Title: <%= properties.get("jcr:title") %><br /> <h2>currentPage</h2> Title: <%= currentPage.getTitle() %><br /> Name: <%= currentPage.getName() %><br /> Path: <%= currentPage.getPath() %><br /> Depth: <%= currentPage.getDepth() %><br /> <h2>currentNode</h2> Title: <%= currentNode.getProperty("jcr:title").getString() %><br /> Name: <%= currentNode.getName() %><br /> Path: <%= currentNode.getPath() %><br /> Depth: <%= currentNode.getDepth() %><br /> </body> Bringing the Digital Experience to Life ! 56 Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 www.adobe.com
</html>
3. Test your script by requesting a Page in CQ5 Siteadmin that implements this Page Component.
! If successful, you should now see content related to the requested Page being displayed dynamically, similar to the image below.
CQ5 is built using Apache Sling, a Web application framework based on REST principles that provides easy development of content-oriented applications. Sling uses a JCR repository, such as Apache Jackrabbit or Day's CRX, as its data store. Apache Sling is included in the installation of CQ5. Sling has since been contributed to the Apache Software Foundation - further information can be found at Apache (http://sling.apache.com). Using Apache Sling, the type of content to be rendered is not the first processing consideration. Instead the main consideration is whether the URL resolves to a content object for which a script can then be found to perform the rendering. This provides excellent support for Web content authors to build Pages which are easily customized to their requirements. The advantages of this flexibility are apparent in applications with a wide range of different content elements, or when you need Pages that can be easily customized/viewed differently.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
58 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
59 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
60 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
61 www.adobe.com
For example, given the /content structure defined in the last example and the /apps structure defined in the figure above, consider a request to access the resource /content/corporate/jobs/developer.print.a4.html of type sling:resourceType="hr/jobs". Assuming we have the following list of scripts in the locations shown, then the order of preference would be as shown: 1. 2. 3. 4. 5. 6. 7. 8. /apps/hr/jobs/print/a4.html.jsp /apps/hr/jobs/print/a4/html.jsp /apps/hr/jobs/print/a4.jsp /apps/hr/jobs/print.html.jsp /apps/hr/jobs/print.jsp /apps/hr/jobs/html.jsp /apps/hr/jobs/jobs.jsp /apps/hr/jobs/GET.jsp
62 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
Folders (i.e. nodes of type nt:folder) take precedence over jsp file names when resolving using selectors, at least for the first selector. Only one selector in a file name has any effect - any files with names containing two selectors don't ever get selected, but names of folders can be used to match the selectors in the request. Scripts with HTTP method names (e.g.,GET.jsp) is selected as a last resort, (after the default script: jobs.jsp, in this case). Scripts with names that include HTTP methods in addition to another selector or extension in a .jsp file name are NEVER selected.
The resolution process The Servlet Resolution Process four elements of a SlingHttpServletRequest: 1. The resource type as retrieved through request.getResource ().getResourceType(). Because the resource type may be a node type such as nt:file, the resource type is mangled into a path by replacing any colons contained to forward slashes. Also, any backslashes contained are replaced to forward slashes. This should give a relative path. Of course a resource type may also be set to an absolute path. 2. The request selectors as retrieved through request.getRequestPathInfo().getSelectorString(). The selector string is turned into a relative path by replacing all separating dots by forward slashes. For example the selector string print.a4 is converted into the relative path print/a4. 3. The request extension as retrieved through request.getRequestPathInfo().getExtension() if the request method is GET or HEAD and the request extension is not empty.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
63 www.adobe.com
4.
The request method name for any request method except GET or HEAD or if the request extension is empty.
The resource type is used as a (relative) parent path to the Servlet while the request extension or request method is used as the Servlet (base) name. The Servlet is retrieved from the Resource tree by calling the ResourceResolver.getResource(String) method which handles absolute and relative paths correctly by searching relative paths in the configured search path. How to create multiple scripts/renderers: 1. Right-click /apps/<application name>/components/page/contentpage -then select New, JSP.
How to create multiple scripts/renderers: 1. Right-click /apps/<application name>/components/page/contentpage -then select New, JSP.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
64 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
65 www.adobe.com
4. Repeat these processes for a script/renderer named m.html.jsp.# Change the text in the m.html.jsp script to read#
<h1>This is the MOBILE HTML script/renderer </h1>#
Remember to Save. 5. Test your multiple scripts/renderers by requesting a Page in CQ5 Siteadmin that implements this Page Component.
! /content/trainingSite/en/company.html
/content/trainingSite/en/company.m.html
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
66 www.adobe.com
The <%@ include file="myScript.jsp" %> directive informs the JSP compiler to include a complete file into the current file at compilation time. It is as if the contents of the included file were pasted directly into the original file. The <cq:include script="myScript.jsp" /> directive is different in that it includes the file at runtime. Often the question is asked: "Should I use <cq:include> or <sling:include>?" When developing CQ5 components, Day recommends that you use <cq:include /> tag. This allows you to directly include script files by their name when using the script attribute. This takes component and resource type inheritance into account, and is often simpler than strict adherence to Slings script resolution using selectors and extensions. How to include a script at runtime using <cq:include /> in your contentpage Component: 1. Remove (or rename) the scripts html.jsp and m.html.jsp from your Page Component by right-clicking them then select Delete. 2. Create a new JSP file named body.jsp in your contentpage Component.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 67 www.adobe.com
3. Cut the body code from contentpage.jsp and paste it in to body.jsp then Save. body.jsp
<%@include file="/libs/foundation/global.jsp"%> <body> <h2>properties</h2> Title: <%= properties.get("jcr:title") %><br /> <h2>currentPage</h2> Title: <%= currentPage.getTitle() %><br /> Name: <%= currentPage.getName() %><br /> Path: <%= currentPage.getPath() %><br /> Depth: <%= currentPage.getDepth() %><br /> <h2>currentNode</h2> Title: <%= currentNode.getProperty("jcr:title").getString() %><br /> Name: <%= currentNode.getName() %><br /> Path: <%= currentNode.getPath() %><br /> Depth: <%= currentNode.getDepth() %><br /> </body>
NOTE
Notice the fact the global.jsp file has been included at the top of this script. Since this script will be included at runtime, it will be unaware of any previous includes of the global.jsp.
4. Open the file contentpage.jsp, and enter some JSP and HTML code, similar to below, replacing the <body> section then Save. contentpage.jsp
<%@include file="/libs/foundation/global.jsp"%> <html> <head> <title><%= currentPage.getTitle() == null ? currentPage.getName() : currentPage.getTitle() %></title> </head> <cq:include script="body.jsp" /> </html>
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
68 www.adobe.com
5. Test your script by requesting a Page in CQ5 Siteadmin that implements this Page Component.
! If successful, you should see no difference between what is displayed now, and what was displayed before.
Congratulations! You have successfully broken out a portion of your Page Component, and have included a script at runtime. Again, this type of technique will allow you to reuse scripts for different Components in the future.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
69 www.adobe.com
The WCM initialization script performs all necessary steps to provide the whole WCM functionality on a page, including: Dialogs, Widgets, WCM CSS & JS, Sidekick, etc. Some WCM functionality such as the Page properties (no Dialog defined yet) may not work when only the initialization script is included. There are steps missing which we perform in a later exercise. How to initialize the WCM in your Page Component: 1. Open the file contentpage.jsp, and enter some JSP code, similar to below, adding to the <head> section an include of the initialization script then Save. contentpage.jsp
<%@include file="/libs/foundation/global.jsp"%> <html> <head> <title><%= currentPage.getTitle() == null ? currentPage.getName() : currentPage.getTitle() %></title> <cq:include script="/libs/wcm/core/components/init/init.jsp"/> </head> <cq:include script="body.jsp" /> </html> Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 70 www.adobe.com
2. Test your script by requesting a Page in CQ5 Siteadmin that implements this Page Component.
! If successful, you should now see the Sidekick appear, which will give authors the ability to manage content.
Congratulations! You have successfully initialized the WCM, and all of its related tools. Again, this initialization is critical in enabling numerous CQ5 tools, allowing content authors to work more efficiently.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 71 www.adobe.com
Components can be given a hierarchical structure to implement the inheritance of included script files, Dialogs, etc. Therefore it is possible for a specific Page Component (or any Component) to inherit from a base Component. For example, allowing inheritance of a script file for a specific part of the page (e.g. the <head> section). Components within CQ5 are subject to 3 different hierarchies:
! Resource Type Hierarchy ! This is used to extend components using the property sling:resourceSuperType. This enables the Component to inherit from a base Component. For example, a text Component will inherit various attributes from the foundation text component, including: ! ! ! ! scripts (resolved by Sling) Dialogs descriptions (including thumbnail images, icons, etc.)
Important to note is the fact that a local copy/instance of a Component element (e.g. body.jsp) will take precedence over an inherited element.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
72 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
73 www.adobe.com
How to extend the foundation Page Component using CRXDE: 1. Right-click the Training contentpage component then select New, Property.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
74 www.adobe.com
<%@include file="/libs/foundation/global.jsp"%> <html> <cq:include script="head.jsp" /> <cq:include script="body.jsp" /> </html>
4. Test your script by requesting a Page in CQ5 Siteadmin that implements this Training Page Component.
! ! If successful, you should see no difference between what is displayed now, and what was displayed before. You can also see that the Page Properties functionality is now available in your Sidekick, since we inherited the Dialog from the foundation Page Component.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
76 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
77 www.adobe.com
Again, this exercise is merely an extension of a previous exercise where you added the <body> section of the Page Component to a new script (body.jsp), and then included that script. Day feels it is important you become well versed in this capability, as it will allow you to more easily reuse Components in the future. In addition, you are attempting to reflect the Geometrixx structure of its Contentpage Component, so that you may recreate the Web site in its entirety. How to add additional structure to the Page Component: 1. Create 3 new JSPs (header.jsp, content.jsp, footer.jsp) in the Training Contentpage Page Component.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
78 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
79 www.adobe.com
3. Open the file content.jsp, and enter some HTML and JSP code, similar to below then Save. content.jsp
<%@include file="/libs/foundation/global.jsp" %> <div class="container_16"> <div class="grid_16"> <div> breadcrumb </div> <div> title </div> </div> <div class="grid_12 body_container"> <div> par </div> </div> <div class="grid_4 right_container"> <div> newslist </div> <div> rightpar </div> </div> <div class="clear"></div> </div>
4. Open the file footer.jsp, and enter some HTML and JSP code, similar to below then Save. footer.jsp
<%@include file="/libs/foundation/global.jsp" %> <div class="footer container_16"> <div class="grid_6"> <div> toolbar </div> </div> <div class="clear"></div> </div>
5. Open the file body.jsp, and enter some HTML and JSP code, similar to below then Save. body.jsp
<%@include file="/libs/foundation/global.jsp" %> <body> <div class="bg"> <cq:include script="header.jsp"/> <cq:include script="content.jsp"/> <cq:include script="footer.jsp"/> </div> </body> Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 80 www.adobe.com
6. Test your script by requesting a Page in CQ5 Siteadmin that implements this Training Page Component.
! If successful, you should see a simple text output (which we will fix soon) of words and the Sidekick, similar to the image below.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
81 www.adobe.com
By creating and assigning a Design(er) in CQ5, it allows you to enforce a consistent look and feel across your Web site, as well as share global content. The many Pages that use the same Design(er), will have access to common CSS files, defining the formats of specific areas/Components, and images that you use for features, such as backgrounds and buttons. CQ5 has been developed to maximize compliance with the Web Accessibility Guidelines. Web accessibility means that people with disabilities can perceive, understand, navigate, and interact with the Web, and that they can contribute to the Web. This can include measures such as providing textual alternatives to images (or any non-text item). These can then be used to help people with sight impairment by outputting the text on a Braille keypad, or through a voice synthesizer. Such measures can also benefit people with slow internet connections, or any internet user - when the measures offer the user more information. Such mechanisms must be carefully planned and designed to ensure that they provide the information required for the user to successfully understand and
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 82 www.adobe.com
use the content. Certain aspects are integral to CQ5, whereas other aspects must be realized during your project development. How to create a Design(er) for your Web site, using CQ5 Tools Console: 1. Navigate to the Tools section of CQ5.
! URL: http://localhost:4502/libs/wcm/core/content/misc.html
3. Enter the Design(er) Title (Training Design) and Name (trainingDesign) in the dialog then select Create.
4. Select the Geometrixx Design(er), afterward selecting the static.css and the images folder then select Copy.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
84 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
85 www.adobe.com
NOTE
You may want to examine the Geometrixx design to discover how themes can be used with the design. We will be discussing the use of Client Library Folders to organize stylesheets, javaScript files, and other design objects when we learn about creating custom input widgets.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
88 www.adobe.com
Providing dynamic navigation capabilities, allowing for the easy addition and removal of Pages, is one of the most important (and sometimes difficult) things you can do as a developer in CQ5. Consider the following image, which represents a simple Web site structure:
If you want to create a dynamic navigation Component that displays all the valid, children Pages of a language Page (e.g. en), you would need to identify the following:
! What Page is being requested? ! ! Is it under the en section or the es section, as you will want to display the appropriate children of the language the visitor is browsing? At what level does the requested Page exist? ! This is important because if you wish to display the children of a language, then a request to a level 1 Page (i.e. training) would break the assumption requests would only be made to level 2 (e.g. en) or level 3 (e.g. company) Pages. ! Is the requested Page valid? ! In CQ5, it is possible to configure a Page to not display in any dynamic navigation script, as well as define a specific On Time and Off Time.
After these questions have been answered, it is relatively easy to collect the title of the Page, which will be displayed, and the path of the Page, which will be used to provide navigation functionality. Important Java classes/interfaces you should understand include:
! ! ! com.day.cq.wcm.api.Page com.day.cq.wcm.api.PageFilter com.day.cq.wcm.api.PageManager
How to create a dynamic navigation Component: 1. Right-click /apps/<application name>/components then select New, Component. 2. Enter the desired Component Label, Title, Description then click Finish.
! Label = the name of the Component/node that will be created
90 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
! !
Title (property jcr:title) = the title that will be assigned to the Component Description (property jcr:description) = the description that will be assigned to the Component
This is a similar process to the Page Component we created earlier using CRXDE Lite.
NOTE
At this time, we are only concerned with the Label, Title, and Description properties. We will examine all the properties and what they mean as the course continues.
3. Open the file topnav.jsp, and enter some HTML and JSP code, similar to below then Save.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
91 www.adobe.com
topnav.jsp
<%-Draws the top navigation --%> <%@include file="/libs/foundation/global.jsp"%><% %><%@ page import="java.util.Iterator, com.day.text.Text, com.day.cq.wcm.api.PageFilter, com.day.cq.wcm.api.Page, com.day.cq.commons.Doctype, org.apache.commons.lang.StringEscapeUtils" %><%
// get navigation root page Page Page navRootPage = currentPage.getAbsoluteParent(2); // check to make sure the page exists if (navRootPage == null && currentPage != null) { navRootPage = currentPage; } if (navRootPage != null) { Iterator<Page> children = navRootPage.listChildren(new PageFilter (request)); %> <ul> <% while (children.hasNext()) { Page child = children.next(); %> <li> <a href="<%= child.getPath() %>.html"> <%= StringEscapeUtils.escapeXml(child.getTitle())%> </a> </li> <% } %> </ul> <% } %>
4. Open the file header.jsp in the Training Contentpage Component and replace the topnav <div> section with a <cq:include> of the navigation Component you just created, similar to below then Save.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 92 www.adobe.com
path ! The path to the resource object to be included in the current request processing. If this path is relative, it is appended to the path of the current resource whose script is including the given resource.
resourceType ! The resource type of the resource to be included. If the resource type is set, the path must be the exact path to a resource object: in this case, adding parameters, selectors and extensions to the path is not supported. ! If the resource to be included is specified with the path attribute that cannot be resolved to a resource, the tag may create a synthetic resource object out of the path and this resource type.
header.jsp
<%@include file="/libs/foundation/global.jsp" %> <div class="header"> <div class="container_16"> <div class="grid_8"> <div> logo </div> </div> <div class="grid_8"> <div class="search_area"> <div> userinfo </div> <div> toptoolbar </div> <div> search </div> <div class="clear"></div> </div> </div> <cq:include path="topnav" resourceType="training/components/topnav" /> </div> </div>
5. Test your script by requesting a Page in CQ5 Siteadmin that implements this Training Page Component.
! If successful, you should see navigation links/titles directly related to your Web site structure.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 93 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
94 www.adobe.com
In the daily life of a developer, it is often crucial to monitor the values of variables assigned/used. There are several possibilities, in various usability levels. CQ5 and CRXDE make your life a little easier by implementing the popular Log4j framework, which is designed to provide an easy-to-use logging solution.
The initialization of a Logger object, called log, has already been accomplished during the inclusion of global.jsp in whatever Component you may be working on. The log file entries are formatted according to the Sling configuration. Two pieces of information are required to append an entry to the log file:
log level ! This is provided by the corresponding method call. For example, a log.debug(<message>) produces a message with log level debug, while a log.info(<message>) produces a message with log level info. Possible methods of the Logger object include: ! trace()
95 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
! ! ! ! ! message !
The message itself is provided as a parameter to the method call. For example, log.debug("This is the log message") appends the message "This is the log message" with a log level of debug to the error.log file.
NOTE
In a default configuration, the log file is located under <cq-install-dir>/crx-quickstart/logs/ error.log.
How to add a log message: 1. Open the file topnav.jsp in the Training topnav Component, and enter some JSP code, similar to below then Save. topnav.jsp
<%@include file="/libs/foundation/global.jsp"%> <%@ page import="java.util.Iterator, com.day.text.Text, com.day.cq.wcm.api.PageFilter, com.day.cq.wcm.api.Page, com.day.cq.commons.Doctype, org.apache.commons.lang.StringEscapeUtils" %> <% // get navigation root page Page Page navRootPage = currentPage.getAbsoluteParent(2); // check to make sure the page exists if (navRootPage == null && currentPage != null) { navRootPage = currentPage; } if (navRootPage != null) { // create an iterator object of all nav root's child pages Iterator<Page> children = navRootPage.listChildren(new PageFilter()); %> <ul> <% Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 96 www.adobe.com
while (children.hasNext()) { // get next child page Page child = children.next(); //log message log.info("Child page [{}] found.", child.getTitle()); // display the link in an <A HREF... %> <li> <a href="<%= child.getPath() %>.html"> <%= StringEscapeUtils.escapeXml(child.getTitle())%> </a> </li> <% } %> </ul> <% } %>
2. Test your script by requesting a Page in CQ5 Siteadmin that implements this Training Page Component.
! If successful, you should see no difference between what is displayed now, and what was displayed before. However, if you were to inspect the error.log file, you would see a message similar to below:
04.12.2009 11:23:22.921 *INFO* [127.0.0.1 [1259943802812] GET /content/ trainingSite/en/company.html HTTP/1.1] apps.training.components.content.topnav.topnav$jsp child page [Company] found.
Congratulations! You have successfully added a log message to your script. Again, it is often crucial to monitor the values of variables assigned/used. The Logger object is a useful tool that will enable you to do so.
NOTE
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
97 www.adobe.com
In CRXDE you can display the file error.log that is located on the file system at <cq-installdir>/crx-quickstart/server/logs and filter it with the appropriate log level. This can be done by proceeding as follows in CRXDE:
1. Select the Console tab located at the bottom of the window then select the arrow beside the Open Console then select System Log.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
98 www.adobe.com
Sometimes, outputting variable values in a log file is not enough for a developer to monitor the sequence of steps executed by the system. The best way to accomplish this is the usage of a debugger. Many modern IDEs like Eclipse and CRXDE provide this functionality. Again, the goal of this exercise is to learn how to use the built-in debugger in CRXDE. A debugging session consists of a server and a client. In this training, you will use CRXDE as the client, while the server is provided by CQ. For performance reasons, Day recommends not enabling debugging for CQ production instances, as this would consume too many resources, thus hindering performance. How to enable debugging in CQ and CRXDE: 1. Shutdown your CQ author and CRXDE instance. 2. Navigate to the directory where the Java servlet engine (CQSE) has been installed using your command line.
! e.g. <cq-install-dir>/crx-quickstart/server
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
99 www.adobe.com
NOTE
By default, port 30303 will be used by the server for debugging communication. You can customize the server.bat/start file for future use. In addition, you can call the debugger directly: java -Xmx512m -Xdebug Xrunjdwp:transport=dt_socket,server=y,address=30303,suspend=n -jar cq-author-4502.jar
4. Start CRXDE. 5. Open the file topnav.jsp in the Training topnav Component. 6. Right-click the left-side of the JSP editor on a line of code (e.g. line 17: if (navRootPage != null) {) then select Toggle Breakpoints.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
100 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
101 www.adobe.com
NOTE
You are now in debug mode. Your CRXDE view should look similar to the image below.
! !
In CRXDE, you will notice your script stops at the line of code containing the breakpoint Here you will be able to investigate variables, execution, and other related elements, in addition to "stepping" through your code
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
103 www.adobe.com
What is a Dialog?
During this training you have focused mostly on rendering content (static and dynamic), which is important as one could argue it comprises 50% of what you do as a CQ5 developer. What needs to be accomplished for this exercise is to provide content authors the ability to write content. You can accomplish this by learning how to create a Component Dialog. A CQ5 Dialog is similar to other dialogs you have used/created in the past: it gathers user input via a form, potentially validates it, and then makes that input available for further use (storage, configuration, etc.). CQ5 makes use of the popular ExtJS JavaScript framework. It allows developers the ability to easily create Rich Internet Applications (RIA) through the use of AJAX. It includes:
! ! ! High performance, customizable UI widgets Well designed and extensible Component model An intuitive, easy to use API
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
104 www.adobe.com
In relation to the Component the Dialog is being created for, the root node of the Dialog has to be of node type cq:Dialog and named dialog. Below this Dialog root node, the nodes for the tabs of the Dialog have to be added. These tab nodes must be of node type cq:WidgetCollection. Below the tab nodes the widget nodes can then be added. The widget nodes must be of node type cq:Widget. How to create a title Component with a Dialog: 1. Create a new title content Component.
2. Open the file title.jsp, and enter some HTML and JSP code, similar to below then Save. title.jsp
<%@include file="/libs/foundation/global.jsp"%> <h2><%= properties.get("title", currentPage.getTitle()) %></h2> Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 105 www.adobe.com
NOTE
You will notice the use of the Sling ValueMap class/object properties. This object allows you to easily get properties associated with this instance of this Component.
3. Open the file content.jsp in the Training Contentpage Component and replace the title <div> section with a <cq:include> of the title Component you just created, similar to below then Save. content.jsp
<%@include file="/libs/foundation/global.jsp" %> <div class="container_16"> <div class="grid_16"> <div> breadcrumb </div> <cq:include path="title_node" resourceType="training/components/title" /> </div> <div class="grid_12 body_container"> <div> par </div> </div> <div class="grid_4 right_container"> <div> newslist </div> <div> rightpar </div> </div> <div class="clear"></div> </div>
4. Test your script by requesting a Page in CQ5 Siteadmin that implements this Training title Component.
! If successful, you should see the default Page title, similar to the image below.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
106 www.adobe.com
7. Right-click the tab1 node - then select New, Node. 8. Enter the desired "Name" (items) and "Type" (cq:WidgetCollection).
10. Right-click the newly created title node - then select New, Property.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 108 www.adobe.com
11. Enter the desired "Name", "Type", and "Value" for the properties listed below.
! the property that will define where the content is stored ! ! ! ! Name = name Type = String Value = ./title
the property that will define the Widget type (i.e. user interface control) ! ! ! Name = xtype Type = String Value = textfield Name = fieldLabel Type = String Value = Enter Title Here
the property that will define the label applied to the Widget ! ! !
NOTE
These are but a few of the many properties and Widgets you can use to create a Dialog that meets the needs of your users/content authors. You can find a complete listing of widgets consulting the widget definitions at the following URL: http://dev.day.com/docs/en/cq/current/widgets-api/index.html
12. Test your script/Dialog by requesting a Page in CQ5 Siteadmin that implements this Training title Component - then double-click the "title" content to invoke the Dialog.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
109 www.adobe.com
Dialog of title
NOTE
Notice how tab1's label is "Tab 1." If you want to change this value, simply assign a property named title (type String) to the tab1 node, and assign a value.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
110 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
111 www.adobe.com
5. Set up a page iterator, filtering by valid pages 6. Iterate over the children 7. For each child, write out a link 8. Create a dialog box 9. Place an input widget on the dialog box so the author can enter the list parent. 10. Edit content.jsp. Replace the placeholder for newslist with a <cq:include> of your new component. Congratulations! You have successfully created a listChildren Component, with a Dialog, that allows content authors to enter content and have it used as a list root. This is a significant step in your development capabilities, as you are now able to create CQ Components that allow you to write content to the repository and use that information to create new rendered content.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
112 www.adobe.com
As discussed earlier, a Design(er) can be used to enforce a consistent look and feel across your Web site, as well as share global content. This global content is editable when using a Design Dialog. So once again, the many Pages that use the same Design(er) will have access to this global content. Fortunately, the process to create a Design Dialog is almost identical to creating a "normal" Dialog - the only difference being the name of the Dialog itself (i.e. dialog vs. design_dialog).
How to create a logo Component with a Design Dialog: 1. Using the same steps that we have used before, create a new logo Component.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
113 www.adobe.com
When using the Dialog Widget smartimage, as you will to complete this exercise, it is recommended to extend this "helper" Component. It contains the Java source img.GET.java, which allows you to more easily manage/transform images in fewer lines of code.
2. Open the file logo.jsp, and enter some HTML and JSP code, similar to below then Save. logo.jsp
<%@include file="/libs/foundation/global.jsp"%><% %><%@ page import="com.day.text.Text, com.day.cq.wcm.foundation.Image, com.day.cq.commons.Doctype" %><% String home = Text.getAbsoluteParent(currentPage.getPath(), 2); Resource res = currentStyle.getDefiningResource("fileReference"); if (res == null) { Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 114 www.adobe.com
res = currentStyle.getDefiningResource(file"); } ! log.error(path is: + currentStyle.getpath()); %><a href="<%= home %>.html"><% if (res == null) { %>Home Page<% } else { Image img = new Image(res); img.setItemName(Image.NN_FILE, "file"); img.setItemName(Image.PN_REFERENCE, "fileReference"); img.setSelector("img"); img.setDoctype(Doctype.fromRequest(request)); img.setAlt("Home Page"); img.draw(out); } %></a>
3. Open the file header.jsp in the Training Contentpage Component and replace the logo <div> section with a <cq:include> of the logo Component you just created, similar to below then Save. header.jsp
<%@include file="/libs/foundation/global.jsp" %> <div class="header"> <div class="container_16"> <div class="grid_8"> <cq:include path="logo" resourceType="training/components/logo" /> </div> <div class="grid_8"> <div class="search_area"> <div> userinfo </div> <div> toptoolbar </div> <div> search </div> <div class="clear"></div> </div> </div> <cq:include path="topnav" resourceType="training/components/topnav" /> </div> </div>
4. Test your script by requesting a Page in CQ5 Siteadmin that implements this Training logo Component.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 115 www.adobe.com
If successful, you should see the default logo output, similar to the image below.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
the property that defines the Widget type ! ! ! Name = xtype Type = String Value = textfield Name = fieldLabel Type = String Value = Parent Level (absolute) Name = fieldDescription Type = String Value = (e.g., 1 for /content/site)
the property that will give the author extra information about the Widget ! ! !
9. To get/define the smartimage widget that we will use for input and maintenance of the logo image, copy the node /libs/foundation/components/ image/dialog/items/image - then paste to the logo's Design Dialog so that it is a peer of the tab1 node.
! e.g. /apps/training/components/logo/design_dialog/items/items
NOTE
Instead of always reinventing the wheel, it is often more efficient to copy-and-paste existing Dialogs/Widgets that meet your needs. That being said, it is wise to review what you have just copied to better understand the internal workings of CQ. In addition, you may have noticed this Widget was pasted in the location where tabs are typically located. The smartimage xtype (along with a few others) is unique in that it provides a better content author experience when "casted" as a tab.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
117 www.adobe.com
11. Test your script/Design Dialog by requesting a Page in CQ5 Siteadmin that implements this Training logo Component - then select Design mode on your Sidekick, and select "edit" for the logo Component to invoke the Design Dialog.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
118 www.adobe.com
13. Select Edit mode - then review the Page output of the logo Component.
! If successful, you should see the custom Page logo, similar to the image below.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
119 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
120 www.adobe.com
Day provides a large amount of Components with its CQ product out-of-thebox. They range anywhere from a simple title Component, to the more complex paragraph system Component, which we will cover later. These Components are located at:
! /libs/foundation/components
It is strongly recommended you perform a complete review of each Component before beginning actual development. Not only are they learning tools, providing excellent examples of what you can do as within CQ as a developer, but you may find an existing foundation Component that provides a completed solution as required by content authors. In addition, you can extend these Components to provide a custom solution, much like you did with the logo Component (which is an extension of the foundation parbase Component).
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
121 www.adobe.com
How to include the foundation breadcrumb Component: 1. Open the file content.jsp in the Training Contentpage Component and replace the trail <div> section with a <cq:include> of the foundation breadcrumb Component, similar to below then Save. content.jsp
<%@include file="/libs/foundation/global.jsp" %> <div class="container_16"> <div class="grid_16"> <cq:include path="breadcrumb" resourceType="foundation/components/ breadcrumb" /> <cq:include path="title_node" resourceType="training/components/ title" /> </div> <div class="grid_12 body_container"> <div> par </div> </div> <div class="grid_4 right_container"> <cq:include path="newslist" resourceType="training/components/ listChildren" /> <div> rightpar </div> </div> <div class="clear"></div> </div>
NOTE
As always, it is a good idea to review what you have just included. Take note of the fact this Component only contains a Design Dialog (i.e. design_dialog), thus can only be modified in Design mode.
2. Test your script by requesting a Page in CQ5 Siteadmin that implements this foundation breadcrumb Component.
! If successful, you should see a breadcrumb trail, similar to the image below. ! A Cube Page has been added below the Products Page merely for example. Add your own pages below the Products page and open them to test the breadcrumb. ! In Design mode, feel free to modify the depth at which the breadcrumb trail begins.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 122 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
123 www.adobe.com
Congratulations! You have successfully modified the Foundation breadcrumb Component. Again, this is an exercise to use your knowledge to modify a Foundation component.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 124 www.adobe.com
Congratulations! You have successfully modified your topnav Component. Again, this is an exercise to use your knowledge of the currentStyle to set and extract design elements and use them to render content objects.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
125 www.adobe.com
The use of the CQ paragraph system Component is a necessity when wanting to have manageable and scalable Page content, without requiring excessive coding/Template creation. This foundation Component can be located at the path below:
! /libs/foundation/components/parsys
It allows content authors the ability to dynamically add, delete, move, copy, and paste "paragraphs" on a Page, not to mention the ability to use the column control Component to structure your content in columns. In addition, you can decide what "content" Components are allowed to be used by specific instances of the parsys. It is Day's STRONG opinion that the parsys should be used as often as possible, thus allowing for mere simple Component configuration as opposed to creating a large number of Templates that developers then have to maintain.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
126 www.adobe.com
How to include the foundation paragraph system Component: 1. Open the file content.jsp in the Training Contentpage Component and replace the par <div> section with a <cq:include> of the foundation paragraph system Component, similar to below then Save.
content.jsp
<%@include file="/libs/foundation/global.jsp" %> <div class="container_16"> <div class="grid_16"> <cq:include path="breadcrumb" resourceType="foundation/components/ breadcrumb" /> <cq:include path="title_node" resourceType="training/components/ title" /> </div> <div class="grid_12 body_container"> <cq:include path="par" resourceType="foundation/components/parsys" /> </div> <div class="grid_4 right_container"> <cq:include path="newslist" resourceType="training/components/ listChildren" /> <div> rightpar</div> </div> <div class="clear"></div> </div>
NOTE
As always, it is a good idea to review what you have just included. Take note of the fact this Component only contains a Design Dialog (i.e. design_dialog), thus can only be modified in Design mode.
2. Test your script by requesting a Page in CQ5 Siteadmin that implements this foundation paragraph system Component.
! If successful, you should see the paragraph system enabled, similar to the image below
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 127 www.adobe.com
3. Select Design mode on your Sidekick - then select "edit" for the paragraph system Component to invoke the Design Dialog. 4. Select the Components you would like to allow for this instance of the paragraph system - then select OK.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
128 www.adobe.com
NOTE
Notice how Components now appear in the Sidekick. These Components are now available to use in the paragraph system you recently added to the Template.
6. Add content (i.e. paragraphs) to the Page by click-and-dragging desired Component(s) into the paragraph system - then write content using the available Dialog.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
130 www.adobe.com
Congratulations! You have successfully included the paragraph system foundation Component. Day cannot stress enough the importance of this Component and how it can greatly affect your productivity if used wisely. Please be sure evaluate its use and optimization for every Template that is developed/ deployed.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
131 www.adobe.com
In this exercise, you will create a Component to output background images overlaid with any desired custom text. To be able to create dynamic images, you need a mechanism to request the rendering of the image object. To achieve this, you will add a selector to the request of the image of a page (e.g. /path/ to/a/resource.title.png). Requests with such a selector have to be handled by an image processing mechanism. To achieve this, you will use Sling's request processing mechanism. You will need to add an image processing script or Java servlet that will handle all requests with the specific selector(s) "*title.png". For the rendering of images with an overlay of text, the abstract Java servlet AbstractImageServlet is very helpful. You will merely have to overwrite the method createLayer() to implement your desired logic. Relevant functionalities (API calls) you will use are:
! ! ! ! ! com.day.cq.wcm.commons.AbstractImageServlet com.day.cq.wcm.commons.WCMUtils com.day.cq.wcm.foundation.ImageHelper com.day.image.Font com.day.image.Layer
132 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
In the interest of time, Day Training has provided the Java servlet and background image that will achieve this image processing/text overlay. You will simply perform a code review in class. These items can be found in: <usb>/ exercises/image-title. For more detailed information concerning the AbstractImageServlet and other Day related image processing capabilities, please review the CQ Javadocs provided with CQ WCM and on your USB. How to create a Title Image Component: 1. Create a new titleImage Component. Enter the desired Component Label, Title, Description, etc, then click Finish.
! ! ! ! ! Label = titleImage Title = Training Title Image Description = Training Custom Image component Group = Training Allowed Parents = */*parsys
2. Open the file titleImage.jsp, and enter some HTML and JSP code, similar to below then Save. titleImage.jsp
<%@include file="/libs/foundation/global.jsp"%><% %><%@ page import="org.apache.commons.lang.StringEscapeUtils, com.day.cq.commons.Doctype, org.apache.sling.api.resource.ResourceUtil" %> <% // first calculate the correct title - look for our sources if not set in paragraph String title = properties.get("title", currentPage.getTitle());
// use image title if type is "small" but not if diff should be displayed if (properties.get("type", "large").equals("small")) { String suffix = currentDesign.equals(resourceDesign) ? "" : "/" + currentDesign.getId(); // add mod timestamp to avoid client-side caching of updated images long tstamp = properties.get("jcr:lastModified", properties.get ("jcr:created", System.currentTimeMillis())); suffix += "/" + tstamp + ".png"; String xs = Doctype.isXHTML(request) ? "/" : ""; %> <img src="<%= resource.getPath() %>.title.png<%= suffix %>" alt="<%= StringEscapeUtils.escapeXml(title) %>"<%=xs%>><% // large title } else { %><h1><%= StringEscapeUtils.escapeHtml(title) %></h1><% } %>
3. Copy the files title.png.java and bgImage.ng from the USB (<usb>/ exercises/image-title) - then paste into the Title Image Component.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 134 www.adobe.com
4. Review the title.png.java file for a better understanding of the AbstractImageServlet. WARNING
It is possible you will need to modify the Java package to match the current location of the Training Contentpage Component.
e.g. apps.training.components.title
5. Create a component Dialog for the Title Image Component. 6. Right-click the tab1 node - then select New, Node. 7. Enter the desired "Name" (items) and "Type" (cq:WidgetCollection).
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
135 www.adobe.com
the property that will define the Widget type (i.e. user interface control) ! ! ! Name = xtype Type = String Value = textfield Name = fieldLabel Type = String Value = Title
the property that will define the label applied to the Widget ! ! !
11. Add the following properties to the type node. You will notice a new xtype being used here. We are introducing a dropdown selection widget.
! the property that will define where the content is stored ! ! ! ! Name = name Type = String Value = ./type
the property that will define the Widget type (i.e. user interface control) ! ! ! Name = xtype Type = String Value = selection Name = fieldLabel Type = String
136 CQ 5.4 Rev 2.1 20110506 www.adobe.com
the property that will define the label applied to the Widget ! !
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
! ! ! ! !
the property that will define the Widget type (i.e. user interface control) ! ! ! Name = value Type = String Value = large
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
! ! !
the property that will define the Widget type (i.e. user interface control) ! ! ! Name = value Type = String Value = small
17. Make sure that the Title Image component is in your Training Component Group and appears in the Sidekick.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
138 www.adobe.com
18. Test your script dragging the Title Image component into the Paragraph System and entering a custom title into the dialog box.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
139 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
140 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
141 www.adobe.com
use an xtype of cqinclude to refer to the smartimage widget in the Foundation Image Component Dialog. 2. Define the following properties on the items parent of the tab1 node:
! the property that defines widget reference ! ! ! ! ! ! ! Name = xtype Type = String Value = cqinclude Name = path Type = String Value = /libs/foundation/components/image/dialog/items.infinity.json
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
143 www.adobe.com
3. Delete the tab1 node. We dont need this node because we are now referring to the Foundation Image Component dialog structures.
Add the myImage Component to the Sidekick 1. Select Design mode by clicking on the ruler icon at the bottom of the Sidekick. 2.Click Edit button on Design of par edit bar. 5. Select Training Group 6. Return to Edit mode by expanding the Sidekick.
Test your Image component. 1. Drag the Training Image component onto a page. 2. Try to drag an image onto the thumbnail.# You will note that the drag-anddrop does not work.# This is because we have not yet defined the editConfig nodes and properties that will support this functionality. 3. Drag-and-drop into the dialog box does work.# This is because of the inherent functionality of the smartimage widget.# Double-click the thumbnail to open the dialog box. 4. Drag an image onto the dialog box. 5. Click OK.
Dening editCong
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 144 www.adobe.com
Now that we have our basic component working, let's add an editConfig to allow drag-and-drop from the Content Finder. 1. Right-click on your Image component.# Select New ... Node.##
! ! Name:### cq:editConfig Type:### cq:EditConfig
2. Right-click the new cq:editConfig node and select New ... Node.
! ! Name:## cq:dropTargets Type:### nt:unstructured
3. Right-click the new cq:dropTargets node and select New ... Node
! ! Name:## image Type:### cq:dropTargetConfig
And then enter the groups, accept, and propertyName properties as shown in the figure below:
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 145 www.adobe.com
4. Test the new functionality by dragging a new Training Image component onto the page and then dragging an image from the Content Finder onto the new paragraph.
Congratulations! You have successfully created a Simple Image component that allows drag-and-drop from the Content Finder.# As an exercise, examine a few of the other components in /libs/foundation/components that support dragand-drop from the Content Finder.# For example, the Download, Slideshow, and List components.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
146 www.adobe.com
Since the creation of "complex" Components is a common occurence in CQ, it would benefit you to observe a mock requirements analysis. This exercise provides just that. First, you will observe the needs of a user. Secondly, you will observe how a Day Solution Engineer may translate those needs. USER'S NEEDS: A Component that can be dropped into a paragraph system and displays an image, rich text, and the path of a Page in the system. The image:
1. 2. Must be editable by a content author. Can be dragged-and-dropped from the Content Finder
Must be editable by a content author Must allow for tables to be created. Must have a default value of "This is some text."
147 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
SOLUTION ENGINEER'S TRANSLATION: A paragraph system Component that allows for the writing and displaying of three properties (2 paragraph properties, 1 design/style property), and has both a Dialog and Design Dialog. The image:
1. 2. Is a Dialog Widget, most likely an xtype of smartimage. Must be configured in the Component's cq:editConfig to allow for draggingand-dropping of images from the Content Finder.
Is a Dialog Widget, most likely an xtype of richtext. Widget should enable all the features of the rich text editing plugin table. Widget should populate property defaultValue with "This is some text."
Is a Design Dialog Widget, most likely an xtype of pathcompletion. Widget should have property regex with a regular expression validating the user's input (e.g. "/^\/content\/training\/(.)*$/"). Widget should have property regexText with an error message if regular expression fails.
Though the order of sequence can differ, an Adobe Solution Engineer would most likely:
1. 2. 3. 4. Create a Component, making sure to allow that any paragraph system Component can be this Component's "parent." Edit the default JSP so it displays the content/properties in an appropriate manner, even without any written content. Create a Dialog for the Component. Create a Design Dialog for the Component.
148 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
5. 6. 7. 8. 9.
Add this Component to the list of allowed Components for a paragraph system Component. Test this Component by adding it to a Page to observe its output without any written content. Add a rich text Widget to the Dialog. Add an image Widget to the Dialog. Add a path completion Widget to the Design Dialog.
10. Perform necessary Component configurations. 11. Test this Component by writing content using the newly created Dialog and Design Dialog.
How to create a complex Component using CRXDE: 1. Create a new complex "content" Component.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
149 www.adobe.com
NOTE
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 150 www.adobe.com
For this exercise, do not concern yourself greatly with how the content is displayed, as this can easily be altered via code changes and/or CSS.
4. Add your complex Component to the paragraph system Component in Design mode.
Notice how your complex Component is listed under the Training group. This is because you declared such during the creation of your Component.
5. Test your script by adding an instance of this Component (i.e. paragraph) to the paragraph system Component of a Training Page.
! If successful, you should see the default complex Component output, similar to the image below.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 151 www.adobe.com
the property that will define to hide the label of the Widget
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
! ! ! ! !
Value = true Name = defaultValue Type = String Value = This is some text.
the property that will define the the default value of the Widget
9. Create an rtePlugins node (nodeType nt:unstructured) under the newly created text node. 10. Create a table node (nodeType nt:unstructured) under the newly created rtePlugins node. 11. Assign the features property (Type = String, Value = *) to the newly created table node.
NOTE
Once again, it is often more efficient to copy-and-paste existing Dialogs/Widgets that meet your needs. That being said, it is wise to review what you have just copied to better understand the internal workings of CQ. Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 153 www.adobe.com
If you examine closely enough, you will see the Widget is actually storing image related content at a level deeper than current resource (e.g. ./image/file, ./image/fileReference, etc.). This ties nicely with your previously written code (Image image = new Image(resource, "image");).
13. Now we build out the Design Dialog. Create an items node (nodeType cq:WidgetCollection) under the tab1 node of your Component's Design Dialog. 14. Create a path node (nodeType cq:Widget) under the newly created items node. 15. Assign the following properties to the newly created path node:
! the property that will define where content is stored ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! Name = name Type = String Value = ./path Name = xtype Type = String Value = pathfield Name = fieldLabel Type = String Value = Enter a Path Name = rootPath Type = String Value = /content/trainingSite Name = regex Type = String Value = /^\/content\/trainingSite\/(.)*$/
the property that will define the label applied to the Widget
the property that will define the regular expression used to evaluate user input
the property that will define the error message if a user's input fails the regular expression ! ! Name = regexText Type = String
154 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
16. Copy the node /libs/foundation/components/textimage/cq:editConfig then paste to the root node of your complex Component (e.g. /apps/training/ components/complex).
! enables drag-and-drop capabilities from the Content Finder
In order to be able to drag-and-drop assets from the Content Finder to a Component on a Page, there must be a drop targets configuration node called cq:dropTargets (of type nt:unstructured) below the edit configuration node (cq:editConfig) of a Component. 17. Using CRXDE, navigate to <path-to-complexcomponent>/cq:editConfig/cq:dropTargets/image Validate that the image node has the following properties:
! ! ! accept (Type = String) - the media types to be accepted (e.g. image/.*, etc.) groups (Type = String) - the groups in the Content Finder assets can be accepted from (e.g. media) propertyName (Type = String) - the property the reference should be stored (e.g. ./image/fileReference)
18. Navigate to the parameters node that is a child to the image node. Change the value of the sling:resourceType property to have the value: training/ components/complex. Remember that the sling:resourceType property should reference the location to find a rendering script. 19. Test your script/Dialog by requesting a Page in CQ5 Siteadmin that implements this Training complex Component - then interact with the Dialog and Design Dialog.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
155 www.adobe.com
If successful, you should see Page output, a Dialog and Design Dialog similar to the images below.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
156 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
158 www.adobe.com
Finishing the layout: Including the Foundation Toolbar and Userinfo components 1. Open the file header.jsp in the Training Contentpage Component and replace the userinfo <div> section with a <cq:include> of the foundation userinfo Component - then Save.
! ! path = userinfo resourceType = foundation/components/userinfo
2. Replace the toptoolbar <div> section with a <cq:include> of the foundation toolbar Component then Save.
! ! path = toptoolbar resourceType = foundation/components/toolbar
3. Open the file footer.jsp and replace the toolbar <div> section with a <cq:include> of the foundation toolbar Component then Save.
! ! path = toolbar resourceType = foundation/components/toolbar
159 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
4. Open the Site Admin Console and navigate to Training Site > English. Create a Toolbar page under English. (make sure that the name = toolbar) 5. Under Toolbar, create the following pages:
! ! ! ! Contacts Login Search Feedback
When you load any of the pages in your website, the toolbar will look as follows:
5. Enter Design Mode by clicking on the Design Mode icon at the bottom of the Sidekick. 6. Open the toptoolbar design dialog and enter top . In Toolbar Selector, check Use HTML List. 7. Open the toolbar design dialog and enter bottom. In Toolbar Selector, check Use HTML List. Including the Foundation Timing component The Foundation Timing component will record data on component script execution time. We will use the results of this component in the Performance Optimization section of the course. 1. Insert a <cq:include> of the foundation timing Component directly above the </body> element in the file body.jsp then Save.
! ! path = timing resourceType = foundation/components/timing
160 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
Including the Foundation Inherited Paragraph System component The inherited paragraph system (iparsys) is a paragraph system that also allows you to inherit the created paragraphs from the parent page. You add paragraphs to iparsys at for example,#/content/trainingSite/en.html#and as result, all the subpages of#English#that also have an iparsys with the same name inherit the created paragraphs from the English parent. On each level, you can add more paragraphs, which are then inherited by the children pages. You can also cancel paragraph inheritance at a level at any time. 1. Open the file content.jsp in the Training Contentpage Component and replace the rightpar <div> section with a <cq:include> of the foundation inherited paragraph system (i.e. iparsys) Component then Save.
! ! path = rightpar resourceType = foundation/components/iparsys
2. Test your script by requesting a Page in CQ5 Siteadmin that implements these multiple# foundation Components.
! If successful, you should see a Page view similar to the image below.
Congratulations! You have successfully included multiple foundation Components. Again, this exercise is used to apply finishing touches to the look and feel of the Training "Page" Component.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
162 www.adobe.com
Searching for content in CQ is very similar to "traditional" searches you have created in the past.
1. 2. 3. 4. 5. 6. An HTML form is needed to collect the user's input (search string). Once the form has been submitted, you need to capture the search string. You need to prepare a query statement based on the search string. A query object needs to be created that will connect to the content repository, and implement the query statement. You need to collect and parse the query results, if any. Output related to the query results should be displayed appropriately.
When querying a Java Content Repository (JCR), some basic functionality (API calls) need to be implemented:
! javax.jcr.Session - JCR session, can be reached for example by Node.getSession() 163 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
javax.jcr.query.QueryManager - QueryManager is used to create a Query object and can be reached via Workspace.getQueryManager() ! createQuery(String statement, String language) - creates the Query object for the provided statement in the provided language (e.g. SQL)
! !
javax.jcr.Query ! ! execute() - executes this Query and returns a QueryResult object getRows() - returns an iterator over the Rows of the query result table javax.jcr.query.QueryResult
For more detailed information, please review the Javadoc of the JCR and CRX provided on the USB. How to create a search Component: 1. Create a new search "content" Component.
! String stmt = "select * from cq:Page where jcr:path like '/content/ training/%' and contains(*, '" + slingRequest.getParameter("q") + "') order by jcr:score desc"; ! Query query = currentNode.getSession().getWorkspace().getQueryManager ().createQuery(stmt, Query.SQL); ! QueryResult results = query.execute(); ! if (results.getNodes() != null && results.getNodes().hasNext()) { ! ! NodeIterator it = results.getNodes(); ! ! while (it.hasNext()) { ! ! Node node = it.nextNode(); ! ! String npath = node.getPath(); ! ! Page contentPage = pageManager.getContainingPage (resourceResolver.getResource(npath)); ! ! String title = contentPage.getTitle(); ! ! String path = contentPage.getPath() + ".html"; %> ! ! <div class="searchresult"><a href="<%= path %>"> ! ! <%= title %></a></div> <% ! } } else { %> <div class="searchresult">No results found ... Please try again ...</div> <% } } %>
3. Add your search Component to the paragraph system Component in Design mode.
! Notice how the Component will be found in the "Training" group - this was defined during the creation of the Component
4. Test your script by adding an instance of this Component (i.e. paragraph) to the paragraph system Component of a Training Page.
! If successful, you should see the default complex Component output, similar to the image below.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
166 www.adobe.com
Congratulations! You have successfully created a search Component that queries the content in your Training Web site structure. You can further enhance this Component by adding Widgets to the Dialog to output default messages, written by a content author, if the search was successful, or unsuccessful.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
167 www.adobe.com
As stated earlier, i18n allows you to provide dynamic messaging based on the authors language preference. Internationalization is stored in the repository under nodes (nodeType sling:Folder) named i18n. The children nodes (nodeType sling:Folder + mixin mix:langauge) of the i18n node represent languages and are named after the ISO code of the languages that should be supported (e.g. en, de, fr, etc.). Below these language nodes are the message nodes (nodeType sling:MessageEntry), which will contain a simple key-message pair. The location of the i18n node within the repository decides its scope. If located in a project directory (e.g. /apps/training), it should contain only messages related to the current project. However, if located in a Component hierarchy, it should contain only Component specific translations. Globally used messages should be place in /apps/i18n. How to apply i18n to the title Component: 1. Create an i18n node (nodeType sling:Folder) under the root node of the title Component.
! e.g. /apps/training/components/content/title
168 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
2. Create an en node (nodeType sling:Folder) under the newly created i18n node. 3. Open a Content Explorer window and assign the mixin, mix:language to the newly created en node. Although they appear to be represented as properties, mixins are used to add functions to a node. They are basically reusable feature sets that can be added to any node type.
choose mixin
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
169 www.adobe.com
4. Return to CRXDE. Refresh the en node. 5. Set the following property on the newly created en node:
! the property that identifies the language using the ISO language code ! ! ! Name = jcr:language Type = String Value = en
6. Create a fieldLabel node (nodeType sling:MessageEntry) under the newly created en node. 7. Assign the following properties to the newly created fieldLabel node:
! the property that identifies the message key ! ! ! ! ! ! ! Name = sling:key Type = String Value = i18n-title Name = sling:message Type = String Value = Enter Title Here (i18n style)
170 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
8. Change the fieldLabel property (Value = i18n-title) on the title Component's Dialog title node.
! i.e. <path-to-component>/dialog/items/items/tab1/items/title
10. Test your script/Dialog by requesting a Page in CQ5 Siteadmin that implements this Training title Component - then invoke the Dialog to observe the changes.
! If successful, you should see Dialog output similar to the image below.
preference is English, the en message you defined earlier should appear. Change your default language to Spanish and see the Spanish label.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
172 www.adobe.com
Actually, you may never need to create a custom Widget. The CQ and ExtJS Widgets provided to you OOTB cover a large array of potential user input usecases and are highly configurable. It is Day's strong recommendation you thoroughly study available Widgets and potential configurations via the CQWIDGETS-API at the following URL:
http://dev.day.com/docs/en/cq/current/widgets-api/index.html
In this exercise we will introduce the <cq:includeClientLib> tag. The <cq:includeClientLib> tag#includes a CQ html client library, which can be a js, a css or a theme library. For multiple inclusions of different types,#for example js and css, this tag needs to be used multiple times in the jsp. This tag is a convenience wrapper around the com.day.cq.widget.HtmlLibraryManager service interface.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 173 www.adobe.com
The <cq:includeClientLib> tag has the following attributes: categories A list of comma-separated client lib categories. This will include all Javascript and CSS libraries for the given categories. The theme name is extracted from the request. Equivalent to: com.day.cq.widget.HtmlLibraryManager#writeIncludes theme A list of comma-separated client lib categories. This will include all theme related libraries (both CSS and JS) for the given categories. The theme name is extracted from the request. Equivalent to: com.day.cq.widget.HtmlLibraryManager#writeThemeInclude js A list of comma-separated client lib categories. This will include all Javascript libraries for the given categories. Equivalent to: com.day.cq.widget.HtmlLibraryManager#writeJsInclude css A list of comma-separated client lib categories. This will include all CSS libraries for the given categories. Equivalent to: com.day.cq.widget.HtmlLibraryManager#writeCssInclude themed A flag that indicates of only themed or non themed libraries should be included. If omitted, both sets are included. Only applies to pure JS or CSS includes (not for categories or theme includes). The <cq:includeClientLib> tag is documented at the following location: http:// dev.day.com/docs/en/cq/current/howto/taglib.html.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 174 www.adobe.com
How to create a JS library for new xtypes/Widgets: 1. Create a widgets node (nodeType cq:ClientLibraryFolder) under the root node of the Training project (e.g., /apps/training/widgets).
NOTE
The location of the client library can technically be anywhere in the repository as long as the node type is of cq:ClientLibraryFolder. For widget libraries /apps/<myproject>/clientlib would be a good convention, however, any .cs and .js libraries that must be available to visitors in a publish instance should be placed into /etc/clientlib or into /etc/designs, depending on the purpose of the library. As a best practice, you should place your client library folders under /etc/designs/<mydesign> and no longer under /apps, if these are required for the public website. They can/should probably be placed under /apps/<myproject> if this clientlib is meant to be as an extension to the cq.widgets for the authoring UI and therefore not accessible by web site visitors. Most of the core CQ library structures that need to be accessed on publish instances by web users, such as css, images, etc., have been moved out out of /libs and /apps, as the goal is to make those folders non-readable for anonymous visitors (to generally protect any code in there or authoring UIs residing under /libs). Thus those core CQ clientlibs (those that are used on publish instances) have been moved to /etc, such as /etc/clientlibs, or into the respective designs, as the design contains css and images already and /etc/designs and such should be readable on publish instances.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
175 www.adobe.com
the property that identifies the category these custom Widgets will be referenced by ! ! ! ! ! ! ! Name = categories Type = String[] Value = training.widgets Name = dependencies Type = String [] Value = cq.widgets Name = sling:resourceType Type = String Value = widgets/clientlib
3. Create a files node (nodeType sling:Folder) under the newly created widgets node. 4. In the widgets client library folder, create a file named "js.txt". In js.txt create a comma-separated list of widgets (js filenames) in the order that you want them to be included. For example:
! #base=files training.js
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
176 www.adobe.com
Congratulations! You have successfully created a JS library for custom xtypes/ Widgets. When you wish to add custom Widgets, all you need to do is drop it in the newly created files folder. Before you can use any custom xtypes/Widgets, you must first register the library in which they exist, which occurs during the WCM initialization process. To register your JS library you will need to modify /libs/foundation/ components/page/headlibs.jsp to add the reference to your Client Library Folder. Since you will want these widgets to be available for all your projects, you might want to consider creating a local page superType and move headlibs.jsp from your contentpage component to the local page superType. If you do create a local superType, remember that you must decide what other reusable files might go into that superType - for example: head.jsp, body.jsp and any reusable pieces.
How to register your newly created JS library using CRXDE: 1. Copy the file /libs/foundation/components/page/headlibs.jsp. Paste headlibs.jsp into the /apps/<application name>/components/page/ contentpage. 2. Open the file headlibs.jsp, and enter some HTML and JSP code, similar to below - the Save. headlibs.jsp
<%@include file="/libs/foundation/global.jsp" %><% %> <cq:includeClientLib categories="cq.foundation-main"/> <cq:includeClientLib js="training.widgets" /> <% currentDesign.writeCssIncludes(pageContext); %>
Congratulations! You have successfully registered a JS library for custom xtypes/ Widgets. Again, when you wish to add custom Widgets, all you need to do is drop it in the files folder of a registered JS library.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 177 www.adobe.com
Finally, we will create a new xtype/Widget by extending an existing xtype/ Widget. ExtJS is a large, powerful, and somewhat complicated JS framework. If possible, it may benefit you to attend ExtJS training. How to create and test a custom xtype/Widget: 1. Create a new file in the folder /apps/training/widgets/files.
Training.Selection.superclass.constructor.call(this, config); this.selectionForm = new CQ.Ext.form.TimeField({ name: this.name, hideLabel: true, anchor: "100%", minValue: '8:00am', maxValue: '6:00pm, ! intDate: new Date() }); this.add(this.selectionForm); }, processRecord: function(record, path){ this.selectionForm.setValue(record.get(this.getName())); }
3. Now it is time to use our new xtype. Create a training node (nodeType cq:Widget) under the Training title Component's Dialog tab1 widget collection.
! e.g. /apps/training/components/content/title/dialog/items/items/tab1/items
the property that will define the label applied to the Widget
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
179 www.adobe.com
5. Test your script/Dialog by requesting a Page in CQ5 Siteadmin that implements this Training xtype/Widget (i.e. the title Component) - then double-click the "title" content to invoke the Dialog.
! If successful, you should see the custom Dialog xtype, similar to the image below.
Congratulations! You have successfully created and applied a custom xtype/ Widget. This is a significant step in your development capabilities, as you are now able to create custom CQ xtypes/Widgets. To fully complete this exercise, you would output/use the user's selection in manner deemed appropriate.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
180 www.adobe.com
OSGi defines an architecture for developing and deploying modular applications and libraries (it is also known as the Dynamic Module System for Java). OSGi containers allow you to break your application into individual modules (are JAR files with additional meta information and called#bundles#in OSGi terminology) and manage the cross-dependencies between them with:
! ! services#implemented within the container a#contract#between the container and your application
These services and contracts provide an architecture which enables individual elements to dynamically discover each other for collaboration. An OSGi framework then offers you dynamic loading/unloading, configuration and control of these bundles - without requiring restarts. This architecture allows you to extend Sling with application specific modules. Sling, and therefore CQ5, uses the#Apache Felix#implementation of OSGi and is based on the OSGi Service Platform Release 4 Version 4.2 Specifications. They are both collections of OSGi bundles running within an OSGi framework.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
181 www.adobe.com
This enables you to perform the following actions on any of the packages within your installation:
! ! ! ! ! ! ! install start stop update uninstall see the current status access more detailed information (e.g. symbolic name, version, location, etc) about the specific bundles
How to create and consume an OSGi bundle: 1. Select and right-click the Training projects OSGi bundle source directory (i.e. /apps/training/src) - then select Build .. Create Bundle.
2. Enter the "Symbolic Bundle Name", "Bundle Name", "Bundle Description", and "Package" - then click Finish.
NOTE
The Bundle wizard creates the following elements: ! ! ! The node org.training.test.TestBundle#of type#nt:folder - it is the bundle container node The file org.training.test.TestBundle.bnd - it acts as deployment descriptor for your bundle and consists of a set of headers The folder structures: src/main/java/org/training/test - it will contain the packages and the Java classes ! src/main/resources - it will contain the resources used within the bundle The#Activator.java#file - it is the optional listener class to be notified of bundle start and stop events !
4. Create a new Java class in the newly created bundle source directory (i.e. src/ main/java/org/training/test).
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
184 www.adobe.com
! ! !
7. Select and right-click the HelloWorld.java file - then select Build .. Compile.
8. Select and right-click the org.training.test.TestBundle.bnd file - then select Build Bundle.
! You should get a Build completed successfully message dialog.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
186 www.adobe.com
9. Open the Training title Component's title.jsp, and enter some HTML and JSP code, similar to below - then Save.
! The focus is to import the newly created Java class and use it
title.jsp
<%@include file="/libs/foundation/global.jsp"%> <%@ page import="org.training.test.HelloWorld" %> <h1><%= properties.get("title", currentPage.getTitle()) %></h1> <% HelloWorld hw = new HelloWorld(); %> <h3><%= hw.getMessage() %></h3>
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
187 www.adobe.com
10. Test your bundle/script by requesting a Page in CQ5 Siteadmin that implements this Training bundle (i.e. the title Component).
! If successful, you should see the title Component output, similar to the image below.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
188 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
Process (Script, Java method call)# Container (Sub Workflow)# OR Split/Join# AND Split/Join All the steps share the following common properties:#AutoAdvance and Timeout alerts (scriptable). Transition Defines the link between two consecutive steps. It is possible to apply rules to the Transition. WorkItem The workItem is the there is a task identifier and is put into the respective inbox. A workflow instance can have one or many WorkItems at the same time (depending on the workflow model). The WorkItem references the workflow instance. In the repository the WorkItem is stored below the workflow instance. Payload References the resource that has to be advanced through a workflow. The payload implementation references a resource in the repository (by either a path or an UUID) or a resource by a URL or by a serialized java object. Referencing a resource in the repository is very flexible and in conjunction with sling very productive: for example the referenced node could be rendered as a form. Lifecycle Is created when starting a new workflow (by choosing the respective workflow model and defining the payload) and ends when the end node is processed.# The following actions are possible on a workflow instance:## Terminate Suspend Resume
190 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
Restart Completed and terminated instances are archived. Inbox Each logged in user has its own workflow inbox in which the assigned WorkItems are accessible. The WorkItems are assigned#either to the user itself or to the group to which he belongs.
Workow Console
The Workflow console is the centralized location for workflow management in CQ. It can be accessed via the Workflows button on the Welcome page or through the Workflows button in the toolbar on any CQ5 console (for example: Websites, Tools, Tagging). Within the console there are 4 tabs: Models Lists the workflow models currently available. Here you can create, edit or delete workflow models. Instances Shows you details of workflow instances which are currently active. These instances are also version dependent. Archive Enables you to access details of workflow instances which have terminated, for whatever reason. Launcher Allows you to define a workflow to be launched if a specific node has been updated.
Starting a Workow
Workflow Console
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
191 www.adobe.com
SiteAdmin Console (Websites tab) Right Context Menu Workflow item in Toolbar Sidekick NOTE
The payload is assigned to the current version of the workflow; if the main copy of the workflow is updated later, the changes will have no impact on the currently running instance.
We will be starting the workflow from the SiteAdmin console. 1. Open the SiteAdmin console, either by clicking on the Websites button from the Welcome page or by clicking on the globe icon at the bottom of your sidekick. 2. Right-click on one of your pages to open the context menu. Select Workflow...
3. Select the Publish Example workflow and fill in any desired optional information and click Start.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
192 www.adobe.com
4. You will notice that the workflow icon shows up in the SiteAdmin console next to the page you chose.
5. Change to the Workflow Console by returning to the Welcome Screen and selecting Workflows. Select the Models tab. Open the Publish Example workflow by double-clicking the workflow model entry.
You will notice that the Publish Example workflow has 2 steps: Validate Content and Publish Content.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 193 www.adobe.com
The Validate Content step is a Participant step assigned to the user admin. The Publish Content step is a Process step with the Implementation Property set to ActivatePageProcess. You can validate the values of the step properties by double-clicking on the step to open the dialog box.
6.
Switch to the Inbox by changing to either the Welcome Screen or the SiteAdmin Screen and clicking on the Inbox tab to change context. The Inbox will show the WorkItem entry for the page you put into workflow.
7. Select the WorkItem Validate Content and click Complete. Notice that the WorkItem disappears from the Inbox. You will also note that the page is now no longer in workflow (the workflow icon is gone from the status column) and the page has been published or is pending publication (depending on whether you have a CQ5 Publish instance running).
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
194 www.adobe.com
Congratulations! You have learned about the Workflow Console. Also, you have successfully placed a page in workflow and moved that page through the workflow steps to the the end of the workflow. In the next exercise, you will use this knowledge to help you create a custom process step and define a workflow to use that custom process step.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
195 www.adobe.com
A workflow is made of steps. The steps that define a workflow are either participant steps or process steps. Participant steps require manual intervention by a person to advance the workflow. Process steps, on the other hand, are automatic actions that are executed by the system if certain specified conditions are met. CQ provides a number of predefined process steps that perform common actions, which an administrators can use when building a new workflow. Custom process steps can also be added for tasks not covered by the built-in steps. Process steps, also called automated steps, can be defined by using either an#ECMA script or a service (a Java class in a bundle). Services can be developed to listen to special workflow events and perform tasks according to the business logic. The following instructions explain how to create a workflow custom process step using a Java class. To successfully complete and understand these instructions, you will need:
! ! A running CQ5 Author instance A completed Training project with appropriate extensions
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
196 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
197 www.adobe.com
3. Open the newly created Java class file MyProcess.java, and enter some Java code, similar to below - then Save.
package com.mycompany.test; import import import import import import import import import import import com.day.cq.workflow.WorkflowException; com.day.cq.workflow.WorkflowSession; com.day.cq.workflow.exec.WorkItem; com.day.cq.workflow.exec.WorkflowData; com.day.cq.workflow.exec.WorkflowProcess; com.day.cq.workflow.metadata.MetaDataMap; org.apache.felix.scr.annotations.Component; org.apache.felix.scr.annotations.Properties; org.apache.felix.scr.annotations.Property; org.apache.felix.scr.annotations.Service; org.osgi.framework.Constants;
import javax.jcr.Node; import javax.jcr.RepositoryException; /** * Sample workflow process that sets an <code>approve</code> property to the payload based on the process argument value. */ @Component @Service @Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "A sample workflow process implementation."), @Property(name = Constants.SERVICE_VENDOR, value = "Adobe"), @Property(name = "process.label", value = "My Sample Workflow Process")}) public class MyProcess implements WorkflowProcess { private static final String TYPE_JCR_PATH = "JCR_PATH"; public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException { WorkflowData workflowData = item.getWorkflowData(); if (workflowData.getPayloadType().equals(TYPE_JCR_PATH)) { String path = workflowData.getPayload().toString() + "/ jcr:content"; try { Node node = (Node) session.getSession().getItem(path); if (node != null) { node.setProperty("approved", readArgument(args)); session.getSession().save(); } Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 198 www.adobe.com
} catch (RepositoryException e) { throw new WorkflowException(e.getMessage(), e); } } } private boolean readArgument(MetaDataMap args) { String argument = args.get("PROCESS_ARGS", "false"); return argument.equalsIgnoreCase("true"); } }
4. Compile the Java class using Build..Compile. NOTE The java methods, respectively the classes that implement the executable Java method are registered as OSGI services, enabling you to add methods at anytime during runtime. 5. Build the Bundle using Build..Build Bundle. Once you get the Build Successful message, you will notice that the bundle .jar file shows up in the install directory. The bundle is now uploaded and installed into CQ. Congratulations! You have created a new Java class that can be used as a custom Implementation in a Process step.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
199 www.adobe.com
2. Open the Approval workflow by double-clicking on the Name. 3. You will notice that the new Approval workflow model has a Start, End and Step 1.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
200 www.adobe.com
To edit Step 1, double-click on the step itself. 4. Assign the following values for the Step 1 properties: !
! !
5.
Add a Process step to the workflow by dragging-and-dropping the Process Step component onto the workflow model.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
201 www.adobe.com
6. Open the Process Step dialog and set the properties of your new step: ! Description = Set approved property ! Implementation = My Sample Workflow Process
! ! Title = Final Approval Process Arguments = true
Click Save.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
202 www.adobe.com
7.
Test your new workflow. In the WebSites panel, select any page. Bring up the right context menu and choose Workflow... Select the new Approval workflow and click Start.
8.
Monitor the progress of your workflow from the inbox and move the page through the workflow. Check for the approved property on the page once the workflow has completed.
Congratulations! You have successfully created a custom Implementation for a workflow process step. You can use this same methodology for any custom Implementation you need to create for your workflows.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
203 www.adobe.com
Packages can include content and project-related data. A package is a zip file that contains the content in the form of a file-system serialization (called "vault" serialization) that represents the content from the repository as an easyto-use-and-edit representation of files and folders. Additionally, it contains vault meta information, including a filter definition, and import configuration information. Additional content properties can be included in the package, such as a description, a visual image, or an icon. These properties are#for the content package consumer#for informational purposes only. You can perform the following actions with packages:
! ! ! ! ! ! ! ! ! Create new packages Modify existing packages Build packages Upload packages Install packages Download packages from the package share library Download packages from CQ to a local machine Apply package filters View package information
204 CQ 5.4 Rev 2.1 20110506 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA
There are multiple ways to manage content packages: ! ! ! CRX Package Manager - using the direct CRX interface CQ Package Manager cURL actions - command line option that allows package actions to be automated In this exercise, we will be using the CRX Package Manager. You should take some time to explore the documentation for the CQ and cURL methods of managing packages.
How to create, build, and download a CQ package in the "Tools" section of CQ5: 1. Navigate to the CRX Main Console. 2.Select the Package Manager.
CQ5 packages
3. Select Create Package. 4. Enter the package "Group Name" (training) and "Package Name" (trainingproject).
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
205 www.adobe.com
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
206 www.adobe.com
8. Click on the browser icon to select the paths to be included in the package. Choose /apps/training.
/apps/foundation/components/breadcrumb
This creates a package definition to save everything that we have done this week into the content package. You can then upload all these structures into any instance of CQ5.
10. Preview by clicking More...Preview and then Build the package. The Activity Log will show you what is being included in the package.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
208 www.adobe.com
Congratulations! You have successfully created a package, added a rule to the filter definition, built the package, and have downloaded the package, which you can now share with your CQ development team.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 209 www.adobe.com
A key issue is the time your Web site takes to respond to visitor requests. Although this value will vary for each request, an average target value can be defined. Once this value is proven to be both achievable and maintainable, it can be used to monitor the performance of the Web site and indicate the development of potential problems. The response times you will be aiming for will be different on the author and publish environments, reflecting the different characteristics of the target audience: Author Environment This environment is used by authors entering, and updating content, so it must#cater for a small number of users who each generate a high number of performance intensive requests when updating content pages and the individual elements on those pages. Publish Environment This environment contains content which you make available to your users, where the number of requests is even greater and the#speed is just as vital, but since the nature of the requests is less dynamic, additional performance
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
210 www.adobe.com
enhancing mechanisms can be leveraged, such as that#the content is cached or#load-balancing is applied. Performance Optimization Methodology A performance optimization methodology for CQ projects can be summed up to five very simple rules that can be followed to avoid performance issues from the start.#These rules, to a large degree,#apply#to Web projects in general, and are relevant to project managers and system administrators to ensure that their projects will not face performance challenges when launch time comes. Planning for Optimization Around 10% of the project effort should be planned for the performance optimization phase. Of course, the actual performance optimization requirements will depend on the level of complexity of a project and the experience of the development team. While your project may ultimately not require all of the allocated time, it is good practice to always plan for performance optimization in that suggested range. Whenever possible, a project should first be soft-launched to a limited audience#in order to gather real-life experience and perform further optimizations, without the additional pressure that follows a full announcement. Once you are "live", performance optimization is not over. This is the point in time when you experience the "real" load on your system. It is important to plan for additional adjustments after the launch. Since your system load changes and the performance profiles of your system shifts over time, a performance "tune-up" or "health-check" should be scheduled at 6-12 months intervals. Simulate Reality
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
211 www.adobe.com
If you go live with a Web site and you find out after the launch that you run into performance issues there is only one reason for that: Your load and performance tests did not simulate reality close enough. Simulating reality is difficult and how much effort you will reasonably want to invest into getting "real"#depends on the nature of your project. "Real" means not just "real code" and "real traffic", but also "real content", especially regarding content size and structure. Keep in mind that your templates may behave completely different depending on the size and structure of the repository. Establish Solid Goals The importance of properly establishing#performance#goals is not to be underestimated. Often, once people are focused on specific performance goals, it is very hard to change these goals afterwards,#even if they are based on wild assumptions. Establishing good, solid performance goals is really one of the trickiest areas. It is often best to collect real life logs and benchmarks from a comparable Web site (for example the new Web site's predecessor). Stay Relevant It is important to optimize one bottleneck at a time. If you do things in parallel without validating the impact of the one optimization, you will lose track of which optimization measure actually helped. Agile Iteration Cycles Performance tuning is an iterative process that involves, measuring, analysis, optimization and validation until the goal is reached. In order to properly take this aspect into account, implement an#agile validation process in the optimization phase rather than a more heavy-weight testing process after each iteration.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
212 www.adobe.com
This largely means that the developer implementing the optimization should have a quick way to tell if the optimization has already reached the goal, which is valuable information, because when the goal is reached, optimization is over. Basic Performance Guidelines Generally speaking, keep your uncached html requests to less than 100ms.#More specifically, the following may serve as a guideline:
! ! ! ! ! 70% of the requests for pages should be responded to in less than 100ms. 25% of the requests for pages should get a response within 100ms-300ms. 4% of the requests for pages should#get a response within#300ms-500ms. 1% of the requests for pages should#get a response within#500ms-1000ms. No pages should respond slower than 1 second.
There are a certain number of issues that frequently contribute to performance issues which mainly revolve around (a) dispatcher caching inefficiency and (b) the use of queries in normal display templates.#JVM and OS level tuning usually do not lead to big leaps in performance and should therefore be performed at the very tail end of the optimization cycle. Your best friends during a usual performance optimization exercise are the request.log, component based timing, and last but not least - a Java profiler. How to monitor Page response times: 1. Navigate to and open the file request.log located at <cq-install-dir>/crxquickstart/logs. 2. Request a Page in author that utillizes your Training Template and Components.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 213 www.adobe.com
e.g. /content/trainingSite/en/company
3. Review the response times directly related to the previous step's request.
! A Page request of /content/trainingSite/en/company
NOTE
Though this is clearly the response time of a Page while in author, it is good practice to be able to identify where response times are located (request.log) and how to identify a specific Page request/response in the log file itself. Ideally, this test would occur on the publish instance to get a better idea of its expected behavior in production.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
214 www.adobe.com
Congratulations! You have successfully reviewed the response time of a Page in CQ using the request.log. Again, this will aid your development in being able to monitor response times of Pages that implement custom Templates and Components, and comparing said time to your project goals.
How to find long lasting request/response pairs: 1. Navigate to the helper tool rlog.jar located in <cq-install-dir>/crxquickstart/opt/helpers using your command line.
NOTE
Essentially, the rlog.jar tool is parsing the request.log to find and display the 10 longest requests/responses. You can use this information to further investigate what may be the cause of the long response.
Congratulations! You have successfully found and displayed long lasting requests/ responses in CQ. Again, this is just one of many tools to help you meet your project's performance goals. Finally, we will view timing statistics for Page rendering.
How to monitor Component based timing: 1. Request a Page in author that was created from your Training Template and Components.
! e.g. /content/trainingSite/en/company
2. View the HTML source of the Page requested in step 1. 3. Navigate to and select the "Timing chart URL" located in the HTML source.
! You will find this URL most likely near the bottom of the HTML source, as it is generated by the foundation timing Component
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
217 www.adobe.com
4. Copy the "Timing chart URL" - then paste it in the address bar of your favorite Web browser. 5. Investigate the visual output to identify any Component that may be causing a slow response time.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
218 www.adobe.com
NOTE
The light blue color identifies when the Component/JSP started. The dark blue color identifies how long the Component/JSP took to respond.
Congratulations! You have successfully monitored Component based timing using the foundation timing Component. Again, this will aid your development in being able to monitor the response times of specific Components within the context of an actual Page/Template request.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
219 www.adobe.com
NOTE The cloning method used here is a developer convenience. To clone a CQ5 instance for production, please consult the documentation and the CQ5 knowledge base.
A Publish instance is the CQ5 installation from which web site visitors will request pages. How to clone an Author instance: 1. Make sure that your Author instance is stopped. You cannot successfully clone a running CQ5 instance. 2. Copy your author folder (e.g. C:/day/cq5/author). 3. Paste your author folder into the same folder structure (e.g. C:/day/cq5). 4. After the copy rename your author-copy folder to publish (e.g. C:/day/cq5/ publish). 5. Rename the CQ5 quickstart JAR to cq-publish-4503.jar.
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506 220 www.adobe.com
! ! ! NOTE
cq = the application publish = the WCM mode it will run in (e.g. author or publish) 4503 = the port it will run in (e.g. any available port is acceptable)
If no port number is provided in the file name, CQ5 will select the first available port from the following list: 1) 4502, 2) 8080, 3) 8081, 4) 8082, 5) 8083, 6) 8084, 7) 8085, 8) 8888, 9) 9362, 10) random.
Congratulations! You have successfully cloned and started a CQ5 publish instance. To start CQ5 in the future, double-click the renamed CQ5 quickstart JAR file (e.g. cq-publish-4503.jar).
Bringing the Digital Experience to Life ! Copyright 2011, Adobe Systems, Inc. USA CQ 5.4 Rev 2.1 20110506
221 www.adobe.com