1 22 package org.apache.webdav.ant.taskdefs; 23 24 import java.io.IOException ; 25 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.Project; 28 import org.apache.webdav.ant.Utils; 29 import org.apache.webdav.lib.methods.DepthSupport; 30 31 36 public class Lock extends WebdavTask { 37 private String lockTokenProperty = null; 38 private int timeout = 3600; 39 private String ownerInfo = null; 40 private int depth = DepthSupport.DEPTH_INFINITY; 41 42 45 public void execute() throws BuildException { 46 validate(); 47 try { 48 log("Locking " + getUrl(), Project.MSG_INFO); 49 String locktoken = Utils.lockResource( 50 getHttpClient(), 51 getUrl(), 52 this.ownerInfo, 53 this.depth, 54 this.timeout 55 ); 56 getProject().setProperty(this.lockTokenProperty, locktoken); 57 } 58 catch (IOException e) { 59 throw Utils.makeBuildException("Can't lock!", e); 60 } 61 } 62 63 protected void validate() throws BuildException 64 { 65 super.validate(); 66 67 if (this.lockTokenProperty == null) { 68 throw new BuildException("Attribute property required!"); 69 } 70 if (this.ownerInfo == null) { 71 this.ownerInfo = "ant-webdav " + getUserid(); 72 } 73 } 74 75 76 public void setProperty (String name) { 77 this.lockTokenProperty = name; 78 } 79 public void setTimeout(int value) { 80 if (value > 0) { 81 this.timeout = value; 82 } else { 83 throw new BuildException("Invalid timeout value (Must be " + 84 "positive integer)"); 85 } 86 } 87 public void setOwnerinfo(String value) { 88 this.ownerInfo = value; 89 } 90 public void setDepth(String value) { 91 if ("0".trim().equals(value)) { 92 this.depth = DepthSupport.DEPTH_0; 93 } 94 else if ("infinity".trim().toLowerCase().equals(value)) { 95 this.depth = DepthSupport.DEPTH_INFINITY; 96 } 97 else { 98 throw new BuildException("Invalid value of depth attribute." 99 + " (One of '0' or 'infinity' exprected)"); 100 } 101 } 102 } 103 | Popular Tags |