org.opencms.webdav
Class CmsWebdavServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.opencms.webdav.CmsWebdavServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class CmsWebdavServlet
extends javax.servlet.http.HttpServlet

Servlet which adds support for WebDAV level 2.

Since:
6.5.6
Version:
$Revision: 1.10 $
Author:
Remy Maucherat, Craig R. McClanahan, Peter Bonrad
See Also:
Serialized Form

Field Summary
static java.lang.String AUTHORIZATION_BASIC_PREFIX
          Basic authorization prefix constant.
static int BUFFER_SIZE
          Size of file transfer buffer in bytes.
protected static java.text.DateFormat HTTP_DATE_FORMAT
          Date format for the last modified date.
protected static java.text.DateFormat ISO8601_FORMAT
          Date format for the creation date.
protected  int m_input
          The input buffer size to use when serving resources.
protected static java.security.MessageDigest m_md5Helper
          MD5 message digest provider.
protected  int m_output
          The output buffer size to use when serving resources.
protected static CmsMD5Encoder MD5_ENCODER
          The MD5 helper object for this class.
protected static java.lang.String METHOD_COPY
          WebDAV method: COPY.
protected static java.lang.String METHOD_DELETE
          HTTP Method: DELETE.
protected static java.lang.String METHOD_GET
          HTTP Method: GET.
protected static java.lang.String METHOD_HEAD
          HTTP Method: HEAD.
protected static java.lang.String METHOD_LOCK
          WebDAV method: LOCK.
protected static java.lang.String METHOD_MKCOL
          WebDAV method: MKCOL.
protected static java.lang.String METHOD_MOVE
          WebDAV method: MOVE.
protected static java.lang.String METHOD_OPTIONS
          HTTP Method: OPTIONS.
protected static java.lang.String METHOD_POST
          HTTP Method: POST.
protected static java.lang.String METHOD_PROPFIND
          WebDAV method: PROPFIND.
protected static java.lang.String METHOD_PROPPATCH
          WebDAV method: PROPPATCH.
protected static java.lang.String METHOD_PUT
          HTTP Method: PUT.
protected static java.lang.String METHOD_TRACE
          HTTP Method: TRACE.
protected static java.lang.String METHOD_UNLOCK
          WebDAV method: UNLOCK.
protected static java.lang.String MIME_SEPARATION
          MIME multipart separation string.
static java.lang.String SEPARATOR_CREDENTIALS
          Credentials separator constant.
protected static java.util.BitSet URL_SAFE_CHARS
          Chars which are safe for urls.
 
Constructor Summary
CmsWebdavServlet()
           
 
Method Summary
static org.dom4j.Element addElement(org.dom4j.Element parent, java.lang.String name)
          Adds an xml element to the given parent and sets the appropriate namespace and prefix.
protected  void copy(I_CmsRepositoryItem item, java.io.InputStream is, java.io.PrintWriter writer)
          Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).
protected  void copy(I_CmsRepositoryItem item, java.io.InputStream is, javax.servlet.ServletOutputStream ostream)
          Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).
protected  void copy(I_CmsRepositoryItem item, java.io.PrintWriter writer, CmsWebdavRange range)
          Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).
protected  void copy(I_CmsRepositoryItem item, java.io.PrintWriter writer, java.util.Iterator ranges, java.lang.String contentType)
          Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).
protected  void copy(I_CmsRepositoryItem item, javax.servlet.ServletOutputStream ostream, CmsWebdavRange range)
          Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).
protected  void copy(I_CmsRepositoryItem item, javax.servlet.ServletOutputStream ostream, java.util.Iterator ranges, java.lang.String contentType)
          Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).
protected  java.io.IOException copyRange(java.io.InputStream istream, javax.servlet.ServletOutputStream ostream)
          Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).
protected  java.io.IOException copyRange(java.io.InputStream istream, javax.servlet.ServletOutputStream ostream, long start, long end)
          Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).
