You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by un...@apache.org on 2004/07/06 21:04:09 UTC
cvs commit: jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/taskdefs Move.java Copy.java
unico 2004/07/06 12:04:09
Modified: webdavclient/ant/src/java/org/apache/webdav/ant antlib.xml
taskdefs.properties Utils.java
Added: webdavclient/ant/src/java/org/apache/webdav/ant/taskdefs
Move.java Copy.java
Log:
add copy and move tasks
Revision Changes Path
1.2 +5 -3 jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/antlib.xml
Index: antlib.xml
===================================================================
RCS file: /home/cvs/jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/antlib.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- antlib.xml 24 May 2004 09:20:25 -0000 1.1
+++ antlib.xml 6 Jul 2004 19:04:09 -0000 1.2
@@ -1,11 +1,13 @@
<?xml version="1.0"?>
<antlib>
- <taskdef name="put" classname="org.apache.webdav.ant.taskdefs.Put"/>
- <taskdef name="get" classname="org.apache.webdav.ant.taskdefs.Get"/>
+ <taskdef name="davput" classname="org.apache.webdav.ant.taskdefs.Put"/>
+ <taskdef name="davget" classname="org.apache.webdav.ant.taskdefs.Get"/>
<taskdef name="lock" classname="org.apache.webdav.ant.taskdefs.Lock"/>
<taskdef name="unlock" classname="org.apache.webdav.ant.taskdefs.Unlock"/>
<taskdef name="mkcol" classname="org.apache.webdav.ant.taskdefs.Mkcol"/>
- <taskdef name="delete" classname="org.apache.webdav.ant.taskdefs.Delete"/>
+ <taskdef name="davdelete" classname="org.apache.webdav.ant.taskdefs.Delete"/>
<taskdef name="proppatch" classname="org.apache.webdav.ant.taskdefs.Proppatch"/>
+ <taskdef name="davcopy" classname="org.apache.webdav.ant.taskdefs.Copy"/>
+ <taskdef name="davmove" classname="org.apache.webdav.ant.taskdefs.Move"/>
</antlib>
1.2 +3 -1 jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/taskdefs.properties
Index: taskdefs.properties
===================================================================
RCS file: /home/cvs/jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/taskdefs.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- taskdefs.properties 24 May 2004 09:20:25 -0000 1.1
+++ taskdefs.properties 6 Jul 2004 19:04:09 -0000 1.2
@@ -4,4 +4,6 @@
unlock=org.apache.webdav.ant.taskdefs.Unlock
mkcol=org.apache.webdav.ant.taskdefs.Mkcol
davdelete=org.apache.webdav.ant.taskdefs.Delete
-proppatch=org.apache.webdav.ant.taskdefs.Proppatch
\ No newline at end of file
+proppatch=org.apache.webdav.ant.taskdefs.Proppatch
+davcopy=org.apache.webdav.ant.taskdefs.Copy
+davmove=org.apache.webdav.ant.taskdefs.Move
\ No newline at end of file
1.3 +43 -3 jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/Utils.java
Index: Utils.java
===================================================================
RCS file: /home/cvs/jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/Utils.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Utils.java 8 Jun 2004 14:34:23 -0000 1.2
+++ Utils.java 6 Jul 2004 19:04:09 -0000 1.3
@@ -48,8 +48,10 @@
import org.apache.webdav.lib.PropertyName;
import org.apache.webdav.lib.ResponseEntity;
import org.apache.webdav.lib.WebdavException;
+import org.apache.webdav.lib.methods.CopyMethod;
import org.apache.webdav.lib.methods.LockMethod;
import org.apache.webdav.lib.methods.MkcolMethod;
+import org.apache.webdav.lib.methods.MoveMethod;
import org.apache.webdav.lib.methods.PropFindMethod;
import org.apache.webdav.lib.methods.UnlockMethod;
import org.apache.webdav.lib.properties.ResourceTypeProperty;
@@ -343,6 +345,44 @@
throw ex;
}
}
+
+ public static void copyResource(HttpClient client, HttpURL url,
+ String destination, int depth, boolean overwrite)
+ throws IOException, HttpException
+ {
+ CopyMethod copy = new CopyMethod(url.getURI(), destination, overwrite, depth);
+ int status = client.executeMethod(copy);
+ switch (status) {
+ case WebdavStatus.SC_OK:
+ case WebdavStatus.SC_CREATED:
+ case WebdavStatus.SC_NO_CONTENT:
+ return;
+
+ default:
+ HttpException ex = new HttpException();
+ ex.setReasonCode(status);
+ throw ex;
+ }
+ }
+
+ public static void moveResource(HttpClient client, HttpURL url,
+ String destination, int depth, boolean overwrite)
+ throws IOException, HttpException
+ {
+ MoveMethod move = new MoveMethod(url.getURI(), destination, overwrite, depth);
+ int status = client.executeMethod(move);
+ switch (status) {
+ case WebdavStatus.SC_OK:
+ case WebdavStatus.SC_CREATED:
+ case WebdavStatus.SC_NO_CONTENT:
+ return;
+
+ default:
+ HttpException ex = new HttpException();
+ ex.setReasonCode(status);
+ throw ex;
+ }
+}
public static BuildException makeBuildException(String msg, Exception e) {
if (e instanceof HttpException) {
1.1 jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/taskdefs/Move.java
Index: Move.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/taskdefs/Move.java,v 1.1 2004/07/06 19:04:09 unico Exp $
* $Revision: 1.1 $
* $Date: 2004/07/06 19:04:09 $
* ========================================================================
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================================
*/
package org.apache.webdav.ant.taskdefs;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
import org.apache.webdav.ant.Utils;
import org.apache.webdav.lib.methods.DepthSupport;
/**
* WebDAV task for moving resources and collections.
*
* @see <a href="../doc-files/tasks.htm#davmove">Task documentation</a>
* @author <a href="mailto:unico@hippo.nl">Unico Hommes</a>
*/
public class Move extends WebdavMatchingTask {
private String destination;
private int depth;
private boolean overwrite;
/*
* @see org.apache.tools.ant.Task#execute()
*/
public void execute() throws BuildException {
validate();
try {
log("Moving " + getUrl(), ifVerbose());
Utils.moveResource(
getHttpClient(),
getUrl(),
this.destination,
this.depth,
this.overwrite
);
}
catch (IOException e) {
throw Utils.makeBuildException("Can't move!", e);
}
}
public void setDestination(String destination) {
this.destination = destination;
}
public void setDepth(String value) {
if ("0".trim().equals(value)) {
this.depth = DepthSupport.DEPTH_0;
}
else if ("infinity".trim().toLowerCase().equals(value)) {
this.depth = DepthSupport.DEPTH_INFINITY;
}
else {
throw new BuildException("Invalid value of depth attribute."
+ " (One of '0' or 'infinity' expected)");
}
}
public void setOverwrite(boolean value) {
this.overwrite = value;
}
protected void validate() {
super.validate();
if (destination == null) {
throw new BuildException("Missing required attribute destination");
}
}
}
1.1 jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/taskdefs/Copy.java
Index: Copy.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/taskdefs/Copy.java,v 1.1 2004/07/06 19:04:09 unico Exp $
* $Revision: 1.1 $
* $Date: 2004/07/06 19:04:09 $
* ========================================================================
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================================
*/
package org.apache.webdav.ant.taskdefs;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
import org.apache.webdav.ant.Utils;
import org.apache.webdav.lib.methods.DepthSupport;
/**
* WebDAV task for copying resources and collections.
*
* @see <a href="../doc-files/tasks.htm#davcopy">Task documentation</a>
* @author <a href="mailto:unico@hippo.nl">Unico Hommes</a>
*/
public class Copy extends WebdavMatchingTask {
private String destination;
private int depth;
private boolean overwrite;
/*
* @see org.apache.tools.ant.Task#execute()
*/
public void execute() throws BuildException {
validate();
try {
log("Copying " + getUrl(), ifVerbose());
Utils.copyResource(
getHttpClient(),
getUrl(),
this.destination,
this.depth,
this.overwrite
);
}
catch (IOException e) {
throw Utils.makeBuildException("Can't copy!", e);
}
}
public void setDestination(String destination) {
this.destination = destination;
}
public void setDepth(String value) {
if ("0".trim().equals(value)) {
this.depth = DepthSupport.DEPTH_0;
}
else if ("infinity".trim().toLowerCase().equals(value)) {
this.depth = DepthSupport.DEPTH_INFINITY;
}
else {
throw new BuildException("Invalid value of depth attribute."
+ " (One of '0' or 'infinity' expected)");
}
}
public void setOverwrite(boolean value) {
this.overwrite = value;
}
protected void validate() {
super.validate();
if (destination == null) {
throw new BuildException("Missing required attribute destination");
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org