Author: vgritsenko Date: Wed Jun 27 21:26:07 2007 New Revision: 551440 URL: http://svn.apache.org/viewvc?view=rev&rev=551440 Log: modify dav request to support default servlet (servlet mapped to '/', with null pathInfo)
Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/DAVRequest.java xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Propfind.java Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/DAVRequest.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/DAVRequest.java?view=diff&rev=551440&r1=551439&r2=551440 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/DAVRequest.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/DAVRequest.java Wed Jun 27 21:26:07 2007 @@ -17,22 +17,24 @@ package org.apache.xindice.webadmin.webdav; -import org.w3c.dom.Document; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + +import org.w3c.dom.Document; import org.xml.sax.InputSource; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.ServletInputStream; + import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; /** - * This is a wrapper class that provides additional DAV-specific functionality - * + * This is a wrapper class that provides additional DAV-specific functionality. + * * @version $Revision$, $Date$ */ public class DAVRequest { @@ -40,13 +42,13 @@ public static final int DEPTH_1 = 1; public static final int DEPTH_INFINITY = -1; - protected Document requestDoc; - private boolean documentInit = false; - protected String location; - private HttpServletRequest httpRequest; - private static final Log log = LogFactory.getLog(DAVRequest.class); + private HttpServletRequest httpRequest; + private String contextPath; + private Document requestDoc; + private boolean documentInit; + /** * Creates new instance of DAVRequest based on incoming HTTP request. * @@ -54,7 +56,24 @@ */ public DAVRequest(HttpServletRequest request) { httpRequest = request; - location = getLocationPath(); + contextPath = makeContextPath(); + } + + /** + * @return the path to calling servlet (not null and no ending '/') + */ + private String makeContextPath() { + StringBuffer path = new StringBuffer(); + path.append(httpRequest.getContextPath()); + // Is it default servlet? If not, servletPath is added to contextPath path. + if (httpRequest.getPathInfo() != null) { + path.append(httpRequest.getServletPath()); + } + if (path.length() > 0 && path.charAt(path.length() - 1) == '/') { + path.deleteCharAt(path.length() - 1); + } + + return path.toString(); } /** @@ -74,11 +93,23 @@ } /** - * Wrapper method, gets servlet path info. + * Wrapper method, gets resource path. + * + * If servlet is mapped as default servlet (with url pattern '/'), + * resource path is obtained from [EMAIL PROTECTED] HttpServletRequest#getServletPath}, + * and [EMAIL PROTECTED] HttpServletRequest#getPathInfo} is always null. + * + * If servlet is mapped to a path pattern (url pattern like '/foo/*'), + * resource path is retrieved from [EMAIL PROTECTED] HttpServletRequest#getPathInfo}. + * * @return Called servlet path. */ public String getPath() { - return httpRequest.getPathInfo(); + String path = httpRequest.getPathInfo(); + if (path == null) { + path = httpRequest.getServletPath(); + } + return path; } /** @@ -134,7 +165,6 @@ * @return Local part of the destination path */ public String getDestinationPath() { - String destinationPath = httpRequest.getHeader("Destination"); if (destinationPath == null) { return null; @@ -200,7 +230,7 @@ * @return Called servlet context path. */ public String getContextPath() { - return location; + return contextPath; } private Document parseRequestContent() throws IOException { @@ -220,20 +250,6 @@ } return null; - } - - /** - * @return the path to calling servlet (not null and no ending '/') - */ - private String getLocationPath() { - StringBuffer path = new StringBuffer(); - path.append(httpRequest.getContextPath()); - path.append(httpRequest.getServletPath()); - if (path.length() > 0 && path.charAt(path.length() - 1) == '/') { - path.deleteCharAt(path.length() - 1); - } - - return path.toString(); } /** Modified: xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Propfind.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Propfind.java?view=diff&rev=551440&r1=551439&r2=551440 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Propfind.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Propfind.java Wed Jun 27 21:26:07 2007 @@ -341,20 +341,18 @@ ArrayList props = (ArrayList) statusList.get(status); if (props != null && props.size() > 0) { - PartialResponse.Content propstat = new PartialResponse.Content("propstat"); - PartialResponse.Content prop = new PartialResponse.Content("prop"); - for (Iterator j = props.iterator(); j.hasNext(); ) { - PartialResponse.Content node = (PartialResponse.Content) j.next(); - prop.addChild(node); + prop.addChild((PartialResponse.Content) j.next()); } + PartialResponse.Content stat = new PartialResponse.Content("status"); + stat.setValue(res.getProtocol() + " " + status + " " + WebdavStatus.getStatusText(status.intValue())); + + PartialResponse.Content propstat = new PartialResponse.Content("propstat"); propstat.addChild(prop); + propstat.addChild(stat); - PartialResponse.Content st = new PartialResponse.Content("status"); - st.setValue(res.getProtocol() + " " + status + " " + WebdavStatus.getStatusText(status.intValue())); - propstat.addChild(st); response.addContent(propstat); } }