juergen     2003/04/02 04:58:19

  Added:       src/webdav/client/src/org/apache/webdav/lib/methods
                        AclReportMethod.java
  Log:
  implemented WebDAVResource.aclReportMethod. thanks to Martin Dulisch [EMAIL 
PROTECTED] for the donation.
  
  Revision  Changes    Path
  1.1                  
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/AclReportMethod.java
  
  Index: AclReportMethod.java
  ===================================================================
  package org.apache.webdav.lib.methods;
  
  import org.apache.commons.httpclient.HttpConnection;
  import org.apache.commons.httpclient.HttpException;
  import org.apache.commons.httpclient.HttpState;
  import org.apache.util.XMLPrinter;
  
  import java.io.IOException;
  import java.util.Collection;
  
  /**
   * WebDAV Report method
   * This class is used to send an report
   * from the ACL specification.
   * In this version only the principal-property-search is supported.
   * 
   * @author Martin Dulisch, 07.02.2003
   */
  public class AclReportMethod extends XMLResponseMethodBase implements DepthSupport {
  
        //supported method types
        public final static int PRINCIPAL_PROPERTY_SEARCH = 1;
  
        private PropertyBodyHelper propertyBodyHelper = null;
        private int depth = DepthSupport.DEPTH_INFINITY;
        private int reportType = 0;
  
        /**
         * @param path
         * @param requested properties
         * @param depth
         * @param reportType - one of the supported report types
         */
        public AclReportMethod(
                String path,
                Collection propertyNames,
                int depth,
                int reportType) {
  
                super(path);
                setDepth(depth);
                this.reportType = reportType;
                propertyBodyHelper = new PropertyBodyHelper();
                propertyBodyHelper.setPropertyNames(propertyNames);
        }
  
        /**
         * @see org.apache.commons.httpclient.HttpMethod#getName()
         */
        public String getName() {
                return "REPORT";
        }
  
        /**
         * @see org.apache.webdav.lib.methods.DepthSupport#setDepth(int)
         */
        public void setDepth(int depth) {
                checkNotUsed();
                this.depth = depth;
        }
  
        /**
         * @see org.apache.webdav.lib.methods.DepthSupport#getDepth()
         */
        public int getDepth() {
                return depth;
        }
  
        /**
         * Set header. handle the special case of Depth.
         *
         * @param headerName Header name
         * @param headerValue Header value
         */
        public void setRequestHeader(String headerName, String headerValue) {
                if (headerName.equalsIgnoreCase("Depth")) {
                        int depth = -1;
                        if (headerValue.equals("0")) {
                                depth = DEPTH_0;
                        }
                        if (headerValue.equals("1")) {
                                depth = DEPTH_1;
                        } else if (headerValue.equalsIgnoreCase("infinity")) {
                                depth = DEPTH_INFINITY;
                        }
                        setDepth(depth);
                } else {
                        super.setRequestHeader(headerName, headerValue);
                }
        }
  
        /**
         * Generate additional headers needed by the request.
         *
         * @param host the host
         * @param state State token
         */
        public void addRequestHeaders(HttpState state, HttpConnection conn)
                throws IOException, HttpException {
  
                super.addRequestHeaders(state, conn);
  
                super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
  
                switch (getDepth()) {
                        case DEPTH_0 :
                                super.setRequestHeader("Depth", "0");
                                break;
                        case DEPTH_1 :
                                super.setRequestHeader("Depth", "1");
                                break;
                        case DEPTH_INFINITY :
                                super.setRequestHeader("Depth", "infinity");
                                break;
                }
        }
  
        /**
         * @see 
org.apache.webdav.lib.methods.XMLResponseMethodBase#generateRequestBody()
         */
        protected String generateRequestBody() {
                XMLPrinter printer = new XMLPrinter();
                printer.writeXMLHeader();
  
                switch (reportType) {
                        case PRINCIPAL_PROPERTY_SEARCH :
                                generatePrincipalPropertySearchBody(printer);
                                break;
                        default :
                                System.err.println("AclReportMethod: type not 
supported " + reportType);
                }
                return printer.toString();
        }
  
        /**
         * Generate the body for a principal-property-search report.
         * Currently the <property-search> section is constant.
         * 
         */
        private void generatePrincipalPropertySearchBody(XMLPrinter printer) {
                printer.writeElement(
                        "D",
                        "DAV:",
                        "principal-property-search",
                        XMLPrinter.OPENING);
  
                //property-search
                printer.writeElement("D", "property-search", XMLPrinter.OPENING);
                printer.writeElement("D", "prop", XMLPrinter.OPENING);
                printer.writeElement("D", "displayname", XMLPrinter.NO_CONTENT);
                printer.writeElement("D", "prop", XMLPrinter.CLOSING);
                printer.writeElement("D", "caseless-substring", XMLPrinter.NO_CONTENT);
                printer.writeElement("D", "property-search", XMLPrinter.CLOSING);
  
                //resulting properties
                propertyBodyHelper.wirtePropElement(printer);
  
                printer.writeElement("D", "principal-property-search", 
XMLPrinter.CLOSING);
        }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to