1 13 package info.magnolia.cms.util; 14 15 import info.magnolia.cms.beans.config.ContentRepository; 16 17 import javax.jcr.RepositoryException; 18 import javax.jcr.observation.Event; 19 import javax.jcr.observation.EventListener; 20 import javax.jcr.observation.ObservationManager; 21 22 import org.slf4j.Logger; 23 import org.slf4j.LoggerFactory; 24 25 26 30 public class ObservationUtil { 31 32 35 private static Logger log = LoggerFactory.getLogger(ObservationUtil.class); 36 37 43 public static void registerChangeListener(String repository, String observationPath, EventListener listener) { 44 log.debug("Registering event listener for path [{}]", observationPath); 46 try { 47 48 ObservationManager observationManager = ContentRepository 49 .getHierarchyManager(repository) 50 .getWorkspace() 51 .getObservationManager(); 52 53 observationManager.addEventListener(listener, Event.NODE_ADDED 54 | Event.NODE_REMOVED 55 | Event.PROPERTY_ADDED 56 | Event.PROPERTY_CHANGED 57 | Event.PROPERTY_REMOVED, observationPath, true, null, null, false); 58 } 59 catch (RepositoryException e) { 60 log.error("Unable to add event listeners for " + observationPath, e); } 62 } 63 } 64 | Popular Tags |