org.apache.webdav.lib.methods
Class WebdavMethodBase

java.lang.Object
  |
  +--org.apache.webdav.lib.methods.WebdavMethodBase
All Implemented Interfaces:
WebdavMethod
Direct Known Subclasses:
GetMethod, HeadMethod, MkcolMethod, OptionsMethod, PutMethod, UnlockMethod, XMLResponseMethodBase

public abstract class WebdavMethodBase
extends java.lang.Object
implements WebdavMethod

WebDAV method abstract implementation.

Author:
Remy Maucherat

Field Summary
protected  int debug
          Debug.
protected  java.util.Hashtable headers
          Headers.
protected  java.lang.String name
          Method name.
protected  java.util.Hashtable parameters
          URL parameters.
protected  java.lang.String path
          Server path.
protected  java.lang.String query
           
protected  java.lang.String queryString
           
protected  State state
          Global state.
protected  int statusCode
          Status code.
protected  java.lang.String statusText
          Status text.
 
Fields inherited from interface org.apache.webdav.lib.methods.WebdavMethod
PROTOCOL
 
Constructor Summary
WebdavMethodBase()
          Method constructor.
WebdavMethodBase(java.lang.String path)
          Method constructor.
 
Method Summary
protected  void checkNotUsed()
          Check if the method has been executed, and throws an IllegalStateException otherwise.
protected  void checkUsed()
          Check if the method has been executed, and throws an IllegalStateException otherwise.
 boolean followRedirects()
          True if this methods should automatically follow redirects.
 void generateHeaders(State state)
          Deprecated. this method is deprecated in favour of the generateHeaders(String, State) method.
 void generateHeaders(java.lang.String host, State state)
          Generate additional headers needed by the request.
 java.lang.String generateQuery()
          Generate the query body.
 java.lang.String generateRequestLine()
          Generate the HTTP request line.
 Header getHeader(java.lang.String headerName)
          Get header.
 java.util.Enumeration getHeaders()
          Get headers.
 java.lang.String getName()
          Name property getter.
 java.lang.String getPath()
          Path property getter.
 int getStatusCode()
          Status code property getter.
 java.lang.String getStatusText()
          Status text property getter.
 boolean hasBeenUsed()
          Checks if this method's instance has already been used, and has not been recycled.
 boolean isStreamedQuery()
          Is the query body submitted through an InputStream of with a String.
 boolean needContentLength()
          Return true if the method needs a content-length header in the request.
abstract  void parseResponse(java.io.InputStream is)
          Parse response.
 void processResponseHeaders(java.util.Hashtable headers)
          Process response headers.
 void recycle()
          Recycle the method object, so that it can be reused again.
 void removeHeader(java.lang.String headerName)
          Remove header.
 void setDebug(int debug)
          Debug property setter.
 void setHeader(java.lang.String headerName, java.lang.String headerValue)
          Set header.
 void setParameter(java.lang.String parameterName, java.lang.String parameterValue)
          Set URL parameter.
 void setPath(java.lang.String path)
          Path property setter.
 void setQuery(java.lang.String query)
          Set the query String as a XML document.
 void setQueryString(java.lang.String queryString)
          Set query string.
 void setState(State state)
          Set the state token.
 void setStatusCode(int statusCode)
          Status code property setter.
 void setStatusText(java.lang.String statusText)
          Status text property setter.
 void setUsed()
          Set the method as used.
 void streamQuery(java.io.OutputStream out)
          Stream the body of the query.
 boolean validate()
          Ensures the correctness of the request according to criterions which are method dependent.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

protected int debug
Debug.

statusCode

protected int statusCode
Status code.

statusText

protected java.lang.String statusText
Status text.

path

protected java.lang.String path
Server path.

name

protected java.lang.String name
Method name.

headers

protected java.util.Hashtable headers
Headers.

parameters

protected java.util.Hashtable parameters
URL parameters.

state

protected State state
Global state.

query

protected java.lang.String query

queryString

protected java.lang.String queryString
Constructor Detail

WebdavMethodBase

public WebdavMethodBase()
Method constructor.

WebdavMethodBase

public WebdavMethodBase(java.lang.String path)
Method constructor.
Method Detail

setDebug

public void setDebug(int debug)
Debug property setter.
Specified by:
setDebug in interface WebdavMethod
Parameters:
int - Debug

setStatusCode

public void setStatusCode(int statusCode)
Status code property setter.
Specified by:
setStatusCode in interface WebdavMethod
Parameters:
int - Status code

getStatusCode

public int getStatusCode()
Status code property getter.
Specified by:
getStatusCode in interface WebdavMethod
Returns:
int Status code

setStatusText

public void setStatusText(java.lang.String statusText)
Status text property setter.
Specified by:
setStatusText in interface WebdavMethod
Parameters:
statusText - Status text

getStatusText

public java.lang.String getStatusText()
Status text property getter.
Specified by:
getStatusText in interface WebdavMethod
Returns:
String status text

