incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r781285 - in /incubator/sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
Date Wed, 03 Jun 2009 07:26:51 GMT
Author: fmeschbe
Date: Wed Jun  3 07:26:51 2009
New Revision: 781285

URL: http://svn.apache.org/viewvc?rev=781285&view=rev
Log:
SLING-991 remove fragment/query before mapping and reappend at
the end of mapping

Modified:
    incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
    incubator/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java

Modified: incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java?rev=781285&r1=781284&r2=781285&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
(original)
+++ incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
Wed Jun  3 07:26:51 2009
@@ -254,9 +254,25 @@
     //   - return absolute uri if possible
     public String map(final HttpServletRequest request, final String resourcePath) {
 
-        String mappedPath = resourcePath;
-        boolean mappedPathIsUrl = false;
-        String resolutionPathInfo;
+        // find a fragment or query
+        int fragmentQueryMark = resourcePath.indexOf('#');
+        if (fragmentQueryMark < 0) {
+            fragmentQueryMark = resourcePath.indexOf('?');
+        }
+        
+        // cut fragment or query off the resource path
+        String mappedPath;
+        final String fragmentQuery;
+        if (fragmentQueryMark >= 0) {
+            fragmentQuery = resourcePath.substring(fragmentQueryMark);
+            mappedPath = resourcePath.substring(0, fragmentQueryMark);
+            log.debug("map: Splitting resource path '{}' into '{}' and '{}'",
+                new Object[] { resourcePath, mappedPath, fragmentQuery });
+        } else {
+            fragmentQuery = null;
+            mappedPath = resourcePath;
+        }
+        
 
         // cut off scheme and host, if the same as requested
         String schemehostport;
@@ -274,6 +290,7 @@
 
         }
 
+        String resolutionPathInfo;
         Resource res = resolveInternal(mappedPath);
         if (res != null) {
 
@@ -313,6 +330,7 @@
 
         }
 
+        boolean mappedPathIsUrl = false;
         for (MapEntry mapEntry : resourceMapper.getMapMaps()) {
             String[] mappedPaths = mapEntry.replace(mappedPath);
             if (mappedPaths != null) {
@@ -393,11 +411,16 @@
             }
 
             log.debug(
-                "map: Returning path {} (after mangling, inlc. context) for {}",
+                "map: Returning path {} (after mangling, incl. context) for {}",
                 mappedPath, resourcePath);
 
         }
 
+        // reappend fragment and/or query
+        if (fragmentQuery != null) {
+            mappedPath = mappedPath.concat(fragmentQuery);
+        }
+
         return mappedPath;
     }
 
@@ -735,23 +758,20 @@
 
     private String mangleNamespaces(String absPath) {
         if (factory.isMangleNamespacePrefixes() && absPath.contains(MANGLE_NAMESPACE_OUT_SUFFIX))
{
-            final int queryPos = absPath.indexOf('?');
-            final String path = (queryPos == -1 ? absPath : absPath.substring(0, queryPos));
-
             Pattern p = Pattern.compile(MANGLE_NAMESPACE_OUT);
-            Matcher m = p.matcher(path);
+            Matcher m = p.matcher(absPath);
+            
             StringBuffer buf = new StringBuffer();
             while (m.find()) {
                 String replacement = MANGLE_NAMESPACE_IN_PREFIX + m.group(1) + MANGLE_NAMESPACE_IN_SUFFIX;
                 m.appendReplacement(buf, replacement);
             }
+            
             m.appendTail(buf);
-            if ( queryPos != -1 ) {
-                buf.append(absPath.substring(queryPos));
-            }
+            
             absPath = buf.toString();
         }
-
+        
         return absPath;
     }
 

Modified: incubator/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java?rev=781285&r1=781284&r2=781285&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
(original)
+++ incubator/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
Wed Jun  3 07:26:51 2009
@@ -1041,6 +1041,74 @@
         String path = rootNode.getPath();
         String mapped = resResolver.map(path);
         assertEquals(path, mapped);
+        
+        Node child = rootNode.addNode("child");
+        session.save();
+        
+        // absolute path, expect rootPath segment to be
+        // cut off the mapped path because we map the rootPath
+        // onto root
+        final String selExt = ".html/some/suffx.pdf";
+        path = "/child" + selExt;
+        mapped = resResolver.map(child.getPath() + selExt);
+        assertEquals(path, mapped);
+    }
+    
+    public void testMapFragment() throws Exception {
+        String path = rootNode.getPath();
+        String mapped = resResolver.map(path);
+        assertEquals(path, mapped);
+        
+        Node child = rootNode.addNode("child");
+        session.save();
+        
+        // absolute path, expect rootPath segment to be
+        // cut off the mapped path because we map the rootPath
+        // onto root
+        final String selExt = "#sec:1";
+        path = "/child" + selExt;
+        mapped = resResolver.map(child.getPath() + selExt);
+        assertEquals(path, mapped);
+    }
+    
+    public void testMapQuery() throws Exception {
+        String path = rootNode.getPath();
+        String mapped = resResolver.map(path);
+        assertEquals(path, mapped);
+        
+        Node child = rootNode.addNode("child");
+        session.save();
+        
+        // absolute path, expect rootPath segment to be
+        // cut off the mapped path because we map the rootPath
+        // onto root
+        final String selExt = "?a:b=2";
+        path = "/child" + selExt;
+        mapped = resResolver.map(child.getPath() + selExt);
+        assertEquals(path, mapped);
+    }
+    
+    public void testMapFragmentQuery() throws Exception {
+        String path = rootNode.getPath();
+        String mapped = resResolver.map(path);
+        assertEquals(path, mapped);
+        
+        Node child = rootNode.addNode("child");
+        session.save();
+        
+        // absolute path, expect rootPath segment to be
+        // cut off the mapped path because we map the rootPath
+        // onto root
+        final String selExt = "#sec:1?a:b=1";
+        path = "/child" + selExt;
+        mapped = resResolver.map(child.getPath() + selExt);
+        assertEquals(path, mapped);
+    }
+    
+    public void testMapExtensionFragmentQuery() throws Exception {
+        String path = rootNode.getPath();
+        String mapped = resResolver.map(path);
+        assertEquals(path, mapped);
 
         Node child = rootNode.addNode("child");
         session.save();
@@ -1048,7 +1116,7 @@
         // absolute path, expect rootPath segment to be
         // cut off the mapped path because we map the rootPath
         // onto root
-        final String selExt = ".html/some/suffx.pdf";
+        final String selExt = ".html#sec:1?a:b=1";
         path = "/child" + selExt;
         mapped = resResolver.map(child.getPath() + selExt);
         assertEquals(path, mapped);



Mime
View raw message