KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

36 public class Move extends WebdavMatchingTask {
37
38     private String JavaDoc destination;
39     private boolean overwrite;
40     private HttpURL destinationURL;
41
42     /*
43      * @see org.apache.tools.ant.Task#execute()
44      */

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 JavaDoc e) {
57             throw Utils.makeBuildException("Can't move!", e);
58         }
59     }
60
61     public void setDestination(String JavaDoc 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