Skip to content

Commit

Permalink
2.4: Merged revisions 1232035 and 1232404 from trunk
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/branches/2.4@1232549 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jukka committed Jan 17, 2012
2 parents 116167d + af903b0 commit 5c68c57
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
Expand Up @@ -17,7 +17,6 @@
package org.apache.jackrabbit.webdav.jcr.observation;

import org.apache.jackrabbit.commons.webdav.EventUtil;
import org.apache.jackrabbit.commons.webdav.JcrRemotingConstants;
import org.apache.jackrabbit.server.SessionProviderImpl;
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.commons.AdditionalEventInfo;
Expand Down Expand Up @@ -45,12 +44,9 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.sun.org.apache.xalan.internal.xsltc.dom.ExtendedSAX;

import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
import javax.jcr.observation.Event;
import javax.jcr.observation.EventIterator;
import javax.jcr.observation.EventListener;
Expand Down Expand Up @@ -476,8 +472,7 @@ public Element toXml(Document document) {
.getSessionAttribute(SessionProviderImpl.ATTRIBUTE_SESSION_ID);
boolean isLocal = forSessionId
.equals(eventforSessionId);
DomUtil.setAttribute(bundle, XML_EVENT_LOCAL,
NAMESPACE, Boolean.toString(isLocal));
DomUtil.setAttribute(bundle, XML_EVENT_LOCAL, null, Boolean.toString(isLocal));
} catch (UnsupportedRepositoryOperationException ex) {
// optional feature
}
Expand Down
Expand Up @@ -149,7 +149,7 @@ public void testRefreshNotLive() throws Exception {
/**
* Test {@link javax.jcr.lock.Lock#getNode()}.
*
* @throws RepositoryException If an execption occurs.
* @throws RepositoryException If an exception occurs.
*/
public void testLockHoldingNode() throws RepositoryException {
assertTrue("Lock.getNode() must be lockholding node.", lock.getNode().isSame(lockedNode));
Expand All @@ -158,7 +158,7 @@ public void testLockHoldingNode() throws RepositoryException {
/**
* Test {@link LockManager#isLocked(String)} and {@link javax.jcr.Node#isLocked()}.
*
* @throws RepositoryException If an execption occurs.
* @throws RepositoryException If an exception occurs.
*/
public void testNodeIsLocked() throws RepositoryException {
assertTrue("Node must be locked after lock creation.", lockedNode.isLocked());
Expand All @@ -168,7 +168,7 @@ public void testNodeIsLocked() throws RepositoryException {
/**
* Test {@link LockManager#holdsLock(String)} and {@link javax.jcr.Node#holdsLock()}.
*
* @throws RepositoryException If an execption occurs.
* @throws RepositoryException If an exception occurs.
*/
public void testNodeHoldsLocked() throws RepositoryException {
assertTrue("Node must hold lock after lock creation.", lockedNode.holdsLock());
Expand Down Expand Up @@ -201,7 +201,7 @@ public void testIsSessionScoped() {
/**
* Test {@link javax.jcr.lock.Lock#isLockOwningSession()}
*
* @throws RepositoryException If an execption occurs.
* @throws RepositoryException If an exception occurs.
*/
public void testIsLockOwningSession() throws RepositoryException {
assertTrue("Session must be lock owner", lock.isLockOwningSession());
Expand Down Expand Up @@ -429,7 +429,7 @@ public void testRemoveMixLockableFromLockedNode() throws RepositoryException,
lockedNode.removeMixin(mixLockable);
lockedNode.save();

// the mixin got removed -> the lock should implicitely be released
// the mixin got removed -> the lock should implicitly be released
// as well in order not to have inconsistencies
String msg = "Lock should have been released.";
assertFalse(msg, lock.isLive());
Expand Down
Expand Up @@ -61,11 +61,10 @@ public EventImpl(ItemId eventId, Path eventPath, NodeId parentId, int eventType,
Element eventElement, NamePathResolver resolver, QValueFactory qvFactory) throws NamespaceException,
IllegalNameException {
super(getSpiEventType(eventType), eventPath, eventId, parentId, getNameSafe(
DomUtil.getChildTextTrim(eventElement, XML_EVENTPRIMARNODETYPE, NAMESPACE), resolver), getNames(
DomUtil.getChildren(eventElement, XML_EVENTMIXINNODETYPE, NAMESPACE), resolver), userId, DomUtil
.getChildTextTrim(eventElement, XML_EVENTUSERDATA, NAMESPACE), Long.parseLong(DomUtil.getChildTextTrim(
eventElement, XML_EVENTDATE, NAMESPACE)), getEventInfo(
DomUtil.getChildElement(eventElement, XML_EVENTINFO, NAMESPACE), resolver, qvFactory));
DomUtil.getChildTextTrim(eventElement, N_EVENTPRIMARYNODETYPE), resolver), getNames(
DomUtil.getChildren(eventElement, N_EVENTMIXINNODETYPE), resolver), userId, DomUtil.getChildTextTrim(
eventElement, N_EVENTUSERDATA), Long.parseLong(DomUtil.getChildTextTrim(eventElement, N_EVENTDATE)),
getEventInfo(DomUtil.getChildElement(eventElement, N_EVENTINFO), resolver, qvFactory));
}

//--------------------------------------------------------------------------
Expand Down
Expand Up @@ -2235,14 +2235,12 @@ private EventBundle[] poll(String uri, String subscriptionId, long timeout, Sess
} else {
Element discEl = disc.toXml(DomUtil.createDocument());
ElementIterator it = DomUtil.getChildren(discEl,
ObservationConstants.XML_EVENTBUNDLE,
ObservationConstants.NAMESPACE);
ObservationConstants.N_EVENTBUNDLE);
List<EventBundle> bundles = new ArrayList<EventBundle>();
while (it.hasNext()) {
Element bundleElement = it.nextElement();
String value = DomUtil.getAttribute(bundleElement,
ObservationConstants.XML_EVENT_LOCAL,
ObservationConstants.NAMESPACE);
ObservationConstants.XML_EVENT_LOCAL, null);
// check if it matches a batch id recently submitted
boolean isLocal = false;
if (value != null) {
Expand Down Expand Up @@ -2270,7 +2268,7 @@ private EventBundle[] poll(String uri, String subscriptionId, long timeout, Sess

private List<Event> buildEventList(Element bundleElement, SessionInfoImpl sessionInfo) throws IllegalNameException, NamespaceException {
List<Event> events = new ArrayList<Event>();
ElementIterator eventElementIterator = DomUtil.getChildren(bundleElement, ObservationConstants.XML_EVENT, ObservationConstants.NAMESPACE);
ElementIterator eventElementIterator = DomUtil.getChildren(bundleElement, ObservationConstants.N_EVENT);

String userId = null;

Expand All @@ -2285,7 +2283,7 @@ private List<Event> buildEventList(Element bundleElement, SessionInfoImpl sessio

while (eventElementIterator.hasNext()) {
Element evElem = eventElementIterator.nextElement();
Element typeEl = DomUtil.getChildElement(evElem, ObservationConstants.XML_EVENTTYPE, ObservationConstants.NAMESPACE);
Element typeEl = DomUtil.getChildElement(evElem, ObservationConstants.N_EVENTTYPE);
EventType[] et = DefaultEventType.createFromXml(typeEl);
if (et.length == 0 || et.length > 1) {
// should not occur.
Expand Down Expand Up @@ -2346,7 +2344,7 @@ private List<Event> buildEventList(Element bundleElement, SessionInfoImpl sessio

if (userId == null) {
// user id not retrieved from container
userId = DomUtil.getChildTextTrim(evElem, ObservationConstants.XML_EVENTUSERID, ObservationConstants.NAMESPACE);
userId = DomUtil.getChildTextTrim(evElem, ObservationConstants.N_EVENTUSERID);
}

events.add(new EventImpl(eventId, eventPath, parentId, type, userId, evElem,
Expand Down
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.jackrabbit.webdav.observation;

import javax.xml.namespace.QName;

import org.apache.jackrabbit.webdav.property.DavPropertyName;
import org.apache.jackrabbit.webdav.xml.Namespace;

Expand Down Expand Up @@ -78,7 +80,18 @@ public interface ObservationConstants {
public static final String XML_EVENTINFO = "eventinfo";
public static final String XML_EVENTPRIMARNODETYPE = "eventprimarynodetype";
public static final String XML_EVENTMIXINNODETYPE = "eventmixinnodetype";


public static final QName N_EVENT = new QName(NAMESPACE.getURI(), XML_EVENT);
public static final QName N_EVENTBUNDLE = new QName(NAMESPACE.getURI(), XML_EVENTBUNDLE);
public static final QName N_EVENTDATE = new QName(NAMESPACE.getURI(), XML_EVENTDATE);
public static final QName N_EVENTDISCOVERY = new QName(NAMESPACE.getURI(), XML_EVENTDISCOVERY);
public static final QName N_EVENTINFO = new QName(NAMESPACE.getURI(), XML_EVENTINFO);
public static final QName N_EVENTMIXINNODETYPE = new QName(NAMESPACE.getURI(), XML_EVENTMIXINNODETYPE);
public static final QName N_EVENTPRIMARYNODETYPE = new QName(NAMESPACE.getURI(), XML_EVENTPRIMARNODETYPE);
public static final QName N_EVENTTYPE = new QName(NAMESPACE.getURI(), XML_EVENTTYPE);
public static final QName N_EVENTUSERDATA = new QName(NAMESPACE.getURI(), XML_EVENTUSERDATA);
public static final QName N_EVENTUSERID = new QName(NAMESPACE.getURI(), XML_EVENTUSERID);

//---< Property Names >-----------------------------------------------------
/**
* The protected subscription discovery property is used to find out about
Expand Down
Expand Up @@ -252,6 +252,22 @@ public static String getChildTextTrim(Element parent, String childLocalName, Nam
return (child == null) ? null : getTextTrim(child);
}

/**
* Calls {@link #getTextTrim(Element)} on the first child element that matches
* the given name.
*
* @param parent
* @param childName
* @return text contained in the first child that matches the given name
* or <code>null</code>. Note, that leading and trailing whitespace
* is removed from the text.
* @see #getTextTrim(Element)
*/
public static String getChildTextTrim(Element parent, QName childName) {
Element child = getChildElement(parent, childName);
return (child == null) ? null : getTextTrim(child);
}

/**
* Returns true if the given parent node has a child element that matches
* the specified local name and namespace.
Expand Down

0 comments on commit 5c68c57

Please sign in to comment.