jericho     01/04/13 07:23:59

  Modified:    src/webdav/client/src/org/apache/webdav/util
                        WebdavResource.java
  Log:
  - Fix to get properties.
    Its operation was depent on servers.
    Because it didn't get the href tag from the specified WebDAV server.
  - Add debug messages.
  
  The bug of propget reported by "Valeriy Podkolzin" <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.40      +43 -60    
jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java
  
  Index: WebdavResource.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- WebdavResource.java       2001/04/13 11:03:29     1.39
  +++ WebdavResource.java       2001/04/13 14:23:57     1.40
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
 1.39 2001/04/13 11:03:29 jericho Exp $
  - * $Revision: 1.39 $
  - * $Date: 2001/04/13 11:03:29 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
 1.40 2001/04/13 14:23:57 jericho Exp $
  + * $Revision: 1.40 $
  + * $Date: 2001/04/13 14:23:57 $
    *
    * ====================================================================
    *
  @@ -247,15 +247,15 @@
   
   
       /**
  -     * The WebDAV client for the HTTP communication with WebDAV servers.
  +     * Table of the hrefs gotten in a collection.
        */
  -    private WebdavClient client;
  +    private WebdavResources children = new WebdavResources();
   
   
       /**
  -     * Table of the hrefs gotten in a collection.
  +     * the flag for this resource.
        */
  -    private WebdavResources children = new WebdavResources();
  +    private boolean thisResource;
   
   
       /**
  @@ -429,13 +429,14 @@
                   (ResponseEntity) responses.nextElement();
   
               boolean itself = false;
  +            String href = (String) response.getHref();
  +            if (!href.startsWith("/"))
  +                href = HttpURL.getPath(href);
               String httpURLPath = httpURL.getPath();
  -            String hrefPath = HttpURL.getPath((String) response.getHref());
  -            int compared = httpURLPath.compareTo(hrefPath);
  +            int compared = httpURLPath.compareTo(href);
               // Compare with the href path and requested-path itself.
  -            if (compared == 0 || compared == -1 && hrefPath.endsWith("/") ||
  +            if (compared == 0 || compared == -1 && href.endsWith("/") ||
                   compared == 1 && httpURLPath.endsWith("/")) {
  -
                   if (response.getStatusCode() > 0)
                       setStatusCode(response.getStatusCode());
                   setExistence(true);
  @@ -540,7 +541,7 @@
                   }
               }
               if (displayName == null) {
  -                displayName = HttpURL.getName(hrefPath);
  +                displayName = HttpURL.getName(href);
                   if (itself) {
                       setDisplayName(displayName);
                   } else {
  @@ -1262,7 +1263,8 @@
                   hrefList.addElement(longFormat);
               } catch (Exception e) {
                   // FIXME: After if's gotten an exception, any solution?
  -                // e.printStackTrace();
  +                if (debug > 0)
  +                    e.printStackTrace();
               }
           }
   
  @@ -1371,11 +1373,13 @@
               fos.flush();
   
           } catch(WebdavException we) {
  +            if (debug > 0)
  +                we.printStackTrace();
               throw new WebdavException
                   (we.getMessage(), method.getStatusCode());
  -            // we.printStackTrace();
           } catch(Exception e) {
  -            // e.printStackTrace();
  +            if (debug > 0)
  +                e.printStackTrace();
           } finally {
   
               try {
  @@ -1691,8 +1695,6 @@
   
           // Set the status code.
           setStatusCode(method.getStatusCode());
  -        // In order to save this session.
  -        this.client = client;
   
           return method.getResponses();
       }
  @@ -1753,11 +1755,10 @@
           client.setDebug(debug);
           method.setDebug(debug);
           client.executeMethod(method);
  -        
  -        // Set the status code.
  -        setStatusCode(method.getStatusCode());
  -        // In order to save this session.
  -        this.client = client;
  +
  +        if (thisResource)
  +            // Set the status code.
  +            setStatusCode(method.getStatusCode());
           
           return method.getResponses();
       }
  @@ -1829,52 +1830,34 @@
        */
       public Enumeration propfindMethod(String path, Vector properties)
           throws WebdavException, IOException {
  -
  -        WebdavClient client = getSessionInstance(this.httpURL);
  +        
  +        WebdavClient client = getSessionInstance(httpURL);
   
           // Check the path alright.
           path = HttpURL.getPath(path);
  -        // Default depth=1, type=by_name
  +        // Default depth=0, type=by_name
           PropFindMethod method =
  -            new PropFindMethod(path, properties.elements());
  +            new PropFindMethod(path, DepthSupport.DEPTH_0,
  +                               properties.elements());
           client.setDebug(debug);
           method.setDebug(debug);
           client.executeMethod(method);
  -
  -        // Actually, the multi-status status code has the first priority.
  -        setStatusCode(method.getStatusCode());
  -
  +        
           // It contains the results.
           Vector results = new Vector();
  -        HttpURL httpURL = new HttpURL(this.httpURL.getAuthority() + path);
  -        String href = httpURL.getHttpURLExceptForUserInfo().toString();
  -        Enumeration enum = method.getResponseProperties(href);
  -        while (enum.hasMoreElements()) {
  -            Property property = (Property) enum.nextElement();
  -            if (property.getStatusCode() > 0) {
  -                // Set the right status code by multi-status.
  -                setStatusCode(property.getStatusCode());
  -            }
  -            // Do loop as many as requested.
  -            for (int i = 0; i < properties.size(); i++) {
  -                // Do not need to be more strict.
  -                results.addElement
  -                    (DOMUtils.getTextValue(property.getElement()));
  -            }
  -        }
  -        if (href.length() > 1) {
  -            if (href.endsWith("/")) {
  -                href = href.substring(0, href.length()-1);
  -            } else {
  -                href += "/";
  -            }
  -            enum = method.getResponseProperties(href);
  -            while (enum.hasMoreElements()) {
  -                Property property = (Property) enum.nextElement();
  -                if (property.getStatusCode() > 0) {
  -                    // Set the right status code by multi-status.
  -                    setStatusCode(property.getStatusCode());
  -                }
  +
  +        Enumeration responses = method.getResponses();
  +        if (responses.hasMoreElements()) {
  +            ResponseEntity response =
  +                (ResponseEntity) responses.nextElement();
  +            String href = (String) response.getHref();
  +            if (response.getStatusCode() > 0)
  +                setStatusCode(response.getStatusCode());
  +            Enumeration responseProperties =
  +                method.getResponseProperties(href);
  +            while (responseProperties.hasMoreElements()) {
  +                Property property =
  +                    (Property) responseProperties.nextElement();
                   // Do loop as many as requested.
                   for (int i = 0; i < properties.size(); i++) {
                       // Do not need to be more strict.
  @@ -1883,7 +1866,7 @@
                   }
               }
           }
  -
  +        
           return results.elements();
       }
   
  
  
  

Reply via email to