remm 01/05/15 17:56:25
Modified: src/webdav/client/src/org/apache/webdav/lib/properties
LockDiscoveryProperty.java
Log:
- Reapply the changes made by Sung-Gu, after fixing the build of
the UI components.
Revision Changes Path
1.4 +107 -101
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LockDiscoveryProperty.java 2001/05/15 20:26:37 1.3
+++ LockDiscoveryProperty.java 2001/05/16 00:56:20 1.4
@@ -1,7 +1,7 @@
/*
- * $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 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/LockDiscoveryProperty.java,v
1.4 2001/05/16 00:56:20 remm Exp $
+ * $Revision: 1.4 $
+ * $Date: 2001/05/16 00:56:20 $
*
* ====================================================================
*
@@ -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;
@@ -73,15 +73,22 @@
import org.apache.webdav.lib.ResponseEntity;
import org.apache.webdav.lib.BaseProperty;
+import org.apache.webdav.lib.Lock;
+import org.apache.webdav.lib.methods.DepthSupport;
/**
- * 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 +114,111 @@
// --------------------------------------------------------- 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 Lock[] A lock array.
+ */
+ public Lock[] 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 ("activelock".equals(localName)) {
+ buff.addElement(parseLock(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()+" | ";
+ Lock[] activeLocks = new Lock[buff.size()];
+ for (int i = 0; i < buff.size(); i++) {
+ activeLocks[i] = (Lock) buff.elementAt(i);
}
-
- return (getName()+" = owners: "+owners+"\n");
+ return activeLocks;
}
-}//End of LockdiscoveryProperty class
+ // ------------------------------------------------------ Protected Methods
+ /**
+ * Parse a lock.
+ */
+ protected Lock parseLock(Element element) {
+ int ls = -1;
+ Element child = DOMUtils.getFirstElement(element, "DAV:", "lockscope");
+ if (child != null) {
+ Element lockScope =
+ DOMUtils.getFirstElement(child, "DAV:", "exclusive");
+ if (lockScope != null) {
+ ls = Lock.SCOPE_EXCLUSIVE;
+ }
+ lockScope = DOMUtils.getFirstElement(child, "DAV:", "shared");
+ if (lockScope != null) {
+ ls = Lock.SCOPE_SHARED;
+ }
+ }
+
+ int lt = -1;
+ child = DOMUtils.getFirstElement(element, "DAV:", "locktype");
+ if (child != null) {
+ Element lockType =
+ DOMUtils.getFirstElement(child, "DAV:", "write");
+ if (lockType != null) {
+ lt = Lock.TYPE_WRITE;
+ }
+ }
+ int d = -1;
+ child = DOMUtils.getFirstElement(element, "DAV:", "depth");
+ if (child != null) {
+ String depth = DOMUtils.getTextValue(child);
+ if (depth != null) {
+ if ("0".equals(depth)) {
+ d = DepthSupport.DEPTH_0;
+ } else if ("1".equals(depth)) {
+ d = DepthSupport.DEPTH_1;
+ } else if ("infinity".equals(depth)) {
+ d = DepthSupport.DEPTH_INFINITY;
+ }
+ }
+ }
+ String owner = null;
+ child = DOMUtils.getFirstElement(element, "DAV:", "depth");
+ owner = DOMUtils.getTextValue(child);
+
+ long t = -1;
+ child = DOMUtils.getFirstElement(element, "DAV:", "timeout");
+ if (child != null) {
+ String timeout = DOMUtils.getTextValue(child);
+ int at = timeout.indexOf('-');
+ if (at > 0)
+ t = Long.parseLong(timeout.substring(at + 1));
+ }
+ String lockToken = null;
+ child = DOMUtils.getFirstElement(element, "DAV:", "locktoken");
+ if (child != null) {
+ Element href = DOMUtils.getFirstElement(child, "DAV:", "href");
+ if (href != null) {
+ lockToken = DOMUtils.getTextValue(href);
+ }
+ }
+ return new Lock(ls, lt, d, owner, t, lockToken);
+ }
+}