Chuyển đến nội dung chính

[CQ/AEM] Introduction

CQ Introduction

Introduction Day’s CQ5 platform allows you to build compelling content-centric applications that combine Web Content Management, Workflow Management, Digital Asset Management and Social Collaboration.
The product has been completely redesigned from Communiqué 4, allowing Day to use new
architecture and technologies, thus increasing functionality while reducing complexity. Extensive use of standards helps ensure long-term stability
The Graphical User Interface has been completely re-engineered using AJAX and the latest browser technologies. This leads to an unparalleled user experience. With the help of the Apache Sling framework (a core part of the CQ5 platform) it becomes fast and efficient to develop content-enabled vertical applications (CEVA) that are both JCR-based and REST-style.
All these changes ensure that CQ:
  • is easily scalable
  • is highly reliable
  • makes it easier to reuse, or extend, elements
  • is faster
  • allows for rapid development
  • is already feature-rich when taken straight out-of-the-box

CQ in-Depth

JSR-170 and the JCR API

JSR 170 is the Java Specification Request for the Content Repository for JavaTM technology API.
Specification lead is held by Day Software AG.
The JCR API package, javax.jcr.* is used for the direct access and manipulation of repository
content.The Java Content Repository (JCR) is fully leveraged with many important features; including search, versioning, access control and observation.
CRX is Day’s proprietary implementation of the JCR.
Apache Jackrabbit is an open source, fully conforming, implementation of this API.

CQ DAM

CQ DAM (Communiqué Digital Asset Management) is used to centrally manage all digital media
files and essential metadata information.

Widgets

CQ WCM has been developed using the ExtJS library of widgets.
Widget API: dev.day.com/docs/en/cq/current/widgets-api/index.html?class=CQ.form.rte.HtmlRules.Serializer

FileVault (source revision system)

FileVault provides your JCR repository with file system mapping and version control. It can be used to manage CQ development projects with full support for storing and versioning project code,content, configurations and so on, in standard version control systems (for example, Subversion).

Workflow Engine

Your content is often subject to organizational processes, including steps such as approval and sign-off by various participants. These processes can be represented as workflows, defined within CQ, then applied to the appropriate content pages or digital assets as required.The Workflow Engine is used to manage the implementation of your workflows, and their subsequent application to your content. More information on how to use Workflows is given in the http://docs.adobe.com/docs/en/cq/current.html#Working%20with%20AEM%20Workflows

Dispatcher

The Dispatcher is Day’s tool for both caching and/or load balancing. Further information can be found under Tools – the Dispatcher http://docs.adobe.com/docs/en/dispatcher.html.

Localization

Localization is at the core of CQ5. It provides support for adapting applications, created using the CQ5 platform, into different languages and regional configurations . While processing the request, the Locale is extracted. This is then used to reference a language code, and optionally a country code, which can be used for controlling either the specific content or format of certain output. Localization will be used throughout CQ5 – wherever reasonable. One notable exception is the system log information of CQ5 itself, this is never localized and always in English.
CQ Translator: http://docs.adobe.com/docs/en/cq/current/developing/cq5-translator.html

Sling Request Processing

INTRODUCTION TO SLING

AEM is built using 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 in the case of AEM, the CRX Content Repository, as its data store. Sling has been contributed to the Apache Software Foundation - further information can be found at Apache.
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. In particular, when implementing a Web Content Management system such as the WCM in the WEM solution.
A 15min screencast presents the first steps for developing with Sling.
The following diagram explains Sling script resolution: it shows how to get from HTTP request to content node, from content node to resource type, from resource type to script and what scripting variables are available.
The following diagram explains all the hidden, but powerful, request parameters you can use when dealing with the SlingPostServlet, the default handler for all POST requests that gives you endless options for creating, modifying, deleting, copying and moving nodes in the repository.

SLING IS CONTENT CENTRIC

Sling is content-centric. This means that processing is focused on the content as each (HTTP) request is mapped onto content in the form of a JCR resource (a repository node):
  • the first target is the resource (JCR node) holding the content
  • secondly, the representation, or script, is located from the resource properties in combination with certain parts of the request (e.g. selectors and/or the extension)

RESTFUL SLING

Due to the content-centric philosophy, Sling implements a REST-oriented server and thus features a new concept in web application frameworks. The advantages are:
  • very RESTful, not just on the surface; resources and representations are correctly modelled inside the server
  • removes one or more data models
    • previously the following were needed: URL structure, business objects, DB schema;
    • this is now reduced to: URL = resource = JCR structure

URL DECOMPOSITION

In Sling, processing is driven by the URL of the user request. This defines the content to be displayed by the appropriate scripts. To do this, information is extracted from the URL.
If we analyze the following URL:
We can break it down into its composite parts:
protocol
host
content path
selector(s)
extension
suffix
param(s)
http://
myhost
tools/spy
.printable.a4.
html
/
a/b
?
x=12
protocol: HTTP
host: Name of the website.
content path: Path specifying the content to be rendered. Is used in combination with the extension; in this example they translate to tools/spy.
selector(s): Used for alternative methods of rendering the content; in this example a printer-friendly version in A4 format. (printable.a4)
extension: Content format; also specifies the script to be used for rendering. (html)
suffix: Can be used to specify additional information. (a/b)
param(s): Any parameters required for dynamic content. (x=12)

From URL to Content and Scripts

Using these principles:
  • the mapping uses the content path extracted from the request to locate the resource
  • when the appropriate resource is located, the sling resource type is extracted, and used to locate the script to be used for rendering the content
The figure below illustrates the mechanism used, which will be discussed in more detail in the following sections.
file
With Sling, you specify which script renders a certain entity (by setting the sling:resourceType property in the JCR node). This mechanism offers more freedom than one in which the script accesses the data entities (as an SQL statement in a PHP script would do) as a resource can have several renditions.

Mapping requests to resources

The request is broken down and the necessary information extracted. The repository is searched for the requested resource (content node):
  • first Sling checks whether a node exists at the location specified in the request; e.g. ../content/corporate/jobs/developer.html
  • if no node is found, the extension is dropped and the search repeated; e.g. ../content/corporate/jobs/developer
  • if no node is found then Sling will return the http code 404 (Not Found).
Sling also allows things other than JCR nodes to be resources, but this is an advanced feature.

LOCATING THE SCRIPT

When the appropriate resource (content node) is located, the sling resource type is extracted. This is a path, which locates the script to be used for rendering the content.
The path specified by the sling:resourceType can be either:
  • absolute
  • relative, to a configuration parameter
  • Relative paths are recommended by Adobe as they increase portability.
All Sling scripts are stored in subfolders of either /apps or /libs, which will be searched in this order (see Customizing Components and Other Elements).
A few other points to note are:
  • when the Method (GET, POST) is required, it will be specified in uppercase as according to the HTTP specification e.g. jobs.POST.esp (see below)
  • various script engines are supported:
    • .esp, .ecma: ECMAScript (JavaScript) Pages (server-side execution)
    • .jsp: Java Server Pages (server-side execution)
    • .java: Java Servlet Compiler (server-side execution)
    • .jst: JavaScript templates (client-side execution)
