incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1337414 - in /sling/trunk/bundles/jcr/resource: pom.xml src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
Date Fri, 11 May 2012 23:33:06 GMT
Author: fmeschbe
Date: Fri May 11 23:33:05 2012
New Revision: 1337414

URL: http://svn.apache.org/viewvc?rev=1337414&view=rev
Log:
SLING-2474 Make sure update events for the sling:match property are handled by MapEntries

Modified:
    sling/trunk/bundles/jcr/resource/pom.xml
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java

Modified: sling/trunk/bundles/jcr/resource/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/pom.xml?rev=1337414&r1=1337413&r2=1337414&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/pom.xml (original)
+++ sling/trunk/bundles/jcr/resource/pom.xml Fri May 11 23:33:05 2012
@@ -247,5 +247,11 @@
             <version>2.1.0</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>3.0.8</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java?rev=1337414&r1=1337413&r2=1337414&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
Fri May 11 23:33:05 2012
@@ -124,34 +124,9 @@ public class MapEntries implements Event
 
         doInit();
 
-        // build a filter which matches if any of the nodeProps (JCR
-        // properties modified) is listed in any of the eventProps (event
-        // properties listing modified JCR properties)
-        // this allows to only get events interesting for updating the
-        // internal structure
-        final String[] nodeProps = {
-            "sling:vanityPath", "sling:vanityOrder", JcrResourceResolver.PROP_REDIRECT_EXTERNAL_REDIRECT_STATUS,
-            JcrResourceResolver.PROP_REDIRECT_EXTERNAL, JcrResourceResolver.PROP_REDIRECT_INTERNAL,
-            JcrResourceResolver.PROP_REDIRECT_EXTERNAL_STATUS
-        };
-        final String[] eventProps = {
-            "resourceAddedAttributes", "resourceChangedAttributes", "resourceRemovedAttributes"
-        };
-        StringBuilder filter = new StringBuilder();
-        filter.append("(|");
-        for (String eventProp : eventProps) {
-            filter.append("(|");
-            for (String nodeProp : nodeProps) {
-                filter.append('(').append(eventProp).append('=').append(nodeProp).append(')');
-            }
-            filter.append(")");
-        }
-        filter.append("(" + EventConstants.EVENT_TOPIC + "=" + SlingConstants.TOPIC_RESOURCE_REMOVED
+ ")");
-        filter.append(")");
-
         final Dictionary<String, String> props = new Hashtable<String, String>();
         props.put(EventConstants.EVENT_TOPIC, "org/apache/sling/api/resource/*");
-        props.put(EventConstants.EVENT_FILTER, filter.toString());
+        props.put(EventConstants.EVENT_FILTER, createFilter());
         props.put(Constants.SERVICE_DESCRIPTION, "Map Entries Observation");
         props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
         this.registration = bundleContext.registerService(EventHandler.class.getName(), this,
props);
@@ -674,6 +649,36 @@ public class MapEntries implements Event
         entries.put(path, entry);
     }
 
