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/14 02:08:12 UTC
cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties CurrentUserPrivilegeSetProperty.java LockDiscoveryProperty.java GetLastModifiedProperty.java ResourceTypeProperty.java
remm 01/05/13 17:08:12
Modified: src/webdav/client/src/org/apache/webdav/lib/properties
GetLastModifiedProperty.java
ResourceTypeProperty.java
Added: src/webdav/client/src/org/apache/webdav/lib/properties
CurrentUserPrivilegeSetProperty.java
LockDiscoveryProperty.java
Log:
- The Properties are no longer interfaces, which allows to move some code away
from the XML response base.
- The properties extend BaseProperty.
- Add two new properties : CurrentUserPrivilegeSet and LockDiswcovery,
which were contributed by Jojada J. Tirtowidjojo.
Revision Changes Path
1.3 +55 -8 jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/GetLastModifiedProperty.java
Index: GetLastModifiedProperty.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/GetLastModifiedProperty.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- GetLastModifiedProperty.java 2000/12/10 05:07:54 1.2
+++ GetLastModifiedProperty.java 2001/05/14 00:08:12 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/GetLastModifiedProperty.java,v 1.2 2000/12/10 05:07:54 bcholmes Exp $
- * $Revision: 1.2 $
- * $Date: 2000/12/10 05:07:54 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/GetLastModifiedProperty.java,v 1.3 2001/05/14 00:08:12 remm Exp $
+ * $Revision: 1.3 $
+ * $Date: 2001/05/14 00:08:12 $
*
* ====================================================================
*
@@ -63,9 +63,19 @@
package org.apache.webdav.lib.properties;
import java.util.Date;
+import java.util.Locale;
-import org.apache.webdav.lib.Property;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
+import org.w3c.dom.Element;
+
+import org.apache.util.DOMUtils;
+
+import org.apache.webdav.lib.ResponseEntity;
+import org.apache.webdav.lib.BaseProperty;
+
/**
* This interface models the <code><D:getlastmodified></code> property,
* which indicates the last time the resource was modified. It does not, as
@@ -73,25 +83,62 @@
* recently modified property.
*
* @author BC Holmes
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
-public interface GetLastModifiedProperty extends Property {
+public class GetLastModifiedProperty extends BaseProperty {
+
+
+ // -------------------------------------------------------------- Constants
+
/**
* The property name.
*/
public static final String TAG_NAME = "getlastmodified";
+
/**
* The standard date format for the last modified date, as specified in
* the HTTP 1.1 specification (RFC 2068).
*/
public static final String DATE_FORMAT = "EEE, d MMM yyyy kk:mm:ss z";
+
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Default constructor for the property.
+ */
+ public GetLastModifiedProperty(ResponseEntity response, Element element) {
+ super(response, element);
+ // RFC 1123, 822. Date and time specification is English.
+ format = new SimpleDateFormat(DATE_FORMAT, Locale.US);
+ }
+
+
+ // ----------------------------------------------------- Instance Variables
+
+
+ protected DateFormat format = null;
+
+
+ // --------------------------------------------------------- Public Methods
+
+
/**
* Get the date of the last modification.
*
* @returns the last modified date.
*/
- public abstract Date getDate();
-}
\ No newline at end of file
+ public Date getDate() {
+ Date date = null;
+ try {
+ date = format.parse(DOMUtils.getTextValue(element));
+ } catch (ParseException e) {
+ }
+ return date;
+ }
+
+
+}
1.3 +47 -8 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ResourceTypeProperty.java 2000/12/10 05:07:54 1.2
+++ ResourceTypeProperty.java 2001/05/14 00:08:12 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/ResourceTypeProperty.java,v 1.2 2000/12/10 05:07:54 bcholmes Exp $
- * $Revision: 1.2 $
- * $Date: 2000/12/10 05:07:54 $
+ * $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 $
*
* ====================================================================
*
@@ -63,9 +63,13 @@
package org.apache.webdav.lib.properties;
-import org.apache.webdav.lib.Property;
-
import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import org.apache.util.DOMUtils;
+
+import org.apache.webdav.lib.BaseProperty;
+import org.apache.webdav.lib.ResponseEntity;
/**
* An interface that describes a standard Resource Type property (as defined by
@@ -73,14 +77,33 @@
*
* @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
*/
-public interface ResourceTypeProperty extends Property {
+public class ResourceTypeProperty extends BaseProperty {
+
+
+ // -------------------------------------------------------------- Constants
+
/**
* The property name.
*/
public static final String TAG_NAME = "resourcetype";
+
+ // ----------------------------------------------------------- Constructors
+
+
/**
+ * Default constructor for the property.
+ */
+ public ResourceTypeProperty(ResponseEntity response, Element element) {
+ super(response, element);
+ }
+
+
+ // --------------------------------------------------------- Public Methods
+
+
+ /**
* Returns true if the resource is a collection. A collection is indicated
* by a response like this:
*
@@ -88,5 +111,21 @@
* <D:resourcetype><D:collection/></D:resourcetype>
* </pre>
*/
- public boolean isCollection();
-}
\ No newline at end of file
+ public boolean isCollection() {
+ boolean isCollection = false;
+ NodeList tmp = element.getChildNodes();
+ for (int i = 0;
+ tmp != null && !isCollection && i < tmp.getLength(); i++ ) {
+ try {
+ Element child = (Element) tmp.item(i);
+ isCollection = isCollection ||
+ ("collection".equals(DOMUtils.getElementLocalName(child))
+ && "DAV:".equals(DOMUtils.getElementNamespaceURI(child)));
+ } catch (ClassCastException e) {
+ }
+ }
+ return (tmp.getLength() > 0);
+ }
+
+
+}
1.1 jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/CurrentUserPrivilegeSetProperty.java
Index: CurrentUserPrivilegeSetProperty.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/CurrentUserPrivilegeSetProperty.java,v 1.1 2001/05/14 00:08:12 remm Exp $
* $Revision: 1.1 $
* $Date: 2001/05/14 00:08:12 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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 org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.apache.webdav.lib.ResponseEntity;
import org.apache.webdav.lib.BaseProperty;
/**
* Title: CurrentUserPrivilegeSetProperty.java
* Description:
* Company: SpeedLegal Holdings Inc.
* @author Jojada J. Tirtowidjojo
* @version 1.0
*/
public class CurrentUserPrivilegeSetProperty extends BaseProperty {
// -------------------------------------------------------------- Constants
/**
* The property name.
*/
public static final String TAG_NAME = "currentuserprivilegeset";
// ----------------------------------------------------------- Constructors
/**
* Default constructor for the property.
*/
public CurrentUserPrivilegeSetProperty
(ResponseEntity response, Element element) {
super(response, element);
}
// --------------------------------------------------------- Public Methods
public boolean hasReadAccess() {
NodeList readPrivilege = getElement().getElementsByTagName("read");
return (readPrivilege.getLength() == 1);
}
public boolean hasWriteAccess() {
NodeList writePrivilege = getElement().getElementsByTagName("write");
return (writePrivilege.getLength() == 1);
}
public boolean hasReadWriteAccess() {
return (hasReadAccess() && hasWriteAccess());
}
public String getPropertyAsString() {
String theResult="";
theResult = (hasReadAccess()) ? "Read" : theResult;
theResult = (hasWriteAccess()) ? theResult+" Write" : theResult;
return getName()+" = "+theResult.trim()+"\n";
}
}
1.1 jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/properties/LockDiscoveryProperty.java
Index: LockDiscoveryProperty.java
===================================================================
/*
* $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 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.ArrayList;
import java.util.Iterator;
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.ResponseEntity;
import org.apache.webdav.lib.BaseProperty;
/**
* Title: LockdiscoveryProperty.java
* Description:
* Company: SpeedLegal Holdings Inc.
* @author Jojada J. Tirtowidjojo
* @version 1.0
*/
public class LockDiscoveryProperty extends BaseProperty {
// -------------------------------------------------------------- Constants
/**
* The property name.
*/
public static final String TAG_NAME = "lockdiscovery";
// ----------------------------------------------------------- Constructors
/**
* Default constructor for the property.
*/
public LockDiscoveryProperty(ResponseEntity response, Element element) {
super(response, element);
}
// --------------------------------------------------------- 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));
}
}
}//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()+" | ";
}
return (getName()+" = owners: "+owners+"\n");
}
}//End of LockdiscoveryProperty class