KickJava   Java API By Example, From Geeks To Geeks.

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


1 // vi: set ts=3 sw=3:
2
/*
3  * $Header: /home/cvs/jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/taskdefs/Unlock.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
30 /**
31  * WebDAV task for removing locks.
32  *
33  * @see <a HREF="../doc-files/tasks.htm#unlock">documentation</a>
34  */

35 public class Unlock extends WebdavTask {
36    private String JavaDoc locktoken = null;
37    
38    /*
39     * @see org.apache.tools.ant.Task#execute()
40     */

41    public void execute() throws BuildException {
42       validate();
43       try {
44          log("Unlocking " + getUrl(), Project.MSG_INFO);
45          Utils.unlockResource(
46                getHttpClient(),
47                getUrl(),
48                this.locktoken
49          );
50       }
51       catch (IOException JavaDoc e) {
52          throw Utils.makeBuildException("Can't unlock!", e);
53       }
54    }
55    
56    protected void validate() throws BuildException
57    {
58       super.validate();
59       
60       if (this.locktoken == null) {
61          throw new BuildException("Required locktoken attribute missing!");
62       }
63    }
64    
65    public void setLocktoken(String JavaDoc token) {
66       this.locktoken = token;
67       if (!this.locktoken.startsWith("opaquelocktoken:")) {
68          throw new BuildException("Invalid locktoken: " + token);
69       }
70    }
71
72 }
73
Popular Tags