use of javax.jcr.observation.EventListener in project sling by apache.
the class ScriptableTestsProvider method activate.
protected void activate(final Map<String, Object> props) throws Exception {
pid = (String) props.get(Constants.SERVICE_PID);
session = repository.loginAdministrative(repository.getDefaultWorkspace());
Map<String, Object> auth = new HashMap<>();
auth.put(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, session);
resolver = resolverFactory.getResourceResolver(auth);
// Copy resource resolver paths and make sure they end with a /
final String[] paths = resolver.getSearchPath();
allowedRoots = new String[paths.length];
System.arraycopy(paths, 0, allowedRoots, 0, paths.length);
for (int i = 0; i < allowedRoots.length; i++) {
if (!allowedRoots[i].endsWith("/")) {
allowedRoots[i] += "/";
}
}
// Listen to changes to sling:Test nodes under allowed roots
final int eventTypes = Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED;
final boolean isDeep = true;
final boolean noLocal = true;
final String[] nodeTypes = { SLING_TEST_NODETYPE };
final String[] uuid = null;
for (String path : allowedRoots) {
final EventListener listener = new RootListener(path);
listeners.add(listener);
session.getWorkspace().getObservationManager().addEventListener(listener, eventTypes, path, isDeep, uuid, nodeTypes, noLocal);
log.debug("Listening for JCR events under {}", path);
}
log.info("Activated, will look for test resources under {}", Arrays.asList(allowedRoots));
}
Aggregations