Thursday 26 April 2018

How to use System user to access the crx repository?

System user is configured in the user mapper configuration in the felix console. In the below example datawrite is the system user.
The below code demonstrates the way in which we can use a system user to access the repository to make changes to it.

Map<String, Object> paramsMap = new HashMap<String, Object>();
paramsMap.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resourceResolver = null;
resourceResolver = resourceResolverFactory.getServiceResourceResolver(paramsMap);
Resource res = resourceResolver.getResource("<Path in the repository>");
//Write logic to make changes to the resource.
//Then commit the changes done to the repository.
res.getResourceResolver().commit();

Wednesday 11 April 2018

Event Handler and Event Listener

Event Handler:: The sling level events can be captured by implementing the event handler interface. A property called EventConstants.EVENT_TOPIC has to be fined which signifies what event has to be captured. In this case the event handler catches the page being created. handleEvent(Event event)  method is implemented which can have the code to implement the business logic. Like we cna set a new property on creation of a page
 Example::
@Component(service = EventHandler.class, immediate = true, property = {
Constants.SERVICE_DESCRIPTION + "=Your Description here",
EventConstants.EVENT_TOPIC + "=com/day/cq/wcm/core/page" })

Event Listener:: The event handling at the jcr level can be captured by implementing the event listener interface. It is mostly concerned about the low level jcr events like node or property movement, addition, deletion etc.  The onEvent(EventIterator events) can be used to include the business logic, like deleting some property on node being copied. Observation manager can be used is used to listen to listen to events like Event.NODE_ADDED.

Example:: observationManager.addEventListener(this, Event.NODE_ADDED, path, true, null, null, false); :: In this example the event listener listens to the node being added to the jcr repository.


extraClientlibs Usage

The purpose of property "extraClientlibs" is to selectively load client library for a dialog. This prevents the unnecessary load o...