You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2014/04/25 16:08:27 UTC
svn commit: r1590034 -
/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
Author: cziegeler
Date: Fri Apr 25 14:08:26 2014
New Revision: 1590034
URL: http://svn.apache.org/r1590034
Log:
Internal refactoring to make it easier to override the public api - no functional changes!
Modified:
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1590034&r1=1590033&r2=1590034&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java (original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java Fri Apr 25 14:08:26 2014
@@ -195,9 +195,11 @@ public class ResourceResolverImpl extend
/**
* @see org.apache.sling.api.resource.ResourceResolver#resolve(java.lang.String)
*/
- public Resource resolve(final String absPath) {
+ public Resource resolve(final String path) {
checkClosed();
- return resolve(null, absPath);
+
+ final Resource rsrc = this.resolveInternal(null, path);
+ return rsrc;
}
/**
@@ -206,17 +208,24 @@ public class ResourceResolverImpl extend
@SuppressWarnings("javadoc")
public Resource resolve(final HttpServletRequest request) {
checkClosed();
+
// throws NPE if request is null as required
- return resolve(request, request.getPathInfo());
+ final Resource rsrc = this.resolveInternal(request, request.getPathInfo());
+ return rsrc;
}
/**
* @see org.apache.sling.api.resource.ResourceResolver#resolve(javax.servlet.http.HttpServletRequest,
* java.lang.String)
*/
- public Resource resolve(final HttpServletRequest request, String absPath) {
+ public Resource resolve(final HttpServletRequest request, String path) {
checkClosed();
+ final Resource rsrc = this.resolveInternal(request, path);
+ return rsrc;
+ }
+
+ private Resource resolveInternal(final HttpServletRequest request, String absPath) {
// make sure abspath is not null and is absolute
if (absPath == null) {
absPath = "/";
@@ -560,13 +569,34 @@ public class ResourceResolverImpl extend
*/
public Resource getResource(String path) {
checkClosed();
+ final Resource result = this.getResourceInternal(path);
+ return result;
+ }
+
+ /**
+ * @see org.apache.sling.api.resource.ResourceResolver#getResource(org.apache.sling.api.resource.Resource,
+ * java.lang.String)
+ */
+ public Resource getResource(final Resource base, final String path) {
+ checkClosed();
+
+ String absolutePath = path;
+ if (absolutePath != null && !absolutePath.startsWith("/") && base != null) {
+ absolutePath = base.getPath() + "/" + absolutePath;
+ }
+
+ final Resource result = getResourceInternal(absolutePath);
+ return result;
+ }
+
+ private Resource getResourceInternal(String path) {
Resource result = null;
if ( path != null ) {
// if the path is absolute, normalize . and .. segments and get res
if (path.startsWith("/")) {
path = ResourceUtil.normalize(path);
- result = (path != null) ? getResourceInternal(path, false) : null;
+ result = (path != null) ? getAbsoluteResourceInternal(path, false) : null;
if (result != null) {
result = this.factory.getResourceDecoratorTracker().decorate(result);
}
@@ -590,20 +620,6 @@ public class ResourceResolverImpl extend
}
/**
- * @see org.apache.sling.api.resource.ResourceResolver#getResource(org.apache.sling.api.resource.Resource,
- * java.lang.String)
- */
- public Resource getResource(final Resource base, String path) {
- checkClosed();
-
- if (path != null && !path.startsWith("/") && base != null) {
- path = base.getPath() + "/" + path;
- }
-
- return getResource(path);
- }
-
- /**
* @see org.apache.sling.api.resource.ResourceResolver#listChildren(org.apache.sling.api.resource.Resource)
*/
public Iterator<Resource> listChildren(final Resource parent) {
@@ -788,7 +804,7 @@ public class ResourceResolverImpl extend
final ResourcePathIterator it = new ResourcePathIterator(absPath);
while (it.hasNext() && resource == null) {
curPath = it.next();
- resource = getResourceInternal(curPath, true);
+ resource = getAbsoluteResourceInternal(curPath, true);
}
} catch (final Exception ex) {
throw new SlingException("Problem trying " + curPath + " for request path " + absPath, ex);
@@ -808,7 +824,7 @@ public class ResourceResolverImpl extend
// no direct resource found, so we have to drill down into the
// resource tree to find a match
- resource = getResourceInternal("/", true);
+ resource = getAbsoluteResourceInternal("/", true);
final StringBuilder resolutionPath = new StringBuilder();
final StringTokenizer tokener = new StringTokenizer(absPath, "/");
while (resource != null && tokener.hasMoreTokens()) {
@@ -867,7 +883,7 @@ public class ResourceResolverImpl extend
} else {
path = parent.getPath() + '/' + childName;
}
- Resource child = getResourceInternal( ResourceUtil.normalize(path), true );
+ Resource child = getAbsoluteResourceInternal( ResourceUtil.normalize(path), true );
if (child != null) {
final String alias = ResourceResolverContext.getProperty(child, PROP_REDIRECT_INTERNAL);
if (alias != null) {
@@ -895,7 +911,7 @@ public class ResourceResolverImpl extend
} else {
aliasPath = parent.getPath() + '/' + aliasName;
}
- final Resource aliasedChild = getResourceInternal( ResourceUtil.normalize(aliasPath), true );
+ final Resource aliasedChild = getAbsoluteResourceInternal( ResourceUtil.normalize(aliasPath), true );
logger.debug("getChildInternal: Found Resource {} with alias {} to use", aliasedChild, childName);
return aliasedChild;
}
@@ -911,7 +927,7 @@ public class ResourceResolverImpl extend
for (final String alias : aliases) {
if (childName.equals(alias)) {
logger.debug("getChildInternal: Found Resource {} with alias {} to use", child, childName);
- final Resource aliasedChild = getResourceInternal( ResourceUtil.normalize(child.getPath()) , true);
+ final Resource aliasedChild = getAbsoluteResourceInternal( ResourceUtil.normalize(child.getPath()) , true);
return aliasedChild;
}
}
@@ -928,7 +944,7 @@ public class ResourceResolverImpl extend
/**
* Creates a resource with the given path if existing
*/
- private Resource getResourceInternal(final String path, final boolean isResolve) {
+ private Resource getAbsoluteResourceInternal(final String path, final boolean isResolve) {
final Resource resource = this.factory.getRootProviderEntry().getResource(this.context, this, path ,isResolve);
if (resource != null) {