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 import org.apache.commons.httpclient.protocol.Protocol; 31 32 33 37 public class MoveMethod 38 extends XMLResponseMethodBase { 39 40 41 43 44 47 public MoveMethod() { 48 } 49 50 51 54 public MoveMethod(String source) { 55 super(source); 56 } 57 58 59 62 public MoveMethod(String source, String destination) { 63 this(source); 64 setDestination(destination); 65 } 66 67 68 71 public MoveMethod(String source, String destination, boolean overwrite) { 72 this(source, destination); 73 setOverwrite(overwrite); 74 } 75 76 77 79 80 83 private String destination; 84 85 86 89 private boolean overwrite = true; 90 91 92 94 95 96 103 public void setRequestHeader(String headerName, String headerValue) { 104 if (headerName.equalsIgnoreCase("Overwrite")){ 105 setOverwrite(! (headerValue.equalsIgnoreCase("F") || 106 headerValue.equalsIgnoreCase("False") ) ); 107 } 108 else if(headerName.equalsIgnoreCase("Destination")){ 109 setDestination(headerValue); 110 } 111 else{ 112 super.setRequestHeader(headerName, headerValue); 113 } 114 } 115 116 117 118 123 public void setDestination(String destination) { 124 checkNotUsed(); 125 this.destination = destination; 126 } 127 128 129 134 public String getDestination() { 135 return destination; 136 } 137 138 139 144 public void setOverwrite(boolean overwrite) { 145 checkNotUsed(); 146 this.overwrite = overwrite; 147 } 148 149 150 155 public boolean isOverwrite() { 156 return overwrite; 157 } 158 159 160 165 public boolean getOverwrite() { 166 return overwrite; 167 } 168 169 170 172 173 public String getName() { 174 return "MOVE"; 175 } 176 177 183 public void addRequestHeaders(HttpState state, HttpConnection conn) 184 throws IOException , HttpException { 185 186 super.addRequestHeaders(state, conn); 187 188 String absoluteDestination = getAbsoluteDestination(conn, destination); 189 super.setRequestHeader("Destination", absoluteDestination); 190 191 if (!isOverwrite()) 192 super.setRequestHeader("Overwrite", "F"); 193 194 } 195 196 217 static String getAbsoluteDestination(HttpConnection conn, String absolutePathOrURL) { 218 219 String absoluteDestination = absolutePathOrURL; 220 221 if (absolutePathOrURL.startsWith("/")) { 223 224 Protocol protocol = conn.getProtocol(); 226 StringBuffer bufDest = new StringBuffer (protocol.getScheme()); 227 bufDest.append("://").append(conn.getHost()); 228 229 if (conn.getPort() != protocol.getDefaultPort()) { 231 bufDest.append(':').append(conn.getPort()); 232 } 233 234 bufDest.append(absolutePathOrURL); 236 absoluteDestination = bufDest.toString(); 237 } 238 return absoluteDestination; 239 } 240 241 242 } 243 244 | Popular Tags |