jericho     01/05/15 10:14:10

  Modified:    src/webdav/client/src/org/apache/webdav/lib/properties
                        LockDiscoveryProperty.java
               src/webdav/client/src/org/apache/webdav/lib/methods
                        DepthSupport.java
  Added:       src/webdav/client/src/org/apache/webdav/lib/properties
                        ActiveLockProperty.java
  Log:
  - Rewrite the lockdiscovery and activelock properties.
  - Change the DEPTH_INFINITY constant to 2.
    When the getDepth failed, it return -1.
  
  Revision  Changes    Path
  1.2       +42 -112   
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/LockDiscoveryProperty.java
  
  Index: LockDiscoveryProperty.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/LockDiscoveryProperty.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LockDiscoveryProperty.java        2001/05/14 00:08:12     1.1
  +++ LockDiscoveryProperty.java        2001/05/15 17:13:57     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/LockDiscoveryProperty.java,v
 1.1 2001/05/14 00:08:12 remm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/05/14 00:08:12 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/LockDiscoveryProperty.java,v
 1.2 2001/05/15 17:13:57 jericho Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/05/15 17:13:57 $
    *
    * ====================================================================
    *
  @@ -62,8 +62,8 @@
    */
   package org.apache.webdav.lib.properties;
   
  -import java.util.ArrayList;
  -import java.util.Iterator;
  +import java.util.Enumeration;
  +import java.util.Vector;
   
   import org.w3c.dom.Element;
   import org.w3c.dom.NodeList;
  @@ -75,13 +75,18 @@
   import org.apache.webdav.lib.BaseProperty;
   
   /**
  - * Title:        LockdiscoveryProperty.java
  - * Description:
  - * Company:      SpeedLegal Holdings Inc.
  - * @author       Jojada J. Tirtowidjojo
  - * @version 1.0
  + * This class represents a listing of who has lock, what type of lock he has,
  + * the timeout type and the time remaining on the timeout, and the associated
  + * lock token.  The server is free to withhold any or all of this information
  + * if the requesting principal does not have sufficient access rights to see
  + * the requested data.
  + *
  + * <!ELEMENT lockdiscovery (activelock)* >
  + *
  + * @author Jojada J. Tirtowidjojo at SpeedLegal Holdings Inc.
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Park, Sung-Gu</a>
  + * $@version$
    */
  -
   public class LockDiscoveryProperty extends BaseProperty {
   
   
  @@ -107,112 +112,37 @@
   
       // --------------------------------------------------------- Public Methods
   
  -
  -    public ArrayList getActiveLockOwners() {
  -        ArrayList theActiveLockOwners = new ArrayList();
  -        
  -        NodeList ownerList = getElement().getElementsByTagName("owner");
  -        for (int i=0; i < ownerList.getLength(); i++) {
  -            Element ownerElement = (Element) ownerList.item(i);
  -            String activeLockOwner =  DOMUtils.getTextValue(ownerElement);
  -            theActiveLockOwners.add(activeLockOwner);
  -        }//for(i)
  -
  -        return theActiveLockOwners;
  -    } //getActiveLockOwners()
  -
  -
  -    public NodeList getActiveLocks() {
  -        return getElement().getElementsByTagName("activelock");
  -    }
  -
  -
  -    public Element getActiveLock(String ownerName)  {
  -        String owner = "/users/"+ownerName;
   
  -        Element theActiveLock = null;
  -        
  -        NodeList activeLockList = getActiveLocks();
  -        boolean notFound = true;
  -        
  -        for (int i = 0; notFound && i < activeLockList.getLength(); i++ ) {
  -            Element activeLockElement = (Element) activeLockList.item(i);
  -            NodeList ownerList = 
  -                activeLockElement.getElementsByTagName("owner");
  -
  -            if (ownerList.getLength() == 1) { //if exists
  -                Element ownerElement = (Element) ownerList.item(0);
  -                
  -                String activeLockOwner = DOMUtils.getTextValue(ownerElement);
  -
  -                notFound = (owner.indexOf(activeLockOwner)>=0) ? false : true;
  -                theActiveLock = (notFound) ? null : activeLockElement;
  -                
  -            } //if (ownerList.getLength() == 1);
  -        }//for(i)
  -
  -        return theActiveLock;
  -    }//getAcctiveLock()
  -
  -
  -    public String getLockToken(String ownerName)  {
  -        String theLockToken=null;
  -        Element activeLock = getActiveLock(ownerName);
  -        if (activeLock != null) {
  -            NodeList list = activeLock.getElementsByTagName("locktoken");
  -
  -            if (list.getLength() == 1) { //if exists
  -                Element locktoken = (Element) list.item(0);
  -                NodeList list2 = locktoken.getElementsByTagName("href");
  -                if (list2.getLength() == 1) {
  -                    theLockToken = DOMUtils.getTextValue(list2.item(0));
  +    /** 
  +     * Retruns the activelock properties.
  +     * 
  +     * @return ActiveLockProeprty[] An activelock property array.
  +     */
  +    public ActiveLockProperty[] getActiveLocks() {
  +        NodeList children = element.getChildNodes();
  +        if (children == null || children.getLength() == 0)
  +            return null;
  +        Vector buff = new Vector();
  +        for (int i = 0; i < children.getLength(); i++) {
  +            try {
  +                Element child = (Element) children.item(i);
  +                String namespace = DOMUtils.getElementNamespaceURI(child);
  +                if (namespace != null && namespace.equals("DAV:")) {
  +                    String localName = DOMUtils.getElementLocalName(child);
  +                    if (ActiveLockProperty.TAG_NAME.equals(localName)) {
  +                        buff.addElement
  +                            (new ActiveLockProperty(response, child));
  +                    }
                   }
  +            } catch (ClassCastException e) {
               }
  -        }//if (activeLock != null);
  -
  -        return theLockToken;
  -    }//getLockToken()
  -
  -
  -    public long getTimeout(String ownerName)  {
  -        long theTimeout=0;
  -        Element activeLockElement = getActiveLock(ownerName);
  -        
  -        if (activeLockElement != null)  {
  -            NodeList list = activeLockElement.getElementsByTagName("timeout");
  -            if (list.getLength() == 1) { //if exists
  -                String timeoutString = DOMUtils.getTextValue(list.item(0));
  -                int signIndex = timeoutString.indexOf('-');
  -                theTimeout = Long.parseLong
  -                    (timeoutString.substring(signIndex+1));
  -            }
           }
  -
  -        return theTimeout;
  -    }
  -
  -
  -    public String getPropertyAsString() {
  -        String owners="";
  -
  -        ArrayList ownerList = getActiveLockOwners();
  -        for (Iterator i = ownerList.iterator(); i.hasNext();) {
  -            owners += (String) i.next()+" | ";
  +        ActiveLockProperty[] activeLocks = new ActiveLockProperty[buff.size()];
  +        for (int i = 0; i < buff.size(); i++) {
  +            activeLocks[i] = (ActiveLockProperty) buff.elementAt(i);
           }
  -
  -        return (getName()+" = owners: "+owners+"\n");
  +        return activeLocks;
       }
  -
  -
  -}//End of LockdiscoveryProperty class
  -
  -
  -
  -
  -
  -
  -
  -
  -
   
  +}
   
  
  
  
  1.1                  
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/ActiveLockProperty.java
  
  Index: ActiveLockProperty.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/ActiveLockProperty.java,v
 1.1 2001/05/15 17:14:01 jericho Exp $
   * $Revision: 1.1 $
   * $Date: 2001/05/15 17:14:01 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  package org.apache.webdav.lib.properties;
  
  import java.util.Enumeration;
  import java.util.Vector;
  
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Node;
  
  import org.apache.util.DOMUtils;
  
  import org.apache.webdav.lib.methods.DepthSupport;
  import org.apache.webdav.lib.ResponseEntity;
  import org.apache.webdav.lib.BaseProperty;
  
  /**
   * This class represents a lock on a resource.
   *  <!ELEMENT activelock (lockscope, locktype, depth, owner?, timeout?,
   * locktoken?) >
   *
   * @author Jojada J. Tirtowidjojo at SpeedLegal Holdings Inc.
   * @author <a href="mailto:[EMAIL PROTECTED]";>Park, Sung-Gu</a>
   * $@version$
   */
  public class ActiveLockProperty extends BaseProperty {
  
      // -------------------------------------------------------------- Constants
  
  
      /**
       * The property name.
       */
      public static final String TAG_NAME = "activelock";
  
  
      /**
       * The write constant in the locktype.
       */
      public static final short TYPE_WRITE = 0;
  
  
      /**
       * The exclusive constant in the lockscope.
       */
      public static final short SCOPE_EXCLUSIVE = 0;
  
  
      /**
       * The shared constant in the lockscope.
       */
      public static final short SCOPE_SHARED = 1;
  
  
      // ----------------------------------------------------------- Constructors
  
      /**
       * Default constructor for the property.
       */
      public ActiveLockProperty(ResponseEntity response, Element element) {
          super(response, element);
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Get whether a lock is an exclusive lock, or a shared lock.
       *
       * @return The lock scope.  If it's not set, it could be -1.
       */
      public short getLockScope() {
          Element child = DOMUtils.getFirstElement(element, "DAV:", "lockscope");
          if (child != null) {
              Element lockScope =
                  DOMUtils.getFirstElement(child, "DAV:", "exclusive");
              if (lockScope != null) {
                  return SCOPE_EXCLUSIVE;
              }
              lockScope = DOMUtils.getFirstElement(child, "DAV:", "shared");
              if (lockScope != null) {
                  return SCOPE_SHARED;
              }
          }
          return -1;
      }
  
  
      /**
       * Get the access type of a lock.
       *
       * @return The lock type. If it's not set, it could be -1.
       */
      public short getLockType() {
          Element child = DOMUtils.getFirstElement(element, "DAV:", "locktype");
          if (child != null) {
              Element lockType =
                  DOMUtils.getFirstElement(child, "DAV:", "write");
              if (lockType != null) {
                  return TYPE_WRITE;
              }
          }
          return -1;
      }
  
  
      /**
       * Get the value of the depth.
       *
       * @return The depth vlaue. If it's not set, it could be -1.
       */
      public short getDepth() {
          Element child = DOMUtils.getFirstElement(element, "DAV:", "depth");
          if (child != null) {
              String depth = DOMUtils.getTextValue(child);
              if (depth != null) {
                  if ("0".equals(depth)) {
                      return DepthSupport.DEPTH_0;
                  } else if ("1".equals(depth)) {
                      return DepthSupport.DEPTH_1;
                  } else if ("infinity".equals(depth)) {
                      return DepthSupport.DEPTH_INFINITY;
                  }
              }
          }
          return -1;
      }
      
  
      /**
       * Get information about the principal taking out a lock.
       *
       * @return The owner.
       */
      public String getOwner() {
          Element child = DOMUtils.getFirstElement(element, "DAV:", "depth");
          return DOMUtils.getTextValue(child);
      }
  
  
      /**
       * Get the timeout associated with a lock.
       *
       * @return The timeout vlaue. If it's not set, it could be -1.
       */
      public long getTimeout() {
          Element child = DOMUtils.getFirstElement(element, "DAV:", "timeout");
          if (child != null) {
              String timeout = DOMUtils.getTextValue(child);
              int at = timeout.indexOf('-');
              if (at > 0) 
                  return Long.parseLong(timeout.substring(at + 1));
          }
          return -1;
      }
  
  
      /**
       * Get the access type of a lock.
       *
       * @return The lock token.
       */
      public String getLockToken() {
          Element child = DOMUtils.getFirstElement(element, "DAV:", "locktoken");
          if (child != null) {
              Element href = DOMUtils.getFirstElement(child, "DAV:", "href");
              if (href != null) {
                  return DOMUtils.getTextValue(href);
              }
          }
          return null;
      }
     
  }
  
  
  
  1.2       +10 -9     
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/DepthSupport.java
  
  Index: DepthSupport.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/DepthSupport.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DepthSupport.java 2000/12/07 06:56:59     1.1
  +++ DepthSupport.java 2001/05/15 17:14:07     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/DepthSupport.java,v
 1.1 2000/12/07 06:56:59 bcholmes Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/12/07 06:56:59 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/DepthSupport.java,v
 1.2 2001/05/15 17:14:07 jericho Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/05/15 17:14:07 $
    *
    * ====================================================================
    *
  @@ -82,12 +82,6 @@
   
   
       /**
  -     * Request with depth infinity.
  -     */
  -    public static final int DEPTH_INFINITY = -1;
  -
  -
  -    /**
        * Request with depth 0.
        */
       public static final int DEPTH_0 = 0;
  @@ -97,6 +91,13 @@
        * Request with depth 1.
        */
       public static final int DEPTH_1 = 1;
  +
  +
  +    /**
  +     * Request with depth infinity.
  +     */
  +    public static final int DEPTH_INFINITY = 2;
  +
   
       // ------------------------------------------------------------- Properties
   
  
  
  

Reply via email to