jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r781296 - in /jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav: EventImpl.java RepositoryServiceImpl.java
Date Wed, 03 Jun 2009 08:26:18 GMT
Author: angela
Date: Wed Jun  3 08:26:17 2009
New Revision: 781296

URL: http://svn.apache.org/viewvc?rev=781296&view=rev
Log:
JCR-2108: JSR 283 Observation   (work in progress)

- adjust spi2dav

Modified:
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventImpl.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventImpl.java?rev=781296&r1=781295&r2=781296&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventImpl.java
Wed Jun  3 08:26:17 2009
@@ -18,12 +18,28 @@
 
 import org.apache.jackrabbit.spi.Event;
 import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 import org.apache.jackrabbit.webdav.observation.ObservationConstants;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.webdav.xml.ElementIterator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * <code>EventImpl</code>...
  */
@@ -31,13 +47,19 @@
         extends org.apache.jackrabbit.spi.commons.EventImpl
         implements ObservationConstants {
 
+    private static Logger log = LoggerFactory.getLogger(EventImpl.class);
+
+    private static final NameFactory N_FACTORY = NameFactoryImpl.getInstance();
+
     public EventImpl(ItemId eventId, Path eventPath, NodeId parentId, int eventType,
-                     Element eventElement) {
+                     Element eventElement, NamePathResolver resolver, QValueFactory qvFactory)
{
         super(getSpiEventType(eventType), eventPath, eventId, parentId,
                 null, // TODO not available from XML_EVENT element
                 null, // TODO not available from XML_EVENT element
-                DomUtil.getChildTextTrim(eventElement, XML_EVENTUSERID, NAMESPACE));
-        // TODO: extend jcr-server to deliver jsr 283 event information
+                DomUtil.getChildTextTrim(eventElement, XML_EVENTUSERID, NAMESPACE),
+                DomUtil.getChildTextTrim(eventElement, XML_EVENTUSERDATA, NAMESPACE),
+                Long.parseLong(DomUtil.getChildTextTrim(eventElement, XML_EVENTDATE, NAMESPACE)),
+                getEventInfo(DomUtil.getChildElement(eventElement, XML_EVENTINFO, NAMESPACE),
resolver, qvFactory));
     }
 
     //--------------------------------------------------------------------------
@@ -61,4 +83,32 @@
                 throw new IllegalArgumentException("Invalid event type: " + jcrEventType);
         }
     }
+
+    private static Map<Name, QValue> getEventInfo(Element infoElement,
+                                                  NamePathResolver resolver,
+                                                  QValueFactory qvFactory) {
+        if (infoElement == null) {
+            return Collections.EMPTY_MAP;
+        }
+
+        Map<Name, QValue> info = new HashMap();
+        ElementIterator it = DomUtil.getChildren(infoElement);
+        while (it.hasNext()) {
+            Element el = it.nextElement();
+            String uri = el.getNamespaceURI();
+            String localName = el.getLocalName();
+            String value = DomUtil.getTextTrim(el);
+            try {
+                Name n = N_FACTORY.create(uri, localName);
+                QValue qv = null;
+                if (value != null) {
+                    qv = ValueFormat.getQValue(value, PropertyType.PATH, resolver, qvFactory);
+                }
+                info.put(n, qv);
+            } catch (RepositoryException e) {
+                log.error("Internal Error: ", e.getMessage());
+            }
+        }
+        return info;
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?rev=781296&r1=781295&r2=781296&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Wed Jun  3 08:26:17 2009
@@ -201,13 +201,15 @@
 
     private static Logger log = LoggerFactory.getLogger(RepositoryServiceImpl.class);
 
-    private static final EventType[] ALL_EVENTS = new EventType[5];
+    private static final EventType[] ALL_EVENTS = new EventType[7];
     static {
         ALL_EVENTS[0] = SubscriptionImpl.getEventType(javax.jcr.observation.Event.NODE_ADDED);
         ALL_EVENTS[1] = SubscriptionImpl.getEventType(javax.jcr.observation.Event.NODE_REMOVED);
         ALL_EVENTS[2] = SubscriptionImpl.getEventType(javax.jcr.observation.Event.PROPERTY_ADDED);
         ALL_EVENTS[3] = SubscriptionImpl.getEventType(javax.jcr.observation.Event.PROPERTY_CHANGED);
         ALL_EVENTS[4] = SubscriptionImpl.getEventType(javax.jcr.observation.Event.PROPERTY_REMOVED);
+        ALL_EVENTS[5] = SubscriptionImpl.getEventType(javax.jcr.observation.Event.NODE_MOVED);
+        ALL_EVENTS[6] = SubscriptionImpl.getEventType(javax.jcr.observation.Event.PERSIST);
     }
     private static final SubscriptionInfo S_INFO = new SubscriptionInfo(ALL_EVENTS, true,
INFINITE_TIMEOUT);
 
@@ -345,7 +347,11 @@
 
     protected NamePathResolver getNamePathResolver(SessionInfo sessionInfo) throws RepositoryException
{
         checkSessionInfo(sessionInfo);
-        NamePathResolver resolver = ((SessionInfoImpl) sessionInfo).getNamePathResolver();
+        return getNamePathResolver(((SessionInfoImpl) sessionInfo));
+    }
+
+    private NamePathResolver getNamePathResolver(SessionInfoImpl sessionInfo) {
+        NamePathResolver resolver = sessionInfo.getNamePathResolver();
         if (resolver == null) {
             resolver = new NamePathResolverImpl(sessionInfo);
             ((SessionInfoImpl) sessionInfo).setNamePathResolver(resolver);
@@ -1878,7 +1884,7 @@
         }
     }
 
-    private List buildEventList(Element bundleElement, SessionInfo sessionInfo) {
+    private List buildEventList(Element bundleElement, SessionInfoImpl sessionInfo) {
         List events = new ArrayList();
         ElementIterator eventElementIterator = DomUtil.getChildren(bundleElement, ObservationConstants.XML_EVENT,
ObservationConstants.NAMESPACE);
         while (eventElementIterator.hasNext()) {
@@ -1926,7 +1932,8 @@
                 log.warn("Unable to build event parentId: ", e.getMessage());
             }
 
-            events.add(new EventImpl(eventId, eventPath, parentId, type, evElem));
+
+            events.add(new EventImpl(eventId, eventPath, parentId, type, evElem, getNamePathResolver(sessionInfo),
getQValueFactory()));
         }
 
         return events;



Mime
View raw message