Hi Antoine.
The three methods of WebdavResource where this change needs to be made are:
propfindMethod(String, int)
propfindMethod(String, int, Vector)
propfindMethod(String, Vector)
The code with the updates is below. For what its worth, my Slide-client based
code is working without a hitch with the changes. Also, once I re-code
sections of my app to take advantage of the now-working exists() function, my
code should also run faster (since I can determine whether a file exists or not
without possibly incurring exception throw/catch overhead).
Cheers!
Mike N. Christoff
---------------
/**
* Execute PROPFIND method with allprop for the given path.
* Get list of all WebDAV properties on the given resource.
*
* <p>Once used this method, the the status code in the 207
* reponse is need to be set for the method of WebdavResource.
*
* <p>The values of DepthSupport.DEPTH_0, DepthSupport.DEPTH_1,
* DepthSupport.DEPTH_INFINITY is possbile for the depth.
*
* @param path the server relative path of the resource to request
* @param depth
* @return an enumeration of <code>ResponseEntity</code>
* @exception HttpException
* @exception IOException
*/
public Enumeration propfindMethod(String path, int depth)
throws HttpException, IOException {
setClient();
// Change the depth for allprop
PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
depth);
method.setDebug(debug);
// Default depth=infinity, type=allprop
generateTransactionHeader(method);
int status = client.executeMethod(method);
// Set status code for this resource.
if (thisResource == true) {
setStatusCode(status);
}
// Also accept OK sent by buggy servers.
/**
* OLD CODE
if (status != HttpStatus.SC_MULTI_STATUS
&& status != HttpStatus.SC_OK) {
HttpException ex = new HttpException();
ex.setReasonCode(status);
throw ex;
}
*/
// FIX
if (status != HttpStatus.SC_MULTI_STATUS
&& status != HttpStatus.SC_NOT_FOUND // <---
&& status != HttpStatus.SC_OK
) {
HttpException ex = new HttpException();
ex.setReasonCode(status);
throw ex;
}
// END FIX
thisResource = false;
return method.getResponses();
}
public Enumeration propfindMethod(String path, int depth,
Vector properties)
throws HttpException, IOException {
setClient();
// Change the depth for prop
PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
depth,
properties.elements());
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
generateTransactionHeader(method);
int status = client.executeMethod(method);
// Set status code for this resource.
if (thisResource == true) {
// Set the status code.
setStatusCode(method.getStatusLine().getStatusCode());
}
// Also accept OK sent by buggy servers.
/*
* OLD CODE
*
if (status != HttpStatus.SC_MULTI_STATUS
&& status != HttpStatus.SC_OK) {
HttpException ex = new HttpException();
ex.setReasonCode(status);
throw ex;
}
*/
// FIX
if (status != HttpStatus.SC_MULTI_STATUS
&& status != HttpStatus.SC_NOT_FOUND // <---
&& status != HttpStatus.SC_OK) {
HttpException ex = new HttpException();
ex.setReasonCode(status);
throw ex;
}
// END FIX
thisResource = false;
return method.getResponses();
}
/**
* Execute PROPFIND method for the given path and properties.
* Get list of given WebDAV properties on the given resource.
*
* @param path the server relative path of the resource to request
* @param properties the WebDAV properties to find.
* @return Enumeration list of WebDAV properties on a resource.
* @exception HttpException
* @exception IOException
*/
public Enumeration propfindMethod(String path, Vector properties)
throws HttpException, IOException {
setClient();
// Default depth=0, type=by_name
PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
DepthSupport.DEPTH_0,
properties.elements());
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
generateTransactionHeader(method);
int status = client.executeMethod(method);
// Also accept OK sent by buggy servers.
/*
* OLD CODE
*
if (status != HttpStatus.SC_MULTI_STATUS
&& status != HttpStatus.SC_OK) {
HttpException ex = new HttpException();
ex.setReasonCode(status);
throw ex;
}
*/
// FIX
if (status != HttpStatus.SC_MULTI_STATUS
&& status != HttpStatus.SC_NOT_FOUND // <---
&& status != HttpStatus.SC_OK) {
HttpException ex = new HttpException();
ex.setReasonCode(status);
throw ex;
}
// END FIX
// It contains the results.
Vector results = new Vector();
Enumeration responses = method.getResponses();
if (responses.hasMoreElements()) {
ResponseEntity response =
(ResponseEntity) responses.nextElement();
String href = response.getHref();
// Set status code for this resource.
if ((thisResource == true) && (response.getStatusCode() > 0))
setStatusCode(response.getStatusCode());
thisResource = false;
Enumeration responseProperties =
method.getResponseProperties(href);
while (responseProperties.hasMoreElements()) {
Property property =
(Property) responseProperties.nextElement();
results.addElement(property.getPropertyAsString());
}
}
return results.elements();
}
Cheers!
-mike
-----Original Message-----
From: Antoine Levy-Lambert [mailto:[EMAIL PROTECTED]
Sent: February 13, 2007 10:37 PM
To: Slide Developers Mailing List
Subject: Re: Possible solutions to WebdavResource.exists() method
Hello Michael,
I like your solution of adding a test for NOT_FOUND.
I will work on this as soon as I can.
Best regards,
Antoine
On Feb 13, 2007, at 7:23 PM, Michael Christoff wrote:
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]