protected  java.io.IOException copyRange(java.io.Reader reader, java.io.PrintWriter writer)
          Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).
protected  java.io.IOException copyRange(java.io.Reader reader, java.io.PrintWriter writer, long start, long end)
          Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).
protected  void doCopy(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Process a COPY WebDAV request for the specified resource.
protected  void doDelete(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Process a DELETE WebDAV request for the specified resource.
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Process a GET request for the specified resource.
protected  void doHead(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Process a HEAD request for the specified resource.
protected  void doLock(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Process a LOCK WebDAV request for the specified resource.
protected  void doMkcol(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Process a MKCOL WebDAV request for the specified resource.
protected  void doMove(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Process a MOVE WebDAV request for the specified resource.
protected  void doOptions(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Process a OPTIONS WebDAV request for the specified resource.
protected  void doPropfind(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Process a PROPFIND WebDAV request for the specified resource.
protected  void doProppatch(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Process a PROPPATCH WebDAV request for the specified resource.
protected  void doPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Process a POST request for the specified resource.
protected  void doUnlock(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Process a UNLOCK WebDAV request for the specified resource.
protected  java.io.File executePartialPut(javax.servlet.http.HttpServletRequest req, CmsWebdavRange range, java.lang.String path)
          Handle a partial PUT.
protected  java.lang.String getETag(I_CmsRepositoryItem item)
          Get the ETag associated with a file.
 void init()
          Initialize this servlet.
protected  java.util.ArrayList parseRange(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, I_CmsRepositoryItem item)
          Parse the range header.
protected  java.io.InputStream renderHtml(java.lang.String contextPath, java.lang.String path)
          Return an InputStream to an HTML representation of the contents of this directory.
protected  java.lang.String renderSize(long size)
          Render the specified file size (in bytes).
protected  java.lang.String rewriteUrl(java.lang.String path)
          URL rewriter.
protected  void serveResource(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean content)
          Serve the specified resource, optionally including the data content.
protected  void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Handles the special WebDAV methods.
 
Methods inherited from class javax.servlet.http.HttpServlet
doPost, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTHORIZATION_BASIC_PREFIX

public static final java.lang.String AUTHORIZATION_BASIC_PREFIX
Basic authorization prefix constant.

See Also:
Constant Field Values

BUFFER_SIZE

public static final int BUFFER_SIZE
Size of file transfer buffer in bytes.

See Also:
Constant Field Values

SEPARATOR_CREDENTIALS

public static final java.lang.String SEPARATOR_CREDENTIALS
Credentials separator constant.

See Also:
Constant Field Values

HTTP_DATE_FORMAT

protected static final java.text.DateFormat HTTP_DATE_FORMAT
Date format for the last modified date.


ISO8601_FORMAT

protected static final java.text.DateFormat ISO8601_FORMAT
Date format for the creation date.


m_md5Helper

protected static java.security.MessageDigest m_md5Helper
MD5 message digest provider.


MD5_ENCODER

protected static final CmsMD5Encoder MD5_ENCODER
The MD5 helper object for this class.


METHOD_COPY

protected static final java.lang.String METHOD_COPY
WebDAV method: COPY.

See Also:
Constant Field Values

METHOD_DELETE

protected static final java.lang.String METHOD_DELETE
HTTP Method: DELETE.

See Also:
Constant Field Values

METHOD_GET

protected static final java.lang.String METHOD_GET
HTTP Method: GET.

See Also:
Constant Field Values

METHOD_HEAD

protected static final java.lang.String METHOD_HEAD
HTTP Method: HEAD.

See Also:
Constant Field Values

METHOD_LOCK

protected static final java.lang.String METHOD_LOCK
WebDAV method: LOCK.

See Also:
Constant Field Values

METHOD_MKCOL

protected static final java.lang.String METHOD_MKCOL
WebDAV method: MKCOL.

See Also:
Constant Field Values

METHOD_MOVE

protected static final java.lang.String METHOD_MOVE
WebDAV method: MOVE.

See Also:
Constant Field Values

METHOD_OPTIONS

protected static final java.lang.String METHOD_OPTIONS
HTTP Method: OPTIONS.

See Also:
Constant Field Values

METHOD_POST

protected static final java.lang.String METHOD_POST
HTTP Method: POST.

See Also:
Constant Field Values

METHOD_PROPFIND

protected static final java.lang.String METHOD_PROPFIND
WebDAV method: PROPFIND.

See Also:
Constant Field Values

METHOD_PROPPATCH

protected static final java.lang.String METHOD_PROPPATCH
WebDAV method: PROPPATCH.

See Also:
Constant Field Values

METHOD_PUT

protected static final java.lang.String METHOD_PUT
HTTP Method: PUT.

See Also:
Constant Field Values

METHOD_TRACE

protected static final java.lang.String METHOD_TRACE
HTTP Method: TRACE.

See Also:
Constant Field Values

METHOD_UNLOCK

protected static final java.lang.String METHOD_UNLOCK
WebDAV method: UNLOCK.

See Also:
Constant Field Values

MIME_SEPARATION

protected static final java.lang.String MIME_SEPARATION
MIME multipart separation string.

See Also:
Constant Field Values

URL_SAFE_CHARS

protected static final java.util.BitSet URL_SAFE_CHARS
Chars which are safe for urls.


m_input

protected int m_input
The input buffer size to use when serving resources.


m_output

protected int m_output
The output buffer size to use when serving resources.

Constructor Detail

CmsWebdavServlet

public CmsWebdavServlet()
Method Detail

addElement

public static org.dom4j.Element addElement(org.dom4j.Element parent,
                                           java.lang.String name)
Adds an xml element to the given parent and sets the appropriate namespace and prefix.

Parameters:
parent - the parent node to add the element
name - the name of the new element
Returns:
the created element with the given name which was added to the given parent

init

public void init()
          throws javax.servlet.ServletException
Initialize this servlet.

Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException - if something goes wrong

copy

protected void copy(I_CmsRepositoryItem item,
                    java.io.InputStream is,
                    java.io.PrintWriter writer)
             throws java.io.IOException
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).

Parameters:
item - the RepositoryItem
is - the input stream to copy from
writer - the writer to write to
Throws:
java.io.IOException - if an input/output error occurs

copy

protected void copy(I_CmsRepositoryItem item,
                    java.io.InputStream is,
                    javax.servlet.ServletOutputStream ostream)
             throws java.io.IOException
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).

Parameters:
item - the RepositoryItem
is - the input stream to copy from
ostream - the output stream to write to
Throws:
java.io.IOException - if an input/output error occurs

copy

protected void copy(I_CmsRepositoryItem item,
                    java.io.PrintWriter writer,
                    CmsWebdavRange range)
             throws java.io.IOException
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).

Parameters:
item - the RepositoryItem
writer - the writer to write to
range - the range the client wants to retrieve
Throws:
java.io.IOException - if an input/output error occurs

copy

protected void copy(I_CmsRepositoryItem item,
                    java.io.PrintWriter writer,
                    java.util.Iterator ranges,
                    java.lang.String contentType)
             throws java.io.IOException
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).

Parameters:
item - the RepositoryItem
writer - the writer to write to
ranges - iterator of the ranges the client wants to retrieve
contentType - the content type of the resource
Throws:
java.io.IOException - if an input/output error occurs

copy

protected void copy(I_CmsRepositoryItem item,
                    javax.servlet.ServletOutputStream ostream,
                    CmsWebdavRange range)
             throws java.io.IOException
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).

Parameters:
item - the RepositoryItem
ostream - the output stream to write to
range - the range the client wants to retrieve
Throws:
java.io.IOException - if an input/output error occurs

copy

protected void copy(I_CmsRepositoryItem item,
                    javax.servlet.ServletOutputStream ostream,
                    java.util.Iterator ranges,
                    java.lang.String contentType)
             throws java.io.IOException
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).

Parameters:
item - the RepositoryItem
ostream - the output stream to write to
ranges - iterator of the ranges the client wants to retrieve
contentType - the content type of the resource
Throws:
java.io.IOException - if an input/output error occurs

copyRange

protected java.io.IOException copyRange(java.io.InputStream istream,
                                        javax.servlet.ServletOutputStream ostream)
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).

Parameters:
istream - the input stream to read from
ostream - the output stream to write to
Returns:
the exception which occurred during processing

copyRange

protected java.io.IOException copyRange(java.io.InputStream istream,
                                        javax.servlet.ServletOutputStream ostream,
                                        long start,
                                        long end)
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).

Parameters:
istream - the input stream to read from
ostream - the output stream to write to
start - the start of the range which will be copied
end - the end of the range which will be copied
Returns:
the exception which occurred during processing

copyRange

protected java.io.IOException copyRange(java.io.Reader reader,
                                        java.io.PrintWriter writer)
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).

Parameters:
reader - the reader to read from
writer - the writer to write to
Returns:
the exception which occurred during processing

copyRange

protected java.io.IOException copyRange(java.io.Reader reader,
                                        java.io.PrintWriter writer,
                                        long start,
                                        long end)
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).

