1 23 24 package org.apache.webdav.lib.methods; 25 26 import java.io.IOException ; 27 import java.util.Collection ; 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.XMLPrinter; 32 33 40 public class AclReportMethod extends XMLResponseMethodBase implements DepthSupport { 41 42 public final static int PRINCIPAL_PROPERTY_SEARCH = 1; 44 45 private PropertyBodyHelper propertyBodyHelper = null; 46 private int depth = DepthSupport.DEPTH_INFINITY; 47 private int reportType = 0; 48 49 55 public AclReportMethod( 56 String path, 57 Collection propertyNames, 58 int depth, 59 int reportType) { 60 61 super(path); 62 setDepth(depth); 63 this.reportType = reportType; 64 propertyBodyHelper = new PropertyBodyHelper(); 65 propertyBodyHelper.setPropertyNames(propertyNames); 66 } 67 68 71 public String getName() { 72 return "REPORT"; 73 } 74 75 78 public void setDepth(int depth) { 79 checkNotUsed(); 80 this.depth = depth; 81 } 82 83 86 public int getDepth() { 87 return depth; 88 } 89 90 97 public void setRequestHeader(String headerName, String headerValue) { 98 if (headerName.equalsIgnoreCase("Depth")) { 99 int depth = -1; 100 if (headerValue.equals("0")) { 101 depth = DEPTH_0; 102 } 103 if (headerValue.equals("1")) { 104 depth = DEPTH_1; 105 } else if (headerValue.equalsIgnoreCase("infinity")) { 106 depth = DEPTH_INFINITY; 107 } 108 setDepth(depth); 109 } else { 110 super.setRequestHeader(headerName, headerValue); 111 } 112 } 113 114 120 public void addRequestHeaders(HttpState state, HttpConnection conn) 121 throws IOException , HttpException { 122 123 super.addRequestHeaders(state, conn); 124 125 if (getRequestHeader("Content-Type") == null ) super.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 127 128 switch (getDepth()) { 129 case DEPTH_0 : 130 super.setRequestHeader("Depth", "0"); 131 break; 132 case DEPTH_1 : 133 super.setRequestHeader("Depth", "1"); 134 break; 135 case DEPTH_INFINITY : 136 super.setRequestHeader("Depth", "infinity"); 137 break; 138 } 139 } 140 141 144 protected String generateRequestBody() { 145 XMLPrinter printer = new XMLPrinter(); 146 147 printer.writeXMLHeader(); 148 149 switch (reportType) { 150 case PRINCIPAL_PROPERTY_SEARCH : 151 generatePrincipalPropertySearchBody(printer); 152 break; 153 default : 154 System.err.println("AclReportMethod: type not supported " + reportType); 155 } 156 return printer.toString(); 157 } 158 159 164 private void generatePrincipalPropertySearchBody(XMLPrinter printer) { 165 printer.writeElement( 166 "D", 167 "DAV:", 168 "principal-property-search", 169 XMLPrinter.OPENING); 170 171 printer.writeElement("D", "property-search", XMLPrinter.OPENING); 173 printer.writeElement("D", "prop", XMLPrinter.OPENING); 174 printer.writeElement("D", "displayname", XMLPrinter.NO_CONTENT); 175 printer.writeElement("D", "prop", XMLPrinter.CLOSING); 176 printer.writeElement("D", "caseless-substring", XMLPrinter.NO_CONTENT); 177 printer.writeElement("D", "property-search", XMLPrinter.CLOSING); 178 179 propertyBodyHelper.wirtePropElement(printer); 181 182 printer.writeElement("D", "principal-property-search", XMLPrinter.CLOSING); 183 } 184 185 } 186 | Popular Tags |