com.xpn.xwiki.plugin.webdav.utils
Class XWikiDavContext

java.lang.Object
  extended by com.xpn.xwiki.plugin.webdav.utils.XWikiDavContext

public class XWikiDavContext
extends java.lang.Object

Holds context information about a webdav request. TODO: Get rid of this class (Move to components).

Version:
$Id: XWikiDavContext.java 34662 2011-02-14 19:14:17Z vmassol $

Constructor Summary
XWikiDavContext(org.apache.jackrabbit.webdav.DavServletRequest request, org.apache.jackrabbit.webdav.DavServletResponse response, javax.servlet.ServletContext servletContext, org.apache.jackrabbit.webdav.DavResourceFactory resourceFactory, org.apache.jackrabbit.webdav.DavSession davSession, org.apache.jackrabbit.webdav.lock.LockManager lockManager)
          Creates a new xwiki webdav context.
 
Method Summary
 void addAttachment(com.xpn.xwiki.doc.XWikiDocument doc, byte[] data, java.lang.String attachmentName)
          Adds an attachment to the XWikiDocument represented by this resource.
 void checkAccess(java.lang.String right, java.lang.String fullDocName)
          Validates if the user (in the context) has the given access level on the document in question, if not, throws a DavException.
 void cleanUp()
          Release any resources acquired.
 void deleteAttachment(com.xpn.xwiki.doc.XWikiAttachment attachment)
          Deletes the given attachment from it's document.
 void deleteDocument(com.xpn.xwiki.doc.XWikiDocument document)
          Deletes the specified xwiki document from the current xwiki.
 boolean exists(java.lang.String fullDocName)
          Checks whether the specified xwiki document exists or not.
 byte[] getContent(com.xpn.xwiki.doc.XWikiAttachment attachment)
          Returns the content of the attachment.
 org.apache.jackrabbit.webdav.DavSession getDavSession()
           
 com.xpn.xwiki.doc.XWikiDocument getDocument(java.lang.String fullDocName)
          Finds the xwiki document matching the given document name.
 byte[] getFileContentAsBytes(java.io.InputStream in)
          Utility method for reading a given input stream into a byte array.
 org.apache.jackrabbit.webdav.lock.LockManager getLockManager()
           
 java.lang.String getMethod()
           
 java.lang.String getMimeType(com.xpn.xwiki.doc.XWikiAttachment attachment)
          Returns the mime type of the given attachment.
 org.apache.jackrabbit.webdav.DavResourceFactory getResourceFactory()
           
 java.util.List<java.lang.String> getSpaces()
           
 java.lang.String getUser()
           
 XWikiDavUserStorage getUserStorage()
          Returns the session storage allocated for the current user.
 com.xpn.xwiki.XWikiContext getXwikiContext()
           
 boolean hasAccess(java.lang.String right, java.lang.String fullDocName)
          Returns if the user (in the context) has the given access level on the document in question.
 boolean isCreateCollectionRequest()
           
 boolean isCreateFileRequest()
           
 boolean isCreateOrMoveRequest()
           
 boolean isCreateResourceRequest()
           
 boolean isDeleteResourceRequest()
           
 boolean isMoveAttachmentRequest(com.xpn.xwiki.doc.XWikiDocument doc)
          Utility method for checking whether the current webdav request is trying to move / rename an attachment.
 boolean isMoveResourceRequest()
           
 void moveAttachment(com.xpn.xwiki.doc.XWikiAttachment attachment, com.xpn.xwiki.doc.XWikiDocument destinationDoc, java.lang.String newAttachmentName)
          Moves the given attachment under the target document.
 void renameDocument(com.xpn.xwiki.doc.XWikiDocument document, java.lang.String newDocumentName)
          Renames the given xwiki document into the new document name provided.
 void saveDocument(com.xpn.xwiki.doc.XWikiDocument document)
          Saves the given xwiki document into current xwiki.
 java.util.List<java.lang.Object> search(java.lang.String sql)
          A shortcut to XWikiStoreInterface.search(String, int, int, XWikiContext).
 java.util.List<java.lang.String> searchDocumentsNames(java.lang.String sql)
          A shortcut to , returns all the results found.
 java.util.List<java.lang.String> searchDocumentsNames(java.lang.String sql, int nb, int start)
          A shortcut to .
 java.lang.String toXML(com.xpn.xwiki.doc.XWikiDocument document)
          Converts the given xwiki document into an xml representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XWikiDavContext

