Last active
July 22, 2020 05:13
-
-
Save aanchalsikka/0e1d49512627adee577dee4cfca72e06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
import org.apache.sling.api.resource.LoginException; | |
import org.apache.sling.api.resource.ResourceResolver; | |
import org.apache.sling.api.resource.ResourceResolverFactory; | |
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; | |
@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 SamplePostProcessListener implements EventHandler { | |
private static final Logger LOG = LoggerFactory.getLogger(SamplePostProcessListener.class); | |
@Reference | |
private ResourceResolverFactory resolverFactory; | |
@Override | |
public void handleEvent(Event event) { | |
String path = (String) event.getProperty("path"); | |
// Fetch resource resolver | |
Map<String, Object> serviceParams = new HashMap<>(); | |
serviceParams.put(ResourceResolverFactory.SUBSERVICE, "someServiceUser"); | |
ResourceResolver resolver = null; | |
try { | |
resolver = resolverFactory.getServiceResourceResolver(serviceParams); | |
LOG.info("path of DITA Asset: {} ", path); | |
} catch (LoginException e) { | |
LOG.error("Exception while acessing info about DITA asset ", e); | |
} finally { | |
if (resolver != null) { | |
resolver.close(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment