Skip to content

Instantly share code, notes, and snippets.

@saulovenancio
Forked from cqtips/SampleEventHandler.java
Last active August 29, 2015 14:16
Show Gist options
  • Save saulovenancio/e502581dcfcdf277ed73 to your computer and use it in GitHub Desktop.
Save saulovenancio/e502581dcfcdf277ed73 to your computer and use it in GitHub Desktop.
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingConstants;
import org.apache.sling.event.EventUtil;
import org.apache.sling.event.jobs.JobProcessor;
import org.apache.sling.event.jobs.JobUtil;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
//@formatter:off
@Service(value = EventHandler.class)
@Component(immediate = true, metatype = false)
@Properties({
@Property(name = EventConstants.EVENT_TOPIC, value = SlingConstants.TOPIC_RESOURCE_ADDED)
})
//@formatter:on
public class SampleEventHandler implements EventHandler, JobProcessor {
public boolean process(Event event) {
String path = (String) event.getProperty("path");
String resourceType = (String) event.getProperty("resourceType");
if (path.startsWith("/content/mysite/myfolder")) {
// process event here
}
return true;
}
public void handleEvent(Event event) {
if (EventUtil.isLocal(event)) {
JobUtil.processJob(event, this);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment