mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
WebDAV: separation of command execution and response generation.
* created hook that allows separation of command execution and response generation. * refactored PropPatchMethod to use the new hook. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@34483 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -40,9 +40,11 @@ import org.xml.sax.Attributes;
|
|||||||
*/
|
*/
|
||||||
public class PropPatchMethod extends PropFindMethod
|
public class PropPatchMethod extends PropFindMethod
|
||||||
{
|
{
|
||||||
|
|
||||||
// Properties to patch
|
// Properties to patch
|
||||||
protected ArrayList<PropertyAction> m_propertyActions = null;
|
protected ArrayList<PropertyAction> m_propertyActions = null;
|
||||||
|
private String strHRef;
|
||||||
|
private WebDAVProperty failedProperty;
|
||||||
|
private String basePath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns <tt>false</tt> always
|
* @return Returns <tt>false</tt> always
|
||||||
@@ -56,9 +58,6 @@ public class PropPatchMethod extends PropFindMethod
|
|||||||
@Override
|
@Override
|
||||||
protected void executeImpl() throws WebDAVServerException, Exception
|
protected void executeImpl() throws WebDAVServerException, Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS);
|
|
||||||
|
|
||||||
FileInfo pathNodeInfo = null;
|
FileInfo pathNodeInfo = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -72,10 +71,33 @@ public class PropPatchMethod extends PropFindMethod
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkNode(pathNodeInfo);
|
checkNode(pathNodeInfo);
|
||||||
|
|
||||||
|
// Create the path for the current location in the tree
|
||||||
|
StringBuilder baseBuild = new StringBuilder(256);
|
||||||
|
baseBuild.append(getPath());
|
||||||
|
if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar)
|
||||||
|
{
|
||||||
|
baseBuild.append(WebDAVHelper.PathSeperatorChar);
|
||||||
|
}
|
||||||
|
basePath = baseBuild.toString();
|
||||||
|
|
||||||
|
// Build the href string for the current node
|
||||||
|
boolean isFolder = pathNodeInfo.isFolder();
|
||||||
|
strHRef = getURLForPath(m_request, basePath, isFolder);
|
||||||
|
|
||||||
|
// Do the real work: patch the properties
|
||||||
|
patchProperties(pathNodeInfo, basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void generateResponseImpl() throws Exception
|
||||||
|
{
|
||||||
|
m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS);
|
||||||
|
|
||||||
// Set the response content type
|
// Set the response content type
|
||||||
m_response.setContentType(WebDAV.XML_CONTENT_TYPE);
|
m_response.setContentType(WebDAV.XML_CONTENT_TYPE);
|
||||||
|
|
||||||
// Create multistatus response
|
// Create multistatus response
|
||||||
XMLWriter xml = createXMLWriter();
|
XMLWriter xml = createXMLWriter();
|
||||||
|
|
||||||
@@ -87,19 +109,34 @@ public class PropPatchMethod extends PropFindMethod
|
|||||||
WebDAV.XML_MULTI_STATUS + nsdec,
|
WebDAV.XML_MULTI_STATUS + nsdec,
|
||||||
WebDAV.XML_NS_MULTI_STATUS + nsdec,
|
WebDAV.XML_NS_MULTI_STATUS + nsdec,
|
||||||
getDAVHelper().getNullAttributes());
|
getDAVHelper().getNullAttributes());
|
||||||
|
|
||||||
|
// Output the response block for the current node
|
||||||
|
xml.startElement(
|
||||||
|
WebDAV.DAV_NS,
|
||||||
|
WebDAV.XML_RESPONSE,
|
||||||
|
WebDAV.XML_NS_RESPONSE,
|
||||||
|
getDAVHelper().getNullAttributes());
|
||||||
|
|
||||||
// Create the path for the current location in the tree
|
xml.startElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF, getDAVHelper().getNullAttributes());
|
||||||
StringBuilder baseBuild = new StringBuilder(256);
|
xml.write(strHRef);
|
||||||
baseBuild.append(getPath());
|
xml.endElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF);
|
||||||
if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar)
|
|
||||||
|
if (failedProperty != null)
|
||||||
{
|
{
|
||||||
baseBuild.append(WebDAVHelper.PathSeperatorChar);
|
generateError(xml);
|
||||||
}
|
}
|
||||||
String basePath = baseBuild.toString();
|
|
||||||
|
|
||||||
// Output the response for the root node, depth zero
|
|
||||||
generateResponse(xml, pathNodeInfo, basePath);
|
|
||||||
|
|
||||||
|
for (PropertyAction propertyAction : m_propertyActions)
|
||||||
|
{
|
||||||
|
WebDAVProperty property = propertyAction.getProperty();
|
||||||
|
int statusCode = propertyAction.getStatusCode();
|
||||||
|
String statusCodeDescription = propertyAction.getStatusCodeDescription();
|
||||||
|
generatePropertyResponse(xml, property, statusCode, statusCodeDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close off the response element
|
||||||
|
xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE);
|
||||||
|
|
||||||
// Close the outer XML element
|
// Close the outer XML element
|
||||||
xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS);
|
xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS);
|
||||||
|
|
||||||
@@ -107,6 +144,7 @@ public class PropPatchMethod extends PropFindMethod
|
|||||||
flushXML(xml);
|
flushXML(xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the request body
|
* Parse the request body
|
||||||
*
|
*
|
||||||
@@ -208,42 +246,13 @@ public class PropPatchMethod extends PropFindMethod
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void patchProperties(FileInfo nodeInfo, String path) throws WebDAVServerException
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates the required response XML
|
|
||||||
*
|
|
||||||
* @param xml XMLWriter
|
|
||||||
* @param node NodeRef
|
|
||||||
* @param path String
|
|
||||||
*/
|
|
||||||
protected void generateResponse(XMLWriter xml, FileInfo nodeInfo, String path) throws Exception
|
|
||||||
{
|
{
|
||||||
boolean isFolder = nodeInfo.isFolder();
|
failedProperty = null;
|
||||||
|
|
||||||
// Output the response block for the current node
|
|
||||||
xml.startElement(
|
|
||||||
WebDAV.DAV_NS,
|
|
||||||
WebDAV.XML_RESPONSE,
|
|
||||||
WebDAV.XML_NS_RESPONSE,
|
|
||||||
getDAVHelper().getNullAttributes());
|
|
||||||
|
|
||||||
// Build the href string for the current node
|
|
||||||
String strHRef = getURLForPath(m_request, path, isFolder);
|
|
||||||
|
|
||||||
xml.startElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF, getDAVHelper().getNullAttributes());
|
|
||||||
xml.write(strHRef);
|
|
||||||
xml.endElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF);
|
|
||||||
|
|
||||||
|
|
||||||
boolean failed = false;
|
|
||||||
WebDAVProperty failedProperty = null;
|
|
||||||
for (PropertyAction action : m_propertyActions)
|
for (PropertyAction action : m_propertyActions)
|
||||||
{
|
{
|
||||||
if (action.getProperty().isProtected())
|
if (action.getProperty().isProtected())
|
||||||
{
|
{
|
||||||
generateError(xml);
|
|
||||||
failed = true;
|
|
||||||
failedProperty = action.getProperty();
|
failedProperty = action.getProperty();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -255,7 +264,7 @@ public class PropPatchMethod extends PropFindMethod
|
|||||||
String statusCodeDescription;
|
String statusCodeDescription;
|
||||||
WebDAVProperty property = propertyAction.getProperty();
|
WebDAVProperty property = propertyAction.getProperty();
|
||||||
|
|
||||||
if (!failed)
|
if (failedProperty == null)
|
||||||
{
|
{
|
||||||
if (PropertyAction.SET == propertyAction.getAction())
|
if (PropertyAction.SET == propertyAction.getAction())
|
||||||
{
|
{
|
||||||
@@ -283,13 +292,9 @@ public class PropPatchMethod extends PropFindMethod
|
|||||||
statusCodeDescription = WebDAV.WEBDAV_SC_FAILED_DEPENDENCY_DESC;
|
statusCodeDescription = WebDAV.WEBDAV_SC_FAILED_DEPENDENCY_DESC;
|
||||||
}
|
}
|
||||||
|
|
||||||
generatePropertyResponse(xml, property, statusCode, statusCodeDescription);
|
propertyAction.setResult(statusCode, statusCodeDescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close off the response element
|
|
||||||
xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -378,6 +383,9 @@ public class PropPatchMethod extends PropFindMethod
|
|||||||
// Action
|
// Action
|
||||||
private int action;
|
private int action;
|
||||||
|
|
||||||
|
private int statusCode;
|
||||||
|
|
||||||
|
private String statusCodeDescription;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@@ -391,6 +399,22 @@ public class PropPatchMethod extends PropFindMethod
|
|||||||
this.property = property;
|
this.property = property;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setResult(int statusCode, String statusCodeDescription)
|
||||||
|
{
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
this.statusCodeDescription = statusCodeDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatusCode()
|
||||||
|
{
|
||||||
|
return this.statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatusCodeDescription()
|
||||||
|
{
|
||||||
|
return this.statusCodeDescription;
|
||||||
|
}
|
||||||
|
|
||||||
public int getAction()
|
public int getAction()
|
||||||
{
|
{
|
||||||
return action;
|
return action;
|
||||||
@@ -410,6 +434,10 @@ public class PropPatchMethod extends PropFindMethod
|
|||||||
str.append(getAction() == 0 ? "SET" : "REMOVE");
|
str.append(getAction() == 0 ? "SET" : "REMOVE");
|
||||||
str.append(",property=");
|
str.append(",property=");
|
||||||
str.append(getProperty());
|
str.append(getProperty());
|
||||||
|
str.append(",statusCode=");
|
||||||
|
str.append(getStatusCode());
|
||||||
|
str.append(",statusCodeDescription=");
|
||||||
|
str.append(getStatusCodeDescription());
|
||||||
str.append("]");
|
str.append("]");
|
||||||
|
|
||||||
return str.toString();
|
return str.toString();
|
||||||
|
@@ -335,6 +335,7 @@ public abstract class WebDAVMethod
|
|||||||
boolean isReadOnly = isReadOnly();
|
boolean isReadOnly = isReadOnly();
|
||||||
// Execute the method
|
// Execute the method
|
||||||
getTransactionService().getRetryingTransactionHelper().doInTransaction(executeImplCallback, isReadOnly);
|
getTransactionService().getRetryingTransactionHelper().doInTransaction(executeImplCallback, isReadOnly);
|
||||||
|
generateResponseImpl();
|
||||||
}
|
}
|
||||||
catch (AccessDeniedException e)
|
catch (AccessDeniedException e)
|
||||||
{
|
{
|
||||||
@@ -384,6 +385,20 @@ public abstract class WebDAVMethod
|
|||||||
*/
|
*/
|
||||||
protected abstract void executeImpl() throws WebDAVServerException, Exception;
|
protected abstract void executeImpl() throws WebDAVServerException, Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does 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 the {@link #executeImpl} 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.
|
||||||
|
* <p>
|
||||||
|
* Older methods, until refactored will not override this method, relying only on {@link #executeImpl()}.
|
||||||
|
*/
|
||||||
|
protected void generateResponseImpl() throws Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the given request body represented as an XML document and sets any necessary context
|
* Parses the given request body represented as an XML document and sets any necessary context
|
||||||
* ready for execution.
|
* ready for execution.
|
||||||
|
Reference in New Issue
Block a user