setPath

public void setPath(java.lang.String path)
Path property setter.
Specified by:
setPath in interface WebdavMethod
Parameters:
path - Absolute path

getPath

public java.lang.String getPath()
Path property getter.
Specified by:
getPath in interface WebdavMethod
Returns:
String path

getName

public java.lang.String getName()
Name property getter.
Specified by:
getName in interface WebdavMethod
Returns:
String name

setHeader

public void setHeader(java.lang.String headerName,
                      java.lang.String headerValue)
Set header.
Specified by:
setHeader in interface WebdavMethod
Parameters:
headerName - Header name
headerValue - Header value

getHeader

public Header getHeader(java.lang.String headerName)
Get header.
Specified by:
getHeader in interface WebdavMethod
Parameters:
headerName - Header name
Returns:
String header value (null if the header doesn't exist)

removeHeader

public void removeHeader(java.lang.String headerName)
Remove header.
Specified by:
removeHeader in interface WebdavMethod
Parameters:
headerName - Header name

hasBeenUsed

public final boolean hasBeenUsed()
Checks if this method's instance has already been used, and has not been recycled.
Specified by:
hasBeenUsed in interface WebdavMethod
Returns:
boolean True if the method's instance has already been used

followRedirects

public boolean followRedirects()
True if this methods should automatically follow redirects.
Specified by:
followRedirects in interface WebdavMethod
Returns:
boolean True if auto redirect should be used for this method

setState

public void setState(State state)
Set the state token.
Specified by:
setState in interface WebdavMethod

setParameter

public void setParameter(java.lang.String parameterName,
                         java.lang.String parameterValue)
Set URL parameter.
Specified by:
setParameter in interface WebdavMethod
Parameters:
parameterName - Parameter name
parameterValue - Parameter value

setQueryString

public void setQueryString(java.lang.String queryString)
Set query string.
Specified by:
setQueryString in interface WebdavMethod
Parameters:
queryString - Query string

setUsed

public void setUsed()
Set the method as used.
Specified by:
setUsed in interface WebdavMethod

validate

public boolean validate()
Ensures the correctness of the request according to criterions which are method dependent.
Specified by:
validate in interface WebdavMethod
Returns:
boolean True if the method is valid

recycle

public void recycle()
Recycle the method object, so that it can be reused again. Any attempt to reuse an object without recycling it will throw a WebdavException.
Specified by:
recycle in interface WebdavMethod

getHeaders

public java.util.Enumeration getHeaders()
Get headers.
Specified by:
getHeaders in interface WebdavMethod
Returns:
Enumeration

generateHeaders

public void generateHeaders(State state)
Deprecated. this method is deprecated in favour of the generateHeaders(String, State) method.

Generate additional headers needed by the request.
Parameters:
state - State token

generateHeaders

public void generateHeaders(java.lang.String host,
                            State state)
Generate additional headers needed by the request.
Specified by:
generateHeaders in interface WebdavMethod
Parameters:
host - the host
state - State token

isStreamedQuery

public boolean isStreamedQuery()
Is the query body submitted through an InputStream of with a String. If an InputStream is available, it's used.
Specified by:
isStreamedQuery in interface WebdavMethod
Returns:
boolean True if the content is avalable in an InputStream

setQuery

public void setQuery(java.lang.String query)
Set the query String as a XML document. If the query string is already given as an XML document this low level function will set the query string directly. This method make only sense in the context of lock, propFind, and propPatch. In all other cases this method call is ignored.
Specified by:
setQuery in interface WebdavMethod

generateQuery

public java.lang.String generateQuery()
Generate the query body.
Specified by:
generateQuery in interface WebdavMethod
Returns:
String query

streamQuery

public void streamQuery(java.io.OutputStream out)
                 throws java.io.IOException
Stream the body of the query. This function should be used to send large request bodies.
Specified by:
streamQuery in interface WebdavMethod

processResponseHeaders

public void processResponseHeaders(java.util.Hashtable headers)
Process response headers. The contract of this method is that it only parses the response headers.
Specified by:
processResponseHeaders in interface WebdavMethod
Parameters:
headers - Headers list

parseResponse

public abstract void parseResponse(java.io.InputStream is)
                            throws java.io.IOException,
                                   WebdavException
Parse response.
Specified by:
parseResponse in interface WebdavMethod
Parameters:
is - Input stream

generateRequestLine

public final java.lang.String generateRequestLine()
Generate the HTTP request line.
Specified by:
generateRequestLine in interface WebdavMethod
Returns:
String request line

needContentLength

public boolean needContentLength()
Return true if the method needs a content-length header in the request.
Specified by:
needContentLength in interface WebdavMethod
Returns:
true if a content-length header will be expected by the server

checkUsed

protected void checkUsed()
Check if the method has been executed, and throws an IllegalStateException otherwise.

checkNotUsed

protected void checkNotUsed()
Check if the method has been executed, and throws an IllegalStateException otherwise.