jericho 01/03/26 03:08:31
Modified: src/webdav/client/src/org/apache/webdav/util
WebdavResource.java HttpURL.java
Added: src/webdav/client/src/org/apache/webdav/util
WebdavResources.java
Log:
- Improved to be possible to access the child-resources recursively.
- For that, WebdavResources class added.
- Some constructor and methods added.
Revision Changes Path
1.19 +711 -486
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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- WebdavResource.java 2001/03/23 05:06:42 1.18
+++ WebdavResource.java 2001/03/26 11:08:29 1.19
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
1.18 2001/03/23 05:06:42 remm Exp $
- * $Revision: 1.18 $
- * $Date: 2001/03/23 05:06:42 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
1.19 2001/03/26 11:08:29 jericho Exp $
+ * $Revision: 1.19 $
+ * $Date: 2001/03/26 11:08:29 $
*
* ====================================================================
*
@@ -97,115 +97,144 @@
// ------------------------------------------------------- Constructors
- /**
- * Constructor for this class
- *
- * @param httpUrl The specified HttpURL.
- * @exception WebdavException
- * @exception IOException
- * @see #setHttpUrl(HttpURL)
- * @see #setHttpUrl(java.lang.String)
- * @see #setHttpUrl(java.net.URL)
- * @see #setUserInfo(java.lang.String, java.lang.String)
- * @see #setPath(java.lang.String)
- */
- public WebdavResource(HttpURL httpUrl)
- throws WebdavException, IOException {
+ /**
+ * Default constructor.
+ */
+ private WebdavResource() {
+ }
- setHttpUrl(httpUrl);
- }
-
/**
- * Constructor for this class
+ * The constructor.
*
- * @param httpUrl The specified http URL string.
+ * @param httpURL The specified http URL.
* @exception WebdavException
* @exception IOException
- * @see #setHttpUrl(HttpURL)
- * @see #setHttpUrl(java.lang.String)
- * @see #setHttpUrl(java.net.URL)
- * @see #setUserInfo(java.lang.String, java.lang.String)
- * @see #setPath(java.lang.String)
*/
- public WebdavResource(String httpUrl)
+ public WebdavResource(HttpURL httpURL)
throws WebdavException, IOException {
- setHttpUrl(httpUrl);
+ setHttpURL(httpURL);
}
/**
- * Constructor for this class
+ * The constructor.
*
- * @param httpUrl The specified URL.
+ * @param httpURL The specified http URL string.
* @exception WebdavException
* @exception IOException
- * @see #setHttpUrl(HttpURL)
- * @see #setHttpUrl(java.lang.String)
- * @see #setHttpUrl(java.net.URL)
- * @see #setUserInfo(java.lang.String, java.lang.String)
- * @see #setPath(java.lang.String)
*/
- public WebdavResource(URL url)
+ public WebdavResource(String httpURL)
throws WebdavException, IOException {
- setHttpUrl(url);
+ setHttpURL(httpURL);
}
- // ------------------------------------------------------ Class Variables
+ // -------------------------------------- Constants for WebDAV properties.
- /**
- * Constants for WebDAV properties
- */
- public static final String DISPLAYNAME ="displayname";
+ /**
+ * The displayname property.
+ */
+ public static final String DISPLAYNAME = "displayname";
+
+
+ /**
+ * The getcontentlength property.
+ */
public static final String GETCONTENTLENGTH = "getcontentlength";
+
+
+ /**
+ * The getlastmodifed property.
+ */
public static final String GETLASTMODIFIED = "getlastmodified";
+
+
+ /**
+ * The creationdate property.
+ */
public static final String CREATIONDATE = "creationdate";
+
+
+ /**
+ * The resourcetype property.
+ */
public static final String RESOURCETYPE = "resourcetype";
+
+
+ /**
+ * The getcontenttype property.
+ */
public static final String GETCONTENTTYPE = "getcontenttype";
+
+
+ /**
+ * The getetag property.
+ */
public static final String GETETAG = "getetag";
+
+
+ /**
+ * The ishidden property.
+ */
public static final String ISHIDDEN = "ishidden";
+
+
+ /**
+ * The iscollection property.
+ */
public static final String ISCOLLECTION = "iscollection";
+
+
+ /**
+ * The supportedlock property.
+ */
public static final String SUPPORTEDLOCK = "supportedlock";
+ // ------------------------------------------------------------ Constants
+
+
+ /**
+ * The true constant string.
+ */
+ public static final String TRUE = "1";
+
+
/**
+ * The false constant string.
+ */
+ public static final String FALSE = "0";
+
+
+ /**
* Date formats using for Date parsing.
*/
- protected static final SimpleDateFormat formats[] = {
+ public static final SimpleDateFormat formats[] = {
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US),
new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
- new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
+ new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US),
+ new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale.US)
};
+
-
// --------------------------------------------------- Instance Variables
/**
* The HttpURL to represent a WebDAV resource.
- *
- * @see #setHttpUrl(HttpURL)
- * @see #setHttpUrl(java.lang.String)
- * @see #setHttpUrl(java.net.URL)
- * @see #setUserInfo(java.lang.String, java.lang.String)
- * @see #setPath(java.lang.String)
*/
- private HttpURL httpUrl;
+ private HttpURL httpURL;
/**
* A string flag used for checking WebDAV properties.
- *
- * @see #setUsed()
- * @see #getUsed()
- * @see #setUnused()
*/
- private String httpUrlChecked;
+ private String httpURLChecked;
/**
@@ -216,52 +245,42 @@
/**
* Table of the hrefs gotten in a collection.
- *
- * @see #setAllProp(HttpURL)
*/
- private Hashtable hrefTable = new Hashtable();
+ private WebdavResources children = new WebdavResources();
/**
* The allowed HTTP methods.
- *
- * @see #optionsMethod()
- * @see #optionsMethod(java.lang.String)
- * @see #optionsMethod(java.lang.String, java.lang.String)
*/
private Enumeration allowedMethods;
/**
* The capabilities of the WebDAV server.
- *
- * @see #optionsMethod()
- * @see #optionsMethod(java.lang.String)
- * @see #optionsMethod(java.lang.String, java.lang.String)
*/
private Enumeration davCapabilities;
/**
- * A WebdavResource flag to check its existence;
+ * An WebdavResource flag to check its existence;
*/
- private boolean exists = false;
+ private boolean exists;
/**
- * A WebdavResource flag to check overwriting;
+ * An WebdavResource flag to check overwriting;
*/
- private boolean overwrite = false;
+ private boolean overwrite;
/**
- * A status code performed by HTTP methods at the most recent.
+ * An status code performed by HTTP methods at the most recent.
*/
private int latestStatusCode;
/**
- * A status message performed by HTTP methods at the most recent.
+ * An status message performed by HTTP methods at the most recent.
*/
private String latestStatusMessage = "";
@@ -269,228 +288,89 @@
/**
* Owner information for locking and unlocking.
*/
- private static final String defaultOwner = "Slide";
+ public static final String defaultOwner = "Slide";
/**
- * A WebDAV property, displayname.
+ * An WebDAV property, displayname.
*/
private String displayName = "";
/**
- * A WebDAV property, getcontentlength;
+ * An WebDAV property, getcontentlength.
*/
- private String getContentLength = "";
+ private long getContentLength;
/**
- * A WebDAV property, getcontenttype;
+ * An WebDAV property, getcontenttype.
*/
private String getContentType = "";
/**
- * A WebDAV property, resourcetype;
+ * An WebDAV property, resourcetype.
*/
private ResourceTypeProperty resourceType;
/**
- * A WebDAV property, getlastmodified;
+ * An WebDAV property, getlastmodified.
*/
- private String getLastModified;
+ private long getLastModified;
/**
- * A WebDAV property, creationdate.
+ * An WebDAV property, creationdate.
*/
- private String creationDate = "";
+ private long creationDate;
/**
- * A WebDAV property, getetag;
+ * An WebDAV property, getetag.
*/
private String getEtag = "";
/**
- * A WebDAV property, ishidden;
+ * An WebDAV property, ishidden.
*/
- private String isHidden = "";
+ private boolean isHidden;
/**
- * A WebDAV property, iscollection;
+ * An WebDAV property, iscollection.
*/
- private String isCollection = "";
+ private boolean isCollection;
/**
- * A WebDAV property, supportedlock;
+ * An WebDAV property, supportedlock.
*/
private String supportedLock = "";
- // ------------------------------------------------- Methods for http URL
+ // ----------------------------------------------------- Private Methods
/**
- * Get the URL for this WebdavResource.
- *
- * In order to support java.net.URL on JDK 1.1.x.,
- * this method returns URL without the userinfo part.
- *
- * @param path the specified path for this WebdavResource.
- * @exception MalformedURLException
- * @see #setHttpUrl(java.net.URL)
- */
- public URL getURL()
- throws MalformedURLException {
-
- return httpUrl.toURL();
- }
-
-
- /**
- * Set the HttpURL for this WebdavResource.
- *
- * @param httpUrl the specified HttpURL.
- * @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)
- throws WebdavException, IOException {
-
- this.httpUrl = httpUrl;
- setAllProp(httpUrl);
- }
-
-
- /**
- * Set the HttpURL of this WebdavResource.
- *
- * @param httpUrl the specified http URL string.
- * @exception WebdavException
- * @exception IOException
- * @see #setHttpUrl(HttpURL)
- * @see #setHttpUrl(java.net.URL)
- * @see #setUserInfo(java.lang.String, java.lang.String)
- * @see #setPath(java.lang.String)
- * @see #getURL()
- */
- public void setHttpUrl(String httpUrl)
- throws WebdavException, IOException {
-
- setHttpUrl(new HttpURL(httpUrl));
- }
-
-
- /**
- * Set the HttpURL of this WebdavResource.
- *
- * @param httpUrl the specified URL.
- * @exception WebdavException
- * @exception IOException
- * @see #setHttpUrl(HttpURL)
- * @see #setHttpUrl(java.lang.String)
- * @see #setUserInfo(java.lang.String, java.lang.String)
- * @see #setPath(java.lang.String)
- */
- public void setHttpUrl(URL url)
- throws WebdavException, IOException {
-
- setHttpUrl(url.toString());
- }
-
-
- /**
- * Set the path part of this WebdavResource.
- *
- * @param path the specified path.
- * @exception WebdavException
- * @exception IOException
- * @see #setHttpUrl(HttpURL)
- * @see #setHttpUrl(java.lang.String)
- * @see #setHttpUrl(java.net.URL)
- * @see #setUserInfo(java.lang.String, java.lang.String)
- */
- public void setPath(String path)
- throws WebdavException, IOException {
-
- httpUrl.setPath(path);
- setAllProp(httpUrl);
- }
-
-
- /**
- * Get the path part of this WebdavResource.
- *
- * @return the path for this WebdavResource.
- * @see #setPath(java.lang.String)
- */
- public String getPath() {
-
- return httpUrl.getPath();
- }
-
-
- /**
- * Get the hostname of this WebdavResource.
- *
- * @return the hostname.
- * @exception MalformedURLException
- */
- public String getHost() throws MalformedURLException {
-
- return httpUrl.getHost();
- }
-
-
- /**
- * Set the userinfo part of this WebdavResource.
- *
- * @exception MalformedURLException
- * @exception IOException
- * @see #setHttpUrl(HttpURL)
- * @see #setHttpUrl(java.lang.String)
- * @see #setHttpUrl(java.net.URL)
- * @see #setPath(java.lang.String)
- */
- public void setUserInfo(String userName, String password)
- throws WebdavException, IOException {
-
- httpUrl.setUserInfo(userName, password);
- setAllProp(httpUrl);
- }
-
-
- /**
- * Set the URL encoding flag for this http URL.
+ * Parse the <code>java.util.Date</code> string for HTTP-date.
*
- * @param encodeURLs true if it is encoded.
- * @exception MalformedURLException
- * @exception IOException
+ * @return The parsed date.
*/
- public void setEncodeURLs(boolean encodeURLs)
- throws MalformedURLException, IOException {
-
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
-
- State state = client.getState();
- if (state != null) {
- state.setEncodeURLs(encodeURLs);
- client.setState(state);
- WebdavSession.setSession(httpUrl, client);
+ private Date parseDate(String dateValue) {
+ // TODO: move to the common util package related to http.
+ Date date = null;
+ for (int i = 0; (date == null) && (i < formats.length); i++) {
+ try {
+ date = formats[i].parse(dateValue);
+ } catch (ParseException e) {
+ }
}
- }
-
- // ----------------------------------------------------------- Properties
+ return date;
+ }
/**
@@ -502,8 +382,8 @@
*/
private boolean getUsed() {
- if (httpUrl != null && httpUrlChecked != null)
- return httpUrlChecked.equals(httpUrl.toString());
+ if (httpURL != null && httpURLChecked != null)
+ return httpURLChecked.equals(httpURL.toString());
return false;
}
@@ -518,10 +398,10 @@
*/
private void setUsed() throws MalformedURLException {
- httpUrlChecked = httpUrl.toString();
+ httpURLChecked = httpURL.toString();
// Save the current session.
if (client != null)
- WebdavSession.setSession(httpUrl, client);
+ WebdavSession.setSession(httpURL, client);
client = null;
}
@@ -533,8 +413,7 @@
* @see #setUsed()
*/
private void setUnused() {
-
- httpUrlChecked = null;
+ httpURLChecked = null;
}
@@ -542,11 +421,11 @@
* Set WebDAV properties following to the given http URL.
* This method is fundamental for getting information of a collection.
*
- * @param httpUrl the parent http URL to get properties.
+ * @param httpURL the parent http URL to get properties.
* @exception WebdavException
* @exception IOException The socket error with a server.
*/
- private void setAllProp(HttpURL httpUrl)
+ private void setAllProp(HttpURL httpURL)
throws WebdavException, IOException {
// Let me do just once, do not repeat.
@@ -558,123 +437,118 @@
// Basically, get resources with depth 1.
Enumeration responses = propfindMethod(DepthSupport.DEPTH_1);
- // Prepare the hrefTable empty.
- hrefTable.clear();
+ // Make the resources in the collection empty.
+ children.removeAll();
while (responses.hasMoreElements()) {
ResponseEntity response =
(ResponseEntity) responses.nextElement();
boolean itself = false;
- String httpUrlPath = httpUrl.getPath();
+ String httpURLPath = httpURL.getPath();
String href = (String) response.getHref();
String hrefPath = HttpURL.getPath(href);
- int compared = httpUrlPath.compareTo(hrefPath);
+ int compared = httpURLPath.compareTo(hrefPath);
// Compare with the href path and requested-path itself.
if (compared == 0 || compared == -1 && hrefPath.endsWith("/") ||
- compared == 1 && httpUrlPath.endsWith("/")) {
+ compared == 1 && httpURLPath.endsWith("/")) {
if (response.getStatusCode() > 0)
setStatusCode(response.getStatusCode());
- exists = true;
+ setExistence(true);
itself = true;
}
- // Table for the href and its properties
- Hashtable hrefProperties = new Hashtable();
+ // Get to know each resource.
+ WebdavResource workingResource = new WebdavResource();
+ String displayName = null;
+ // Process the resource's properties
Enumeration properties = response.getProperties();
while (properties.hasMoreElements()) {
Property property = (Property) properties.nextElement();
-
// ------------------------------ Checking WebDAV properties
if (property.getLocalName().equals(DISPLAYNAME)) {
- String displayName = property.getPropertyAsString();
- if (!itself) {
- hrefProperties.put(DISPLAYNAME, displayName);
- } else {
- this.displayName = displayName;
- }
+ displayName = property.getPropertyAsString();
+ if (itself) {
+ setDisplayName(displayName);
+ displayName = ".";
+ } else {
+ workingResource.setHttpURL
+ (httpURL, displayName, false);
+ }
+ workingResource.setExistence(true);
+ workingResource.setOverwrite(getOverwrite());
+ workingResource.setDisplayName(displayName);
} else
if (property.getLocalName().equals(GETCONTENTLENGTH)) {
String getContentLength = property.getPropertyAsString();
- if (!itself) {
- hrefProperties.put
- (GETCONTENTLENGTH, getContentLength);
- } else {
- this.getContentLength = getContentLength;
+ if (itself) {
+ setGetContentLength(getContentLength);
}
+
workingResource.setGetContentLength(getContentLength);
} else
if (property.getLocalName().equals(RESOURCETYPE)) {
ResourceTypeProperty resourceType =
(ResourceTypeProperty) property;
- if (!itself) {
- hrefProperties.put(RESOURCETYPE, resourceType);
- } else {
- this.resourceType = resourceType;
+ if (itself) {
+ setResourceType(resourceType);
}
+ workingResource.setResourceType(resourceType);
} else
if (property.getLocalName().equals(GETCONTENTTYPE)) {
String getContentType = property.getPropertyAsString();
- if (!itself) {
- hrefProperties.put(GETCONTENTTYPE, getContentType);
- } else {
- this.getContentType = getContentType;
+ if (itself) {
+ setGetContentType(getContentType);
}
+
workingResource.setGetContentType(getContentType);
} else
if (property.getLocalName().equals(GETLASTMODIFIED)) {
String getLastModified = property.getPropertyAsString();
- if (!itself) {
- hrefProperties.put(GETLASTMODIFIED, getLastModified);
- } else {
- this.getLastModified = getLastModified;
+ if (itself) {
+ setGetLastModified(getLastModified);
}
+
workingResource.setGetLastModified(getLastModified);
} else
if (property.getLocalName().equals(CREATIONDATE)) {
String creationDate = property.getPropertyAsString();
- if (!itself) {
- hrefProperties.put(CREATIONDATE, creationDate);
- } else {
- this.creationDate = creationDate;
+ if (itself) {
+ setCreationDate(creationDate);
}
+ workingResource.setCreationDate(creationDate);
} else
if (property.getLocalName().equals(GETETAG)) {
String getEtag = property.getPropertyAsString();
- if (!itself) {
- hrefProperties.put(GETETAG, getEtag);
- } else {
- this.getEtag = getEtag;
+ if (itself) {
+ setGetEtag(getEtag);
}
+ workingResource.setGetEtag(getEtag);
} else
if (property.getLocalName().equals(ISHIDDEN)) {
String isHidden = property.getPropertyAsString();
- if (!itself) {
- hrefProperties.put(ISHIDDEN, isHidden);
- } else {
- this.isHidden = isHidden;
+ if (itself) {
+ setIsHidden(isHidden);
}
+ workingResource.setIsHidden(isHidden);
} else
if (property.getLocalName().equals(ISCOLLECTION)) {
String isCollection = property.getPropertyAsString();
- if (!itself) {
- hrefProperties.put(ISCOLLECTION, isCollection);
- } else {
- this.isCollection = isCollection;
+ if (itself) {
+ setIsCollection(isCollection);
}
+ workingResource.setIsCollection(isCollection);
} else
if (property.getLocalName().equals(SUPPORTEDLOCK)) {
String supportedLock = property.getPropertyAsString();
- if (!itself) {
- hrefProperties.put(SUPPORTEDLOCK, supportedLock);
- } else {
- this.supportedLock = supportedLock;
+ if (itself) {
+ setSupportedLock(supportedLock);
}
+
workingResource.setSupportedLock(supportedLock);
}
}
- if (!itself)
- hrefTable.put(href, hrefProperties);
+ children.addResource(displayName, workingResource);
}
// The given http URL checked.
@@ -682,25 +556,241 @@
}
+ // ----------------------------------------------- HttpURL Public Methods
+
+
+ /**
+ * Set the HttpURL for this WebdavResource.
+ *
+ * @param httpURL the specified HttpURL.
+ * @param action To profind or not.
+ * @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)
+ */
+ private void setHttpURL(HttpURL httpURL, boolean action)
+ throws WebdavException, IOException {
+
+ this.httpURL = httpURL;
+ if (action) {
+ setAllProp(httpURL);
+ }
+ }
+
+
+ /**
+ * Set the HttpURL for this WebdavResource.
+ *
+ * @param httpURL The specified HttpURL.
+ * @param path The added relative path.
+ * @param action To profind or not.
+ * @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)
+ */
+ private void setHttpURL
+ (HttpURL httpURL, String path, boolean action)
+ throws WebdavException, IOException {
+
+ this.httpURL = new HttpURL(httpURL, path);
+ if (action) {
+ setAllProp(this.httpURL);
+ }
+ }
+
+
+ /**
+ * Set the HttpURL for this WebdavResource.
+ *
+ * @param httpURL The specified HttpURL.
+ * @param path The added relative path.
+ * @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 path)
+ throws WebdavException, IOException {
+
+ setHttpURL(httpURL, path, true);
+ }
+
+
+ /**
+ * Set the HttpURL for this WebdavResource.
+ *
+ * @param httpURL the specified HttpURL.
+ * @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)
+ throws WebdavException, IOException {
+
+ setHttpURL(httpURL, true);
+ }
+
+
+ /**
+ * Set the HttpURL of this WebdavResource.
+ *
+ * @param httpURL the specified http URL string.
+ * @exception WebdavException
+ * @exception IOException
+ * @see #setHttpURL(HttpURL)
+ * @see #setHttpURL(java.net.URL)
+ * @see #setUserInfo(java.lang.String, java.lang.String)
+ * @see #setPath(java.lang.String)
+ */
+ public void setHttpURL(String httpURL)
+ throws WebdavException, IOException {
+
+ setHttpURL(new HttpURL(httpURL));
+ }
+
+
+ /**
+ * Get the HttpURL of this WebdavResource.
+ *
+ * @return httpURL the http URL.
+ */
+ public HttpURL getHttpURL() {
+ return httpURL;
+ }
+
+
/**
+ * Get the HttpURL except for userinfo.
+ *
+ * @return httpURL the http URL.
+ */
+ public HttpURL getHttpURLExceptForUserInfo()
+ throws MalformedURLException {
+
+ return httpURL.getHttpURLExceptForUserInfo();
+ }
+
+
+ /**
+ * Set the path part of this WebdavResource.
+ *
+ * @param path the specified path.
+ * @exception WebdavException
+ * @exception IOException
+ * @see #setHttpURL(HttpURL)
+ * @see #setHttpURL(java.lang.String)
+ * @see #setHttpURL(java.net.URL)
+ * @see #setUserInfo(java.lang.String, java.lang.String)
+ */
+ public void setPath(String path)
+ throws WebdavException, IOException {
+
+ httpURL.setPath(path);
+ setAllProp(httpURL);
+ }
+
+
+ /**
+ * Get the path part of this WebdavResource.
+ *
+ * @return the path for this WebdavResource.
+ * @see #setPath(java.lang.String)
+ */
+ public String getPath() {
+ return httpURL.getPath();
+ }
+
+
+ /**
+ * Get the hostname of this WebdavResource.
+ *
+ * @return the hostname.
+ * @exception MalformedURLException
+ */
+ public String getHost() throws MalformedURLException {
+ return httpURL.getHost();
+ }
+
+
+ /**
+ * Set the userinfo part of this WebdavResource.
+ *
+ * @exception MalformedURLException
+ * @exception IOException
+ * @see #setHttpURL(HttpURL)
+ * @see #setHttpURL(java.lang.String)
+ * @see #setHttpURL(java.net.URL)
+ * @see #setPath(java.lang.String)
+ */
+ public void setUserInfo(String userName, String password)
+ throws WebdavException, IOException {
+
+ httpURL.setUserInfo(userName, password);
+ setAllProp(httpURL);
+ }
+
+
+ // ---------------------------------------- WebDAV Property Public Methods
+
+
+ /**
* Get the value of DAV property, displayname.
*
* @return The displayname string.
*/
public String getDisplayName() {
-
return displayName;
}
/**
+ * Set the value of DAV property, displayname.
+ *
+ * @param displayName The displayname string.
+ */
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+
+ /**
* Get the value of DAV property, getcontentlength.
*
- * @return The getcontentlength string.
+ * @return The getcontentlength value.
*/
public long getGetContentLength() {
+ return getContentLength;
+ }
+
+
+ /**
+ * Set the value of DAV property, getcontentlength.
+ *
+ * @param getContentLength The getcontentlength value.
+ */
+ public void setGetContentLength(long getContentLength) {
+ this.getContentLength = getContentLength;
+ }
+
- return Long.parseLong(getContentLength);
+ /**
+ * Set the value of DAV property, getcontentlength.
+ *
+ * @param getContentLength The getcontentlength value.
+ */
+ public void setGetContentLength(String getContentLength) {
+ this.getContentLength = Long.parseLong(getContentLength);
}
@@ -711,12 +801,21 @@
* @see #isCollection()
*/
public ResourceTypeProperty getResourceType() {
-
return resourceType;
}
/**
+ * Set the value of DAV property, resourcetype.
+ *
+ * @param resourceType The resourcetype property.
+ */
+ public void setResourceType(ResourceTypeProperty resourceType) {
+ this.resourceType = resourceType;
+ }
+
+
+ /**
* Get the value of DAV property, resourcetype
*
* @return The resourcetype string.
@@ -724,7 +823,6 @@
* @see #getIsCollection()
*/
public boolean isCollection() {
-
return getResourceType().isCollection();
}
@@ -735,40 +833,50 @@
* @return The getcontenttype string.
*/
public String getGetContentType() {
-
return getContentType;
}
/**
+ * Set the value of DAV property, getcontenttype.
+ *
+ * @param getContentType The getcontenttype string.
+ */
+ public void setGetContentType(String getContentType) {
+ this.getContentType = getContentType;
+ }
+
+
+ /**
* Get the value of DAV property, getlastmodified.
*
* @return The getlastmodified value.
*/
public long getGetLastModified() {
-
- Date date = parseDate(getLastModified);
-
- return date.getTime();
+ return getLastModified;
}
/**
- * Parse the <code>java.util.Date</code> string for HTTP-date.
+ * Set the value of DAV property, getlastmodified.
*
- * @return The parsed date.
+ * @param getLastModified The getlastmodified value.
+ * @see #setGetLastModified(java.lang.String)
*/
- public Date parseDate(String dateValue) {
+ public void setGetLastModified(long getLastModified) {
+ this.getLastModified = getLastModified;
+ }
- Date date = null;
- for (int i = 0; (date == null) && (i < formats.length); i++) {
- try {
- date = formats[i].parse(dateValue);
- } catch (ParseException e) {
- }
- }
- return date;
+ /**
+ * Set the value of DAV property, getlastmodified.
+ *
+ * @param getLastModified The getlastmodified value.
+ * @see #setGetLastModified(long)
+ */
+ public void setGetLastModified(String getLastModified) {
+ Date date = parseDate(getLastModified);
+ this.getLastModified = date.getTime();
}
@@ -777,42 +885,99 @@
*
* @return The creationdate string.
*/
- public String getCreationDate() {
-
+ public long getCreationDate() {
return creationDate;
}
/**
+ * Set the value of DAV property, creationdate.
+ *
+ * @param creationDate The creationdate string.
+ */
+ public void setCreationDate(long creationDate) {
+ this.creationDate = creationDate;
+ }
+
+
+ /**
+ * Set the value of DAV property, creationdate.
+ *
+ * @param creationDate The creationdate string.
+ */
+ public void setCreationDate(String creationDate) {
+ Date date = parseDate(creationDate);
+ this.creationDate = date.getTime();
+ }
+
+
+ /**
* Get the value of DAV property, getetag.
*
* @return The getetag string.
*/
public String getGetEtag() {
-
return getEtag;
}
/**
+ * Set the value of DAV property, getetag.
+ *
+ * @param getEtag The getetag string.
+ */
+ public void setGetEtag(String getEtag) {
+ this.getEtag = getEtag;
+ }
+
+
+ /**
* Get the value of DAV property, supportedlock.
*
* @return The supportedlock string.
*/
public String getSupportedLock() {
-
return supportedLock;
}
/**
+ * Set the value of DAV property, supportedlock.
+ *
+ * @param supportedLock The supportedlock string.
+ */
+ public void setSupportedLock(String supportedLock) {
+ this.supportedLock = supportedLock;
+ }
+
+
+ /**
* Get the value of DAV property, ishidden.
*
* @return true if it is hidden, otherwise false.
*/
public boolean getIsHidden() {
+ return isHidden;
+ }
+
- return isHidden.equals("1") ? true : false;
+ /**
+ * Set the value of DAV property, ishidden.
+ *
+ * @param isHidden
+ */
+ public void setIsHidden(boolean isHidden) {
+ this.isHidden = isHidden;
+ }
+
+
+ /**
+ * Set the value of DAV property, ishidden.
+ *
+ * @param isHidden
+ */
+ public void setIsHidden(String isHidden) {
+ this.isHidden = isHidden.equals(TRUE) ? true : false;
}
@@ -820,25 +985,74 @@
* Get the value of DAV property, iscollection
*
* @return true if it is collection, otherwise false.
- *
* @see #isCollection()
*/
public boolean getIsCollection() {
+ return isCollection;
+ }
+
+
+ /**
+ * Set the value of DAV property, iscollection
+ *
+ * @param isCollection
+ */
+ public void setIsCollection(boolean isCollection) {
+ this.isCollection = isCollection;
+ }
+
- return isCollection.equals("1") ? true : false;
+ /**
+ * Set the value of DAV property, iscollection
+ *
+ * @param isCollection
+ */
+ public void setIsCollection(String isCollection) {
+ this.isCollection = isCollection.equals(TRUE) ? true : false;
}
- // ------------------------------------- WebdavResource getter and setter
+ // --------------------------------------- WebDAV Resource Public Methods
+ /*
+ * Test if it exists.
+ * This is a wrapper method for getExistence.
+ *
+ * @return true if it exists.
+ * @see #getExistence(boolean)
+ */
+ public boolean exists() {
+ return getExistence();
+ }
+
+
+ /*
+ * Set its existence.
+ *
+ * @param exists The boolean value to be set for its existence.
+ */
+ public void setExistence(boolean exists) {
+ exists = exists;
+ }
+
+
+ /*
+ * Get its existence.
+ *
+ * @return true if it exists.
+ */
+ public boolean getExistence() {
+ return exists;
+ }
+
+
/**
* Set the overwrite flag for PUT method
*
* @return true if it ok with overwriting.
*/
public void setOverwrite(boolean overwrite) {
-
this.overwrite = overwrite;
}
@@ -849,7 +1063,6 @@
* @return true if the current flag is overwriting.
*/
public boolean getOverwrite() {
-
return overwrite;
}
@@ -858,8 +1071,7 @@
* Close the session of this client
*/
public void close() throws IOException {
-
- WebdavSession.unsetSession(httpUrl);
+ WebdavSession.unsetSession(httpURL);
}
@@ -870,7 +1082,6 @@
* @see #setStatusCode()
*/
public String getStatusMessage() {
-
return latestStatusMessage;
}
@@ -884,7 +1095,6 @@
* @see #setStatusMessage(int, java.lang.String)
*/
public int getStatusCode() {
-
return latestStatusCode;
}
@@ -897,7 +1107,6 @@
* @see #setStatusMessage(int, java.lang.String)
*/
public void setStatusCode(int statusCode) {
-
setStatusCode(statusCode, null);
}
@@ -922,21 +1131,43 @@
}
+ /**
+ * Get the allowed methods, checked by HTTP OPTIONS.
+ *
+ * @return the allowed HTTP methods.
+ * @see #optionsMethod(java.lang.String)
+ */
+ public Enumeration getAllowedMethods() {
+ return allowedMethods;
+ }
+
+
+ /**
+ * Get the WebDAV capabilities, checked by HTTP OPTIONS.
+ *
+ * @return the WebDAV capabilities.
+ * @see #optionsMethod(java.lang.String)
+ */
+ public Enumeration getDavCapabilities() {
+ return davCapabilities;
+ }
+
+
/*
- * Get all href information table.
+ * Get all resources in this collection with the depth 1.
*
- * @return the table for href and WebDAV properties.
+ * @return resources in this collection with the depth 1.
* @exception WebdavException
* @exception IOException
*/
- public Hashtable getHrefTable()
+ public WebdavResources getChildren()
throws WebdavException, IOException {
// Check If the http URl is changed.
if (!getUsed())
- setAllProp(httpUrl);
+ setAllProp(httpURL);
- return hrefTable;
+ return children;
}
@@ -952,18 +1183,19 @@
throws WebdavException, IOException {
if (!getUsed())
- setAllProp(httpUrl);
-
- Enumeration hrefs = hrefTable.keys();
- Vector hrefList = new Vector();
- while (hrefs.hasMoreElements()) {
- hrefList.addElement((String) hrefs.nextElement());
- }
+ setAllProp(httpURL);
- int count = hrefList.size();
- String[] pathnames = new String[count];
- for (int i = 0; i < count; i++) {
- pathnames[i] = HttpURL.getName((String) hrefList.elementAt(i));
+ Enumeration hrefs = children.getResourceNames();
+ // To be atomic.
+ Vector hrefList = new Vector();
+ while (hrefs.hasMoreElements()) {
+ hrefList.addElement((String) hrefs.nextElement());
+ }
+ // Calculate the size of the string array.
+ int num = hrefList.size();
+ String[] pathnames = new String[num];
+ for (int i = 0; i < num; i++) {
+ pathnames[i] = (String) hrefList.elementAt(i);
}
return pathnames;
@@ -971,43 +1203,56 @@
/*
- * Get an array of pathnames denoting the WebDAV resources in the
- * collection denoted by this pathname.
+ * Get an array of pathnames and basic information denoting the WebDAV
+ * resources in the denoted by this pathname.
*
- * @return An array of pathnames denoting the resources.
+ * array 0: displayname
+ * array 1: getcontentlength
+ * array 2: iscollection or getcontentype
+ * array 3: getlastmodifieddate
+ *
+ * @return An array of pathnames and more denoting the resources.
* @exception WebdavException
* @exception IOException
*/
- public Vector listCollection()
+ public Vector listInDetail()
throws WebdavException, IOException {
// If information for listing is changed, go for it.
if (!getUsed())
- setAllProp(httpUrl);
+ setAllProp(httpURL);
- Enumeration hrefs = hrefTable.keys();
+ Enumeration hrefs = children.getResourceNames();
Vector hrefList = new Vector();
while (hrefs.hasMoreElements()) {
try {
- String hrefKey = (String) hrefs.nextElement();
- Hashtable pairProperties = (Hashtable) hrefTable.get(hrefKey);
+ String resourceName = (String) hrefs.nextElement();
+ WebdavResource currentResource =
+ children.getResource(resourceName);
+
String[] longFormat = new String[4];
- longFormat[0] = (String) pairProperties.get(DISPLAYNAME);
- String length = (String) pairProperties.get(GETCONTENTLENGTH);
- longFormat[1] = (length == null) ? "" : length;
+ // displayname.
+ longFormat[0] = currentResource.getDisplayName();
+
+ long length = currentResource.getGetContentLength();
+ // getcontentlength
+ longFormat[1] = new Long(length).toString();
ResourceTypeProperty resourceTypeProperty =
- (ResourceTypeProperty) pairProperties.get(RESOURCETYPE);
+ currentResource.getResourceType();
String getContentType =
- (String) pairProperties.get(GETCONTENTTYPE);
+ currentResource.getGetContentType();
+ // iscollection
longFormat[2] = resourceTypeProperty.isCollection() ?
"COLLECTION" : getContentType ;
- String getLastModified =
- (String) pairProperties.get(GETLASTMODIFIED);
- Date date = parseDate(getLastModified);
- longFormat[3] = (date == null) ? getLastModified :
- DateFormat.getDateTimeInstance().format(date);
+ Date date = new
Date(currentResource.getGetLastModified());
+ // getlastmodified
+ // Save the dummy what if failed.
+ longFormat[3] = (date == null) ? "-- -- ----" :
+ // Print the local fancy date format.
+ DateFormat.getDateTimeInstance().format(date);
hrefList.addElement(longFormat);
} catch (Exception e) {
+ // FIXME: After if's gotten an exception, any solution?
// e.printStackTrace();
}
}
@@ -1017,41 +1262,27 @@
/**
- * Get the allowed methods, checked by HTTP OPTIONS.
- *
- * @return the allowed HTTP methods.
- * @see #optionsMethod(java.lang.String)
- */
- public Enumeration getAllowedMethods() {
-
- return allowedMethods;
- }
-
-
- /**
- * Get the WebDAV capabilities, checked by HTTP OPTIONS.
+ * Set the URL encoding flag for this http URL.
*
- * @return the WebDAV capabilities.
- * @see #optionsMethod(java.lang.String)
+ * @param encodeURLs true if it is encoded.
+ * @exception MalformedURLException
+ * @exception IOException
*/
- public Enumeration getDavCapabilities() {
-
- return davCapabilities;
- }
+ public void setEncodeURLs(boolean encodeURLs)
+ throws MalformedURLException, IOException {
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
- /*
- * Check whether httpUrl exists
- *
- * @return true if it exists.
- */
- public boolean exists() {
-
- return exists;
+ State state = client.getState();
+ if (state != null) {
+ state.setEncodeURLs(encodeURLs);
+ client.setState(state);
+ WebdavSession.setSession(httpURL, client);
+ }
}
- // ------------------------------------------------------ WebDAV methods
+ // --------------------------------- WebDAV Request-method Public Methods
/*
@@ -1065,10 +1296,10 @@
public InputStream getInputStream(String tempDir)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
// use disk to save by default
- GetMethod method = new GetMethod(httpUrl.getPath(), tempDir);
+ GetMethod method = new GetMethod(httpURL.getPath(), tempDir);
client.executeMethod(method);
InputStream is = method.getData();
@@ -1106,10 +1337,10 @@
FileOutputStream fos = null;
GetMethod method = null;
try {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
// use disk to save by default
- String source = httpUrl.getPath();
+ String source = httpURL.getPath();
method = new GetMethod(source, tempDir, tempFile);
client.executeMethod(method);
@@ -1159,7 +1390,7 @@
public boolean getMethod(File file)
throws WebdavException, IOException {
- return getMethod(httpUrl.getAbsPath(), file);
+ return getMethod(httpURL.getAbsPath(), file);
}
@@ -1175,7 +1406,7 @@
public boolean getMethod(String path, File file)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
// use disk to save by default
GetMethod method = new GetMethod(HttpURL.getAbsPath(path), file);
@@ -1199,7 +1430,7 @@
public boolean putMethod(String data)
throws WebdavException, IOException {
- return putMethod(httpUrl.getPath(), data);
+ return putMethod(httpURL.getPath(), data);
}
@@ -1215,7 +1446,7 @@
public boolean putMethod(String path, String data)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
PutMethod method = new PutMethod(HttpURL.getPath(path));
method.sendData(data);
@@ -1244,7 +1475,7 @@
public boolean putMethod(File file)
throws WebdavException, IOException {
- return putMethod(httpUrl.getPath(), file);
+ return putMethod(httpURL.getPath(), file);
}
@@ -1260,7 +1491,7 @@
public boolean putMethod(String path, File file)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
PutMethod method = new PutMethod(HttpURL.getPath(path));
method.sendData(file);
@@ -1288,7 +1519,7 @@
public boolean optionsMethod()
throws WebdavException, IOException {
- return optionsMethod(httpUrl.getPath());
+ return optionsMethod(httpURL.getPath());
}
@@ -1304,7 +1535,7 @@
public boolean optionsMethod(String path)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
OptionsMethod method;
if (path.trim().equals("*"))
@@ -1340,7 +1571,7 @@
public boolean optionsMethod(String path, String aMethod)
throws WebdavException, IOException {
- if (aMethod != null && optionsMethod(httpUrl.getPath())) {
+ if (aMethod != null && optionsMethod(httpURL.getPath())) {
while (allowedMethods.hasMoreElements()) {
if (aMethod.equalsIgnoreCase(
(String) allowedMethods.nextElement()))
@@ -1355,17 +1586,17 @@
/*
* Execute OPTIONS method for the given http URL.
*
- * @param httpUrl the http URL.
+ * @param httpURL the http URL.
* @return the allowed methods and capabilities.
* @exception WebdavException
* @exception IOException
*/
- public static Enumeration optionsMethod(HttpURL httpUrl)
+ public static Enumeration optionsMethod(HttpURL httpURL)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
- OptionsMethod method = new OptionsMethod(httpUrl.getPath());
+ OptionsMethod method = new OptionsMethod(httpURL.getPath());
client.executeMethod(method);
Vector options = new Vector();
@@ -1382,7 +1613,7 @@
options.addElement(davCapabilities.nextElement());
}
}
- WebdavSession.unsetSession(httpUrl);
+ WebdavSession.unsetSession(httpURL);
return options.elements();
}
@@ -1406,7 +1637,7 @@
public Enumeration propfindMethod(int depth)
throws WebdavException, IOException {
- return propfindMethod(httpUrl.getPath(), depth);
+ return propfindMethod(httpURL.getPath(), depth);
}
@@ -1429,7 +1660,7 @@
public Enumeration propfindMethod(String path, int depth)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
// Check the path alright.
path = HttpURL.getPath(path);
@@ -1462,7 +1693,7 @@
Vector property = new Vector();
property.addElement(propertyName);
- return propfindMethod(httpUrl.getPath(), property);
+ return propfindMethod(httpURL.getPath(), property);
}
@@ -1497,7 +1728,7 @@
public Enumeration propfindMethod(Vector properties)
throws WebdavException, IOException {
- return propfindMethod(httpUrl.getPath(), properties);
+ return propfindMethod(httpURL.getPath(), properties);
}
@@ -1514,7 +1745,7 @@
public Enumeration propfindMethod(String path, Vector properties)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(this.httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(this.httpURL);
// Check the path alright.
path = HttpURL.getPath(path);
@@ -1528,8 +1759,8 @@
// It contains the results.
Vector results = new Vector();
- HttpURL httpUrl = new HttpURL(this.httpUrl.getAuthority() + path);
- String href = httpUrl.toURL().toString();
+ HttpURL httpURL = new HttpURL(this.httpURL.getAuthority() + path);
+ String href = httpURL.toURL().toString();
Enumeration enum = method.getResponseProperties(href);
while (enum.hasMoreElements()) {
Property property = (Property) enum.nextElement();
@@ -1563,7 +1794,7 @@
throws WebdavException, IOException {
return proppatchMethod
- (httpUrl.getPath(), propertyName, propertyValue);
+ (httpURL.getPath(), propertyName, propertyValue);
}
@@ -1598,7 +1829,7 @@
public boolean proppatchMethod(Hashtable property)
throws WebdavException, IOException {
- return proppatchMethod(httpUrl.getPath(), property);
+ return proppatchMethod(httpURL.getPath(), property);
}
@@ -1614,7 +1845,7 @@
public boolean proppatchMethod(String path, Hashtable property)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
PropPatchMethod method = new PropPatchMethod(HttpURL.getPath(path));
Enumeration names = property.keys();
@@ -1656,7 +1887,7 @@
public boolean headMethod()
throws WebdavException, IOException {
- return headMethod(httpUrl.getPath());
+ return headMethod(httpURL.getPath());
}
@@ -1671,7 +1902,7 @@
public boolean headMethod(String path)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
HeadMethod method = new HeadMethod(HttpURL.getPath(path));
client.executeMethod(method);
@@ -1693,7 +1924,7 @@
public boolean deleteMethod()
throws WebdavException, IOException {
- return deleteMethod(httpUrl.getPath());
+ return deleteMethod(httpURL.getPath());
}
@@ -1708,7 +1939,7 @@
public boolean deleteMethod(String path)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
DeleteMethod method = new DeleteMethod(HttpURL.getPath(path));
client.executeMethod(method);
@@ -1736,7 +1967,7 @@
public boolean moveMethod(String destination)
throws WebdavException, IOException {
- return moveMethod(httpUrl.getPath(), HttpURL.getPath(destination));
+ return moveMethod(httpURL.getPath(), HttpURL.getPath(destination));
}
@@ -1752,7 +1983,7 @@
public boolean moveMethod(String source, String destination)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
MoveMethod method = new MoveMethod(source, destination);
client.executeMethod(method);
@@ -1799,7 +2030,7 @@
public boolean copyMethod(String source, String destination)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
CopyMethod method = new CopyMethod(source, destination);
client.executeMethod(method);
@@ -1829,7 +2060,7 @@
public boolean mkcolMethod()
throws WebdavException, IOException {
- return mkcolMethod(httpUrl.getPath());
+ return mkcolMethod(httpURL.getPath());
}
@@ -1844,7 +2075,7 @@
public boolean mkcolMethod(String path)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
MkcolMethod method = new MkcolMethod(HttpURL.getPath(path));
client.executeMethod(method);
@@ -1876,13 +2107,13 @@
throws WebdavException, IOException {
String owner = null;
- if (httpUrl.getUserName() != null) {
- owner = httpUrl.getUserName() + "@" + httpUrl.getHost();
+ if (httpURL.getUserName() != null) {
+ owner = httpURL.getUserName() + "@" + httpURL.getHost();
} else {
- owner = defaultOwner + "@" + httpUrl.getHost();
+ owner = defaultOwner + "@" + httpURL.getHost();
}
- return lockMethod(httpUrl.getPath(), owner, (short) 120);
+ return lockMethod(httpURL.getPath(), owner, (short) 120);
}
@@ -1899,7 +2130,7 @@
public boolean lockMethod(String owner, short timeout)
throws WebdavException, IOException {
- return lockMethod(httpUrl.getPath(), owner, (short) 120);
+ return lockMethod(httpURL.getPath(), owner, (short) 120);
}
@@ -1915,10 +2146,10 @@
throws WebdavException, IOException {
String owner = null;
- if (httpUrl.getUserName() != null) {
- owner = httpUrl.getUserName() + "@" + httpUrl.getHost();
+ if (httpURL.getUserName() != null) {
+ owner = httpURL.getUserName() + "@" + httpURL.getHost();
} else {
- owner = defaultOwner + "@" + httpUrl.getHost();
+ owner = defaultOwner + "@" + httpURL.getHost();
}
return lockMethod(path, owner, (short) 120);
@@ -1938,7 +2169,7 @@
public boolean lockMethod(String path, String owner, short timeout)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
// default lock type setting
short lockType = LockMethod.SCOPE_EXCLUSIVE;
@@ -1958,7 +2189,7 @@
setStatusCode(statusCode, lock);
if (statusCode >= 200 && statusCode < 300) {
client.setState(state);
- WebdavSession.setSession(httpUrl, client);
+ WebdavSession.setSession(httpURL, client);
return true;
}
@@ -1976,7 +2207,7 @@
public boolean unlockMethod()
throws WebdavException, IOException {
- return unlockMethod(httpUrl.getPath());
+ return unlockMethod(httpURL.getPath());
}
@@ -1991,7 +2222,7 @@
public boolean unlockMethod(String path)
throws WebdavException, IOException {
- WebdavClient client = WebdavSession.getSessionInstance(httpUrl);
+ WebdavClient client = WebdavSession.getSessionInstance(httpURL);
// Get the lock for the given path.
State state = client.getState();
@@ -2016,7 +2247,7 @@
if (statusCode >= 200 && statusCode < 300) {
state.removeLocks(path);
client.setState(state);
- WebdavSession.setSession(httpUrl, client);
+ WebdavSession.setSession(httpURL, client);
return true;
}
@@ -2024,7 +2255,7 @@
}
- // -------------------------------------------------------------- Methods
+ // -------------------------------------------------------- Basic Methods
/*
@@ -2035,37 +2266,32 @@
*/
public int compareToWebdavResource(WebdavResource another) {
- try {
- URL anotherUrl = another.getURL();
- String thisHost = httpUrl.getHost();
- String anotherHost= anotherUrl.getHost();
- if (!thisHost.equalsIgnoreCase(anotherHost))
- return thisHost.compareTo(anotherHost);
-
- int thisPort = httpUrl.getPort();
- int anotherPort= anotherUrl.getPort();
- if (anotherPort == -1)
- anotherPort = 80;
- if (thisPort != anotherPort)
- return (thisPort < anotherPort) ? -1 : 1;
-
- boolean thisCollection = isCollection();
- boolean anotherCollection = another.isCollection();
- if (thisCollection && !anotherCollection)
- return -1;
- if (anotherCollection && !thisCollection)
- return 1;
-
- String thisPath = httpUrl.getPath();
- String anotherPath= anotherUrl.getFile();
- if (anotherPath == null)
- anotherPath = "/";
- return thisPath.compareTo(anotherPath);
+ try {
+ HttpURL anotherUrl = another.getHttpURL();
- // TODO: consider of more dead properties?
- } catch (IOException e) {
- // e.printStackTrace();
- }
+ String thisHost = httpURL.getHost();
+ String anotherHost= anotherUrl.getHost();
+ if (!thisHost.equalsIgnoreCase(anotherHost))
+ return thisHost.compareTo(anotherHost);
+
+ int thisPort = httpURL.getPort();
+ int anotherPort= anotherUrl.getPort();
+ if (thisPort != anotherPort)
+ return (thisPort < anotherPort) ? -1 : 1;
+
+ boolean thisCollection = isCollection();
+ boolean anotherCollection = another.isCollection();
+ if (thisCollection && !anotherCollection)
+ return -1;
+ if (anotherCollection && !thisCollection)
+ return 1;
+
+ String thisPath = httpURL.getAbsPath();
+ String anotherPath= anotherUrl.getAbsPath();
+ return thisPath.compareTo(anotherPath);
+ } catch (Exception e) {
+ // FIXME: not to return 0.
+ }
return 0;
}
@@ -2111,7 +2337,6 @@
* @return the http URL string.
*/
public String toString() {
-
- return httpUrl.toString();
+ return httpURL.toString();
}
}
1.6 +15 -3
jakarta-slide/src/webdav/client/src/org/apache/webdav/util/HttpURL.java
Index: HttpURL.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/HttpURL.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HttpURL.java 2001/03/21 02:18:42 1.5
+++ HttpURL.java 2001/03/26 11:08:29 1.6
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/HttpURL.java,v
1.5 2001/03/21 02:18:42 jericho Exp $
- * $Revision: 1.5 $
- * $Date: 2001/03/21 02:18:42 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/HttpURL.java,v
1.6 2001/03/26 11:08:29 jericho Exp $
+ * $Revision: 1.6 $
+ * $Date: 2001/03/26 11:08:29 $
*
* ====================================================================
*
@@ -118,6 +118,18 @@
super(scheme, host, port, path);
setDefaultScheme(scheme);
setDefaultPort(port);
+ }
+
+
+ /**
+ * This Constructor
+ *
+ * @param httpUrl The http URL.
+ * @param path The added relative path.
+ */
+ public HttpURL(HttpURL httpUrl, String path) {
+
+ this(httpUrl.toString() + path);
}
1.1
jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResources.java
Index: WebdavResources.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResources.java,v
1.1 2001/03/26 11:08:28 jericho Exp $
* $Revision: 1.1 $
* $Date: 2001/03/26 11:08:28 $
*
* ====================================================================
*
* 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.util;
import java.util.Hashtable;
import java.util.Enumeration;
/**
* This WebdavResources class represents WebDAV resources in a collection.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Park, Sung-Gu</a>
*/
public class WebdavResources {
// --------------------------------------------------------- Constructors
/**
* Default constuctor.
*/
public WebdavResources() {
}
/**
* This constuctor.
*
* @param resource A resource to add.
*/
public WebdavResources(WebdavResource resource) {
addResource(resource);
}
// --------------------------------------------------- Instance Variables
/**
* The resources for each href and its properties.
*/
Hashtable hrefTable = new Hashtable();
// ------------------------------------------------------- Public Methods
/**
* Get the number of WebDAV resources for the current collection.
*
* @return the number of resources.
*/
public int size() {
return hrefTable.size();
}
/**
* Test if there is no resource.
*
* @return true if it's empty.
*/
public boolean isEmpty() {
return hrefTable.isEmpty();
}
/**
* Test if there is a resource called the specified resource name.
*
* @param
*/
public boolean isThereResourceName(String resourceName) {
return hrefTable.containsKey(resourceName) ? true : false;
}
/**
* Test if there is a resource.
*
* @param resource The specified resource.
* @return true if it exists.
*/
public boolean isThereResource(WebdavResource resource) {
return hrefTable.contains(resource) ? true : false;
}
/**
* Get an enumeration of the resource names.
*
* @return An enumeration of the resource names.
*/
public Enumeration getResourceNames() {
return hrefTable.keys();
}
/**
* Get an enumeration of the resources.
*
* @return An enumeration of resources.
*/
public Enumeration getResources() {
return hrefTable.elements();
}
/**
* Get an resource.
*
* @param resourceName The resource name.
* @return The wanted resource if it exists.
*/
public WebdavResource getResource(String resourceName) {
return (WebdavResource) hrefTable.get(resourceName);
}
/**
* Maps the resource name to its resource.
* The resource name could be different from the displayname property.
* It's useful for representing itself or parent collection.
*
* @param resourceName The resource name.
* @param resource The resource.
* @see #addWebdavResource(WebdavResource)
*/
public void addResource(String resourceName, WebdavResource resource) {
hrefTable.put(resourceName, resource);
}
/**
* Add the specified resource.
*
* @param resource The resource to add.
*/
public void addResource(WebdavResource resource) {
hrefTable.put(resource.getDisplayName(), resource);
}
/**
* Remove the specified resource name.
*
* @param resourceName The specified resource name.
* @return The wanted resource.
*/
public WebdavResource removeResource(String resourceName) {
return (WebdavResource) hrefTable.remove(resourceName);
}
/**
* Remove all resources.
*/
public void removeAll() {
hrefTable.clear();
}
}