You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2009/05/14 21:27:03 UTC

svn commit: r774890 - in /incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal: JcrResourceResolverWebConsolePlugin.java helper/MapEntries.java helper/MapEntry.java

Author: fmeschbe
Date: Thu May 14 19:27:02 2009
New Revision: 774890

URL: http://svn.apache.org/viewvc?rev=774890&view=rev
Log:
SLING-968 Special handling for matches with trailing $ signs (see issue for details)
  + refactor MapEntry constructor to leverage varargs for map targets
  + return any resolve/map test failures in the console plugin

Modified:
    incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverWebConsolePlugin.java
    incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
    incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java

Modified: incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverWebConsolePlugin.java?rev=774890&r1=774889&r2=774890&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverWebConsolePlugin.java (original)
+++ incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverWebConsolePlugin.java Thu May 14 19:27:02 2009
@@ -43,7 +43,7 @@
 import org.osgi.framework.ServiceRegistration;
 
 public class JcrResourceResolverWebConsolePlugin extends AbstractWebConsolePlugin {
-
+    
     private static final long serialVersionUID = 0;
     
     private static final String ATTR_TEST = "plugin.test";
@@ -54,7 +54,7 @@
 
     private final transient JcrResourceResolverFactoryImpl resolverFactory;
 
-    private ServiceRegistration service;
+    private transient ServiceRegistration service;
 
     JcrResourceResolverWebConsolePlugin(BundleContext context,
             JcrResourceResolverFactoryImpl resolverFactory) {
@@ -236,7 +236,10 @@
                 request.setAttribute(ATTR_RESULT, result.toString());
 
             } catch (Throwable t) {
-                // TOOD: log
+            
+                // some error occurred, report it as a result
+                request.setAttribute(ATTR_RESULT, "Test Failure: " + t);
+
             } finally {
                 if (session != null) {
                     session.logout();

Modified: incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java?rev=774890&r1=774889&r2=774890&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java (original)
+++ incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java Thu May 14 19:27:02 2009
@@ -19,15 +19,12 @@
 package org.apache.sling.jcr.resource.internal.helper;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.TreeSet;
@@ -273,13 +270,16 @@
                 }
             }
 
-            // add trailing slash to child path to append the child
-            if (!trailingSlash) {
-                childPath = childPath.concat("/");
-            }
+            // gather the children of this entry (only if child is not end hooked)
+            if (!childPath.endsWith("$")) {
+
+	            // add trailing slash to child path to append the child
+	            if (!trailingSlash) {
+	                childPath = childPath.concat("/");
+	            }
 
-            // gather the children of this entry
-            gather(resolver, resolveEntries, mapEntries, child, childPath);
+                gather(resolver, resolveEntries, mapEntries, child, childPath);
+            }
         }
     }
 
@@ -318,12 +318,12 @@
                         : -1;
 
                 // 1. entry with exact match
-                entries.add(new MapEntry(url + "$", redirect + ".html", status,
-                    false));
+                entries.add(new MapEntry(url + "$", status, false, redirect
+                    + ".html"));
 
                 // 2. entry with match supporting selectors and extension
-                entries.add(new MapEntry(url + "(\\..*)", redirect + "$1",
-                    status, false));
+                entries.add(new MapEntry(url + "(\\..*)", status, false,
+                    redirect + "$1"));
             }
         }
     }
@@ -340,7 +340,7 @@
                     // this regular expression must match the whole URL !!
                     String url = "^" + ANY_SCHEME_HOST + extPath + "$";
                     String redirect = intPath;
-                    entries.add(new MapEntry(url, redirect, -1, false));
+                    entries.add(new MapEntry(url, -1, false, redirect));
                 }
             }
         }
@@ -365,7 +365,7 @@
             }
             for (Entry<String, List<String>> entry : map.entrySet()) {
                 entries.add(new MapEntry(ANY_SCHEME_HOST + entry.getKey(),
-                    entry.getValue().toArray(new String[0]), -1, false));
+                    -1, false, entry.getValue().toArray(new String[0])));
             }
         }
     }
@@ -407,14 +407,14 @@
             String url, int status) {
         MapEntry entry = entries.get(path);
         if (entry == null) {
-            entry = new MapEntry(path, url, status, false);
+            entry = new MapEntry(path, status, false, url);
         } else {
             String[] redir = entry.getRedirect();
             String[] newRedir = new String[redir.length + 1];
             System.arraycopy(redir, 0, newRedir, 0, redir.length);
             newRedir[redir.length] = url;
-            entry = new MapEntry(entry.getPattern(), newRedir,
-                entry.getStatus(), false);
+            entry = new MapEntry(entry.getPattern(), entry.getStatus(),
+                false, newRedir);
         }
         entries.put(path, entry);
     }

Modified: incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java?rev=774890&r1=774889&r2=774890&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java (original)
+++ incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java Thu May 14 19:27:02 2009
@@ -111,13 +111,13 @@
             if (redirect != null) {
                 int status = props.get(
                     JcrResourceResolver2.PROP_REDIRECT_EXTERNAL_STATUS, 302);
-                return new MapEntry(url, redirect, status, trailingSlash);
+                return new MapEntry(url, status, trailingSlash, redirect);
             }
 
             String[] internalRedirect = props.get(
                 JcrResourceResolver2.PROP_REDIRECT_INTERNAL, String[].class);
             if (internalRedirect != null) {
-                return new MapEntry(url, internalRedirect, -1, trailingSlash);
+                return new MapEntry(url, -1, trailingSlash, internalRedirect);
             }
         }
 
@@ -135,6 +135,13 @@
                 return null;
             }
 
+            // check whether the url is a match hooked to then string end
+            String endHook = "";
+            if (url.endsWith("$")) {
+                endHook = "$";
+                url = url.substring(0, url.length()-1);
+            }
+            
             String[] internalRedirect = props.get(
                 JcrResourceResolver2.PROP_REDIRECT_INTERNAL, String[].class);
             if (internalRedirect != null) {
@@ -152,8 +159,8 @@
                     internalRedirect.length);
                 for (String redir : internalRedirect) {
                     if (!redir.contains("$")) {
-                        prepEntries.add(new MapEntry(redir, url, status,
-                            trailingSlash));
+                        prepEntries.add(new MapEntry(redir.concat(endHook),
+                            status, trailingSlash, url));
                     }
                 }
 
@@ -166,13 +173,8 @@
         return null;
     }
 
-    public MapEntry(String url, String redirect, int status,
-            boolean trailingSlash) {
-        this(url, new String[] { redirect }, status, trailingSlash);
-    }
-
-    public MapEntry(String url, String[] redirect, int status,
-            boolean trailingSlash) {
+    public MapEntry(String url, int status, boolean trailingSlash,
+            String... redirect) {
 
         // ensure trailing slashes on redirects if the url
         // ends with a trailing slash
@@ -193,10 +195,6 @@
         this.status = status;
     }
 
-    public Matcher getMatcher(String value) {
-        return urlPattern.matcher(value);
-    }
-
     // Returns the replacement or null if the value does not match
     public String[] replace(String value) {
         Matcher m = urlPattern.matcher(value);