incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r941335 - in /sling/trunk/bundles/jcr/resource/src/main: java/org/apache/sling/jcr/resource/internal/ java/org/apache/sling/jcr/resource/internal/helper/ resources/OSGI-INF/metatype/
Date Wed, 05 May 2010 15:10:52 GMT
Author: fmeschbe
Date: Wed May  5 15:10:52 2010
New Revision: 941335

URL: http://svn.apache.org/viewvc?rev=941335&view=rev
Log:
SLING-1519 Use colon (:) as a bidirectional URL Mapping indicator instead of the dash (-)
to prevent wrong mappings if the source path contains a dash. The dash is still supported
for backwards compatibility with existing configuration

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/Mapping.java
    sling/trunk/bundles/jcr/resource/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java?rev=941335&r1=941334&r2=941335&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
Wed May  5 15:10:52 2010
@@ -143,15 +143,13 @@ public class JcrResourceResolverFactoryI
      * multivalue properties at the moment. So we just add a dummy direct
      * mapping.
      *
-     * @scr.property values.1="/-/"
+     * @scr.property values.1="/:/"
      */
     private static final String PROP_VIRTUAL = "resource.resolver.virtual";
 
     /**
-     * @scr.property values.1="/-/" values.2="/content/-/"
-     *               Cvalues.3="/apps/×/docroot/-/"
-     *               Cvalues.4="/libs/×/docroot/-/"
-     *               values.5="/system/docroot/-/"
+     * @scr.property values.1="/:/" values.2="/content/:/"
+     *               values.3="/system/docroot/:/"
      */
     private static final String PROP_MAPPING = "resource.resolver.mapping";
 

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/Mapping.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/Mapping.java?rev=941335&r1=941334&r2=941335&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/Mapping.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/Mapping.java
Wed May  5 15:10:52 2010
@@ -18,7 +18,8 @@
  */
 package org.apache.sling.jcr.resource.internal.helper;
 
-import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * The <code>Mapping</code> class conveys the mapping configuration used by
@@ -63,6 +64,13 @@ public class Mapping {
         }
     };
 
+    // Regular expression to split mapping configuration strings into three
+    // groups:
+    //   1 - external path prefix
+    //   2 - direction (Outbound (>), Bidirectional (:), Inbound (>))
+    //   3 - internap path prefix
+    private static final Pattern CONFIG_SPLITTER = Pattern.compile("(.+)([:<>])(.+)");
+
     /** the 'from' (inside, repository) mapping */
     private final String from;
 
@@ -78,36 +86,6 @@ public class Mapping {
     /** the mapping direction */
     private final int direction;
 
-    /**
-     * Creates a new instance of a mapping.
-     *
-     * @param from Handle prefix possible valid in the ContentBus.
-     * @param to URI path prefix to be replaced by from to get a possibly valid
-     *            handle.
-     * @param dir the direction of the mapping. either "inwards", "outwards" or
-     *            "both".
-     * @throws NullPointerException if either <code>from</code> or
-     *             <code>to</code> is <code>null</code>.
-     */
-    public Mapping(String from, String to, String dir) {
-        this(from, to, "in".equals(dir) ? Mapping.INBOUND : ("out".equals(dir)
-                ? Mapping.OUTBOUND
-                : Mapping.BOTH));
-    }
-
-    /**
-     * Creates a new instance of a mapping.
-     *
-     * @param from Handle prefix possible valid in the ContentBus.
-     * @param to URI path prefix to be replaced by from to get a possibly valid
-     *            handle.
-     * @throws NullPointerException if either <code>from</code> or
-     *             <code>to</code> is <code>null</code>.
-     */
-    public Mapping(String from, String to) {
-        this(from, to, Mapping.BOTH);
-    }
-
     public Mapping(String config) {
         this(split(config));
     }
@@ -122,10 +100,10 @@ public class Mapping {
                 ? Mapping.INBOUND
                 : ("<".equals(parts[1]) ? Mapping.OUTBOUND : Mapping.BOTH);
     }
-    
+
     @Override
     public String toString() {
-        return "Mapping (from=" + from + ", to=" + to + ", direction=" + direction 
+        return "Mapping (from=" + from + ", to=" + to + ", direction=" + direction
             + ", lengths=" + fromLength + "/" + toLength;
     }
 
@@ -169,12 +147,12 @@ public class Mapping {
     public String getFrom() {
         return from;
     }
-    
+
     // TODO: temporary
     public String getTo() {
         return to;
     }
-    
+
     /**
      * Checks, if this mapping is defined for inbound mapping.
      *
@@ -207,14 +185,23 @@ public class Mapping {
     }
 
     public static String[] split(String map) {
-        String[] res = new String[3]; // src, op, dst
-        StringTokenizer st = new StringTokenizer(map, "-<>", true);
 
-        for (int i = 0; i < res.length; i++) {
-            res[i] = st.hasMoreTokens() ? st.nextToken() : "";
+        // standard case of mapping <path>[<:>]<path>
+        Matcher mapMatch = CONFIG_SPLITTER.matcher(map);
+        if (mapMatch.matches()) {
+            return new String[] { mapMatch.group(1), mapMatch.group(2),
+                mapMatch.group(3) };
+        }
+
+        // backwards compatibility using "-" instead of ":"
+        int dash = map.indexOf('-');
+        if (dash > 0) {
+            return new String[] { map.substring(0, dash),
+                map.substring(dash, dash + 1),
+                map.substring(dash + 1, map.length()) };
         }
 
-        return res;
+        return new String[] { map, "-", map };
     }
 
 }

Modified: sling/trunk/bundles/jcr/resource/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=941335&r1=941334&r2=941335&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/resources/OSGI-INF/metatype/metatype.properties
Wed May  5 15:10:52 2010
@@ -40,7 +40,7 @@ resource.resolver.allowDirect.descriptio
 
 resource.resolver.virtual.name = Virtual URLs
 resource.resolver.virtual.description = List of virtual URLs and there \
- mappings to real URLs. Format is <externalURL>-<internalURL>. Mappings are \
+ mappings to real URLs. Format is <externalURL>:<internalURL>. Mappings are \
  applied on the complete request URL only.
 
 resource.resolver.mapping.name = URL Mappings
@@ -48,9 +48,10 @@ resource.resolver.mapping.description = 
  Incoming mappings are applied to request URLs to map to Content paths, \
  outgoing mappings are applied to map Content paths to URLs used on subsequent \
  requests. Form ist <externalURLPrefix><op><internalURLPrefix> where <op>
is \
- ">" for incoming mappings, "<" for outgoing mappings and "-" for mappings \
+ ">" for incoming mappings, "<" for outgoing mappings and ":" for mappings \
  applied in both directions. Mappings are applied in configuration order by \
- comparing and replacing URL prefixes.
+ comparing and replacing URL prefixes. Note: The use of "-" as the <op> value \
+ indicating a mapping in both directions is deprecated.
 
 resource.resolver.searchpath.name = Resource Search Path
 resource.resolver.searchpath.description = The list of absolute path prefixes \



Mime
View raw message