Package org.alfresco.repo.webdav
Class WebDAVMethod
- java.lang.Object
-
- org.alfresco.repo.webdav.WebDAVMethod
-
- Direct Known Subclasses:
DeleteMethod,GetMethod,HierarchicalMethod,LockMethod,MkcolMethod,OptionsMethod,PropFindMethod,PutMethod,UnlockMethod
public abstract class WebDAVMethod extends java.lang.ObjectAbstract base class for all the WebDAV method handling classes- Author:
- gavinc
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classWebDAVMethod.ConditionClass used for storing conditions which comes with "If" header of the request
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.commons.logging.Logloggerprotected java.util.Map<org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.cmr.repository.NodeRef>m_childToParentprotected java.util.LinkedList<WebDAVMethod.Condition>m_conditionsprotected WebDAVHelperm_davHelperprotected intm_depthprotected java.util.Map<org.alfresco.service.cmr.repository.NodeRef,org.alfresco.repo.webdav.LockInfo>m_parentLockInfoprotected javax.servlet.http.HttpServletRequestm_requestprotected java.lang.Stringm_resourceTagprotected javax.servlet.http.HttpServletResponsem_responseprotected org.alfresco.service.cmr.repository.NodeRefm_rootNodeRefprotected java.lang.Stringm_strPathprotected java.lang.Stringm_userAgent
-
Constructor Summary
Constructors Constructor Description WebDAVMethod()Default constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected org.alfresco.repo.webdav.LockInfocheckNode(org.alfresco.service.cmr.model.FileInfo fileInfo)Checks if write operation can be performed on node.protected org.alfresco.repo.webdav.LockInfocheckNode(org.alfresco.service.cmr.model.FileInfo fileInfo, boolean ignoreShared, boolean lockMethod)Checks if write operation can be performed on node.protected org.dom4j.io.XMLWritercreateXMLWriter()Create an XML writer for the responsevoidexecute()Executes the method, wrapping the call toexecuteImpl()in an appropriate transaction and handling the error conditions.protected abstract voidexecuteImpl()Access the content repository to satisfy the request and generates the appropriate WebDAV response.protected voidflushXML(org.dom4j.io.XMLWriter writer)Flushes all XML written so far to the responseprotected voidgenerateLockDiscoveryXML(org.dom4j.io.XMLWriter xml, org.alfresco.service.cmr.model.FileInfo lockNodeInfo, boolean emptyNamespace, java.lang.String scope, java.lang.String depth, java.lang.String lToken, java.lang.String owner, java.util.Date expiryDate)Generates the lock discovery XML responseprotected voidgenerateLockDiscoveryXML(org.dom4j.io.XMLWriter xml, org.alfresco.service.cmr.model.FileInfo lockNodeInfo, org.alfresco.repo.webdav.LockInfo lockInfo)Generates the lock discovery XML responseprotected java.lang.StringgenerateNamespaceDeclarations(java.util.HashMap<java.lang.String,java.lang.String> nameSpaces)Generates a list of namespace declarations for the responseprotected voidgenerateResponseImpl()Does nothing unless overridden - for reasons of backwards compatibility.protected org.alfresco.service.cmr.action.ActionServicegetActionService()Convenience method to return the action serviceprotected org.alfresco.service.cmr.security.AuthenticationServicegetAuthenticationService()Convenience method to return the authentication serviceprotected org.alfresco.service.cmr.repository.ContentServicegetContentService()Convenience method to return the content serviceprotected java.lang.StringgetContextPath()protected WebDAVHelpergetDAVHelper()Return the WebDAV protocol helperprotected WebDAVLockServicegetDAVLockService()Retrieve the (WebDAV protocol-level) locking service.intgetDepth()Return the property find depthprotected org.alfresco.service.cmr.model.FileFolderServicegetFileFolderService()protected org.alfresco.service.cmr.repository.MimetypeServicegetMimetypeService()Convenience method to return the mimetype serviceprotected org.alfresco.service.namespace.NamespaceServicegetNamespaceService()Convenience method to return the namespace serviceprotected org.alfresco.service.cmr.model.FileInfogetNodeForPath(org.alfresco.service.cmr.repository.NodeRef rootNodeRef, java.lang.String path)Get the file info for the given pathsprotected org.alfresco.repo.webdav.LockInfogetNodeLockInfo(org.alfresco.service.cmr.model.FileInfo nodeInfo)Returns node Lock token in consideration of WebDav lock depth.protected org.alfresco.service.cmr.repository.NodeServicegetNodeService()Convenience method to return the node servicejava.lang.StringgetPath()Return the relative pathprotected org.alfresco.service.cmr.security.PermissionServicegetPermissionService()Convenience method to return the permission serviceprotected org.w3c.dom.DocumentgetRequestBodyAsDocument()Retrieves the request body as an XML documentprotected org.alfresco.service.cmr.repository.NodeRefgetRootNodeRef()Return the root nodeprotected org.alfresco.service.cmr.search.SearchServicegetSearchService()Convenience method to return the search serviceprotected org.alfresco.service.ServiceRegistrygetServiceRegistry()Return the service registryprotected java.lang.StringgetServletPath()protected java.lang.StringgetSiteId()Get the site ID (short-name) that the current request relates to.protected intgetStatusForAccessDeniedException()Determines status code for AccessDeniedException based on client's HTTP headers.protected java.lang.StringgetTenantDomain()Get the tenant domain for the current user and request.protected org.alfresco.service.transaction.TransactionServicegetTransactionService()Convenience method to return the transaction serviceprotected java.lang.StringgetURLForPath(javax.servlet.http.HttpServletRequest request, java.lang.String path, boolean isFolder)Returns a URL that could be used to access the given path.protected org.alfresco.service.cmr.model.FileInfogetWorkingCopy(org.alfresco.service.cmr.repository.NodeRef nodeRef)Returns a working copy of node for current user.protected org.dom4j.io.OutputFormatgetXMLOutputFormat()Returns the format required for an XML response.protected booleanisReadOnly()Override and return true if the method is a query method only.protected voidparseDepthHeader()Parses "Depth" request headerprotected voidparseIfHeader()Parses "If" header of the request.protected abstract voidparseRequestBody()Parses the given request body represented as an XML document and sets any necessary context ready for execution.protected abstract voidparseRequestHeaders()Parses the HTTP headers of the request and sets any necessary context ready for execution.voidsetDetails(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, WebDAVHelper davHelper, org.alfresco.service.cmr.repository.NodeRef rootNode)Set the request/response detailsprotected booleanshouldFlushXMLWriter()Determines whether the XMLWriter should be flushed when XML is flushed.java.lang.StringtoString()
-
-
-
Field Detail
-
logger
protected static org.apache.commons.logging.Log logger
-
m_request
protected javax.servlet.http.HttpServletRequest m_request
-
m_response
protected javax.servlet.http.HttpServletResponse m_response
-
m_davHelper
protected WebDAVHelper m_davHelper
-
m_rootNodeRef
protected org.alfresco.service.cmr.repository.NodeRef m_rootNodeRef
-
m_strPath
protected java.lang.String m_strPath
-
m_userAgent
protected java.lang.String m_userAgent
-
m_conditions
protected java.util.LinkedList<WebDAVMethod.Condition> m_conditions
-
m_resourceTag
protected java.lang.String m_resourceTag
-
m_depth
protected int m_depth
-
m_childToParent
protected java.util.Map<org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.cmr.repository.NodeRef> m_childToParent
-
m_parentLockInfo
protected java.util.Map<org.alfresco.service.cmr.repository.NodeRef,org.alfresco.repo.webdav.LockInfo> m_parentLockInfo
-
-
Method Detail
-
setDetails
public void setDetails(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, WebDAVHelper davHelper, org.alfresco.service.cmr.repository.NodeRef rootNode)Set the request/response details- Parameters:
req- HttpServletRequestresp- HttpServletResponsedavHelper- WebDAVHelperrootNode- NodeRef
-
isReadOnly
protected boolean isReadOnly()
Override and return true if the method is a query method only. The default implementation returns false.- Returns:
- Returns true if the method transaction may be read-only
-
getDepth
public final int getDepth()
Return the property find depth- Returns:
- int
-
execute
public void execute() throws WebDAVServerExceptionExecutes the method, wrapping the call toexecuteImpl()in an appropriate transaction and handling the error conditions.- Throws:
WebDAVServerException
-
executeImpl
protected abstract void executeImpl() throws WebDAVServerException, java.lang.ExceptionAccess the content repository to satisfy the request and generates the appropriate WebDAV response.- Throws:
WebDAVServerException- a general server exceptionjava.lang.Exception- any unhandled exception
-
generateResponseImpl
protected void generateResponseImpl() throws java.lang.ExceptionDoes nothing unless overridden - for reasons of backwards compatibility. Subclasses implementing this method should separate the WebDAV method execution logic from response generation logic. Execution logic should be contained in theexecuteImpl()method and should NOT contain any code that writes to the response. Conversely response generation logic should NOT contain any code relating to the desired effect of the WebDAV method (e.g. setting properties on a node) and should be contained purely within this method.Older methods, until refactored will not override this method, relying only on
executeImpl().- Throws:
java.lang.Exception
-
parseRequestBody
protected abstract void parseRequestBody() throws WebDAVServerExceptionParses the given request body represented as an XML document and sets any necessary context ready for execution.- Throws:
WebDAVServerException
-
parseRequestHeaders
protected abstract void parseRequestHeaders() throws WebDAVServerExceptionParses the HTTP headers of the request and sets any necessary context ready for execution.- Throws:
WebDAVServerException
-
getRequestBodyAsDocument
protected org.w3c.dom.Document getRequestBodyAsDocument() throws WebDAVServerExceptionRetrieves the request body as an XML document- Returns:
- The body of the request as an XML document or null if there isn't a body
- Throws:
WebDAVServerException
-
parseDepthHeader
protected void parseDepthHeader() throws WebDAVServerExceptionParses "Depth" request header- Throws:
WebDAVServerException
-
parseIfHeader
protected void parseIfHeader() throws WebDAVServerExceptionParses "If" header of the request. Stores conditions that should be checked. Parses both No-tag-list and Tagged-list formats See "10.4.2 Syntax" paragraph of the WebDAV specification for "If" header format.- Throws:
WebDAVServerException
-
getDAVHelper
protected final WebDAVHelper getDAVHelper()
Return the WebDAV protocol helper- Returns:
- WebDAVHelper
-
getServiceRegistry
protected final org.alfresco.service.ServiceRegistry getServiceRegistry()
Return the service registry- Returns:
- ServiceRegistry
-
getTransactionService
protected final org.alfresco.service.transaction.TransactionService getTransactionService()
Convenience method to return the transaction service- Returns:
- TransactionService
-
getNodeService
protected final org.alfresco.service.cmr.repository.NodeService getNodeService()
Convenience method to return the node service- Returns:
- NodeService
-
getSearchService
protected final org.alfresco.service.cmr.search.SearchService getSearchService()
Convenience method to return the search service- Returns:
- SearchService
-
getNamespaceService
protected final org.alfresco.service.namespace.NamespaceService getNamespaceService()
Convenience method to return the namespace service- Returns:
- NamespaceService
-
getFileFolderService
protected final org.alfresco.service.cmr.model.FileFolderService getFileFolderService()
- Returns:
- Returns the general file/folder manipulation service
-
getContentService
protected final org.alfresco.service.cmr.repository.ContentService getContentService()
Convenience method to return the content service- Returns:
- ContentService
-
getMimetypeService
protected final org.alfresco.service.cmr.repository.MimetypeService getMimetypeService()
Convenience method to return the mimetype service- Returns:
- MimetypeService
-
getDAVLockService
protected final WebDAVLockService getDAVLockService()
Retrieve the (WebDAV protocol-level) locking service.- Returns:
- WebDAVLockService
-
getActionService
protected final org.alfresco.service.cmr.action.ActionService getActionService()
Convenience method to return the action service- Returns:
- ActionService
-
getPermissionService
protected final org.alfresco.service.cmr.security.PermissionService getPermissionService()
Convenience method to return the permission service- Returns:
- PermissionService
-
getAuthenticationService
protected final org.alfresco.service.cmr.security.AuthenticationService getAuthenticationService()
Convenience method to return the authentication service- Returns:
- AuthenticationService
-
getServletPath
protected final java.lang.String getServletPath()
- Returns:
- Returns the path of the servlet, e.g. /webdav
-
getContextPath
protected final java.lang.String getContextPath()
- Returns:
- Returns the context path of the servlet, e.g. /alfresco
-
getRootNodeRef
protected final org.alfresco.service.cmr.repository.NodeRef getRootNodeRef()
Return the root node- Returns:
- NodeRef
-
getPath
public java.lang.String getPath()
Return the relative path- Returns:
- String
-
getXMLOutputFormat
protected org.dom4j.io.OutputFormat getXMLOutputFormat()
Returns the format required for an XML response. This may vary per method.
-
createXMLWriter
protected final org.dom4j.io.XMLWriter createXMLWriter() throws java.io.IOExceptionCreate an XML writer for the response- Returns:
- XMLWriter
- Throws:
java.io.IOException
-
generateLockDiscoveryXML
protected void generateLockDiscoveryXML(org.dom4j.io.XMLWriter xml, org.alfresco.service.cmr.model.FileInfo lockNodeInfo, org.alfresco.repo.webdav.LockInfo lockInfo) throws java.lang.ExceptionGenerates the lock discovery XML response- Parameters:
xml- XMLWriterlockNodeInfo- FileInfolockInfo- LockInfo- Throws:
java.lang.Exception
-
generateLockDiscoveryXML
protected void generateLockDiscoveryXML(org.dom4j.io.XMLWriter xml, org.alfresco.service.cmr.model.FileInfo lockNodeInfo, boolean emptyNamespace, java.lang.String scope, java.lang.String depth, java.lang.String lToken, java.lang.String owner, java.util.Date expiryDate) throws java.lang.ExceptionGenerates the lock discovery XML response- Parameters:
xml- XMLWriterlockNodeInfo- FileInfoemptyNamespace- boolean True if namespace should be empty. Used to avoid bugs in WebDAV clients.scope- String lock scopedepth- String lock depthlToken- String locktokenowner- String lock ownerexpiryDate- the date/time the lock should expire- Throws:
java.lang.Exception
-
generateNamespaceDeclarations
protected java.lang.String generateNamespaceDeclarations(java.util.HashMap<java.lang.String,java.lang.String> nameSpaces)
Generates a list of namespace declarations for the response
-
checkNode
protected org.alfresco.repo.webdav.LockInfo checkNode(org.alfresco.service.cmr.model.FileInfo fileInfo, boolean ignoreShared, boolean lockMethod) throws WebDAVServerExceptionChecks if write operation can be performed on node.- Parameters:
fileInfo- - node's file infoignoreShared- - if true ignores shared lockslockMethod- - must be true if used from lock method- Returns:
- node's lock info
- Throws:
WebDAVServerException- if node has shared or exclusive lock or If header preconditions failed
-
checkNode
protected org.alfresco.repo.webdav.LockInfo checkNode(org.alfresco.service.cmr.model.FileInfo fileInfo) throws WebDAVServerExceptionChecks if write operation can be performed on node.- Parameters:
fileInfo- FileInfo- Returns:
- LockInfo
- Throws:
WebDAVServerException- if node has shared or exclusive lock or If header preconditions failed
-
getNodeLockInfo
protected org.alfresco.repo.webdav.LockInfo getNodeLockInfo(org.alfresco.service.cmr.model.FileInfo nodeInfo)
Returns node Lock token in consideration of WebDav lock depth.- Parameters:
nodeInfo- FileInfo- Returns:
- String Lock token
-
getNodeForPath
protected org.alfresco.service.cmr.model.FileInfo getNodeForPath(org.alfresco.service.cmr.repository.NodeRef rootNodeRef, java.lang.String path) throws org.alfresco.service.cmr.model.FileNotFoundExceptionGet the file info for the given paths- Parameters:
rootNodeRef- the acting webdav rootpath- the path to search for- Returns:
- Return the file info for the path
- Throws:
org.alfresco.service.cmr.model.FileNotFoundException- if the path doesn't refer to a valid node
-
getURLForPath
protected java.lang.String getURLForPath(javax.servlet.http.HttpServletRequest request, java.lang.String path, boolean isFolder)Returns a URL that could be used to access the given path.- Parameters:
request- HttpServletRequestpath- the path to search forisFolder- indicates file or folder is requested- Returns:
- URL that could be used to access the given path
-
shouldFlushXMLWriter
protected boolean shouldFlushXMLWriter()
Determines whether the XMLWriter should be flushed when XML is flushed. For some reason this is method specific.- Returns:
trueif the XMLWriter should be flushed when XML is flushed
-
flushXML
protected final void flushXML(org.dom4j.io.XMLWriter writer) throws java.io.IOExceptionFlushes all XML written so far to the response- Parameters:
writer- XMLWriter that should be flushed- Throws:
java.io.IOException
-
getWorkingCopy
protected org.alfresco.service.cmr.model.FileInfo getWorkingCopy(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Returns a working copy of node for current user.- Parameters:
nodeRef- node reference- Returns:
- Returns the working copy's file information
-
getStatusForAccessDeniedException
protected int getStatusForAccessDeniedException()
Determines status code for AccessDeniedException based on client's HTTP headers.- Returns:
- Returns status code
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getSiteId
protected java.lang.String getSiteId()
Get the site ID (short-name) that the current request relates to. The site ID will beDEFAULT_SITE_IDif not specifically set.- Returns:
- The site ID
-
getTenantDomain
protected java.lang.String getTenantDomain()
Get the tenant domain for the current user and request. The tenant domain will beTenantService.DEFAULT_DOMAINif not specifically set.- Returns:
- The tenant domain.
-
-