Event handler in CQ5
Hi,
My requirement is whenever i create a new page CQ has to add the new property.
so i prefered Even handlers and followed the below code.
The problem is i dont know weather the code is running?
i have checked the console i didn't get any log as well.
could anyone please help me and explain how event handlers running in CQ?
@Component public class ExampleObservation implements EventListener { Logger log = LoggerFactory.getLogger(this.getClass()); private Session adminSession; @Reference SlingRepository repository; @Activate public void activate(ComponentContext context) throws Exception { log.info("activating ExampleObservation"); try { adminSession = repository.loginAdministrative(null); adminSession.getWorkspace().getObservationManager().addEventListener(this, //handler
Event.PROPERTY_ADDED|Event.NODE_ADDED, //binary combination of event types
"/content/", //path
true, //is Deep?
null, //uuids filter
null, //nodetypes filter false); } catch (RepositoryException e){ log.error("unable to register session",e); throw new Exception(e); } }@Deactivate public void deactivate(){ if (adminSession != null){ adminSession.logout(); } } public void onEvent(EventIterator eventIterator) { try { while (eventIterator.hasNext()){ log.info("something has been added : {}", eventIterator.nextEvent().getPath()); } } catch(RepositoryException e){ log.error("Error while treating events",e); } } }