Logging in AEM

AEM uses an predefined “log” object to log information. the log object is a instance of org.slf4j.Logger.

Logging levels can be configured in “Apache Sling Logging configuration” via http://localhost:4502/system/console/configMgr

More details are in Adobe Logging  and Sling Logging.

COMPONENT HIERARCHY AND INHERITANCE

Component hierarchy is mentioned in ADOBE official component doucments

Components within AEM are subject to 3 different hierarchies:

1.Resource Type Hierarchy:

This is used to extend components using the property sling:resourceSuperType. This enables the component to inherit; for example a text component will inherit various attributes from the standard component.

  • scripts (resolved by Sling)
  • dialogs
  • descriptions (including thumbnail images, icons, etc)
  • Note: a local copy/instance of a component element will take precedence over an inherited element.

2. Container Hierarchy :

  • This is used to populate configuration settings to the child component and is most commonly used in a parsys scenario.For example, configuration settings for the edit bar buttons, control set layout (editbars, rollover), dialog layout (inline, floating) can be defined on the parent component and propagated to the child components.
  • Configuration settings (related to edit functionality) in cq:editConfig and cq:childEditConfig are propagated.

3. Include Hierarchy:

  • This is imposed at runtime by the sequence of includes.
  • This hierarchy is used by the Designer, which in turn acts as the base for various design aspects of the rendering; including layout information, css information, the available components in a parsys among others.

How to create without template

If you want to create a page without template you can do that but it’s not possible using siteadmin console as it’s content page component uses templates to create pages.

  1. Create a node of type cq:Page and save,
  2. Add cq:PageContent node(named jcr:content) under page node
  3. Add/Copy required properties manually.

Configure the Rich text Editor

It is quit easy to configure the rich text editor as your requirement. The Adobe document is great.

<items jcr:primaryType=”cq:TabPanel”>
<items jcr:primaryType=”cq:WidgetCollection”>
<tab1
jcr:primaryType=”cq:Panel”
title=”Rich Text Editor”>
<items jcr:primaryType=”cq:WidgetCollection”>
<text-value
jcr:primaryType=”cq:Widget”
name=”./text”
xtype=”richtext”
height=”150″
fieldLabel=”Text Value”>
<rtePlugins jcr:primaryType=”nt:unstructured”>
<paraformat jcr:primaryType=”nt:unstructured” features=”*”>
<formats jcr:primaryType=”cq:WidgetCollection”>
    <paragraph jcr:primaryType=”nt:unstructured” tag=”p” description=”Paragraph”/>
     <heading-h2 jcr:primaryType=”nt:unstructured” tag=”h2″ description=”Heading h2″/>
</formats>
</paraformat>
</rtePlugins>
</text-value>
</items>
</tab1>
</items>
</items>

A magic way to get thumbnail in AEM

Today, I just figure out a easy to get a thumbnail of image in AEM by using “thumb” as selector

Example:

If the orginal image is http://localhost:4502/content/page-name/jcr:content/image/file
then the thumbnail of it will be http://localhost:4502/content/page-name/jcr:content/image/file.thumb.jpg
The magic comes from com.day.cq.wcm.core.impl.servlets.ThumbnailServlet which is a core cq servlet to handle thumbnail requests.

Image below is the details I get from http://localhost:4502system/console/components

ThumbnailServlet

Using ResourceResolver in service

Recently, I tried to get ResourceResolver directly from services rather than using request.getResourceResolver().
As API document said,  I can use resolverFactory.getServiceResourceResolver() to get ResourceResolver object.

The main code I used list below:

Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, “properPrivilege”);
resolver = resolverFactory.getServiceResourceResolver(param);

The Major part is the param which I give to getServiceResourceResolver got have proper privilege, Otherwise I got Null ResourceResolver object.

How I can use the proper privilege?

I’ve done this by configrating “Apache Sling Service User Mapper Service” via OSGI configuration(http://localhost:4502/system/console/configMgr)

Look at screen shoot below

sling-service-mappingCreate new config in Service mappings section by following the rule:

Provides mappings from service name to user names. Each entry is of the form ‘serviceName [ “:” subServiceName ] “=” userName’ where serviceName and subServiceName identify the service and userName defines the name of the user to provide to the service. Invalid entries are logged and ignored. (user.mapping)

In my case, com.dale.cq.services.tryservice:properPrivilege=properUser   (properUser should be the user given proper read/write privilege , I use the author user for testing).

Note: “com.dale.cq.services.tryservice” used here is  NOT a package ID, it is a BundleId which can be gotten from http://localhost:4502/system/console/bundles
There are 2 way to simplify :

1. Simplify config it to com.dale.cq.services.tryservice=properUser (in my case is  com.dale.cq.services.tryservice=author)

or

2. Just use resolver = resolverFactory.getServiceResourceResolver(null); and config Default User as a properuser with right privilege (I use the author user for testing)

How to set configuration of different run modes

The generic rule is:

The configuration in specified run mode is override the generic one.

For examples: I config CQ Html Library manager in my project

The file structure is:

/app

—myproject

——/config

———com.day.cq.widget.impl.HtmlLibraryManagerImpl.xml  (Minify:true, Gzip:true)

——/config.author

———com.day.cq.widget.impl.HtmlLibraryManagerImpl.xml  (Minify:false, Gzip:false)

——/config.author.dev

———com.day.cq.widget.impl.HtmlLibraryManagerImpl.xml  (Minify:false, Gzip:true)

The final configuration is same as(Minify:false, Gzip:true) in config.author.dev

Then I remove configuration under  config.author.dev, the configuration become (Minify:false, Gzip:false) as in config.author

Then I remove configuration under  config.author, the configuration become(Minify:true, Gzip:true) as in config

And here is a good article about set run modes