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


Reply via email to