1 19 package org.openharmonise.webdav.client; 20 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 25 import HTTPClient.NVPair; 26 27 35 public abstract class AbstractWebDAVMethod { 36 37 40 private String m_sMethodName = "OPTIONS"; 41 42 45 public static final String WEBDAV_NAMESPACE = 46 WebDAVConnection.WEBDAV_NAMESPACE; 47 48 51 private String m_sDepth = "0"; 52 53 56 public static final String DEPTH_0 = "0"; 57 58 61 public static final String DEPTH_1 = "1"; 62 63 66 public static final String DEPTH_INFINITY = "infinity"; 67 68 71 public static final String DEPTH_NONE = "-1"; 72 73 76 private String m_sDestination = ""; 77 78 81 private String m_sOverwrite = "F"; 82 83 86 public static final String OVERWRITE_T = "T"; 87 88 91 public static final String OVERWRITE_F = "F"; 92 93 96 private Map m_mHeaders = new HashMap (3); 97 98 101 private String m_sURL = ""; 102 103 106 private byte[] m_bData = null; 107 108 114 public AbstractWebDAVMethod(String sMethodName, String sURL) { 115 super(); 116 this.m_sMethodName = sMethodName; 117 this.addHeader("User-Agent", "Simzuki/1.0"); 118 if (sURL != null) { 119 this.m_sURL = sURL; 120 } 121 } 122 123 128 public String getDepth() { 129 return m_sDepth; 130 } 131 132 137 public String getDestination() { 138 return m_sDestination; 139 } 140 141 146 public void setDepth(String sDepth) { 147 m_sDepth = sDepth; 148 } 149 150 155 public void setDestination(String sDestination) { 156 m_sDestination = sDestination; 157 } 158 159 164 public boolean getOverwrite() { 165 return this.m_sOverwrite.equals("T") ? true : false; 166 } 167 168 173 public void setOverwrite(boolean bOverwrite) { 174 m_sOverwrite = bOverwrite ? "T" : "F"; 175 } 176 177 183 public void addHeader(String sName, String sValue) { 184 if (sName.equals("Depth")) { 185 this.setDepth(sValue); 186 } else if (sName.equals("Destination")) { 187 this.setDestination(sValue); 188 } else if (sName.equals("Overwrite")) { 189 if (sValue.equals("T")) { 190 this.setOverwrite(true); 191 } else if (sValue.equals("F")) { 192 this.setOverwrite(false); 193 } else { 194 this.m_mHeaders.put(sName, sValue); 195 } 196 } else { 197 this.m_mHeaders.put(sName, sValue); 198 } 199 } 200 201 207 public String getHeader(String sName) { 208 if (sName.equals("Depth")) { 209 return this.getDepth(); 210 } else if (sName.equals("Destination")) { 211 return this.getDestination(); 212 } else if (sName.equals("Overwrite")) { 213 return this.getOverwrite() ? "T" : "F"; 214 } else { 215 return (String ) this.m_mHeaders.get(sName); 216 } 217 } 218 219 224 protected NVPair[] getAllHeaders() { 225 NVPair[] headers = new NVPair[this.m_mHeaders.size() + 3]; 226 227 Iterator itor = this.m_mHeaders.keySet().iterator(); 228 229 int nCount = 0; 230 while (itor.hasNext()) { 231 String sName = (String ) itor.next(); 232 headers[nCount] = 233 new NVPair(sName, (String ) this.m_mHeaders.get(sName)); 234 nCount++; 235 } 236 237 if(this.m_sDepth!=AbstractWebDAVMethod.DEPTH_NONE) { 238 headers[nCount] = new NVPair("Depth", this.getHeader("Depth")); 239 nCount++; 240 } 241 if (!this.getDestination().equals("")) { 242 headers[nCount] = 243 new NVPair( 244 "Destination", 245 WebDAVConnection.URLEncode(this.getHeader("Destination"))); 246 nCount++; 247 } 248 249 return headers; 250 } 251 252 257 public String getURL() { 258 return m_sURL; 259 } 260 261 266 public void setURL(String sURL) { 267 m_sURL = sURL; 268 } 269 270 275 public byte[] getData() { 276 return m_bData; 277 } 278 279 284 public void setData(byte[] bData) { 285 m_bData = bData; 286 } 287 288 293 public String getName() { 294 return this.m_sMethodName; 295 } 296 297 } 298 | Popular Tags |