Merged BRANCHES/DEV/CLOUD1_SP to HEAD:

38996: WebDAV: added getUrlPathPrefix tests for WebDAVHelper.
   38997: WebDAV: added setter for urlPathPrefix property (to aid in spring config), ensures path prefix terminated in slash.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@39106 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2012-07-11 17:17:57 +00:00
parent 91f9df2b23
commit 771502842d
2 changed files with 48 additions and 10 deletions

View File

@@ -53,6 +53,8 @@ import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.EqualsHelper;
import org.alfresco.util.Pair;
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.URLDecoder;
@@ -853,22 +855,36 @@ public class WebDAVHelper
}
public void setUrlPathPrefix(String urlPathPrefix)
{
m_urlPathPrefix = urlPathPrefix;
}
public String getUrlPathPrefix(HttpServletRequest request)
{
StringBuilder urlStr = null;
if (StringUtils.hasText(m_urlPathPrefix))
{
return m_urlPathPrefix;
// A specific prefix has been configured in, so use it.
urlStr = new StringBuilder(m_urlPathPrefix);
}
StringBuilder urlStr = new StringBuilder(request.getRequestURI());
String servletPath = request.getServletPath();
int rootPos = urlStr.indexOf(servletPath);
if (rootPos != -1)
else
{
urlStr.setLength(rootPos + servletPath.length());
// Extract the path prefix from the request, using the servlet path as a guide.
// e.g. "/preamble/servlet-mapping/folder/file.txt"
// with a servlet path of "/servlet-mapping"
// would result in a path prefix of "/preamble/servlet-mapping" being discovered.
urlStr = new StringBuilder(request.getRequestURI());
String servletPath = request.getServletPath();
int rootPos = urlStr.indexOf(servletPath);
if (rootPos != -1)
{
urlStr.setLength(rootPos + servletPath.length());
}
}
// Ensure the prefix ends in the path separator.
if (urlStr.charAt(urlStr.length() - 1) != PathSeperatorChar)
{
urlStr.append(PathSeperator);