1 17 package org.alfresco.repo.webdav; 18 19 import javax.servlet.http.HttpServletResponse ; 20 21 import org.alfresco.service.cmr.model.FileFolderService; 22 import org.alfresco.service.cmr.model.FileInfo; 23 import org.alfresco.service.cmr.model.FileNotFoundException; 24 import org.alfresco.service.cmr.repository.NodeRef; 25 26 31 public abstract class AbstractMoveOrCopyMethod extends HierarchicalMethod 32 { 33 36 public AbstractMoveOrCopyMethod() 37 { 38 } 39 40 49 protected abstract void moveOrCopy( 50 FileFolderService fileFolderService, 51 NodeRef sourceNodeRef, 52 NodeRef destParentNodeRef, 53 String name) throws Exception ; 54 55 60 protected final void executeImpl() throws WebDAVServerException, Exception 61 { 62 FileFolderService fileFolderService = getFileFolderService(); 63 64 NodeRef rootNodeRef = getRootNodeRef(); 65 String servletPath = getServletPath(); 66 67 if (logger.isDebugEnabled()) 69 { 70 logger.debug("Copy from " + getPath() + " to " + getDestinationPath()); 71 } 72 73 String sourcePath = getPath(); 75 FileInfo sourceInfo = null; 76 try 77 { 78 sourceInfo = getDAVHelper().getNodeForPath(rootNodeRef, sourcePath, servletPath); 79 } 80 catch (FileNotFoundException e) 81 { 82 throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND); 83 } 84 85 String destPath = getDestinationPath(); 87 FileInfo destParentInfo = null; 88 try 89 { 90 destParentInfo = getDAVHelper().getParentNodeForPath(rootNodeRef, destPath, servletPath); 91 } 92 catch (FileNotFoundException e) 93 { 94 if (logger.isDebugEnabled()) 95 { 96 logger.debug("Destination parent folder doesn't exist: " + destPath); 97 } 98 throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND); 99 } 100 101 FileInfo destInfo = null; 103 try 104 { 105 destInfo = getDAVHelper().getNodeForPath(rootNodeRef, destPath, servletPath); 106 if (!hasOverWrite()) 107 { 108 if (logger.isDebugEnabled()) 109 { 110 logger.debug("Destination exists but overwrite is not allowed"); 111 } 112 throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED); 114 } 115 if (!destInfo.getNodeRef().equals(sourceInfo.getNodeRef())) 117 { 118 fileFolderService.delete(destInfo.getNodeRef()); 120 } 121 else 122 { 123 } 125 } 126 catch (FileNotFoundException e) 127 { 128 } 130 131 NodeRef sourceNodeRef = sourceInfo.getNodeRef(); 132 NodeRef destParentNodeRef = destParentInfo.getNodeRef(); 133 String name = getDAVHelper().splitPath(destPath)[1]; 134 moveOrCopy(fileFolderService, sourceNodeRef, destParentNodeRef, name); 135 136 if (destInfo == null) 138 { 139 m_response.setStatus(HttpServletResponse.SC_CREATED); 140 } 141 else 142 { 143 m_response.setStatus(HttpServletResponse.SC_NO_CONTENT); 144 } 145 } 146 } 147 | Popular Tags |