1 17 package com.sslexplorer.vfs.webdav.methods; 18 19 import java.io.IOException ; 20 import java.net.URI ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import com.sslexplorer.vfs.VFSLockManager; 26 import com.sslexplorer.vfs.VFSResource; 27 import com.sslexplorer.vfs.webdav.DAVException; 28 import com.sslexplorer.vfs.webdav.DAVMethod; 29 import com.sslexplorer.vfs.webdav.DAVMultiStatus; 30 import com.sslexplorer.vfs.webdav.DAVProcessor; 31 import com.sslexplorer.vfs.webdav.DAVServlet; 32 import com.sslexplorer.vfs.webdav.DAVTransaction; 33 import com.sslexplorer.vfs.webdav.LockedException; 34 35 43 public class COPY implements DAVMethod { 44 45 final static Log log = LogFactory.getLog(COPY.class); 46 47 52 public COPY() { 53 super(); 54 } 55 56 63 public void process(DAVTransaction transaction, VFSResource resource) throws LockedException, IOException { 64 65 String handle = VFSLockManager.getNewHandle(); 66 VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), false, true, handle); 67 68 String action = (String ) transaction.getRequest().getMethod(); 69 70 VFSResource dest = null; 71 72 try { 73 74 URI target = transaction.getDestination(); 75 76 if (target == null) 77 throw new DAVException(412, "No destination"); 78 if(log.isDebugEnabled()) 79 log.debug("Target " + target.getPath()); 80 81 try { 82 DAVProcessor processor = DAVServlet.getDAVProcessor(transaction.getRequest()); 83 dest = processor.getRepository().getResource(resource.getLaunchSession(), target.getPath(), transaction.getCredentials()); 84 VFSLockManager.getInstance().lock(dest, transaction.getSessionInfo(), true, false, handle); 85 86 } catch (Exception ex) { 87 log.error("Failed to get resource. ", ex); 88 transaction.setStatus(500); 89 return; 90 } 91 92 int depth = transaction.getDepth(); 93 boolean recursive = false; 94 if (depth == 0) { 95 recursive = false; 96 } else if (depth == DAVTransaction.INFINITY) { 97 recursive = true; 98 } else { 99 throw new DAVException(412, "Invalid Depth specified"); 100 } 101 try { 102 resource.copy(dest, transaction.getOverwrite(), recursive); 103 transaction.setStatus(204); 104 } catch (DAVMultiStatus multistatus) { 105 multistatus.write(transaction); 106 } 107 if (action.equals("COPY")) { 108 resource.getMount().resourceCopy(resource, dest, transaction, null); 109 } 110 } catch (Exception e) { 111 if (action.equals("COPY")) { 112 resource.getMount().resourceCopy(resource, dest, transaction, e); 113 } 114 IOException ioe = new IOException (e.getMessage()); 115 ioe.initCause(e); 116 throw ioe; 117 } finally { 118 VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle); 119 } 120 121 } 122 } 123 | Popular Tags |