Author: fmeschbe
Date: Tue Nov 30 13:28:31 2010
New Revision: 1040513
URL: http://svn.apache.org/viewvc?rev=1040513&view=rev
Log:
Cannot use the path info because the getResource method is used to resolve
other paths while handling requests, for example the target path of a move
operation. This target also includes the servlet context and servlet paths as
prefixes but of course using the request path info here is wrong. Hence use a
prefix created on first request from the context path and servlet path
information present in the request
Modified:
sling/whiteboard/fmeschbe/milton/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResourceFactory.java
Modified:
sling/whiteboard/fmeschbe/milton/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResourceFactory.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/milton/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResourceFactory.java?rev=1040513&r1=1040512&r2=1040513&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/milton/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResourceFactory.java
(original)
+++
sling/whiteboard/fmeschbe/milton/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResourceFactory.java
Tue Nov 30 13:28:31 2010
@@ -22,6 +22,7 @@ import java.io.File;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.servlet.http.HttpServletRequest;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.auth.core.AuthenticationSupport;
@@ -35,19 +36,22 @@ public class SlingResourceFactory implem
public static final String NAME =
"org.apache.sling.whiteboard.fmeschbe.miltondav.impl.resources.SlingResourceFactory";
+ private String prefix;
+
public SlingResourceFactory() {
}
- public Resource getResource(final String host, String pathIgnored) {
+ public Resource getResource(final String host, String path) {
+
+ // cut off prefix
+ final String prefixPath = getPrefix();
+ if (path.startsWith(prefixPath)) {
+ path = path.substring(prefixPath.length());
+ }
- // use the request path info as the actual resource path
- // the pathIgnored is prefixed with the servlet context path and
- // the servlet path, which we cannot use here
- String path = MiltonDavServlet.request().getPathInfo();
- if (path == null || path.length() == 0) {
+ // ensure non-empty path
+ if (path.length() == 0) {
path = "/";
- } else if (path.length() > 1 && path.endsWith("/")) {
- path = path.substring(0, path.length() - 1);
}
org.apache.sling.api.resource.Resource slingResource =
getResourceResolver().getResource(
@@ -93,4 +97,29 @@ public class SlingResourceFactory implem
return new ReadOnlyFolderResource(slingResource);
}
+
+ private String getPrefix() {
+ if (prefix == null) {
+ StringBuilder b = new StringBuilder();
+ HttpServletRequest request = MiltonDavServlet.request();
+
+ // start with context path if not null (may be empty)
+ if (request.getContextPath() != null) {
+ b.append(request.getContextPath());
+ }
+
+ // append servlet path if not null (may be empty)
+ if (request.getServletPath() != null) {
+ b.append(request.getServletPath());
+ }
+
+ // cut off trailing slash
+ if (b.length() > 1 && b.charAt(b.length() -1) == '/') {
+ b.setLength(b.length()-1);
+ }
+
+ prefix = b.toString();
+ }
+ return prefix;
+ }
}