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 re...@apache.org on 2001/05/15 22:26:48 UTC

cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties LockDiscoveryProperty.java ActiveLockProperty.java

remm        01/05/15 13:26:46

  Modified:    src/webdav/client/src/org/apache/webdav/lib/properties
                        LockDiscoveryProperty.java
  Removed:     src/webdav/client/src/org/apache/webdav/lib/properties
                        ActiveLockProperty.java
  Log:
  - Revert Sung-Gu's patch (see my other email for the reasons).
  
  Revision  Changes    Path
  1.3       +111 -41   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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LockDiscoveryProperty.java	2001/05/15 17:13:57	1.2
  +++ LockDiscoveryProperty.java	2001/05/15 20:26:37	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $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 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/LockDiscoveryProperty.java,v 1.3 2001/05/15 20:26:37 remm Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/05/15 20:26:37 $
    *
    * ====================================================================
    *
  @@ -62,8 +62,8 @@
    */
   package org.apache.webdav.lib.properties;
   
  -import java.util.Enumeration;
  -import java.util.Vector;
  +import java.util.ArrayList;
  +import java.util.Iterator;
   
   import org.w3c.dom.Element;
   import org.w3c.dom.NodeList;
  @@ -75,18 +75,13 @@
   import org.apache.webdav.lib.BaseProperty;
   
   /**
  - * 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:jericho@thinkfree.com">Park, Sung-Gu</a>
  - * $@version$
  + * Title:        LockdiscoveryProperty.java
  + * Description:
  + * Company:      SpeedLegal Holdings Inc.
  + * @author       Jojada J. Tirtowidjojo
  + * @version 1.0
    */
  +
   public class LockDiscoveryProperty extends BaseProperty {
   
   
  @@ -113,36 +108,111 @@
       // --------------------------------------------------------- Public Methods
   
   
  -    /** 
  -     * 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));
  -                    }
  +    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));
                   }
  -            } 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));
  +            }
           }
  -        ActiveLockProperty[] activeLocks = new ActiveLockProperty[buff.size()];
  -        for (int i = 0; i < buff.size(); i++) {
  -            activeLocks[i] = (ActiveLockProperty) buff.elementAt(i);
  +
  +        return theTimeout;
  +    }
  +
  +
  +    public String getPropertyAsString() {
  +        String owners="";
  +
  +        ArrayList ownerList = getActiveLockOwners();
  +        for (Iterator i = ownerList.iterator(); i.hasNext();) {
  +            owners += (String) i.next()+" | ";
           }
  -        return activeLocks;
  +
  +        return (getName()+" = owners: "+owners+"\n");
       }
  +
  +
  +}//End of LockdiscoveryProperty class
  +
  +
  +
  +
  +
  +
  +
  +
  +
   
  -}