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.webdav.lib.util.XMLPrinter; 31 32 57 public class BindMethod 58 extends XMLResponseMethodBase { 59 60 61 public static final String NAME = "BIND"; 62 63 private boolean overwrite = true; 64 private String segment = null; 65 private String href = null; 66 67 69 70 73 public BindMethod() { 74 } 75 76 public BindMethod(String existingBinding, String newBinding) { 77 super(newBinding.substring(0, newBinding.lastIndexOf('/'))); 78 this.href = existingBinding; 79 this.segment = newBinding.substring(newBinding.lastIndexOf('/') + 1); 80 } 81 82 public String getName() { 83 return NAME; 84 } 85 86 94 public void setOverwrite(boolean overwrite) { 95 checkNotUsed(); 96 this.overwrite = overwrite; 97 } 98 99 100 108 public boolean isOverwrite() { 109 return overwrite; 110 } 111 112 113 119 public void addRequestHeaders(HttpState state, HttpConnection conn) 120 throws IOException , HttpException { 121 122 super.addRequestHeaders(state, conn); 123 124 if (!isOverwrite()) 125 super.setRequestHeader("Overwrite", "F"); 126 127 } 128 129 135 protected String generateRequestBody() { 136 137 if (segment == null || href == null) 138 throw new IllegalStateException 139 ("Segment and Href must be set before " + 140 "calling this function."); 141 142 XMLPrinter printer = new XMLPrinter(); 143 144 printer.writeXMLHeader(); 145 printer.writeElement("D", "DAV:", "bind", XMLPrinter.OPENING); 146 printer.writeElement("D", "segment", XMLPrinter.OPENING); 147 printer.writeText(segment); 148 printer.writeElement("D", "segment", XMLPrinter.CLOSING); 149 printer.writeElement("D", "href", XMLPrinter.OPENING); 150 printer.writeText(href); 151 printer.writeElement("D", "href", XMLPrinter.CLOSING); 152 printer.writeElement("D", "bind", XMLPrinter.CLOSING); 153 154 return printer.toString(); 155 } 156 157 160 public String getHref() { 161 return href; 162 } 163 164 167 public String getSegment() { 168 return segment; 169 } 170 171 174 public void setHref(String href) { 175 this.href = href; 176 } 177 178 181 public void setSegment(String segment) { 182 this.segment = segment; 183 } 184 185 } 186 187 | Popular Tags |