in src/main/java/org/apache/sling/superimposing/impl/SuperimposingManagerImpl.java [361:407]
public void onEvent(EventIterator events) {
if (!isEnabled()) {
return;
}
try {
// collect all actions to be performed for this event
final Map<String, Boolean> actions = new HashMap<>();
boolean nodeAdded = false;
boolean nodeRemoved = false;
while (events.hasNext()) {
final Event event = events.nextEvent();
final String path = event.getPath();
final String name = ResourceUtil.getName(path);
if (event.getType() == Event.NODE_ADDED) {
nodeAdded = true;
} else if (event.getType() == Event.NODE_REMOVED && superimposingProviders.containsKey(path)) {
nodeRemoved = true;
actions.put(path, false);
} else if (StringUtils.equals(name, PROP_SUPERIMPOSE_SOURCE_PATH)
|| StringUtils.equals(name, PROP_SUPERIMPOSE_REGISTER_PARENT)
|| StringUtils.equals(name, PROP_SUPERIMPOSE_OVERLAYABLE)) {
final String nodePath = ResourceUtil.getParent(path);
actions.put(nodePath, true);
}
}
// execute all collected actions (having this outside the above
// loop prevents repeated registrations within one transaction
// but allows for several superimposings to be added within a single
// transaction)
for (Map.Entry<String, Boolean> action : actions.entrySet()) {
if (action.getValue()) {
registerProvider(action.getKey());
} else {
unregisterProvider(action.getKey());
}
}
if (nodeAdded && nodeRemoved) {
// maybe a superimposing was moved, re-register all superimposings
// (existing ones will be skipped)
registerAllSuperimposings();
}
} catch (RepositoryException e) {
log.error("Unexpected repository exception during event processing.");
}
}