KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > lib > methods > CopyMethod


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

23
24 package org.apache.webdav.lib.methods;
25
26 import java.io.IOException JavaDoc;
27 import org.apache.commons.httpclient.HttpConnection;
28 import org.apache.commons.httpclient.HttpException;
29 import org.apache.commons.httpclient.HttpState;
30
31
32 /**
33  * COPY Method.
34  *
35  */

36 public class CopyMethod
37     extends XMLResponseMethodBase {
38
39
40     // ----------------------------------------------------------- Constructors
41

42
43     /**
44      * Method constructor.
45      */

46     public CopyMethod() {
47     }
48
49
50     /**
51      * Method constructor.
52      */

53     public CopyMethod(String JavaDoc source) {
54         super(source);
55     }
56
57
58     /**
59      * Method constructor.
60      */

61     public CopyMethod(String JavaDoc source, String JavaDoc destination) {
62         this(source);
63         setDestination(destination);
64     }
65
66
67     /**
68      * Method constructor.
69      */

70     public CopyMethod(String JavaDoc source, String JavaDoc destination, boolean overwrite) {
71         this(source, destination);
72         setOverwrite(overwrite);
73     }
74
75     public CopyMethod(String JavaDoc source, String JavaDoc destination, boolean overwrite, int depth) {
76         this(source, destination, overwrite);
77         setDepth(depth);
78     }
79
80     // ----------------------------------------------------- Instance Variables
81

82
83     /**
84      * Destination.
85      */

86     private String JavaDoc destination;
87
88
89     /**
90      * Overwrite.
91      */

92     private boolean overwrite = true;
93
94     /**
95      * Depth.
96      */

97     private int depth = DepthSupport.DEPTH_INFINITY;
98
99     // ----------------------------------------------------- Instance Variables
100

101
102     /**
103      * Set a header value, redirecting the special case of Overwrite and Destination headers
104      * to {@link #setOverwrite} and {@link #setDestination} as appropriate.
105      *
106      * @param headerName Header name
107      * @param headerValue Header value
108      */

109     public void setRequestHeader(String JavaDoc headerName, String JavaDoc headerValue) {
110         if (headerName.equalsIgnoreCase("Overwrite")){
111             setOverwrite(! (headerValue.equalsIgnoreCase("F") ||
112                            headerValue.equalsIgnoreCase("False") ) );
113         }
114         else if (headerName.equalsIgnoreCase("Destination")){
115             setDestination(headerValue);
116         }
117         else if (headerName.equalsIgnoreCase("Depth")) {
118             if (headerValue.equalsIgnoreCase("Infinity")) {
119                 setDepth(DepthSupport.DEPTH_INFINITY);
120             }
121             else if (headerValue.equalsIgnoreCase("0")) {
122                 setDepth(0);
123             }
124         }
125         else{
126             super.setRequestHeader(headerName, headerValue);
127         }
128     }
129
130
131
132
133     /**
134      * Destination setter.
135      *
136      * @param destination New destination value
137      */

138     public void setDestination(String JavaDoc destination) {
139         checkNotUsed();
140         this.destination = destination;
141     }
142
143
144     /**
145      * Destination getter.
146      *
147      * @return String destination value
148      */

149     public String JavaDoc getDestination() {
150         return destination;
151     }
152
153
154     /**
155      * Overwrite setter.
156      *
157      * @param overwrite New overwrite value
158      */

159     public void setOverwrite(boolean overwrite) {
160         checkNotUsed();
161         this.overwrite = overwrite;
162     }
163
164
165     /**
166      * Overwrite getter.
167      *
168      * @return boolean Overwrite value
169      */

170     public boolean isOverwrite() {
171         return overwrite;
172     }
173
174
175     /**
176      * Overwrite getter.
177      *
178      * @return boolean Overwrite value
179      */

180     public boolean getOverwrite() {
181         return overwrite;
182     }
183
184     /**
185      * Depth setter.
186      *
187      * @param depth New depth value
188      */

189     public void setDepth(int depth) {
190         checkNotUsed();
191         this.depth = depth;
192     }
193     
194     /**
195      * Depth getter.
196      *
197      * @return int Depth value
198      */

199     public int getDepth() {
200         return this.depth;
201     }
202
203     public String JavaDoc getName() {
204         return "COPY";
205     }
206
207     // --------------------------------------------------- WebdavMethod Methods
208

209
210     /**
211      * Generate additional headers needed by the request.
212      *
213      * @param state HttpState token
214      * @param conn The connection being used for the request.
215      */

216     public void addRequestHeaders(HttpState state, HttpConnection conn)
217     throws IOException JavaDoc, HttpException {
218
219         super.addRequestHeaders(state, conn);
220
221         String JavaDoc absoluteDestination = MoveMethod.getAbsoluteDestination(conn, destination);
222         super.setRequestHeader("Destination", absoluteDestination);
223
224         if (!isOverwrite())
225             super.setRequestHeader("Overwrite", "F");
226
227         switch (depth) {
228             case DepthSupport.DEPTH_0:
229                 super.setRequestHeader("Depth", "0");
230                 break;
231             case DepthSupport.DEPTH_INFINITY:
232                 super.setRequestHeader("Depth", "Infinity");
233                 break;
234         }
235     }
236
237 }
238
239
Popular Tags