Author: fmeschbe
Date: Tue May 5 11:05:07 2009
New Revision: 771666
URL: http://svn.apache.org/viewvc?rev=771666&view=rev
Log:
SLING-955 properly support multi-value sling:vanityPath properties
Modified:
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
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=771666&r1=771665&r2=771666&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
Tue May 5 11:05:07 2009
@@ -43,6 +43,7 @@
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.resource.internal.JcrResourceResolver2;
import org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl;
@@ -287,32 +288,34 @@
// sling:VanityPath (uppercase V) is the mixin name
// sling:vanityPath (lowercase) is the property name
final String queryString = "SELECT sling:vanityPath, sling:redirect
FROM sling:VanityPath WHERE sling:vanityPath IS NOT NULL ORDER BY
sling:vanityOrder DESC";
- final Iterator<Map<String, Object>> i = resolver.queryResources(
+ final Iterator<Resource> i = resolver.findResources(
queryString, Query.SQL);
while (i.hasNext()) {
- Map<String, Object> row = i.next();
+ Resource resource = i.next();
+ ValueMap row = resource.adaptTo(ValueMap.class);
+ if (row == null) {
+ continue;
+ }
// url is ignoring scheme and host.port and the path is
// what is stored in the sling:vanityPath property
- Object pVanityPath = row.get("sling:vanityPath");
- if (pVanityPath != null) {
+ String[] pVanityPaths = row.get("sling:vanityPath", new String[0]);
+ for (String pVanityPath : pVanityPaths) {
String url = "^" + ANY_SCHEME_HOST
+ String.valueOf(pVanityPath);
// redirect target is the node providing the sling:vanityPath
// property (or its parent if the node is called jcr:content)
- String redirect = String.valueOf(row.get("jcr:path"));
+ String redirect = resource.getPath();
if (ResourceUtil.getName(redirect).equals("jcr:content")) {
redirect = ResourceUtil.getParent(redirect);
}
// whether the target is attained by a 302/FOUND or by an
// internal redirect is defined by the sling:redirect property
- int status = -1;
- if (row.containsKey("sling:redirect")
- &&
Boolean.valueOf(String.valueOf(row.get("sling:redirect")))) {
- status = HttpServletResponse.SC_FOUND;
- }
+ int status = row.get("sling:redirect", false)
+ ? HttpServletResponse.SC_FOUND
+ : -1;
// 1. entry with exact match
entries.add(new MapEntry(url + "$", redirect + ".html", status,