cmlenz      02/04/03 08:40:56

  Modified:    src/webdav/server/org/apache/slide/webdav Tag: SLIDE_1_0
                        WebdavServlet.java WebdavUtils.java
               src/webdav/server/org/apache/slide/webdav/method Tag:
                        SLIDE_1_0 PropFindMethod.java
  Log:
  This patch should fix the problems reported about 'scope' support:
  - PROPFIND method altered to generate the correct href elements. I'm not
    sure why Juergen had some of this code commented out, but it now works
    for me.
  - Added WebdavUtils.getAbsolutePath() to map a node URI to the externally
    visible URL, relative to the web-app context path.
  - Changed directory-index-generation code to use the new WebdavUtils method
    getAbsolutePath() for rendering text and links
  I think this stuff could be safely ported to HEAD, but I'm not 100% certain
  that I didn't break anything, especially concerning the character encoding
  problems.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.29.2.3  +27 -24    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/WebdavServlet.java
  
  Index: WebdavServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/WebdavServlet.java,v
  retrieving revision 1.29.2.2
  retrieving revision 1.29.2.3
  diff -u -r1.29.2.2 -r1.29.2.3
  --- WebdavServlet.java        28 Mar 2002 06:41:43 -0000      1.29.2.2
  +++ WebdavServlet.java        3 Apr 2002 16:40:55 -0000       1.29.2.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/WebdavServlet.java,v 
1.29.2.2 2002/03/28 06:41:43 jericho Exp $
  - * $Revision: 1.29.2.2 $
  - * $Date: 2002/03/28 06:41:43 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/WebdavServlet.java,v 
1.29.2.3 2002/04/03 16:40:55 cmlenz Exp $
  + * $Revision: 1.29.2.3 $
  + * $Date: 2002/04/03 16:40:55 $
    *
    * ====================================================================
    *
  @@ -109,7 +109,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
    * @author Dirk Verbeeck
  - * @version $Revision: 1.29.2.2 $
  + * @version $Revision: 1.29.2.3 $
    */
   public class WebdavServlet extends HttpServlet {
       
  @@ -496,6 +496,7 @@
                                               Writer servletWriter)
           throws IOException, SlideException {
           
  +        WebdavServletConfig config = (WebdavServletConfig)getServletConfig();
           String contextPath = req.getContextPath();
           if (contextPath == null)
               contextPath = "";
  @@ -507,17 +508,15 @@
           Structure structure = token.getStructureHelper();
   
           SlideToken slideToken = WebdavUtils.getSlideToken(req);
  -        String resourcePath =
  -            WebdavUtils.getRelativePath(
  -                req, (WebdavServletConfig)getServletConfig());
  +        String resourcePath = WebdavUtils.getRelativePath(req, config);
           ObjectNode object = structure.retrieve(slideToken, resourcePath);
  -        String name = object.getUri();
  +        String path = WebdavUtils.getAbsolutePath(object.getUri(), config);
           
           // Number of characters to trim from the beginnings of filenames
  -        int trim = name.length();
  -        if (!name.endsWith("/"))
  +        int trim = path.length();
  +        if (!path.endsWith("/"))
               trim += 1;
  -        if (name.equals("/"))
  +        if (path.equals("/"))
               trim = 1;
           
           PrintWriter writer = new PrintWriter(servletWriter);
  @@ -528,7 +527,7 @@
           writer.print("<title>");
           writer.print
               (Messages.format
  -                 ("org.apache.slide.webdav.GetMethod.directorylistingfor", name));
  +                 ("org.apache.slide.webdav.GetMethod.directorylistingfor", path));
           writer.print("</title>\r\n</head>\r\n");
           writer.print("<body bgcolor=\"white\">\r\n");
           writer.print("<table width=\"90%\" cellspacing=\"0\"" +
  @@ -538,19 +537,18 @@
           writer.print("<tr><td colspan=\"3\"><font size=\"+2\">\r\n<strong>");
           writer.print
               (Messages.format
  -                 ("org.apache.slide.webdav.GetMethod.directorylistingfor", name));
  +                 ("org.apache.slide.webdav.GetMethod.directorylistingfor", path));
           writer.print("</strong>\r\n</font></td></tr>\r\n");
           
           // Render the link to our parent (if required)
  -        String parentDirectory = name;
  +        String parentDirectory = path;
           if (parentDirectory.endsWith("/")) {
               parentDirectory =
                   parentDirectory.substring(0, parentDirectory.length() - 1);
           }
  -        String scope = ((WebdavServletConfig)getServletConfig()).getScope();
  -        if (parentDirectory.substring(scope.length()).lastIndexOf("/") >= 0) {
  -            String parent = name.substring(0, name.lastIndexOf("/"));
  -            writer.print("<tr><td colspan=\"5\" bgcolor=\"#ffffff\">\r\n");
  +        writer.print("<tr><td colspan=\"5\" bgcolor=\"#ffffff\">\r\n");
  +        if (parentDirectory.lastIndexOf("/") >= 0) {
  +            String parent = path.substring(0, path.lastIndexOf("/"));
               writer.print("<a href=\"");
               writer.print(WebdavUtils.encodeURL(contextPath));
               if (parent.equals(""))
  @@ -560,8 +558,10 @@
               writer.print(Messages.format
                                ("org.apache.slide.webdav.GetMethod.parent", parent));
               writer.print("</a>\r\n");
  -            writer.print("</td></tr>\r\n");
  +        } else {
  +            writer.print("&nbsp;");
           }
  +        writer.print("</td></tr>\r\n");
           
           Enumeration permissionsList = null;
           Enumeration locksList = null;
  @@ -653,9 +653,11 @@
                   
               }
               
  -            String trimmed = currentResource.substring(trim);
  -            if (trimmed.equalsIgnoreCase("WEB-INF") ||
  -                trimmed.equalsIgnoreCase("META-INF"))
  +            String currentResourceUrl =
  +                WebdavUtils.getAbsolutePath(currentResource, config);
  +            String currentResourceTrimmed = currentResourceUrl.substring(trim);
  +            if (currentResourceTrimmed.equalsIgnoreCase("WEB-INF") ||
  +                currentResourceTrimmed.equalsIgnoreCase("META-INF"))
                   continue;
               
               writer.print("<tr");
  @@ -669,9 +671,10 @@
               
               writer.print("<td align=\"left\" colspan=\"3\">&nbsp;&nbsp;\r\n");
               writer.print("<a href=\"");
  -            writer.print(WebdavUtils.encodeURL(contextPath + currentResource));
  +            writer.print(
  +                WebdavUtils.encodeURL(contextPath + currentResourceUrl));
               writer.print("\"><tt>");
  -            writer.print(trimmed);
  +            writer.print(currentResourceTrimmed);
               if (WebdavUtils.isCollection(currentDescriptor)) {
                   writer.print("/");
               }
  
  
  
  1.7.2.3   +29 -6     
