1 23 24 package org.apache.webdav.lib.methods; 25 26 import java.io.IOException ; 27 import org.apache.commons.httpclient.HttpConnection; 28 import org.apache.commons.httpclient.HttpException; 29 import org.apache.commons.httpclient.HttpState; 30 31 32 36 public class CopyMethod 37 extends XMLResponseMethodBase { 38 39 40 42 43 46 public CopyMethod() { 47 } 48 49 50 53 public CopyMethod(String source) { 54 super(source); 55 } 56 57 58 61 public CopyMethod(String source, String destination) { 62 this(source); 63 setDestination(destination); 64 } 65 66 67 70 public CopyMethod(String source, String destination, boolean overwrite) { 71 this(source, destination); 72 setOverwrite(overwrite); 73 } 74 75 public CopyMethod(String source, String destination, boolean overwrite, int depth) { 76 this(source, destination, overwrite); 77 setDepth(depth); 78 } 79 80 82 83 86 private String destination; 87 88 89 92 private boolean overwrite = true; 93 94 97 private int depth = DepthSupport.DEPTH_INFINITY; 98 99 101 102 109 public void setRequestHeader(String headerName, String 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 138 public void setDestination(String destination) { 139 checkNotUsed(); 140 this.destination = destination; 141 } 142 143 144 149 public String getDestination() { 150 return destination; 151 } 152 153 154 159 public void setOverwrite(boolean overwrite) { 160 checkNotUsed(); 161 this.overwrite = overwrite; 162 } 163 164 165 170 public boolean isOverwrite() { 171 return overwrite; 172 } 173 174 175 180 public boolean getOverwrite() { 181 return overwrite; 182 } 183 184 189 public void setDepth(int depth) { 190 checkNotUsed(); 191 this.depth = depth; 192 } 193 194 199 public int getDepth() { 200 return this.depth; 201 } 202 203 public String getName() { 204 return "COPY"; 205 } 206 207 209 210 216 public void addRequestHeaders(HttpState state, HttpConnection conn) 217 throws IOException , HttpException { 218 219 super.addRequestHeaders(state, conn); 220 221 String 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 |