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 38 public class VersionControlMethod 39 extends XMLResponseMethodBase implements DepthSupport { 40 41 42 44 45 46 private String sComment, sCreatorDisplayName; 48 49 private String sTarget = null; 50 51 52 54 55 58 public VersionControlMethod() { 59 sComment ="none"; 60 sCreatorDisplayName ="unknown"; 61 } 62 63 64 67 public VersionControlMethod(String path) { 68 super(path); 69 } 70 71 public VersionControlMethod(String path, String sTarget) { 72 super(path); 73 this.sTarget = sTarget; 74 75 } 76 77 78 79 80 81 83 84 public int getDepth(){ 85 return 0; 86 } 87 88 public void setDepth(int depth){ 89 90 } 91 92 93 public void setRequestHeader(String headerName, String headerValue) { 94 super.setRequestHeader(headerName, headerValue); 95 if (sTarget != null) { 96 if (getRequestHeader("Content-Type") == null ) super.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 98 } 99 } 100 101 102 103 105 106 public String getName() { 107 return "VERSION-CONTROL"; 108 } 109 110 116 protected String generateRequestBody() { 117 118 if (sTarget != null){ 119 XMLPrinter printer = new XMLPrinter(); 120 121 122 printer.writeXMLHeader(); 123 124 printer.writeElement("D", "DAV:", "version-control", XMLPrinter.OPENING); 125 printer.writeElement("D", "version", XMLPrinter.OPENING); 126 127 printer.writeElement("D", "href", XMLPrinter.OPENING); 128 printer.writeText(sTarget); 129 printer.writeElement("D", "href", XMLPrinter.CLOSING); 130 printer.writeElement("D", "version", XMLPrinter.CLOSING); 131 printer.writeElement("D", "version-control", XMLPrinter.CLOSING); 132 133 return printer.toString(); 134 } 135 else 136 return ""; 137 138 } 139 140 145 public void parseResponse(InputStream input, HttpState state, HttpConnection conn) 146 throws IOException , HttpException { 147 try 148 { 149 int code = getStatusLine().getStatusCode(); 150 if (code == WebdavStatus.SC_CONFLICT || 151 code == WebdavStatus.SC_FORBIDDEN ) { 152 parseXMLResponse(input); 153 } 154 } 155 catch (IOException e) { 156 } 158 } 159 160 161 } 162 | Popular Tags |