incubator-sling-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1098497&view=rev
Log:
SLING-2063 : If a node is removed and added in one go, resource added event should be fired

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=1098497&r1=1098496&r2=1098497&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:21:13 2011
@@ -129,24 +129,28 @@ public class JcrResourceListener impleme
         while ( events.hasNext() ) {
             final Event event = events.nextEvent();
             try {
-                Map<String, Event> map = null;
-                String nodePath = event.getPath();
+                final String eventPath;
+                if ( this.mountPrefix != null ) {
+                    eventPath = this.mountPrefix + event.getPath();
+                } else {
+                    eventPath = event.getPath();
+                }
                 if ( event.getType() == Event.PROPERTY_ADDED
                      || event.getType() == Event.PROPERTY_REMOVED
                      || event.getType() == Event.PROPERTY_CHANGED ) {
-                    final int lastSlash = nodePath.lastIndexOf('/');
-                    nodePath = nodePath.substring(0, lastSlash);
-                    map = changedEvents;
+                    final int lastSlash = eventPath.lastIndexOf('/');
+                    changedEvents.put(eventPath.substring(0, lastSlash), event);
                 } else if ( event.getType() == Event.NODE_ADDED ) {
-                    map = addedEvents;
-                }   else if ( event.getType() == Event.NODE_REMOVED) {
-                  map = removedEvents;
-                }
-                if ( map != null ) {
-                    if ( this.mountPrefix != null ) {
-                        map.put(mountPrefix + nodePath, event);
+                    // check if this is a remove/add operation
+                    if ( removedEvents.containsKey(eventPath) ) {
+                        changedEvents.put(eventPath, event);
                     } else {
-                        map.put(nodePath, event);
+                        addedEvents.put(eventPath, event);
+                    }
+                } else if ( event.getType() == Event.NODE_REMOVED) {
+                    // check if this is a add/remove operation
+                    if ( !addedEvents.containsKey(eventPath) ) {
+                        removedEvents.put(eventPath, event);
                     }
                 }
             } catch (RepositoryException e) {
@@ -155,7 +159,7 @@ public class JcrResourceListener impleme
             }
         }
 
-        for (Entry<String, Event> e : removedEvents.entrySet()) {
+        for (final Entry<String, Event> e : removedEvents.entrySet()) {
             // remove is the strongest operation, therefore remove all removed
             // paths from changed and added
             addedEvents.remove(e.getKey());
@@ -169,7 +173,7 @@ public class JcrResourceListener impleme
         }
 
         // add is stronger than changed
-        for (Entry<String, Event> e : addedEvents.entrySet()) {
+        for (final Entry<String, Event> e : addedEvents.entrySet()) {
             changedEvents.remove(e.getKey());
 
             // Launch an OSGi event.
@@ -177,7 +181,7 @@ public class JcrResourceListener impleme
         }
 
         // Send the changed events.
-        for (Entry<String, Event> e : changedEvents.entrySet()) {
+        for (final Entry<String, Event> e : changedEvents.entrySet()) {
             // Launch an OSGi event.
             sendOsgiEvent(e.getKey(), e.getValue(), SlingConstants.TOPIC_RESOURCE_CHANGED,
localEA);
         }



Mime
View raw message