KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > ant > taskdefs > Lock


1 // vi: set ts=3 sw=3:
2
/*
3  * $Header: /home/cvs/jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/taskdefs/Lock.java,v 1.3 2004/07/28 09:31:47 ib Exp $
4  * $Revision: 1.3 $
5  * $Date: 2004/07/28 09:31:47 $
6  * ========================================================================
7  * Copyright 2004 The Apache Software Foundation
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ========================================================================
21  */

22 package org.apache.webdav.ant.taskdefs;
23
24 import java.io.IOException JavaDoc;
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 /**
32  * WebDAV task for locking resources.
33  *
34  * @see <a HREF="../doc-files/tasks.htm#lock">Task documentation</a>
35  */

36 public class Lock extends WebdavTask {
37    private String JavaDoc lockTokenProperty = null;
38    private int timeout = 3600;
39    private String JavaDoc ownerInfo = null;
40    private int depth = DepthSupport.DEPTH_INFINITY;
41    
42    /*
43     * @see org.apache.tools.ant.Task#execute()
44     */

45    public void execute() throws BuildException {
46       validate();
47       try {
48          log("Locking " + getUrl(), Project.MSG_INFO);
49          String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc value) {
88       this.ownerInfo = value;
89    }
90    public void setDepth(String JavaDoc 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