Skip to content

Instantly share code, notes, and snippets.

Created September 19, 2020 10:31
Show Gist options
  • Save aanchalsikka/f34c59b3a8e228ed5d181bcecd2858e3 to your computer and use it in GitHub Desktop.
Save aanchalsikka/f34c59b3a8e228ed5d181bcecd2858e3 to your computer and use it in GitHub Desktop.
package com.techrevel.dam.core.fmdita.listeners;
import java.util.HashMap;
import java.util.Map;
import org.apache.jackrabbit.JcrConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* Appends path property to DITA Assets. Needed for Fluid Topic Integration
@Component(service = EventHandler.class, property = {
EventConstants.EVENT_TOPIC + "=com/adobe/fmdita/postprocess/complete", EventConstants.EVENT_FILTER
+ "=(|(operation=org/apache/sling/api/resource/Resource/ADDED)(operation=org/apache/sling/api/resource/Resource/CHANGED))" })
public class PostProcessingEventHandler implements EventHandler {
private static final Logger LOG = LoggerFactory.getLogger(PostProcessingEventHandler.class);
private ResourceResolverFactory resolverFactory;
public void handleEvent(Event event) {
LOG.debug("Processing the JOB *******");
// The path of the file that triggered this event. Typically, this is the file
// on which an operation has been performed.
String path = (String) event.getProperty("path");
// Fetch resource resolver
Map<String, Object> serviceParams = new HashMap<>();
serviceParams.put(ResourceResolverFactory.SUBSERVICE, "subServiceName");
ResourceResolver resolver = null;
try {
resolver = resolverFactory.getServiceResourceResolver(serviceParams);
// Resolve path of DITA Asset
String ditaResourcePath = path.substring(0, path.indexOf(JcrConstants.JCR_CONTENT) - 1);
// Resolve metadata resource of DITA Asset
String metadataResourcePath = path.substring(0, path.indexOf(DamConstants.RENDITIONS_FOLDER))
} catch (LoginException e) {
LOG.error("Exception while commiting path property ", e);
} finally {
if (resolver != null) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment