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 31 36 public class Move extends WebdavMatchingTask { 37 38 private String destination; 39 private boolean overwrite; 40 private HttpURL destinationURL; 41 42 45 public void execute() throws BuildException { 46 validate(); 47 try { 48 log("Moving " + getUrl(), ifVerbose()); 49 Utils.moveResource( 50 getHttpClient(), 51 getUrl(), 52 this.destinationURL.getURI(), 53 this.overwrite 54 ); 55 } 56 catch (IOException e) { 57 throw Utils.makeBuildException("Can't move!", e); 58 } 59 } 60 61 public void setDestination(String destination) { 62 this.destination = destination; 63 } 64 65 public void setOverwrite(boolean value) { 66 this.overwrite = value; 67 } 68 69 protected void validate() { 70 super.validate(); 71 if (destination == null) { 72 throw new BuildException("Missing required attribute destination"); 73 } 74 75 try { 76 this.destinationURL = Utils.createHttpURL(getUrl(), this.destination); 77 this.destinationURL.setPath(removeDoubleSlashes( 78 this.destinationURL.getPath())); 79 } catch (URIException e) { 80 throw new BuildException("Invalid destination uri!", e); 81 } 82 } 83 84 } 85 | Popular Tags |