1 21 package org.apache.webdav.ant.taskdefs; 22 23 import java.io.IOException ; 24 25 import org.apache.commons.httpclient.HttpURL; 26 import org.apache.commons.httpclient.URIException; 27 28 import org.apache.tools.ant.BuildException; 29 import org.apache.webdav.ant.Utils; 30 import org.apache.webdav.lib.methods.DepthSupport; 31 32 37 public class Copy extends WebdavMatchingTask { 38 39 private String destination; 40 private int depth = DepthSupport.DEPTH_INFINITY; 41 private boolean overwrite = false; 42 private HttpURL destinationURL; 43 44 47 public void execute() throws BuildException { 48 validate(); 49 try { 50 log("Copying " + getUrl(), ifVerbose()); 52 Utils.copyResource( 53 getHttpClient(), 54 getUrl(), 55 this.destinationURL.getURI(), 56 this.depth, 57 this.overwrite 58 ); 59 } 60 catch (IOException e) { 61 throw Utils.makeBuildException("Can't copy!", e); 62 } 63 } 64 65 public void setDestination(String destination) { 66 this.destination = destination; 67 } 68 69 public void setDepth(String value) { 70 if ("0".trim().equals(value)) { 71 this.depth = DepthSupport.DEPTH_0; 72 } 73 else if ("infinity".trim().toLowerCase().equals(value)) { 74 this.depth = DepthSupport.DEPTH_INFINITY; 75 } 76 else { 77 throw new BuildException("Invalid value of depth attribute." 78 + " (One of '0' or 'infinity' expected)"); 79 } 80 } 81 82 public void setOverwrite(boolean value) { 83 this.overwrite = value; 84 } 85 86 protected void validate() { 87 super.validate(); 88 if (destination == null) { 89 throw new BuildException("Missing required attribute destination"); 90 } 91 92 try { 93 this.destinationURL = Utils.createHttpURL(getUrl(), this.destination); 94 this.destinationURL.setPath(removeDoubleSlashes( 95 this.destinationURL.getPath())); 96 } catch (URIException e) { 97 throw new BuildException("Invalid destination uri!", e); 98 } 99 } 100 101 } 102 | Popular Tags |