+    /**
+     * Returns a filter which matches if any of the nodeProps (JCR properties
+     * modified) is listed in any of the eventProps (event properties listing
+     * modified JCR properties) this allows to only get events interesting for
+     * updating the internal structure
+     */
+    private static String createFilter() {
+        final String[] nodeProps = {
+            "sling:vanityPath", "sling:vanityOrder", JcrResourceResolver.PROP_REDIRECT_EXTERNAL_REDIRECT_STATUS,
+            JcrResourceResolver.PROP_REDIRECT_EXTERNAL, JcrResourceResolver.PROP_REDIRECT_INTERNAL,
+            JcrResourceResolver.PROP_REDIRECT_EXTERNAL_STATUS, JcrResourceResolver.PROP_REG_EXP
+        };
+        final String[] eventProps = {
+            "resourceAddedAttributes", "resourceChangedAttributes", "resourceRemovedAttributes"
+        };
+        StringBuilder filter = new StringBuilder();
+        filter.append("(|");
+        for (String eventProp : eventProps) {
+            filter.append("(|");
+            for (String nodeProp : nodeProps) {
+                filter.append('(').append(eventProp).append('=').append(nodeProp).append(')');
+            }
+            filter.append(")");
+        }
+        filter.append("(" + EventConstants.EVENT_TOPIC + "=" + SlingConstants.TOPIC_RESOURCE_REMOVED
+ ")");
+        filter.append(")");
+
+        return filter.toString();
+    }
+
     private static final class MapEntryIterator implements Iterator<MapEntry> {
 
         private final Map<String, List<MapEntry>> resolveMapsMap;

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java?rev=1337414&r1=1337413&r2=1337414&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
Fri May 11 23:33:05 2012
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.when;
 
 import java.io.BufferedReader;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.security.Principal;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -44,6 +45,7 @@ import javax.servlet.http.HttpSession;
 
 import junitx.util.PrivateAccessor;
 
+import org.apache.felix.framework.FilterImpl;
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.resource.NonExistingResource;
@@ -62,6 +64,7 @@ import org.apache.sling.jcr.resource.int
 import org.apache.sling.jcr.resource.internal.helper.RedirectResource;
 import org.apache.sling.jcr.resource.internal.helper.starresource.StarResource;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
 import org.osgi.util.tracker.ServiceTracker;
@@ -176,12 +179,23 @@ public class JcrResourceResolverTest ext
 
         final EventAdmin mockEA = new EventAdmin() {
 
+            private final Filter filter;
+
+            {
+                Method createFilter = MapEntries.class.getDeclaredMethod("createFilter");
+                createFilter.setAccessible(true);
+                final String filterString = (String) createFilter.invoke(null);
+                this.filter = new FilterImpl(filterString);
+            }
+
             public void postEvent(Event event) {
-                mapEntries.handleEvent(event);
+                if (event.matches(this.filter)) {
+                    mapEntries.handleEvent(event);
+                }
             }
 
             public void sendEvent(Event event) {
-                mapEntries.handleEvent(event);
+                postEvent(event);
             }
         };
         final ServiceTracker tracker = mock(ServiceTracker.class);
@@ -751,6 +765,46 @@ public class JcrResourceResolverTest ext
         assertEquals("/libs/nt/folder.html", res.getPath());
     }
 
+    public void testResolveResourceInternalRedirectPathUpdate() throws Exception {
+        HttpServletRequest request = new ResourceResolverTestRequest("https", null, -1, rootPath);
+        Node localhost443 = mapRoot.getNode("map/https/localhost.443");
+        Node toContent = localhost443.addNode("_playground_designground_", "sling:Mapping");
+        toContent.setProperty(JcrResourceResolver.PROP_REG_EXP, "(playground|designground)");
+        toContent.setProperty(JcrResourceResolver.PROP_REDIRECT_INTERNAL, "/content/$1");
+        session.save();
+
+        Thread.sleep(1000L);
+
+        Resource res = resResolver.resolve(request, "/playground.html");
+        assertNotNull(res);
+        assertEquals("/content/playground.html", res.getPath());
+
+        res = resResolver.resolve(request, "/playground/en.html");
+        assertNotNull(res);
+        assertEquals("/content/playground/en.html", res.getPath());
+
+        res = resResolver.resolve(request, "/libs/nt/folder.html");
+        assertNotNull(res);
+        assertEquals("/libs/nt/folder.html", res.getPath());
+
+        // update the match
+        toContent.setProperty(JcrResourceResolver.PROP_REG_EXP, "(homeground|foreignground)");
+        session.save();
+        Thread.sleep(1000L);
+
+        res = resResolver.resolve(request, "/homeground.html");
+        assertNotNull(res);
+        assertEquals("/content/homeground.html", res.getPath());
+
+        res = resResolver.resolve(request, "/foreignground/en.html");
+        assertNotNull(res);
+        assertEquals("/content/foreignground/en.html", res.getPath());
+
+        res = resResolver.resolve(request, "/libs/nt/folder.html");
+        assertNotNull(res);
+        assertEquals("/libs/nt/folder.html", res.getPath());
+    }
+
     public void testResolveResourceInternalRedirectExact() throws Exception {
         HttpServletRequest request = new ResourceResolverTestRequest("https",
             null, -1, rootPath);



Mime
View raw message