}
boolean localFlagSet = false;
while (events.hasNext()) {
Event event = events.nextEvent();
if (!localFlagSet) {
// obtain remote session identifier
localFlagSet = true;
String forSessionId = (String) session
.getAttribute(SessionProviderImpl.ATTRIBUTE_SESSION_ID);
// calculate "local" flags
if (forSessionId != null
&& event instanceof AdditionalEventInfo) {
try {
String eventforSessionId = (String) ((AdditionalEventInfo) event)
.getSessionAttribute(SessionProviderImpl.ATTRIBUTE_SESSION_ID);
boolean isLocal = forSessionId
.equals(eventforSessionId);
DomUtil.setAttribute(bundle, XML_EVENT_LOCAL, null, Boolean.toString(isLocal));
} catch (UnsupportedRepositoryOperationException ex) {
// optional feature
}
}
}
Element eventElem = DomUtil.addChildElement(bundle, XML_EVENT, NAMESPACE);
// href
String eHref = "";
try {
boolean isCollection = (event.getType() == Event.NODE_ADDED || event.getType() == Event.NODE_REMOVED);
eHref = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), event.getPath(), false).getHref(isCollection);
} catch (RepositoryException e) {
// should not occur....
log.error(e.getMessage());
}
eventElem.appendChild(DomUtil.hrefToXml(eHref, document));
// event type
Element eType = DomUtil.addChildElement(eventElem, XML_EVENTTYPE, NAMESPACE);
eType.appendChild(getEventType(event.getType()).toXml(document));
// user id
DomUtil.addChildElement(eventElem, XML_EVENTUSERID, NAMESPACE, event.getUserID());
// try to compute nodetype information
if (event instanceof AdditionalEventInfo) {
try {
DomUtil.addChildElement(eventElem,
XML_EVENTPRIMARNODETYPE, NAMESPACE,
((AdditionalEventInfo) event)
.getPrimaryNodeTypeName().toString());
for (Name mixin : ((AdditionalEventInfo) event)
.getMixinTypeNames()) {
DomUtil.addChildElement(eventElem,
XML_EVENTMIXINNODETYPE, NAMESPACE,
mixin.toString());
}
} catch (UnsupportedRepositoryOperationException ex) {
// optional
}
}
// Additional JCR 2.0 event information
// user data
try {
DomUtil.addChildElement(eventElem, XML_EVENTUSERDATA, NAMESPACE, event.getUserData());
} catch (RepositoryException e) {
log.error("Internal error while retrieving event user data.", e.getMessage());
}
// time stamp
try {
DomUtil.addChildElement(eventElem, XML_EVENTDATE, NAMESPACE, String.valueOf(event.getDate()));
} catch (RepositoryException e) {
log.error("Internal error while retrieving event date.", e.getMessage());
}
// identifier
try {
DomUtil.addChildElement(eventElem, XML_EVENTIDENTIFIER, NAMESPACE, event.getIdentifier());
} catch (RepositoryException e) {
log.error("Internal error while retrieving event identifier.", e.getMessage());
}
// info
Element info = DomUtil.addChildElement(eventElem, XML_EVENTINFO, NAMESPACE);
try {
Map<?, ?> m = event.getInfo();
for (Map.Entry<?, ?> entry : m.entrySet()) {
String key = entry.getKey().toString();
Object value = entry.getValue();
if (value != null) {
DomUtil.addChildElement(info, key, Namespace.EMPTY_NAMESPACE, value.toString());