incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1204886 - /sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
Date Tue, 22 Nov 2011 09:54:58 GMT
Author: fmeschbe
Date: Tue Nov 22 09:54:57 2011
New Revision: 1204886

URL: http://svn.apache.org/viewvc?rev=1204886&view=rev
Log:
SLING-2296 Make sure the OSGi Event is always sent, regardless of the modified or added resource
is (already) visible or not. This allows us to also use the sendOsgiEvent method for removal
events.

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

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=1204886&r1=1204885&r2=1204886&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
Tue Nov 22 09:54:57 2011
@@ -182,13 +182,7 @@ public class JcrResourceListener impleme
 
         for (final Entry<String, Event> e : removedEvents.entrySet()) {
             // Launch an OSGi event
-            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));
+            sendOsgiEvent(e.getKey(), e.getValue(), SlingConstants.TOPIC_RESOURCE_REMOVED,
localEA, null);
         }
 
         for (final Entry<String, Event> e : addedEvents.entrySet()) {
@@ -265,6 +259,7 @@ public class JcrResourceListener impleme
 
     /**
      * Send an OSGi event based on a JCR Observation Event.
+     *
      * @param path The path too the node where the event occurred.
      * @param event The JCR observation event.
      * @param topic The topic that should be used for the OSGi event.
@@ -272,44 +267,52 @@ public class JcrResourceListener impleme
      */
     private void sendOsgiEvent(String path, final Event event, final String topic, final
EventAdmin localEA,
             final ChangedAttributes changedAttributes) {
+
         path = createWorkspacePath(path);
-        Resource resource = this.resolver.getResource(path);
-        if ( resource != null ) {
-            // check for nt:file nodes
-            if ( path.endsWith("/jcr:content") ) {
-                final Node node = resource.adaptTo(Node.class);
-                if ( node != null ) {
-                    try {
-                        if (node.getParent().isNodeType("nt:file") ) {
-                            final Resource parentResource = ResourceUtil.getParent(resource);
-                            if ( parentResource != null ) {
-                                resource = parentResource;
+
+        final Dictionary<String, Object> properties = new Hashtable<String, Object>();
+        properties.put(SlingConstants.PROPERTY_PATH, path);
+        properties.put(SlingConstants.PROPERTY_USERID, event.getUserID());
+        if ( this.isExternal(event) ) {
+            properties.put("event.application", "unknown");
+        }
+        if ( changedAttributes != null ) {
+            changedAttributes.addProperties(properties);
+        }
+
+        if (!SlingConstants.TOPIC_RESOURCE_REMOVED.equals(topic)) {
+            Resource resource = this.resolver.getResource(path);
+            if (resource != null) {
+                // check for nt:file nodes
+                if (path.endsWith("/jcr:content")) {
+                    final Node node = resource.adaptTo(Node.class);
+                    if (node != null) {
+                        try {
+                            if (node.getParent().isNodeType("nt:file")) {
+                                @SuppressWarnings("deprecation")
+                                final Resource parentResource = ResourceUtil.getParent(resource);
+                                if (parentResource != null) {
+                                    resource = parentResource;
+                                }
                             }
+                        } catch (RepositoryException re) {
+                            // ignore this
                         }
-                    } catch (RepositoryException re) {
-                        // ignore this
                     }
                 }
+
+                final String resourceType = resource.getResourceType();
+                if (resourceType != null) {
+                    properties.put(SlingConstants.PROPERTY_RESOURCE_TYPE, resource.getResourceType());
+                }
+                final String resourceSuperType = resource.getResourceSuperType();
+                if (resourceSuperType != null) {
+                    properties.put(SlingConstants.PROPERTY_RESOURCE_SUPER_TYPE, resource.getResourceSuperType());
+                }
             }
-            final Dictionary<String, Object> properties = new Hashtable<String,
Object>();
-            properties.put(SlingConstants.PROPERTY_PATH, resource.getPath());
-            properties.put(SlingConstants.PROPERTY_USERID, event.getUserID());
-            final String resourceType = resource.getResourceType();
-            if ( resourceType != null ) {
-                properties.put(SlingConstants.PROPERTY_RESOURCE_TYPE, resource.getResourceType());
-            }
-            final String resourceSuperType = resource.getResourceSuperType();
-            if ( resourceSuperType != null ) {
-                properties.put(SlingConstants.PROPERTY_RESOURCE_SUPER_TYPE, resource.getResourceSuperType());
-            }
-            if ( this.isExternal(event) ) {
-                properties.put("event.application", "unknown");
-            }
-            if ( changedAttributes != null ) {
-                changedAttributes.addProperties(properties);
-            }
-            localEA.postEvent(new org.osgi.service.event.Event(topic, properties));
         }
+
+        localEA.postEvent(new org.osgi.service.event.Event(topic, properties));
     }
 
     private boolean isExternal(final Event event) {



Mime
View raw message