public XWikiDavContext(org.apache.jackrabbit.webdav.DavServletRequest request,
                       org.apache.jackrabbit.webdav.DavServletResponse response,
                       javax.servlet.ServletContext servletContext,
                       org.apache.jackrabbit.webdav.DavResourceFactory resourceFactory,
                       org.apache.jackrabbit.webdav.DavSession davSession,
                       org.apache.jackrabbit.webdav.lock.LockManager lockManager)
                throws org.apache.jackrabbit.webdav.DavException
Creates a new xwiki webdav context.

Parameters:
request - dav request.
response - dav response.
servletContext - servlet context.
resourceFactory - dav resource factory.
davSession - dav session.
lockManager - lock manager.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while initializing the xwiki context.
Method Detail

getUserStorage

public XWikiDavUserStorage getUserStorage()
Returns the session storage allocated for the current user.

Returns:
Session storage.

hasAccess

public boolean hasAccess(java.lang.String right,
                         java.lang.String fullDocName)
Returns if the user (in the context) has the given access level on the document in question.

Parameters:
right - Access level.
fullDocName - Name of the document.
Returns:
True if the user has the given access level for the document in question, false otherwise.

checkAccess

public void checkAccess(java.lang.String right,
                        java.lang.String fullDocName)
                 throws org.apache.jackrabbit.webdav.DavException
Validates if the user (in the context) has the given access level on the document in question, if not, throws a DavException.

Parameters:
right - Access level.
fullDocName - Name of the document.
Throws:
org.apache.jackrabbit.webdav.DavException - If the user doesn't have enough access rights on the given document or if the access verification code fails.

getMimeType

public java.lang.String getMimeType(com.xpn.xwiki.doc.XWikiAttachment attachment)
Returns the mime type of the given attachment.

Parameters:
attachment - xwiki attachment.
Returns:
a mime type string.

getContent

public byte[] getContent(com.xpn.xwiki.doc.XWikiAttachment attachment)
                  throws org.apache.jackrabbit.webdav.DavException
Returns the content of the attachment.

Parameters:
attachment - xwiki attachment.
Returns:
attachment content as a byte array.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while reading the attachment.

getFileContentAsBytes

public byte[] getFileContentAsBytes(java.io.InputStream in)
                             throws org.apache.jackrabbit.webdav.DavException
Utility method for reading a given input stream into a byte array.

Parameters:
in - input stream.
Returns:
a byte array holding data from the given stream.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while reading the input stream.

addAttachment

public void addAttachment(com.xpn.xwiki.doc.XWikiDocument doc,
                          byte[] data,
                          java.lang.String attachmentName)
                   throws org.apache.jackrabbit.webdav.DavException
Adds an attachment to the XWikiDocument represented by this resource.

Parameters:
attachmentName - Name of this attachment.
data - Data to be put into the attachment (file content).
doc - The document to which the attachment is made.
Throws:
org.apache.jackrabbit.webdav.DavException - Indicates an internal error.

moveAttachment

public void moveAttachment(com.xpn.xwiki.doc.XWikiAttachment attachment,
                           com.xpn.xwiki.doc.XWikiDocument destinationDoc,
                           java.lang.String newAttachmentName)
                    throws org.apache.jackrabbit.webdav.DavException
Moves the given attachment under the target document.

Parameters:
attachment - xwiki attachment.
destinationDoc - target document.
newAttachmentName - new attachment name.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while accessing the wiki.

deleteAttachment

public void deleteAttachment(com.xpn.xwiki.doc.XWikiAttachment attachment)
                      throws org.apache.jackrabbit.webdav.DavException
Deletes the given attachment from it's document.

Parameters:
attachment - xwiki attachment.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while accessing the wiki.

exists

public boolean exists(java.lang.String fullDocName)
Checks whether the specified xwiki document exists or not.

Parameters:
fullDocName - name of the document.
Returns:
true if the documents exists.

getDocument

public com.xpn.xwiki.doc.XWikiDocument getDocument(java.lang.String fullDocName)
                                            throws org.apache.jackrabbit.webdav.DavException
Finds the xwiki document matching the given document name.

Parameters:
fullDocName - name of the xwiki document.
Returns:
xwiki document matching the given document name.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while accessing the wiki.

toXML

public java.lang.String toXML(com.xpn.xwiki.doc.XWikiDocument document)
                       throws org.apache.jackrabbit.webdav.DavException