The list of script engines supported by the given instance of CQ are listed on the Felix Management Console (http://localhost:4502/system/console/config/slingscripting.txt).
Additionally, Apache Sling supports integration with other popular scripting engines (e.g., Groovy, JRuby, Freemarker), and provides a way of integrating new scripting engines.
Using the above example, if the sling:resourceType is hr/jobs then for:
  • GET/HEAD requests, and URLs ending in .html (default request types, default format)
  • The script will be /apps/hr/jobs/jobs.esp; the last section of the sling:resourceType forms the file name.
  • POST requests (all request types excluding GET/HEAD, the method name must be uppercase)
  • POST will be used in the script name.
  • The script will be /apps/hr/jobs/jobs.POST.esp.
  • URLs in other formats, not ending with .html
  • For example ../content/corporate/jobs/developer.pdf
  • The script will be /apps/hr/jobs/jobs.pdf.esp; the suffix is added to the script name.
  • URLs with selectors
  • Selectors can be used to display the same content in an alternative format. For example a printer friendly version, an rss feed or a summary.
  • If we look at a printer friendly version where the selector could be print; as in../content/corporate/jobs/developer.print.html
  • The script will be /apps/hr/jobs/jobs.print.esp; the selector is added to the script name.
  • If no sling:resourceType has been defined then:
    • the content path will be used to search for an appropriate script (if the path based ResourceTypeProvider is active).
    • For example, the script for ../content/corporate/jobs/developer.html would generate a search in/apps/content/corporate/jobs/.
    • the primary node type will be used.
  • If no script is found at all then the default script will be used.
  • The default rendition is currently supported as plain text (.txt), HTML (.html) and JSON (.json), all of which will list the node's properties (suitably formatted). The default rendition for the extension .res, or requests without a request extension, is to spool the resource (where possible).
  • For http error handling (codes 403 or 404) Sling will look for a script at either:
    • the location /apps/sling/servlet/errorhandler for customized scripts
    • or the location of the standard scripts /libs/sling/servlet/errorhandler/403.esp, or 404.esp respectively.
If multiple scripts apply for a given request, the script with the best match is selected. The more specific a match is, the better it is; in other words, the more selector matches the better, regardless of any request extension or method name match.
For example, 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 correct location:
  1. GET.esp
  2. jobs.esp
  3. html.esp
  4. print.esp
  5. print.html.esp
  6. print/a4.esp
  7. print/a4/html.esp
  8. print/a4.html.esp
Then the order of preference would be (8) - (7) - (6) - (5) - (4) - (3) - (2) - (1).
In addition to the resource types (primarily defined by the sling:resourceType property) there is also the resource super type. This is generally indicated by the sling:resourceSuperType property. These super types are also considered when trying to find a script. The advantage of resource super types is that they may form a hierarchy of resources where the default resource type sling/servlet/default (used by the default servlets) is effectively the root.
The resource super type of a resource may be defined in two ways:
  • by the sling:resourceSuperType property of the resource.
  • by the sling:resourceSuperType property of the node to which the sling:resourceType points.
For example:
  • /
    • a
    • b
      • sling:resourceSuperType = a
    • c
      • sling:resourceSuperType = b
    • x
      • sling:resourceType = c
    • y
      • sling:resourceType = c
      • sling:resourceSuperType = a
The type hierarchy of /x is [ c, b, a, <default>] while for /y the hierarchy is [ c, a, <default>] because /y has thesling:resourceSuperType property whereas /x does not and therefore its supertype is taken from its resource type.

Sling Scripts cannot be called directly

Within Sling, scripts cannot be called directly as this would break the strict concept of a REST server; you would mix resources and representations.
If you call the representation (the script) directly you hide the resource inside your script, so the framework (Sling) no longer knows about it. Thus you lose certain features:
  • automatic handling of http methods other than GET, including:
    • POST, PUT, DELETE which are handled with a sling default implementation
    • the POST.jsp script in your sling:resourceType location
  • your code architecture is no longer as clean nor as clearly structured as it should be; of prime importance for large-scale development

SLING API

This uses the Sling API package, org.apache.sling.*, and tag libraries.

REFERENCING EXISTING ELEMENTS USING SLING:INCLUDE

A final consideration is the need to reference existing elements within the scripts.
More complex scripts (aggregating scripts) might need to access multiple resources (for example navigation, sidebar, footer, elements of a list) and do so by including the resource.
To do this you can use the sling:include("/<path>/<resource>") command. This will effectively include the definition of the referenced resource, as in the following statement which references an existing definition for rendering images:
<sling:include resourceType="geometrixx/components/image/img"/>

OSGI

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.

NOTE

Full information on OSGi technology can be found at the OSGi Alliance Technology Overview.
In particular, their Basic Education page holds a collection of presentations and tutorials.
This architecture allows you to extend Sling with application specific modules. Sling, and therefore CQ5, uses theApache Felix implementation of OSGI (Open Services Gateway initiative) 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.
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

Nhận xét

Bài đăng phổ biến từ blog này

How to add a new supported language in CQ / WEM (Translator in CQ)

Use case:  You want to add new language to CQ Change display language options in translator grid Change language name and default countries  Solution: You can access translator UI in CQ with following URL http://<HOST>:<PORT>/libs/cq/i18n/translator.html Create new language location for Dictionary Go to CRXDE lite (or your favorite JCR browser) and add this structure (assuming /apps/myapp/i18n as a typical location for custom apps): /apps/myapp/i18n [sling:Folder]     - de [nt:unstructured]         + jcr:mixinTypes = [mix:language]         + jcr:language = de     - fr [nt:unstructured]         + jcr:mixinTypes = [mix:language]         + jcr:language = fr Then reload the translator and the path /apps/ myapp /i18n should show up in the drop-down at the top. Note: the translator will only save translations for languages that are actually present underneath the path (e.g. /apps/myapp/i18n), others will be skipped. Then on jsp pa

Login / Logout on a Publish instance and Closed User Group (CUG)

In CQ5 there is the login logout could be configured using a Closed User Group. Closed User Groups (CUGs) are used to limit access to specific pages that reside within a published internet site. Such pages require the assigned members to login and provide security credentials. http://dev.day.com/docs/en/cq/5-4/howto/create_apply_cug.html The logout using /libs/cq/core/content/login.logout.html always gets redirected to the geometrixx site   http://localhost:4503/content/geometrixx-outdoors/en.html By configuring the Default login page  under the osgi configuration for com.day.cq.auth.impl.LoginSelectorHandler to be – /content/mysite/en/login But still after logout the page goes to the geometrixx site. IIRC, the redirect first goes to to / which then goes through the standard, somewhat complex handling of the root with multiple redirects: 1) / has a resource type of sling:redirect and redirects to /index.html 2) /index.html is handled by the RootMappingServlet [0] which h

[PERFORMANCE] Adobe WEM/CQ performance tuning

Adobe WEM/CQ performance tuning Contents Caching-related configurations CRX Bundle cache CRX Search index handler (Lucene) cache Tar PM index cache Scalability Maintenance Optimizing Tar Files (for Tar Persistence Manager) Data Store Garbage Collection Main documentation you should consult first: http://dev.day.com/docs/en/cq/current/deploying/performance.html http://dev.day.com/content/kb/home/cq5/CQ5Troubleshooting/performancetuningtips.html Caching-related configurations CRX Bundle cache CRX caches bundles, consisting of a node with all its properties. This is used by all bundle-based Persistence Managers. The default size of BundleCache is 8 MB. If this is too small it can cause an excessive number of read-accesses to the underlying persistence layer. Set the bundleCacheSize to something larger than the default. See more here: http://dev.day.com/docs/en/cq/current/deploying/performance.html#CRX%20Bundle%20Cache CRX Search index handler (Lucene