1 23 24 package org.apache.webdav.lib.methods; 25 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import org.apache.commons.httpclient.HttpConnection; 29 import org.apache.commons.httpclient.HttpException; 30 import org.apache.commons.httpclient.HttpState; 31 import org.apache.webdav.lib.util.WebdavStatus; 32 import org.apache.webdav.lib.util.XMLPrinter; 33 34 35 41 public class UpdateMethod extends XMLResponseMethodBase { 42 43 44 46 47 48 50 private String target = null; 51 52 53 55 56 59 public UpdateMethod() { 60 } 61 62 63 66 public UpdateMethod(String path) { 67 super(path); 68 } 69 70 71 72 78 public UpdateMethod(String path, String target) { 79 super(path); 80 this.target = target; 81 } 82 83 84 public String getName() { 85 return "UPDATE"; 86 } 87 88 94 protected String generateRequestBody() { 95 if (target != null) { 96 XMLPrinter printer = new XMLPrinter(); 97 98 99 printer.writeXMLHeader(); 100 printer.writeElement("D", "DAV:", "update", XMLPrinter.OPENING); 101 printer.writeElement("D", "version", XMLPrinter.OPENING); 102 printer.writeElement("D", "href", XMLPrinter.OPENING); 103 printer.writeText(target); 104 printer.writeElement("D", "href", XMLPrinter.CLOSING); 105 printer.writeElement("D", "version", XMLPrinter.CLOSING); 106 printer.writeElement("D", "update", XMLPrinter.CLOSING); 107 108 return printer.toString(); 109 } 110 else 111 return ""; 112 } 113 114 119 public void parseResponse(InputStream input, HttpState state, HttpConnection conn) 120 throws IOException , HttpException { 121 try 122 { 123 int code = getStatusLine().getStatusCode(); 124 if (code == WebdavStatus.SC_CONFLICT || 125 code == WebdavStatus.SC_MULTI_STATUS || 126 code == WebdavStatus.SC_FORBIDDEN ) { 127 parseXMLResponse(input); 128 } 129 } 130 catch (IOException e) { 131 } 133 } 134 135 136 } 137 | Popular Tags |