dirkv       01/08/06 06:26:42

  Modified:    src/webdav/client/src/org/apache/webdav/lib/properties
                        ResourceTypeProperty.java
  Log:
  fix isCollection test
  cache result of test
  
  Revision  Changes    Path
  1.4       +40 -12    
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/ResourceTypeProperty.java
  
  Index: ResourceTypeProperty.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/ResourceTypeProperty.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ResourceTypeProperty.java 2001/05/14 00:08:12     1.3
  +++ ResourceTypeProperty.java 2001/08/06 13:26:42     1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/ResourceTypeProperty.java,v
 1.3 2001/05/14 00:08:12 remm Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/05/14 00:08:12 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/ResourceTypeProperty.java,v
 1.4 2001/08/06 13:26:42 dirkv Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/08/06 13:26:42 $
    *
    * ====================================================================
    *
  @@ -76,10 +76,13 @@
    * the WebDAV specification).
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>B.C. Holmes</a>
  + * @author Dirk Verbeeck
    */
   public class ResourceTypeProperty extends BaseProperty {
   
  -
  +    private boolean initialized=false;
  +    private boolean isCollection;
  +    
       // -------------------------------------------------------------- Constants
   
   
  @@ -112,20 +115,45 @@
        * </pre>
        */
       public boolean isCollection() {
  -        boolean isCollection = false;
  +        init();
  +        return isCollection;
  +    }
  +
  +    private void init() 
  +    {
  +        // FIXME: only <DAV:collection/> is supported
  +    
  +        if (initialized)
  +            return;
  +            
           NodeList tmp = element.getChildNodes();
  -        for (int i = 0;
  -             tmp != null && !isCollection && i < tmp.getLength(); i++ ) {
  +        for (int i = 0; tmp != null && i < tmp.getLength(); i++ ) {
               try {
                   Element child = (Element) tmp.item(i);
  -                isCollection = isCollection || 
  -                    ("collection".equals(DOMUtils.getElementLocalName(child)) 
  -                     && "DAV:".equals(DOMUtils.getElementNamespaceURI(child)));
  +                if ("collection".equals(DOMUtils.getElementLocalName(child)) 
  +                     && "DAV:".equals(DOMUtils.getElementNamespaceURI(child)))
  +                {
  +                    isCollection=true;
  +                    initialized=true;
  +                    return;
  +                }
               } catch (ClassCastException e) {
               }
           }
  -        return (tmp.getLength() > 0);
  +        isCollection=false;
  +        initialized=true;
       }
  -
   
  +    /**
  +     * This method returns the value of the property.
  +     * For this property "COLLECTION" is returned if
  +     * this resource is a collection, "" otherwise.
  +     * 
  +     * WARNING: this will change in the future
  +     * use isCollection()
  +     */
  +    public String getPropertyAsString() {
  +        init();
  +        return isCollection?"COLLECTION":"";
  +    }
   }
  
  
  

Reply via email to