incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1098502 - in /sling/trunk/bundles/jcr/resource: pom.xml src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
Date Mon, 02 May 2011 06:56:02 GMT
Author: cziegeler
Date: Mon May  2 06:56:02 2011
New Revision: 1098502

URL: http://svn.apache.org/viewvc?rev=1098502&view=rev
Log:
SLING-2068 : Add info if resource event is external or locally

Modified:
    sling/trunk/bundles/jcr/resource/pom.xml
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java

Modified: sling/trunk/bundles/jcr/resource/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/pom.xml?rev=1098502&r1=1098501&r2=1098502&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/pom.xml (original)
+++ sling/trunk/bundles/jcr/resource/pom.xml Mon May  2 06:56:02 2011
@@ -71,6 +71,9 @@
                             org.apache.sling.commons.osgi;version="$(@)",
                             *
                         </Import-Package>
+                        <DynamicImport-Package>
+                            org.apache.jackrabbit.api.observation
+                        </DynamicImport-Package>
                         <Export-Package>
                             org.apache.sling.jcr.resource;version=2.1
                         </Export-Package>
@@ -103,6 +106,12 @@
     
     <dependencies>
         <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-api</artifactId>
+            <version>2.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.scr.annotations</artifactId>
         </dependency>
@@ -205,11 +214,5 @@
             <version>1.4</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.jackrabbit</groupId>
-            <artifactId>jackrabbit-api</artifactId>
-            <version>2.0.0</version>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 </project>

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java?rev=1098502&r1=1098501&r2=1098502&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
Mon May  2 06:56:02 2011
@@ -31,6 +31,7 @@ import javax.jcr.observation.Event;
 import javax.jcr.observation.EventIterator;
 import javax.jcr.observation.EventListener;
 
+import org.apache.jackrabbit.api.observation.JackrabbitEvent;
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.Resource;
@@ -71,6 +72,9 @@ public class JcrResourceListener impleme
     /** The event admin tracker. */
     private final ServiceTracker eventAdminTracker;
 
+    /** Is the Jackrabbit event class available? */
+    private final boolean hasJackrabbitEventClass;
+
     /**
      * Constructor.
      * @param workspaceName The workspace name to observe
@@ -100,6 +104,14 @@ public class JcrResourceListener impleme
         this.session.getWorkspace().getObservationManager().addEventListener(this,
             Event.NODE_ADDED|Event.NODE_REMOVED|Event.PROPERTY_ADDED|Event.PROPERTY_CHANGED|Event.PROPERTY_REMOVED,
             this.startPath, true, null, null, false);
+        boolean foundClass = false;
+        try {
+            this.getClass().getClassLoader().loadClass(JackrabbitEvent.class.getName());
+            foundClass = true;
+        } catch (final Throwable t) {
+            // we ignore this
+        }
+        this.hasJackrabbitEventClass = foundClass;
     }
 
     /**
@@ -169,6 +181,9 @@ public class JcrResourceListener impleme
             final Dictionary<String, String> properties = new Hashtable<String,
String>();
             properties.put(SlingConstants.PROPERTY_PATH, createWorkspacePath(e.getKey()));
             properties.put(SlingConstants.PROPERTY_USERID, e.getValue().getUserID());
+            if ( this.isExternal(e.getValue()) ) {
+                properties.put("event.application", "unknown");
+            }
             localEA.postEvent(new org.osgi.service.event.Event(SlingConstants.TOPIC_RESOURCE_REMOVED,
properties));
         }
 
@@ -194,7 +209,7 @@ public class JcrResourceListener impleme
      * @param topic The topic that should be used for the OSGi event.
      * @param localEA The OSGi Event Admin that can be used to post events.
      */
-    private void sendOsgiEvent(String path, Event event, final String topic, final EventAdmin
localEA) {
+    private void sendOsgiEvent(String path, final Event event, final String topic, final
EventAdmin localEA) {
         path = createWorkspacePath(path);
         Resource resource = this.resolver.getResource(path);
         if ( resource != null ) {
@@ -225,10 +240,21 @@ public class JcrResourceListener impleme
             if ( resourceSuperType != null ) {
                 properties.put(SlingConstants.PROPERTY_RESOURCE_SUPER_TYPE, resource.getResourceSuperType());
             }
+            if ( this.isExternal(event) ) {
+                properties.put("event.application", "unknown");
+            }
             localEA.postEvent(new org.osgi.service.event.Event(topic, properties));
         }
     }
 
+    private boolean isExternal(final Event event) {
+        if ( this.hasJackrabbitEventClass && event instanceof JackrabbitEvent) {
+            final JackrabbitEvent jEvent = (JackrabbitEvent)event;
+            return jEvent.isExternal();
+        }
+        return false;
+    }
+
     private String createWorkspacePath(final String path) {
         if (workspaceName == null) {
             return path;



Mime
View raw message