Author: fmeschbe
Date: Sun Dec 14 14:09:02 2008
New Revision: 726555
URL: http://svn.apache.org/viewvc?rev=726555&view=rev
Log:
SLING-373 support selectors and extension (and suffix by the way)
for the map method
Modified:
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
Modified:
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java?rev=726555&r1=726554&r2=726555&view=diff
==============================================================================
---
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
(original)
+++
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
Sun Dec 14 14:09:02 2008
@@ -132,21 +132,26 @@
return resolveInternal(null, absPath, false);
}
- // trivial implementation not taking into account any mappings in
- // the content
+ // calls map(HttpServletRequest, String) as map(null, resourcePath)
public String map(String resourcePath) {
return map(null, resourcePath);
}
- // trivial implementation not taking into account any mappings in
- // the content and in /etc/map
+ // full implementation
+ // - apply sling:alias from the resource path
+ // - apply /etc/map mappings (inkl. config backwards compat)
+ // - return absolute uri if possible
public String map(HttpServletRequest request, String resourcePath) {
String mappedPath = resourcePath;
boolean mappedPathIsUrl = false;
+ String resolutionPathInfo;
- Resource res = getResourceInternal(mappedPath);
+ Resource res = resolveInternal(mappedPath);
if (res != null) {
+
+ // keep, what we might have cut off in internal resolution
+ resolutionPathInfo =
res.getResourceMetadata().getResolutionPathInfo();
// find aliases for segments
LinkedList<String> names = new LinkedList<String>();
@@ -168,6 +173,12 @@
buf.append(names.removeLast());
}
mappedPath = buf.toString();
+
+ } else {
+
+ // we have no resource, hence no resolution path info
+ resolutionPathInfo = null;
+
}
for (MapEntry mapEntry : resourceMapper.getMapMaps()) {
@@ -188,6 +199,11 @@
mappedPath = resourcePath;
}
+ // append resolution path info, which might have been cut off above
+ if (resolutionPathInfo != null) {
+ mappedPath = mappedPath.concat(resolutionPathInfo);
+ }
+
if (mappedPathIsUrl) {
// TODO: probably need to mangle name spaces
return mappedPath;
Modified:
incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java?rev=726555&r1=726554&r2=726555&view=diff
==============================================================================
---
incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
(original)
+++
incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
Sun Dec 14 14:09:02 2008
@@ -699,10 +699,10 @@
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
@@ -710,18 +710,56 @@
mapped = resResolver.map(child.getPath());
assertEquals(path, mapped);
}
+
+ public void testMapExtension() throws Exception {
+ String path = rootNode.getPath();
+ String mapped = resResolver.map(path);
+ assertEquals(path, mapped);
- public void testAlias() throws Exception {
+ 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 = ".sel1.sel2.html";
+ path = "/child" + selExt;
+ mapped = resResolver.map(child.getPath() + selExt);
+ assertEquals(path, mapped);
+ }
+
+ public void testAlias() throws Exception {
+
Node child = rootNode.addNode("child");
child.setProperty(JcrResourceResolver2.PROP_ALIAS, "kind");
session.save();
-
+
// expect kind due to alias and no parent due to mapping
// the rootPath onto root
String path = "/kind";
String mapped = resResolver.map(child.getPath());
assertEquals(path, mapped);
+
+ Resource res = resResolver.resolve(null, path);
+ Node resNode = res.adaptTo(Node.class);
+ assertNotNull(resNode);
+
+ assertEquals(child.getPath(), resNode.getPath());
+ }
+
+ public void testAliasExtension() throws Exception {
+
+ final String selExt = ".sel1.sel2.html";
+
+ Node child = rootNode.addNode("child");
+ child.setProperty(JcrResourceResolver2.PROP_ALIAS, "kind");
+ session.save();
+
+ // expect kind due to alias and no parent due to mapping
+ // the rootPath onto root
+ String path = "/kind" + selExt;
+ String mapped = resResolver.map(child.getPath() + selExt);
+ assertEquals(path, mapped);
Resource res = resResolver.resolve(null, path);
Node resNode = res.adaptTo(Node.class);