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 62 public class RebindMethod 63 extends XMLResponseMethodBase { 64 65 66 public static final String NAME = "REBIND"; 67 68 private boolean overwrite = true; 69 private String segment = null; 70 private String href = null; 71 72 74 75 78 public RebindMethod() { 79 } 80 81 public RebindMethod(String existingBinding, String newBinding) { 82 super(newBinding.substring(0, newBinding.lastIndexOf('/'))); 83 this.href = existingBinding; 84 this.segment = newBinding.substring(newBinding.lastIndexOf('/') + 1); 85 } 86 87 public String getName() { 88 return NAME; 89 } 90 91 99 public boolean isOverwrite() { 100 return overwrite; 101 } 102 103 104 112 public void setOverwrite(boolean overwrite) { 113 checkNotUsed(); 114 this.overwrite = overwrite; 115 } 116 117 118 124 public void addRequestHeaders(HttpState state, HttpConnection conn) 125 throws IOException , HttpException { 126 127 super.addRequestHeaders(state, conn); 128 129 if (!isOverwrite()) 130 super.setRequestHeader("Overwrite", "F"); 131 132 } 133 134 140 protected String generateRequestBody() { 141 142 if (segment == null || href == null) 143 throw new IllegalStateException 144 ("Segment and Href must be set before " + 145 "calling this function."); 146 147 XMLPrinter printer = new XMLPrinter(); 148 149 printer.writeXMLHeader(); 150 printer.writeElement("D", "DAV:", "rebind", XMLPrinter.OPENING); 151 printer.writeElement("D", "segment", XMLPrinter.OPENING); 152 printer.writeText(segment); 153 printer.writeElement("D", "segment", XMLPrinter.CLOSING); 154 printer.writeElement("D", "href", XMLPrinter.OPENING); 155 printer.writeText(href); 156 printer.writeElement("D", "href", XMLPrinter.CLOSING); 157 printer.writeElement("D", "rebind", XMLPrinter.CLOSING); 158 159 return printer.toString(); 160 } 161 162 165 public String getHref() { 166 return href; 167 } 168 169 172 public String getSegment() { 173 return segment; 174 } 175 176 179 public void setHref(String href) { 180 this.href = href; 181 } 182 183 186 public void setSegment(String segment) { 187 this.segment = segment; 188 } 189 190 } 191 192 | Popular Tags |