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:
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
See Also:
Serialized Form

Field Summary
static String AUTHORIZATION_BASIC_PREFIX
          Basic authorization prefix constant.
static int BUFFER_SIZE
          Size of file transfer buffer in bytes.
protected static DateFormat HTTP_DATE_FORMAT
          Date format for the last modified date.
protected static DateFormat ISO8601_FORMAT
          Date format for the creation date.
protected  int m_input
          The input buffer size to use when serving resources.
protected static 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 String METHOD_COPY
          WebDAV method: COPY.
protected static String METHOD_DELETE
          HTTP Method: DELETE.
protected static String METHOD_GET
          HTTP Method: GET.
protected static String METHOD_HEAD
          HTTP Method: HEAD.
protected static String METHOD_LOCK
          WebDAV method: LOCK.
protected static String METHOD_MKCOL
          WebDAV method: MKCOL.
protected static String METHOD_MOVE
          WebDAV method: MOVE.
protected static String METHOD_OPTIONS
          HTTP Method: OPTIONS.
protected static String METHOD_POST
          HTTP Method: POST.
protected static String METHOD_PROPFIND
          WebDAV method: PROPFIND.
protected static String METHOD_PROPPATCH
          WebDAV method: PROPPATCH.
protected static String METHOD_PUT
          HTTP Method: PUT.
protected static String METHOD_TRACE
          HTTP Method: TRACE.
protected static String METHOD_UNLOCK
          WebDAV method: UNLOCK.
protected static String MIME_SEPARATION
          MIME multipart separation string.
static String SEPARATOR_CREDENTIALS
          Credentials separator constant.
protected static BitSet URL_SAFE_CHARS
          Chars which are safe for urls.
 
Constructor Summary
CmsWebdavServlet()
           
 
Method Summary
static Element addElement(Element parent, String name)
          Adds an xml element to the given parent and sets the appropriate namespace and prefix.
protected  void copy(I_CmsRepositoryItem item, InputStream is, 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, 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, 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, PrintWriter writer, Iterator<CmsWebdavRange> ranges, 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, Iterator<CmsWebdavRange> ranges, 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  IOException copyRange(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  IOException copyRange(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  IOException copyRange(Reader reader, 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  IOException copyRange(Reader reader, 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  File executePartialPut(javax.servlet.http.HttpServletRequest req, CmsWebdavRange range, String path)
          Handle a partial PUT.
protected  String getETag(I_CmsRepositoryItem item)
          Get the ETag associated with a file.
 void init()
          Initialize this servlet.
protected  ArrayList<CmsWebdavRange> parseRange(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, I_CmsRepositoryItem item)
          Parse the range header.
protected  InputStream renderHtml(String contextPath, String path)
          Return an InputStream to an HTML representation of the contents of this directory.
protected  String renderSize(long size)
          Render the specified file size (in bytes).
protected  String rewriteUrl(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 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 String SEPARATOR_CREDENTIALS
Credentials separator constant.

See Also:
Constant Field Values

HTTP_DATE_FORMAT

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


ISO8601_FORMAT

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


m_md5Helper

protected static 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 String METHOD_COPY
WebDAV method: COPY.

See Also:
Constant Field Values

METHOD_DELETE

protected static final String METHOD_DELETE
HTTP Method: DELETE.

See Also:
Constant Field Values

METHOD_GET

protected static final String METHOD_GET
HTTP Method: GET.

See Also:
Constant Field Values

METHOD_HEAD

protected static final String METHOD_HEAD
HTTP Method: HEAD.

See Also:
Constant Field Values

METHOD_LOCK

protected static final String METHOD_LOCK
WebDAV method: LOCK.

See Also:
Constant Field Values

METHOD_MKCOL

protected static final String METHOD_MKCOL
WebDAV method: MKCOL.

See Also:
Constant Field Values

METHOD_MOVE

protected static final String METHOD_MOVE
WebDAV method: MOVE.

See Also:
Constant Field Values

METHOD_OPTIONS

protected static final String METHOD_OPTIONS
HTTP Method: OPTIONS.

See Also:
Constant Field Values

METHOD_POST

protected static final String METHOD_POST
HTTP Method: POST.

See Also:
Constant Field Values

METHOD_PROPFIND

protected static final String METHOD_PROPFIND
WebDAV method: PROPFIND.

See Also:
Constant Field Values

METHOD_PROPPATCH

protected static final String METHOD_PROPPATCH
WebDAV method: PROPPATCH.

See Also:
Constant Field Values

METHOD_PUT

protected static final String METHOD_PUT
HTTP Method: PUT.

See Also:
Constant Field Values

METHOD_TRACE

protected static final String METHOD_TRACE
HTTP Method: TRACE.

See Also:
Constant Field Values

METHOD_UNLOCK

protected static final String METHOD_UNLOCK
WebDAV method: UNLOCK.

See Also:
Constant Field Values

MIME_SEPARATION

protected static final String MIME_SEPARATION
MIME multipart separation string.

See Also:
Constant Field Values

URL_SAFE_CHARS

protected static final 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 Element addElement(Element parent,
                                 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,
                    InputStream is,
                    PrintWriter writer)
             throws 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:
IOException - if an input/output error occurs

copy

protected void copy(I_CmsRepositoryItem item,
                    InputStream is,
                    javax.servlet.ServletOutputStream ostream)
             throws 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:
IOException - if an input/output error occurs

copy

protected void copy(I_CmsRepositoryItem item,
                    PrintWriter writer,
                    CmsWebdavRange range)
             throws 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:
IOException - if an input/output error occurs

copy

protected void copy(I_CmsRepositoryItem item,
                    PrintWriter writer,
                    Iterator<CmsWebdavRange> ranges,
                    String contentType)
             throws 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:
IOException - if an input/output error occurs

copy

protected void copy(I_CmsRepositoryItem item,
                    javax.servlet.ServletOutputStream ostream,
                    CmsWebdavRange range)
             throws 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:
IOException - if an input/output error occurs

copy

protected void copy(I_CmsRepositoryItem item,
                    javax.servlet.ServletOutputStream ostream,
                    Iterator<CmsWebdavRange> ranges,
                    String contentType)
             throws 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:
IOException - if an input/output error occurs

copyRange

protected IOException copyRange(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 IOException copyRange(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 IOException copyRange(Reader reader,
                                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 IOException copyRange(Reader reader,
                                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 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:
IOException - if an input/output error occurs

doGet

protected void doGet(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws 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:
IOException - if an input/output error occurs

doHead

protected void doHead(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response)
               throws 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:
IOException - if an input/output error occurs

doLock

protected void doLock(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse resp)
               throws 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:
IOException - if an input/output error occurs

doMkcol

protected void doMkcol(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse resp)
                throws 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:
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 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:
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 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:
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 File executePartialPut(javax.servlet.http.HttpServletRequest req,
                                 CmsWebdavRange range,
                                 String path)
                          throws 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:
IOException - if an input/output error occurs

getETag

protected 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 ArrayList<CmsWebdavRange> 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 InputStream renderHtml(String contextPath,
                                 String path)
                          throws 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:
IOException - if an input/output error occurs

renderSize

protected 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 String rewriteUrl(String path)
                     throws UnsupportedEncodingException
URL rewriter.

Parameters:
path - path which has to be rewritten
Returns:
a string with the encoded path
Throws:
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 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:
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,
                       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:
IOException - if an input/output error occurs
javax.servlet.ServletException - if a servlet-specified error occurs