diff --git a/source/java/org/alfresco/repo/webdav/LockMethod.java b/source/java/org/alfresco/repo/webdav/LockMethod.java index d16ca13218..61b93c3fba 100644 --- a/source/java/org/alfresco/repo/webdav/LockMethod.java +++ b/source/java/org/alfresco/repo/webdav/LockMethod.java @@ -33,6 +33,7 @@ import org.alfresco.service.cmr.model.FileFolderUtil; import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.model.FileNotFoundException; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; import org.dom4j.io.XMLWriter; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -196,7 +197,7 @@ public class LockMethod extends WebDAVMethod } } } - + /** * Execute the request * @@ -221,7 +222,7 @@ public class LockMethod extends WebDAVMethod try { // Check if the path exists - lockNodeInfo = getDAVHelper().getNodeForPath(getRootNodeRef(), getPath(), m_request.getServletPath()); + lockNodeInfo = getNodeForPath(getRootNodeRef(), getPath(), m_request.getServletPath()); } catch (FileNotFoundException e) { @@ -252,7 +253,7 @@ public class LockMethod extends WebDAVMethod } // create the file - lockNodeInfo = fileFolderService.create(dirInfo.getNodeRef(), splitPath[1], ContentModel.TYPE_CONTENT); + lockNodeInfo = createNode(dirInfo.getNodeRef(), splitPath[1], ContentModel.TYPE_CONTENT); if (logger.isDebugEnabled()) { @@ -292,6 +293,20 @@ public class LockMethod extends WebDAVMethod // We either created a new lock or refreshed an existing lock, send back the lock details generateResponse(lockNodeInfo.getNodeRef(), userName); } + + /** + * Create a new node + * + * @param parentNodeRef the parent node. + * @param name the name of the node + * @param typeQName the type to create + * @return Returns the new node's file information + * + */ + protected FileInfo createNode(NodeRef parentNodeRef, String name, QName typeQName) + { + return getFileFolderService().create(parentNodeRef, name, ContentModel.TYPE_CONTENT); + } /** * Create a new lock @@ -400,10 +415,9 @@ public class LockMethod extends WebDAVMethod } // Send the XML back to the client - xml.flush(); + flushXML(xml); } - - + /** * Generates a list of namespace declarations for the response */ diff --git a/source/java/org/alfresco/repo/webdav/PropPatchMethod.java b/source/java/org/alfresco/repo/webdav/PropPatchMethod.java index 418c877b55..abf7230257 100644 --- a/source/java/org/alfresco/repo/webdav/PropPatchMethod.java +++ b/source/java/org/alfresco/repo/webdav/PropPatchMethod.java @@ -54,7 +54,7 @@ public class PropPatchMethod extends PropFindMethod try { // Check that the path exists - pathNodeInfo = getDAVHelper().getNodeForPath(getRootNodeRef(), m_strPath, m_request.getServletPath()); + pathNodeInfo = getNodeForPath(getRootNodeRef(), m_strPath, m_request.getServletPath()); } catch (FileNotFoundException e) { @@ -95,7 +95,7 @@ public class PropPatchMethod extends PropFindMethod xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS); // Send remaining data - xml.flush(); + flushXML(xml); } /** @@ -216,7 +216,7 @@ public class PropPatchMethod extends PropFindMethod getDAVHelper().getNullAttributes()); // Build the href string for the current node - String strHRef = WebDAV.getURLForPath(m_request, path, isFolder); + String strHRef = getURLForPath(m_request, path, isFolder); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF, getDAVHelper().getNullAttributes()); xml.write(strHRef); diff --git a/source/java/org/alfresco/repo/webdav/UnlockMethod.java b/source/java/org/alfresco/repo/webdav/UnlockMethod.java index 43884d63f2..ecfbe4d9ba 100644 --- a/source/java/org/alfresco/repo/webdav/UnlockMethod.java +++ b/source/java/org/alfresco/repo/webdav/UnlockMethod.java @@ -117,7 +117,7 @@ public class UnlockMethod extends WebDAVMethod FileInfo lockNodeInfo = null; try { - lockNodeInfo = getDAVHelper().getNodeForPath(getRootNodeRef(), getPath(), getServletPath()); + lockNodeInfo = getNodeForPath(getRootNodeRef(), getPath(), getServletPath()); } catch (FileNotFoundException e) { diff --git a/source/java/org/alfresco/repo/webdav/WebDAVMethod.java b/source/java/org/alfresco/repo/webdav/WebDAVMethod.java index a6d7c54690..ed79a322b1 100644 --- a/source/java/org/alfresco/repo/webdav/WebDAVMethod.java +++ b/source/java/org/alfresco/repo/webdav/WebDAVMethod.java @@ -48,6 +48,7 @@ import org.alfresco.service.cmr.lock.LockService; import org.alfresco.service.cmr.lock.LockStatus; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileInfo; +import org.alfresco.service.cmr.model.FileNotFoundException; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.MimetypeService; @@ -346,9 +347,9 @@ public abstract class WebDAVMethod } } } - + /** - * Access the content repository to satisfy the request and generates the appropriate WebDAV + * Access the content repository to satisfy the request and generates the appropriate WebDAV * response. * * @throws WebDAVServerException a general server exception @@ -663,7 +664,7 @@ public abstract class WebDAVMethod * * @return String */ - protected final String getPath() + protected String getPath() { return m_strPath; } @@ -674,7 +675,7 @@ public abstract class WebDAVMethod * @return XMLWriter * @exception IOException */ - protected final XMLWriter createXMLWriter() throws IOException + protected XMLWriter createXMLWriter() throws IOException { // Check if debug output or XML pretty printing is enabled @@ -1142,11 +1143,68 @@ public abstract class WebDAVMethod } } + /** + * Get the file info for the given paths + * + * @param rootNodeRef the acting webdav root + * @param path the path to search for + * @param servletPath the base servlet path, which may be null or empty + * @return Return the file info for the path + * @throws FileNotFoundException if the path doesn't refer to a valid node + */ + protected FileInfo getNodeForPath(NodeRef rootNodeRef, String path, String servletPath) throws FileNotFoundException + { + return getDAVHelper().getNodeForPath(rootNodeRef, path, servletPath); + } + + /** + * Returns a URL that could be used to access the given path. + * + * @param request HttpServletRequest + * @param path the path to search for + * @param isFolder indicates file or folder is requested + * @return URL that could be used to access the given path + */ + protected String getURLForPath(HttpServletRequest request, String path, boolean isFolder) + { + return WebDAV.getURLForPath(request, path, isFolder); + } + + /** + * Flushs a XML Writer. + * + * @param xml XMLWriter that should be flushed + */ + protected void flushXML(XMLWriter xml) throws IOException + { + xml.flush(); + } + + /** + * Returns a working copy of node for current user. + * + * @param nodeRef node reference + * @return Returns the working copy's file information + */ + protected FileInfo getWorkingCopy(NodeRef nodeRef) + { + FileInfo result = null; + NodeRef workingCopy = getServiceRegistry().getCheckOutCheckInService().getWorkingCopy(nodeRef); + if (workingCopy != null) + { + String workingCopyOwner = getNodeService().getProperty(workingCopy, ContentModel.PROP_WORKING_COPY_OWNER).toString(); + if (workingCopyOwner.equals(getAuthenticationService().getCurrentUserName())) + { + result = getFileFolderService().getFileInfo(workingCopy); + } + } + return result; + } + /** * Class used for storing conditions which comes with "If" header of the request * * @author ivanry - * */ protected class Condition {