Parameters:
reader - the reader to read from
writer - the writer to write to
start - the start of the range which will be copied
end - the end of the range which will be copied
Returns:
the exception which occurred during processing

doCopy

protected void doCopy(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse resp)
Process a COPY WebDAV request for the specified resource.

Parameters:
req - the servlet request we are processing
resp - the servlet response we are creating

doDelete

protected void doDelete(javax.servlet.http.HttpServletRequest req,
                        javax.servlet.http.HttpServletResponse resp)
                 throws java.io.IOException
Process a DELETE WebDAV request for the specified resource.

Overrides:
doDelete in class javax.servlet.http.HttpServlet
Parameters:
req - the servlet request we are processing
resp - the servlet response we are creating
Throws:
java.io.IOException - if an input/output error occurs

doGet

protected void doGet(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws java.io.IOException
Process a GET request for the specified resource.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
request - the servlet request we are processing
response - the servlet response we are creating
Throws:
java.io.IOException - if an input/output error occurs

doHead

protected void doHead(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response)
               throws java.io.IOException
Process a HEAD request for the specified resource.

Overrides:
doHead in class javax.servlet.http.HttpServlet
Parameters:
request - the servlet request we are processing
response - the servlet response we are creating
Throws:
java.io.IOException - if an input/output error occurs

doLock

protected void doLock(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse resp)
               throws java.io.IOException
Process a LOCK WebDAV request for the specified resource.

Parameters:
req - the servlet request we are processing
resp - the servlet response we are creating
Throws:
java.io.IOException - if an input/output error occurs

doMkcol

protected void doMkcol(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse resp)
                throws java.io.IOException
Process a MKCOL WebDAV request for the specified resource.

Parameters:
req - the servlet request we are processing
resp - the servlet response we are creating
Throws:
java.io.IOException - if an input/output error occurs

doMove

protected void doMove(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse resp)
Process a MOVE WebDAV request for the specified resource.

Parameters:
req - the servlet request we are processing
resp - the servlet response we are creating

doOptions

protected void doOptions(javax.servlet.http.HttpServletRequest req,
                         javax.servlet.http.HttpServletResponse resp)
Process a OPTIONS WebDAV request for the specified resource.

Overrides:
doOptions in class javax.servlet.http.HttpServlet
Parameters:
req - the servlet request we are processing
resp - the servlet response we are creating

doPropfind

protected void doPropfind(javax.servlet.http.HttpServletRequest req,
                          javax.servlet.http.HttpServletResponse resp)
                   throws java.io.IOException
Process a PROPFIND WebDAV request for the specified resource.

Parameters:
req - the servlet request we are processing
resp - the servlet response we are creating
Throws:
java.io.IOException - if an input/output error occurs

doProppatch

protected void doProppatch(javax.servlet.http.HttpServletRequest req,
                           javax.servlet.http.HttpServletResponse resp)
Process a PROPPATCH WebDAV request for the specified resource.

Not implemented yet.

Parameters:
req - the servlet request we are processing
resp - the servlet response we are creating

doPut

protected void doPut(javax.servlet.http.HttpServletRequest req,
                     javax.servlet.http.HttpServletResponse resp)
              throws java.io.IOException
Process a POST request for the specified resource.

Overrides:
doPut in class javax.servlet.http.HttpServlet
Parameters:
req - the servlet request we are processing
resp - the servlet response we are creating
Throws:
java.io.IOException - if an input/output error occurs

doUnlock

protected void doUnlock(javax.servlet.http.HttpServletRequest req,
                        javax.servlet.http.HttpServletResponse resp)
Process a UNLOCK WebDAV request for the specified resource.

Parameters:
req - the servlet request we are processing
resp - the servlet response we are creating

executePartialPut

protected java.io.File executePartialPut(javax.servlet.http.HttpServletRequest req,
                                         CmsWebdavRange range,
                                         java.lang.String path)
                                  throws java.io.IOException
Handle a partial PUT.

New content specified in request is appended to existing content in oldRevisionContent (if present). This code does not support simultaneous partial updates to the same resource.

Parameters:
req - the servlet request we are processing
range - the range of the content in the file
path - the path where to find the resource
Returns:
the new content file with the appended data
Throws:
java.io.IOException - if an input/output error occurs

getETag

protected java.lang.String getETag(I_CmsRepositoryItem item)
Get the ETag associated with a file.

Parameters:
item - the WebDavItem
Returns:
the created ETag for the resource attributes

parseRange

protected java.util.ArrayList parseRange(javax.servlet.http.HttpServletRequest request,
                                         javax.servlet.http.HttpServletResponse response,
                                         I_CmsRepositoryItem item)
Parse the range header.

Parameters:
request - the servlet request we are processing
response - the servlet response we are creating
item - the WebdavItem with the information
Returns:
Vector of ranges

renderHtml

protected java.io.InputStream renderHtml(java.lang.String contextPath,
                                         java.lang.String path)
                                  throws java.io.IOException
Return an InputStream to an HTML representation of the contents of this directory.

Parameters:
contextPath - context path to which our internal paths are relative
path - the path of the resource to render the html for
Returns:
an input stream with the rendered html
Throws:
java.io.IOException - if an input/output error occurs

renderSize

protected java.lang.String renderSize(long size)
Render the specified file size (in bytes).

Parameters:
size - file size (in bytes)
Returns:
a string with the given size formatted to output to user

rewriteUrl

protected java.lang.String rewriteUrl(java.lang.String path)
                               throws java.io.UnsupportedEncodingException
URL rewriter.

Parameters:
path - path which has to be rewritten
Returns:
a string with the encoded path
Throws:
java.io.UnsupportedEncodingException - if something goes wrong while encoding the url

serveResource

protected void serveResource(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response,
                             boolean content)
                      throws java.io.IOException
Serve the specified resource, optionally including the data content.

Parameters:
request - the servlet request we are processing
response - the servlet response we are creating
content - should the content be included?
Throws:
java.io.IOException - if an input/output error occurs

service

protected void service(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse resp)
                throws javax.servlet.ServletException,
                       java.io.IOException
Handles the special WebDAV methods.

Overrides:
service in class javax.servlet.http.HttpServlet
Parameters:
req - the servlet request we are processing
resp - the servlet response we are creating
Throws:
java.io.IOException - if an input/output error occurs
javax.servlet.ServletException - if a servlet-specified error occurs