Wednesday 8 June 2016

AEM Tagging Framework

Tags : cq:Tag Node Type

The declaration of a tag is captured in the repository in a node of type cq:Tag.
A tag can be a simple word (e.g. sky) or represent a hierarchical taxonomy (e.g. fruit/apple, meaning both the generic fruit and the more specific apple).
Tags are identified by a unique TagID.

Tag Characteristics

  • node type is cq:Tag
  • node name is a component of the TagId
  • the TagId always includes a namespace
  • optional jcr:title property (the Title to display in the UI)
  • optional jcr:description property
  • when containing child nodes, is referred to as a container tag
  • is stored in the repository below a base path called the taxonomy root node.

TagID

A TagID identifies a path which resolves to a tag node in the repository.  
Typically, the TagID is a shorthand TagID starting with the namespace or it can be an absolute TagID starting from the taxonomy root node.
The TagID consists of a namespace followed by the local TagID.  Container tags have sub-tags that represent a hierarchical order in the taxonomy. Sub-tags can be used to reference tags same as  any local TagID.   For example tagging content with "fruit" is allowed, even if it is a container tag with sub-tags, such as "fruit/apple" and "fruit/banana".
The taxonomy root node is the base path for all tags in the repository.  The taxonomy root node must not be a node of type cq:Tag

Resolving TagIDs

The following table shows some sample TagIDs, their elements, and how the TagID resolves to an absolute path in the repository :
The following table shows some sample TagIDs, their elements, and how the TagID resolves to an absolute path in the repository :
The following table shows some sample TagIDs, their elements, and how the TagID resolves to an absolute path in the repository :

TagIDNamespaceLocal IDContainer tag(s)Leaf tagRepository
Absolute tag path
dam:fruit/apple/braeburndamfruit/apple/braeburnfruit, applebraeburn/etc/tags/dam/fruit/apple/braeburn
color/reddefaultcolor/redcolorred/etc/tags/default/color/red
skydefaultsky(none)sky/etc/tags/default/sky
dam:dam(none)(none)(none, the namespace)/etc/tags/dam
/etc/tags/category/carcategorycarcarcar/etc/tags/category/car

Sunday 5 June 2016

Run Modes


Run modes allow you to tune your AEM instance for a specific purpose; for example author or publish, test, development, intranet or others.

Installation Run Modes

Installation (or fixed) run modes are used at installation time and then fixed for the entire lifetime of the instance, they cannot be changed.

Installation run modes are provided out-of-the-box:
  • author
  • publish
  • samplecontent
  • nosamplecontent
These are two pairs of mutually exclusive run modes; for example, you can:
  • define either author or publish, not both at the same time.
  • combine author with either samplecontent or nosamplecontent (but not both).

Customized Run Modes

You can also create your own, customized, run modes. These can be combined to cover scenarios such as:
  • author + development.
  • publish + test.
  • publish + test + golive.
  • publish + intranet.
There are two mechanisms for setting standard and environment specific run mode for your instance:

To set up standard run mode Use the naming convention:
  • cq-<run-mode>-<port-number>. For example, set a standard run mode by naming the jar file cq-author-4502 or cq-publish-4503.
To set up environment specific run mode there are two methods:
  • Open <cq-installation-dir>/crx-quickstart/launchpad/sling.properties.
  • Add the following properties (following example is for author, test, uk):
  • sling.jcrinstall.folder.name.regexp=.*/(install|config)? 
  • sling.run.modes=author,test,uk .
  • In above case config.author.test.uk will get picked up (Or whatever with maximum match).
Configuration values for the run modes are saved in the repository. You can store all configurations in one repository as the run mode is indicated by a suffix on the folder name; for example:
  • config, applicable for all run modes.
  • config.author, used in author run mode.
  • config.publish, used in publish run mode.
  • config.<standard-run-mode>.<environment-specific-mode>, used in the applicable run mode.

Starting CQ with a specific run mode

If you have defined configurations for multiple run modes then you need to define which is to be used upon startup. There are several methods for specifying which run mode to use; the order of resolution is:
  • sling.properties file.(Edit <cq-installation-dir>/crx-quickstart/conf/sling.properties)
  • -r option.(start the jar with java -jar cq-56-p4545.jar -r dev)
  • system properties (-D).(A system property in the start script can be used to specify the run mode. -Dsling.run.modes=publish,prod,us)
  • Filename detection (cq5-<run-mode>-p<port-number>).
To check the runmode:

http://adobeaem-learneasycodeeasy.blogspot.in/search/label/runmode.

Saturday 4 June 2016

Sling Adapters


Sling AdaptTo :


Sling offers an Adapter pattern to conveniently translate objects that implement the Adaptable interface. This interface provides a generic adaptTo() method that will translate the object to the class type being passed as the argument.

For example to translate a Resource object to the corresponding Node object, you can simply do:

Example : Node node = resource.adaptTo(Node.class);

Use Cases :

There are the following use cases:


  • Get implementation-specific objects.For example, a JCR-based implementation of the generic Resource interface provides access to the underlying JCR Node.
  • Shortcut creation of objects that require internal context objects to be passed.For example, the JCR-based ResourceResolver holds a reference to the request's JCR Session, which in turn is needed for many objects that will work based on that request session, such as the PageManager or UserManager.
  • Shortcut to services.A rare case - sling.getService() is simple as well.

How it works :

There are various ways that Adaptable.adaptTo() can be implemented:
  • By the object itself; implementing the method itself and mapping to certain objects.
  • By an AdapterFactory, which can map arbitrary objects.
  • The objects must still implement the Adaptable interface and must extend SlingAdaptable (which passes the adaptTo call to a central adapter manager).
  • This allows hooks into the adaptTo mechanism for existing classes, such as Resource.

Reference : Sling Adapters.


Sling Cheatsheet


This tutorial is to learn how Apache Sling Resource Resolution is done in AEM.

URL Decomposition :


URL – http://localhost:4502/cf#/content/aemTutorials/sightlyPage.test.html/a/b?x=12

Protocol: http
Host: localhost:4502
Content path : content/aemTutorials/sightlyPage
Selector(s) : .test
Extension : html
Suffix : a/b
Param : x=12


Sling Resource Resolution – Mapping URL to Respective JCR Node :



Step-1: Double click on a page in siteadmin , to open respective page in browser.

Step-2-3-4-5:  Analyse the URL /contents/aemTutorials/sightlyPage it is known as content path.

  • The /content path refers to the path of content folder in crx de.
  • /aemTutorials refers to the package under contents folder.
  • /sightlyPage refers to our page that we have created under siteadmin. jcr:content of sightlyPage contains a property sling:ResourceType. Which tells sling where our component is located. As shown in above figure it is at training/components/myComponent , means sling needs to check for myComponent under /apps folder.
Step-6: Analyse selector and extension  test.html.
  • Sling appends the selector and extension after the component name i.e myComponent.test.html If it found this component then it render it else it drops the extension and search again.
Note:- Sling decides rendering of script on the basis of selector + extension . First priority goes to selector, if no selector is available then priority goes to extension.

Now if we double click our page http://localhost:4502/cf#/content/sample/testing.html  then by default myComponent.jsp script will be called because here .html is an extension not selector .

Between jsp and html first priority goes to jsp as by default a component is linked to jsp at the time of creation.

So the final priority order will be myComponent.html.jsp–>html.jsp–>myComponent.jsp –>myComponent.html