jakarta-slide/src/webdav/server/org/apache/slide/webdav/Attic/WebdavUtils.java
  
  Index: WebdavUtils.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/Attic/WebdavUtils.java,v
  retrieving revision 1.7.2.2
  retrieving revision 1.7.2.3
  diff -u -r1.7.2.2 -r1.7.2.3
  --- WebdavUtils.java  28 Mar 2002 06:41:43 -0000      1.7.2.2
  +++ WebdavUtils.java  3 Apr 2002 16:40:55 -0000       1.7.2.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/Attic/WebdavUtils.java,v
 1.7.2.2 2002/03/28 06:41:43 jericho Exp $
  - * $Revision: 1.7.2.2 $
  - * $Date: 2002/03/28 06:41:43 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/Attic/WebdavUtils.java,v
 1.7.2.3 2002/04/03 16:40:55 cmlenz Exp $
  + * $Revision: 1.7.2.3 $
  + * $Date: 2002/04/03 16:40:55 $
    *
    * ====================================================================
    *
  @@ -89,7 +89,7 @@
    *
    *
    * @author Christopher Lenz (cmlenz at apache.org)
  - * @version $Revision: 1.7.2.2 $
  + * @version $Revision: 1.7.2.3 $
    **/
   public class WebdavUtils {
       
  @@ -267,6 +267,31 @@
       
       
       /**
  +     * Maps the URI of a node in the Slide namespace to the corresponding 
  +     * external URI, i.e. the URL by which the resource can be requested 
  +     * through the WebDAV servlet, relative to the web-app root.
  +     *
  +     * @param path URI of the node
  +     * @param config configuration of the WebdavServlet
  +     *
  +     * @return the node URI mapped to the namespace of the Webdav servlet
  +     **/
  +    public static String getAbsolutePath
  +        (String path, WebdavServletConfig config) {
  +        
  +        String scope = config.getScope();
  +        String result = "/";
  +        if (scope.length() == 0) {
  +            result = path;
  +        } else if ((path.length() > scope.length()) && path.startsWith(scope)) {
  +            result = path.substring(scope.length());
  +        }
  +        
  +        return encodeURL(result);
  +    }
  +    
  +    
  +    /**
        * Maps the request URI of a HTTP request to a URI in the Slide namespace
        * (this does not necessarily mean that a node exists at that URI).
        *
  @@ -294,8 +319,6 @@
           
           // prefix the URI with the configured scope
           result = config.getScope() + result;
  -             
  -            
           
           return decodeURL(fixTomcatURL(result));
       }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.39.2.4  +28 -51    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java
  
  Index: PropFindMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
  retrieving revision 1.39.2.3
  retrieving revision 1.39.2.4
  diff -u -r1.39.2.3 -r1.39.2.4
  --- PropFindMethod.java       28 Mar 2002 06:41:44 -0000      1.39.2.3
  +++ PropFindMethod.java       3 Apr 2002 16:40:56 -0000       1.39.2.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
 1.39.2.3 2002/03/28 06:41:44 jericho Exp $
  - * $Revision: 1.39.2.3 $
  - * $Date: 2002/03/28 06:41:44 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
 1.39.2.4 2002/04/03 16:40:56 cmlenz Exp $
  + * $Revision: 1.39.2.4 $
  + * $Date: 2002/04/03 16:40:56 $
    *
    * ====================================================================
    *
  @@ -567,36 +567,21 @@
                   
                   String path = object.getUri();
                   
  -                //              String absoluteUri =
  -                //                  req.getRequestURI();
  -//
  -                //              System.out.println("getContextPath 
"+req.getContextPath());
  -                //              System.out.println("getRequestURI 
"+req.getRequestURI());
  -                //              System.out.println("getPathInfo 
"+req.getPathInfo());
  -                //              System.out.println("getPathTranslated 
"+req.getPathTranslated());
  -                //              System.out.println("getRealPath 
"+req.getRealPath("xx"));
  -                //              System.out.println("getRemoteAddr 
"+req.getRemoteAddr());
  -                //              System.out.println("getRemoteHost 
"+req.getRemoteHost());
  -                //              System.out.println("getServerName 
"+req.getServerName());
  -                //              System.out.println("getServletPath 
"+req.getServletPath());
  -//
  -                //              String relativePath = requestUri;
  -                //              String toAppend = "";
  -                //              if (relativePath.length() <= path.length()) {
  -                //                  toAppend = 
path.substring(relativePath.length());
  -                //                  if ((!absoluteUri.endsWith("/")) &&
  -                //                          (!toAppend.startsWith("/"))) {
  -                //                      toAppend = "/" + toAppend;
  -                //                  }
  -                //                  if (toAppend.equals("/")) {
  -                //                      toAppend = "";
  -                //                  }
  -                //              }
  -                
  +                String absoluteUri = req.getRequestURI();
  +                String relativePath = requestUri;
  +                String toAppend = "";
  +                if (relativePath.length() <= path.length()) {
  +                    toAppend = path.substring(relativePath.length());
  +                    if ((!absoluteUri.endsWith("/")) &&
  +                            (!toAppend.startsWith("/"))) {
  +                        toAppend = "/" + toAppend;
  +                    }
  +                    if (toAppend.equals("/")) {
  +                        toAppend = "";
  +                    }
  +                }
                   generatedXML.writeText(
  -                    WebdavUtils.encodeURL(req.getContextPath() + path, "UTF-8"));
  -                //                generatedXML.writeText(absoluteUri + toAppend);
  -                
  +                    WebdavUtils.encodeURL(absoluteUri + toAppend, "UTF-8"));
               } catch (RevisionDescriptorNotFoundException e) {
                   
                   // The object doesn't have any revision, we create a dummy
  @@ -612,26 +597,18 @@
                   
                   String path = object.getUri();
                   
  -                //              String absoluteUri =
  -                //                  WebdavUtils.getRelativePath(req, getConfig());
  -                //              String relativePath = requestUri;
  -                //              String toAppend = "";
  -                //              if (relativePath.length() <= path.length()) {
  -                //                  toAppend = 
path.substring(relativePath.length());
  -                //                  if ((!absoluteUri.endsWith("/"))
  -                //                      && (!toAppend.startsWith("/"))) {
  -                //                      toAppend = "/" + toAppend;
  -                //                  }
  -                //              }
  -//
  -                
  +                String absoluteUri = req.getRequestURI();
  +                String relativePath = requestUri;
  +                String toAppend = "";
  +                if (relativePath.length() <= path.length()) {
  +                    toAppend = path.substring(relativePath.length());
  +                    if ((!absoluteUri.endsWith("/"))
  +                        && (!toAppend.startsWith("/"))) {
  +                        toAppend = "/" + toAppend;
  +                    }
  +                }
                   generatedXML.writeText(
  -                    WebdavUtils.encodeURL(req.getContextPath() + path, "UTF-8"));
  -                
  -                //              generatedXML.writeText(
  -                //                  WebdavUtils.encodeURL(absoluteUri + toAppend, 
"UTF-8"));
  -                //                generatedXML.writeText(absoluteUri + toAppend);
  -                
  +                    WebdavUtils.encodeURL(absoluteUri + toAppend, "UTF-8"));
               }
               
               generatedXML.writeElement(null, "href", XMLPrinter.CLOSING);
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to