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 "Pill, Juergen" <Ju...@softwareag.com> on 2001/03/22 17:41:03 UTC

client-webdav-method header setting

Hello,

The client WebdavMethods have two possibilities to set their headers:

1) setHeader(name, value);
2) some specialized method to set some special headers (not available for
all methods): setOverwrite, setdepth, ...

Unfortunately the setHeader method can not be used to set the special
headers, but instead the specialized method needs to be used.
This is a little bit unfortunate, because it causes some additional coding
in the application, if the header pair is already known in a generic
application (see coding example at the end).

I want to suggest following change:

All client WebdavMethod classes stay with their special implementation of
the specific header setting methods (as it is today) and these classes
additionally overwrite the setHeader method in a way, that if a special
header is set, the specific header setting method is called, else the call
is delegated to the super(...) method (this would reduce our fillheader
method to few lines and we would be sure we covered all special headers).

e.g.

setHeader(String name, String value) {
	if (value.equalsIgnoreCase("depth") {
		setDepth(value.toInteger()); // will not really compile
	}
	else {
		super(name, value);
	}
}



What do you think?


	private  WebdavMethod fillHeader (Element header, WebdavMethod
method){

		String headerLine = header.getText();
		Header headerToSet = this.getResponseHeader(headerLine);

		method.setHeader(headerToSet.getName(),
headerToSet.getValue());
		
		
		if(headerToSet.getName().equalsIgnoreCase("depth")){
			setDepth(method,
Integer.parseInt(headerToSet.getValue()));
		} else
if(headerToSet.getName().equalsIgnoreCase("destination") && method
instanceof CopyMethod){
			((CopyMethod) method).setDestination(
headerToSet.getValue());
		} else
if(headerToSet.getName().equalsIgnoreCase("destination") && method
instanceof MoveMethod){
			((MoveMethod) method).setDestination(
headerToSet.getValue());
		} else
if(headerToSet.getName().equalsIgnoreCase("overwrite") && method instanceof
CopyMethod){
			if(headerToSet.getValue().equalsIgnoreCase("F")){
				((CopyMethod) method).setOverwrite(false);
			} else {
				((CopyMethod) method).setOverwrite(true);
			}
		} else
if(headerToSet.getName().equalsIgnoreCase("overwrite") && method instanceof
MoveMethod){
			if(headerToSet.getValue().equalsIgnoreCase("F")){
				((MoveMethod) method).setOverwrite(false);
			} else {
				((MoveMethod) method).setOverwrite(true);
			}
		} else if
(headerToSet.getName().equalsIgnoreCase("Lock-Token")){
			((UnlockMethod)
method).setLockToken(headerToSet.getValue());
		} else if
(headerToSet.getName().equalsIgnoreCase("TimeOut")){
			((LockMethod) method).setTimeout(0);
		}
		
		return method;
}



Best regards

Juergen Pill



Re: client-webdav-method header setting

Posted by Remy Maucherat <re...@apache.org>.
----- Original Message -----
From: "Pill, Juergen" <Ju...@softwareag.com>
To: <sl...@jakarta.apache.org>
Sent: Thursday, March 22, 2001 8:41 AM
Subject: client-webdav-method header setting


> Hello,
>
> The client WebdavMethods have two possibilities to set their headers:
>
> 1) setHeader(name, value);
> 2) some specialized method to set some special headers (not available for
> all methods): setOverwrite, setdepth, ...
>
> Unfortunately the setHeader method can not be used to set the special
> headers, but instead the specialized method needs to be used.
> This is a little bit unfortunate, because it causes some additional coding
> in the application, if the header pair is already known in a generic
> application (see coding example at the end).

We're not the only one, actually. The Servlet API does the same with content
length, among others. That's confusing IMO.

> I want to suggest following change:
>
> All client WebdavMethod classes stay with their special implementation of
> the specific header setting methods (as it is today) and these classes
> additionally overwrite the setHeader method in a way, that if a special
> header is set, the specific header setting method is called, else the call
> is delegated to the super(...) method (this would reduce our fillheader
> method to few lines and we would be sure we covered all special headers).
>
> e.g.
>
> setHeader(String name, String value) {
> if (value.equalsIgnoreCase("depth") {
> setDepth(value.toInteger()); // will not really compile
> }
> else {
> super(name, value);
> }
> }
>
>
>
> What do you think?

+1
Of course, there is no way to enforce it, but it's a good idea that at least
our methods are designed like that.

I'm considering moving the XML formatter and facades to
org.apache.slide.webdav.logger (in the WebDAV server tree), since it's
servlet related classes. Or maybe I could put it in the org.apache.util
package.

Remy