jericho 01/04/21 21:53:14
Modified: src/webdav/client/src/org/apache/webdav/util
WebdavResource.java
src/webdav/client/src/org/apache/webdav/cmd Slide.java
Log:
- Make API flexbile to request the XML response of the required level.
- For this, setDefaultAction and setDefaultDepth methods are added.
- In order to to set properties of WebdavResource, the public method,
setProperties with depth and action arguments can be used.
- By default, the action of find properties for this resource is to get the
basic properties.
- API programmer could adjust the wanted XML responses by level.
It's so ideal for the query performance.
- Minor layout change to print help message for the Slide client.
Revision Changes Path
1.45 +281 -61
jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java
Index: WebdavResource.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- WebdavResource.java 2001/04/16 14:19:27 1.44
+++ WebdavResource.java 2001/04/22 04:53:13 1.45
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
1.44 2001/04/16 14:19:27 jericho Exp $
- * $Revision: 1.44 $
- * $Date: 2001/04/16 14:19:27 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
1.45 2001/04/22 04:53:13 jericho Exp $
+ * $Revision: 1.45 $
+ * $Date: 2001/04/22 04:53:13 $
*
* ====================================================================
*
@@ -109,9 +109,40 @@
* The constructor.
*
* @param httpURL The specified http URL.
+ * @param action The action to set properties of this resource.
+ * @param depth The depth to find properties.
* @exception WebdavException
* @exception IOException
*/
+ public WebdavResource(HttpURL httpURL, int action, int depth)
+ throws WebdavException, IOException {
+
+ setHttpURL(httpURL, action, depth);
+ }
+
+
+ /**
+ * The constructor.
+ *
+ * @param httpURL The specified http URL.
+ * @param depth The depth to find properties.
+ * @exception WebdavException
+ * @exception IOException
+ */
+ public WebdavResource(HttpURL httpURL, int depth)
+ throws WebdavException, IOException {
+
+ setHttpURL(httpURL, defaultAction, depth);
+ }
+
+
+ /**
+ * The constructor.
+ *
+ * @param httpURL The specified http URL.
+ * @exception WebdavException
+ * @exception IOException
+ */
public WebdavResource(HttpURL httpURL)
throws WebdavException, IOException {
@@ -200,6 +231,42 @@
/**
+ * No setting to find properties for this resource.
+ */
+ private static final int UNSET = 0;
+
+
+ /**
+ * No action to find properties for this resource.
+ */
+ public static final int NOACTION = 1;
+
+
+ /**
+ * The action setting only the displayname for this resource.
+ */
+ public static final int NAME = 2;
+
+
+ /**
+ * The action setting the basic properties for this resource.
+ */
+ public static final int BASIC = 3;
+
+
+ /**
+ * The action setting the default DAV properties for this resource.
+ */
+ public static final int DEFAULT = 4;
+
+
+ /**
+ * The action setting the all properties for this resource.
+ */
+ public static final int ALL = 5;
+
+
+ /**
* The true constant string.
*/
public static final String TRUE = "1";
@@ -253,6 +320,18 @@
/**
+ * The default action to find properties.
+ */
+ private static int defaultAction = BASIC;
+
+
+ /**
+ * The default depth for WebDAV methods.
+ */
+ private static int defaultDepth = DepthSupport.DEPTH_0;
+
+
+ /**
* The flag to set the status code by propfind.
*/
private boolean thisResource;
@@ -383,6 +462,41 @@
/**
+ * Set only the displayname property for this resource.
+ *
+ * @param depth The depth to find properties.
+ */
+ private void setNameProperties(int depth)
+ throws WebdavException, IOException {
+
+ Vector properties = new Vector();
+ properties.addElement(DISPLAYNAME);
+
+ setNamedProp(depth, properties);
+ }
+
+
+ /**
+ * Set the basic properties like displayname, getcontentlength,
+ * getcontenttype, resourcetype, getlastmodified for this resoruce.
+ *
+ * @param depth The depth to find properties.
+ */
+ private void setBasicProperties(int depth)
+ throws WebdavException, IOException {
+
+ Vector properties = new Vector();
+ properties.addElement(DISPLAYNAME);
+ properties.addElement(GETCONTENTLENGTH);
+ properties.addElement(GETCONTENTTYPE);
+ properties.addElement(RESOURCETYPE);
+ properties.addElement(GETLASTMODIFIED);
+
+ setNamedProp(depth, properties);
+ }
+
+
+ /**
* Set the named properties for this resource.
*
* @param depth The depth.
@@ -461,7 +575,7 @@
setDisplayName(displayName);
} else {
workingResource.setHttpURL
- (httpURL, displayName, false);
+ (httpURL, displayName, NOACTION);
workingResource.setExistence(true);
workingResource.setOverwrite(getOverwrite());
workingResource.setDisplayName(displayName);
@@ -547,7 +661,7 @@
setDisplayName(displayName);
} else {
workingResource.setHttpURL
- (httpURL, displayName, false);
+ (httpURL, displayName, NOACTION);
workingResource.setExistence(true);
workingResource.setOverwrite(getOverwrite());
workingResource.setDisplayName(displayName);
@@ -558,15 +672,60 @@
}
}
+
+ // ------------------------------------------------------------ Properties
+
+
+ /**
+ * Set the default action for this resource.
+ *
+ * ex)
+ * WebdavResource.NOACTION
+ * WebdavResource.NAME
+ * WebdavResource.BASIC
+ * WebdavResource.DEFAULT
+ * WebdavResource.ALL
+ */
+ public static void setDefaultAction(int action) {
+ defaultAction = action;
+ }
+
+
+ /**
+ * Get the default action.
+ */
+ public static int getDefaultAction() {
+ return defaultAction;
+ }
+
+
+ /**
+ * Set the default action for this resource.
+ *
+ * ex)
+ * DepthSupport.DEPTH_0
+ * DepthSupport.DEPTH_1
+ * DepthSupport.DEPTH_INFINITY
+ */
+ public static void setDefaultDepth(int depth) {
+ defaultDepth = depth;
+ }
+
- // ----------------------------------------------- HttpURL Public Methods
+ /**
+ * Get the default action.
+ */
+ public static int getDefaultDepth() {
+ return defaultDepth;
+ }
/**
* Set the HttpURL for this WebdavResource.
*
* @param httpURL the specified HttpURL.
- * @param action To profind or not.
+ * @param action The action to decide properties to find.
+ * @param depth The depth to find properties.
* @exception WebdavException
* @exception IOException
* @see #setHttpURL(java.lang.String)
@@ -574,14 +733,33 @@
* @see #setUserInfo(java.lang.String, java.lang.String)
* @see #setPath(java.lang.String)
*/
- private void setHttpURL(HttpURL httpURL, boolean action)
+ public void setHttpURL(HttpURL httpURL, int action, int depth)
throws WebdavException, IOException {
this.httpURL = httpURL;
// make its existence false
setExistence(false);
- if (action)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(action, depth);
+ }
+
+
+ /**
+ * Set the HttpURL for this WebdavResource.
+ *
+ * @param httpURL the specified HttpURL.
+ * @param depth The depth to find properties.
+ * @exception WebdavException
+ * @exception IOException
+ * @see #setHttpURL(java.lang.String)
+ * @see #setHttpURL(java.net.URL)
+ * @see #setUserInfo(java.lang.String, java.lang.String)
+ * @see #setPath(java.lang.String)
+ */
+ public void setHttpURL(HttpURL httpURL, int depth)
+ throws WebdavException, IOException {
+
+ // Follow the default action.
+ setHttpURL(httpURL, defaultAction, depth);
}
@@ -589,8 +767,9 @@
* Set the HttpURL for this WebdavResource.
*
* @param httpURL The specified HttpURL.
- * @param path The added relative path.
- * @param action To profind or not.
+ * @param additionalPath The added relative path.
+ * @param action The action to decide properties to find.
+ * @param depth The depth.
* @exception WebdavException
* @exception IOException
* @see #setHttpURL(java.lang.String)
@@ -598,15 +777,34 @@
* @see #setUserInfo(java.lang.String, java.lang.String)
* @see #setPath(java.lang.String)
*/
- private void setHttpURL
- (HttpURL httpURL, String path, boolean action)
+ public void setHttpURL
+ (HttpURL httpURL, String additionalPath, int action, int depth)
throws WebdavException, IOException {
- this.httpURL = new HttpURL(httpURL, path);
- // make its existence false
- setExistence(false);
- if (action)
- setAllProp(DepthSupport.DEPTH_0);
+ this.httpURL = new HttpURL(httpURL, additionalPath);
+ setHttpURL(this.httpURL, action, depth);
+ }
+
+
+ /**
+ * Set the HttpURL for this WebdavResource.
+ *
+ * @param httpURL The specified HttpURL.
+ * @param additionalPath The added relative path.
+ * @param action The action to decide properties to find.
+ * @exception WebdavException
+ * @exception IOException
+ * @see #setHttpURL(java.lang.String)
+ * @see #setHttpURL(java.net.URL)
+ * @see #setUserInfo(java.lang.String, java.lang.String)
+ * @see #setPath(java.lang.String)
+ */
+ public void setHttpURL
+ (HttpURL httpURL, String additionalPath, int action)
+ throws WebdavException, IOException {
+
+ this.httpURL = new HttpURL(httpURL, additionalPath);
+ setHttpURL(this.httpURL, action, defaultDepth);
}
@@ -614,7 +812,7 @@
* Set the HttpURL for this WebdavResource.
*
* @param httpURL The specified HttpURL.
- * @param path The added relative path.
+ * @param additionalPath The added relative path.
* @exception WebdavException
* @exception IOException
* @see #setHttpURL(java.lang.String)
@@ -622,10 +820,11 @@
* @see #setUserInfo(java.lang.String, java.lang.String)
* @see #setPath(java.lang.String)
*/
- public void setHttpURL(HttpURL httpURL, String path)
+ public void setHttpURL(HttpURL httpURL, String additionalPath)
throws WebdavException, IOException {
- setHttpURL(httpURL, path, true);
+ this.httpURL = new HttpURL(httpURL, additionalPath);
+ setHttpURL(httpURL, defaultAction, defaultDepth);
}
@@ -643,7 +842,7 @@
public void setHttpURL(HttpURL httpURL)
throws WebdavException, IOException {
- setHttpURL(httpURL, true);
+ setHttpURL(httpURL, defaultAction);
}
@@ -1028,6 +1227,49 @@
// --------------------------------------- WebDAV Resource Public Methods
+ /**
+ * Set the properties for this resource.
+ *
+ * @param action The action to find properties for this resource.
+ * @param depth The depth.
+ */
+ public void setProperties(int action, int depth)
+ throws WebdavException, IOException {
+
+ switch (action) {
+ case NOACTION:
+ break;
+ case NAME:
+ setNameProperties(depth);
+ case UNSET:
+ // Use the basic properties for the performance by default;
+ case BASIC:
+ setBasicProperties(depth);
+ break;
+ case DEFAULT:
+ // TODO: set DAV properties using by default.
+ // break;
+ case ALL:
+ setAllProp(depth);
+ break;
+ default:
+ throw new IllegalArgumentException("No such action type");
+ }
+ }
+
+
+ /**
+ * Set the properties for this resource.
+ *
+ * @param action The action to find properties for this resource.
+ */
+ public void setProperties(int depth)
+ throws WebdavException, IOException {
+
+ setProperties(defaultAction, depth);
+ }
+
+
/*
* Test if it exists.
* This is a wrapper method for getExistence.
@@ -1172,31 +1414,11 @@
public WebdavResources getChildResources()
throws WebdavException, IOException {
- setAllProp(DepthSupport.DEPTH_1);
+ setProperties(DepthSupport.DEPTH_1);
return childResources;
}
-
- /**
- * Set the basic properties like displayname, getcontentlength,
- * iscollection, getcontenttype, resourcetype, getlastmodified
- * for this resoruce.
- */
- public void setBasicProperties()
- throws WebdavException, IOException {
-
- Vector properties = new Vector();
- properties.addElement(DISPLAYNAME);
- properties.addElement(GETCONTENTLENGTH);
- properties.addElement(ISCOLLECTION);
- properties.addElement(GETCONTENTTYPE);
- properties.addElement(RESOURCETYPE);
- properties.addElement(GETLASTMODIFIED);
-
- setNamedProp(DepthSupport.DEPTH_1, properties);
- }
-
/**
* Get an array of resources denoting the WebDAV child resources in the
@@ -1224,11 +1446,9 @@
public String[] list()
throws WebdavException, IOException {
- Vector property = new Vector();
- property.addElement(DISPLAYNAME);
- setNamedProp(DepthSupport.DEPTH_1, property);
-
+ setNameProperties(DepthSupport.DEPTH_1);
Enumeration hrefs = childResources.getResourceNames();
+
// To be atomic.
Vector hrefList = new Vector();
while (hrefs.hasMoreElements()) {
@@ -1261,7 +1481,7 @@
public Vector listBasic()
throws WebdavException, IOException {
- setBasicProperties();
+ setBasicProperties(DepthSupport.DEPTH_1);
Enumeration hrefs = childResources.getResourceNames();
Vector hrefList = new Vector();
@@ -1484,7 +1704,7 @@
boolean result = putMethod(httpURL.getPath(), data);
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
@@ -1529,7 +1749,7 @@
boolean result = putMethod(httpURL.getPath(), file);
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
@@ -1577,7 +1797,7 @@
boolean result = putMethod(httpURL.getPath(), url);
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
@@ -1982,7 +2202,7 @@
boolean result = proppatchMethod
(httpURL.getPath(), propertyName, propertyValue);
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
@@ -2020,7 +2240,7 @@
boolean result = proppatchMethod(httpURL.getPath(), property);
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
@@ -2120,7 +2340,7 @@
boolean result = deleteMethod(httpURL.getPath());
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
@@ -2164,7 +2384,7 @@
boolean result = moveMethod(httpURL.getPath(),
HttpURL.getPath(destination));
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
@@ -2212,7 +2432,7 @@
boolean result = copyMethod(httpURL.getPath(),
HttpURL.getPath(destination));
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
@@ -2258,7 +2478,7 @@
boolean result = mkcolMethod(httpURL.getPath());
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
@@ -2311,7 +2531,7 @@
boolean result = lockMethod(httpURL.getPath(), owner, (short) 120);
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
@@ -2331,7 +2551,7 @@
boolean result = lockMethod(httpURL.getPath(), owner, (short) 120);
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
@@ -2413,7 +2633,7 @@
boolean result = unlockMethod(httpURL.getPath());
if (result)
- setAllProp(DepthSupport.DEPTH_0);
+ setProperties(DepthSupport.DEPTH_0);
return result;
}
1.23 +4 -4
jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java
Index: Slide.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- Slide.java 2001/04/16 14:28:01 1.22
+++ Slide.java 2001/04/22 04:53:14 1.23
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java,v 1.22
2001/04/16 14:28:01 jericho Exp $
- * $Revision: 1.22 $
- * $Date: 2001/04/16 14:28:01 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java,v 1.23
2001/04/22 04:53:14 jericho Exp $
+ * $Revision: 1.23 $
+ * $Date: 2001/04/22 04:53:14 $
*
* ====================================================================
*
@@ -1282,7 +1282,7 @@
private static void printSlideClientUsage() {
System.out.println(version + " commands:");
- System.out.println(" options {http_URL|path} " +
+ System.out.println(" options {http_URL|path} " +
"Print available http methods");
System.out.println(" open [http_URL] " +
"Connect to specified URL");