Converts the given xwiki document into an xml representation.

Parameters:
document - xwiki document.
Returns:
the xml representation of the document.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while accessing the wiki.

renameDocument

public void renameDocument(com.xpn.xwiki.doc.XWikiDocument document,
                           java.lang.String newDocumentName)
                    throws org.apache.jackrabbit.webdav.DavException
Renames the given xwiki document into the new document name provided.

Parameters:
document - xwiki document to be renamed.
newDocumentName - new document name.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while accessing the wiki.

searchDocumentsNames

public java.util.List<java.lang.String> searchDocumentsNames(java.lang.String sql)
                                                      throws org.apache.jackrabbit.webdav.DavException
A shortcut to , returns all the results found.

Parameters:
sql - the HQL query string.
Returns:
document names matching the given criterion.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while accessing the wiki.

searchDocumentsNames

public java.util.List<java.lang.String> searchDocumentsNames(java.lang.String sql,
                                                             int nb,
                                                             int start)
                                                      throws org.apache.jackrabbit.webdav.DavException
A shortcut to .

Parameters:
sql - the HQL where clause.
nb - number of results expected.
start - offset.
Returns:
document names matching the given criterion.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while accessing the wiki.

search

public java.util.List<java.lang.Object> search(java.lang.String sql)
                                        throws org.apache.jackrabbit.webdav.DavException
A shortcut to XWikiStoreInterface.search(String, int, int, XWikiContext).

Parameters:
sql - the HQL query.
Returns:
search results.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while accessing the wiki.

saveDocument

public void saveDocument(com.xpn.xwiki.doc.XWikiDocument document)
                  throws org.apache.jackrabbit.webdav.DavException
Saves the given xwiki document into current xwiki.

Parameters:
document - xwiki document to be saved.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while accessing the wiki.

deleteDocument

public void deleteDocument(com.xpn.xwiki.doc.XWikiDocument document)
                    throws org.apache.jackrabbit.webdav.DavException
Deletes the specified xwiki document from the current xwiki.

Parameters:
document - the xwiki document.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while accessing the wiki.

getSpaces

public java.util.List<java.lang.String> getSpaces()
                                           throws org.apache.jackrabbit.webdav.DavException
Returns:
a list of spaces available in the current xwiki.
Throws:
org.apache.jackrabbit.webdav.DavException - if an error occurs while accessing the wiki.

isCreateCollectionRequest

public boolean isCreateCollectionRequest()
Returns:
true if the current webdav request is trying to create a collection resource (DAV_MKCOL).

isCreateFileRequest

public boolean isCreateFileRequest()
Returns:
true if the current webdav request is trying to create a file resource (DAV_PUT or DAV_POST).

isCreateResourceRequest

public boolean isCreateResourceRequest()
Returns:
true if the current webdav request is trying to create a resource.

isMoveResourceRequest

public boolean isMoveResourceRequest()
Returns:
true if the current webdav request is trying to move (rename) a resource.

isCreateOrMoveRequest

public boolean isCreateOrMoveRequest()
Returns:
true if the current webdav request is trying to create or move (rename) a resource.

isMoveAttachmentRequest

public boolean isMoveAttachmentRequest(com.xpn.xwiki.doc.XWikiDocument doc)
Utility method for checking whether the current webdav request is trying to move / rename an attachment.

Parameters:
doc - the xwiki document to which the attachment belongs to.
Returns:
true if the current webdav request is about moving (or renaming) an attachment from the given xwiki document.

isDeleteResourceRequest

public boolean isDeleteResourceRequest()
Returns:
true if the current webdav request is a DAV_DELETE request.

getMethod

public java.lang.String getMethod()
Returns:
name of the webdav method executed by the current request.

getUser

public java.lang.String getUser()
Returns:
current xwiki user name.

getResourceFactory

public org.apache.jackrabbit.webdav.DavResourceFactory getResourceFactory()
Returns:
dav resource factory.

getDavSession

public org.apache.jackrabbit.webdav.DavSession getDavSession()
Returns:
the dav session.

getLockManager

public org.apache.jackrabbit.webdav.lock.LockManager getLockManager()
Returns:
global lock manager.

getXwikiContext

public com.xpn.xwiki.XWikiContext getXwikiContext()
Returns:
the internal xwiki context.

cleanUp

public void cleanUp()
Release any resources acquired.



Copyright © 2004-2011 XWiki. All Rights Reserved.