You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ms...@apache.org on 2002/08/16 04:53:54 UTC

cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib WebdavResource.java

msmith      2002/08/15 19:53:54

  Modified:    src/webdav/client/src/org/apache/webdav/lib
                        WebdavResource.java
  Log:
  Some minor bugfixes (sending content-type headers, for example), and
  some refactoring to make subclassing this class useful.
  
  Revision  Changes    Path
  1.44      +91 -56    jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java
  
  Index: WebdavResource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- WebdavResource.java	14 Jul 2002 20:48:10 -0000	1.43
  +++ WebdavResource.java	16 Aug 2002 02:53:54 -0000	1.44
  @@ -219,8 +219,7 @@
           super();
           this.client = client;
       }
  -    
  -    
  +
       /**
        * The constructor.
        *
  @@ -813,7 +812,7 @@
                   workingResource = this;
               }
               else {
  -                workingResource = new WebdavResource(client);
  +                workingResource = createWebdavResource(client);
                   workingResource.setDebug(debug);
               }
               String displayName = null;
  @@ -828,52 +827,7 @@
                   Property property = (Property) properties.nextElement();
                   
                   // ------------------------------  Checking WebDAV properties
  -                
  -                if (property.getLocalName().equals(DISPLAYNAME)) {
  -                    displayName = property.getPropertyAsString();
  -                }
  -                else if (property.getLocalName().equals(GETCONTENTLENGTH)) {
  -                    String getContentLength = property.getPropertyAsString();
  -                    workingResource.setGetContentLength(getContentLength);
  -                }
  -                else if (property.getLocalName().equals(RESOURCETYPE)) {
  -                    ResourceTypeProperty resourceType =
  -                        (ResourceTypeProperty) property;
  -                    workingResource.setResourceType(resourceType);
  -                }
  -                else if (property.getLocalName().equals(GETCONTENTTYPE)) {
  -                    String getContentType = property.getPropertyAsString();
  -                    workingResource.setGetContentType(getContentType);
  -                }
  -                else if (property.getLocalName().equals(GETLASTMODIFIED)) {
  -                    String getLastModified = property.getPropertyAsString();
  -                    workingResource.setGetLastModified(getLastModified);
  -                }
  -                else if (property.getLocalName().equals(CREATIONDATE)) {
  -                    String creationDate = property.getPropertyAsString();
  -                    workingResource.setCreationDate(creationDate);
  -                }
  -                else if (property.getLocalName().equals(GETETAG)) {
  -                    String getEtag = property.getPropertyAsString();
  -                    workingResource.setGetEtag(getEtag);
  -                }
  -                else if (property.getLocalName().equals(ISHIDDEN)) {
  -                    String isHidden = property.getPropertyAsString();
  -                    workingResource.setIsHidden(isHidden);
  -                }
  -                else if (property.getLocalName().equals(ISCOLLECTION)) {
  -                    String isCollection = property.getPropertyAsString();
  -                    workingResource.setIsCollection(isCollection);
  -                }
  -                else if (property.getLocalName().equals(SUPPORTEDLOCK)) {
  -                    String supportedLock = property.getPropertyAsString();
  -                    workingResource.setSupportedLock(supportedLock);
  -                }
  -                else if (property.getLocalName().equals(LOCKDISCOVERY)) {
  -                    LockDiscoveryProperty lockDiscovery =
  -                        (LockDiscoveryProperty) property;
  -                    workingResource.setLockDiscovery(lockDiscovery);
  -                }
  +                workingResource.processProperty(property); 
               }
               
               if (displayName == null || displayName.trim().equals("")) {
  @@ -1359,7 +1313,14 @@
       protected void setGetContentType(String getContentType) {
           this.getContentType = getContentType;
       }
  -    
  +
  +    /** 
  +     * Set the content-type to use for this resource, for PUTs.
  +     * @param contentType The content-type string.
  +     */
  +    public void setContentType(String contentType) {
  +        this.getContentType = contentType;
  +    }
       
       /**
        * Get the value of DAV property, getlastmodified.
  @@ -2216,10 +2177,12 @@
       public boolean putMethod(byte[] data)
           throws HttpException, IOException {
           
  -        return putMethod(httpURL.getPathQuery(), data);
  +        boolean result = putMethod(httpURL.getPathQuery(), data);
  +        if (result) refresh();
  +        return result;
       }
  -    
  -    
  +
  +
       /**
        * Execute the PUT method for the given path.
        *
  @@ -2235,6 +2198,8 @@
           setClient();
           PutMethod method = new PutMethod(HttpURL.getPathQuery(path));
           generateIfHeader(method);
  +        if(getGetContentType() != null && !getGetContentType().equals(""))
  +            method.setHeader("Content-Type", getGetContentType());
           method.sendData(data);
           method.setDebug(debug);
           client.executeMethod(method);
  @@ -2276,6 +2241,8 @@
           setClient();
           PutMethod method = new PutMethod(HttpURL.getPathQuery(path));
           generateIfHeader(method);
  +        if(getGetContentType() != null && !getGetContentType().equals(""))
  +            method.setHeader("Content-Type", getGetContentType());
           method.sendData(is);
           method.setDebug(debug);
           client.executeMethod(method);
  @@ -2320,6 +2287,8 @@
           setClient();
           PutMethod method = new PutMethod(HttpURL.getPath(path));
           generateIfHeader(method);
  +        if(getGetContentType() != null && !getGetContentType().equals(""))
  +            method.setHeader("Content-Type", getGetContentType());
           method.sendData(data);
           method.setDebug(debug);
           client.executeMethod(method);
  @@ -2364,6 +2333,8 @@
           setClient();
           PutMethod method = new PutMethod(HttpURL.getPath(path));
           generateIfHeader(method);
  +        if(getGetContentType() != null && !getGetContentType().equals(""))
  +            method.setHeader("Content-Type", getGetContentType());
           method.sendData(file);
           method.setDebug(debug);
           client.executeMethod(method);
  @@ -2411,6 +2382,8 @@
           setClient();
           PutMethod method = new PutMethod(HttpURL.getPath(path));
           generateIfHeader(method);
  +        if(getGetContentType() != null && !getGetContentType().equals(""))
  +            method.setHeader("Content-Type", getGetContentType());
           method.sendData(url);
           method.setDebug(debug);
           client.executeMethod(method);
  @@ -4024,6 +3997,68 @@
           return (statusCode >= 200 && statusCode < 300) ? true : false;
       }
   
  +    /*
  +     * Create a new WebdavResource object (as a seperate method so that it can
  +     * be overridden by subclasses.
  +     * @param client HttpClient to be used by this webdavresource.
  +     * @return A new WebdavResource object.
  +     */
  +    protected WebdavResource createWebdavResource(HttpClient client) {
  +        return new WebdavResource(client);
  +    }
  +
  +    /*
  +     * Process a property, setting various member variables depending
  +     * on what the property is.
  +     * @param property The property to process.
  +     */
  +    protected void processProperty(Property property) {
  +        if (property.getLocalName().equals(DISPLAYNAME)) {
  +             displayName = property.getPropertyAsString();
  +        }
  +        else if (property.getLocalName().equals(GETCONTENTLENGTH)) {
  +            String getContentLength = property.getPropertyAsString();
  +            setGetContentLength(getContentLength);
  +        }
  +        else if (property.getLocalName().equals(RESOURCETYPE)) {
  +            ResourceTypeProperty resourceType =
  +                (ResourceTypeProperty) property;
  +            setResourceType(resourceType);
  +        }
  +        else if (property.getLocalName().equals(GETCONTENTTYPE)) {
  +            String getContentType = property.getPropertyAsString();
  +            setGetContentType(getContentType);
  +        }
  +        else if (property.getLocalName().equals(GETLASTMODIFIED)) {
  +            String getLastModified = property.getPropertyAsString();
  +            setGetLastModified(getLastModified);
  +        }
  +        else if (property.getLocalName().equals(CREATIONDATE)) {
  +            String creationDate = property.getPropertyAsString();
  +            setCreationDate(creationDate);
  +        }
  +        else if (property.getLocalName().equals(GETETAG)) {
  +            String getEtag = property.getPropertyAsString();
  +            setGetEtag(getEtag);
  +        }
  +        else if (property.getLocalName().equals(ISHIDDEN)) {
  +            String isHidden = property.getPropertyAsString();
  +            setIsHidden(isHidden);
  +        }
  +        else if (property.getLocalName().equals(ISCOLLECTION)) {
  +            String isCollection = property.getPropertyAsString();
  +            setIsCollection(isCollection);
  +        }
  +        else if (property.getLocalName().equals(SUPPORTEDLOCK)) {
  +            String supportedLock = property.getPropertyAsString();
  +            setSupportedLock(supportedLock);
  +        }
  +        else if (property.getLocalName().equals(LOCKDISCOVERY)) {
  +            LockDiscoveryProperty lockDiscovery =
  +                (LockDiscoveryProperty) property;
  +            setLockDiscovery(lockDiscovery);
  +        }
  +    }
   }
   
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>