Hi all.
I've just developed a new Event Listener, which let the inner command to
know which JCR action has triggered the event.
It let you to fulfill this use-case:
Define only 1 observationListener config, with more than one event
action defined, like this:
eventTypes : NODE_ADDED, NODE_REMOVED, PROPERTY_CHANGED
and let one command do action on the node, knowing also which action
triggered the event.
Without this class, I would have to insert till 5 listener config for
each "shared" command.
HTH,
matteo
(It is in attachment, ActionAwareEventListener)
----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------
package ch.rtsi.prisma.magnolia.modules.labs.commands;
import
info.magnolia.module.observation.commands.RestrictToNodeTypeEventListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.jcr.observation.Event;
import javax.jcr.observation.EventIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ActionAwareEventListener extends RestrictToNodeTypeEventListener {
public static final String PARAM_EVENTTYPE = "eventType";
private static final Logger log =
LoggerFactory.getLogger(ActionAwareEventListener.class);
/**
* @see
info.magnolia.module.observation.commands.ActionAwareEventListener#onEvent
*/
@Override
public void onEvent(EventIterator events) {
while (events.hasNext()) {
try {
Event event = events.nextEvent();
if (checkIfEventIsProcessed(event)) {
List paths = new ArrayList();
String path = null;
path = getPath(event);
if (path == null ||
paths.contains(path)) {
continue;
} else {
Map params = (null ==
getParams()) ? new HashMap() : getParams();
params.put(PARAM_EVENTTYPE,
event.getType());
setParams(params);
super.onEvent(events);
break;
}
}
} catch (Exception e) {
log.error("Can't deliver event", e);
}
}
}
}