KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > util > ObservationUtil


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

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 /**
27  * @author Philipp Bracher
28  * @version $Revision: 6341 $ ($Author: philipp $)
29  */

30 public class ObservationUtil {
31
32     /**
33      * Logger
34      */

35     private static Logger log = LoggerFactory.getLogger(ObservationUtil.class);
36
37     /**
38      * Register a single event listener, bound to the given path.
39      * @param repository
40      * @param observationPath repository path
41      * @param listener event listener
42      */

43     public static void registerChangeListener(String JavaDoc repository, String JavaDoc observationPath, EventListener listener) {
44         log.debug("Registering event listener for path [{}]", observationPath); //$NON-NLS-1$
45

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); //$NON-NLS-1$
61
}
62     }
63 }
64
Popular Tags