juergen     02/01/02 07:13:31

  Modified:    src/webdav/client/src/org/apache/webdav/lib/methods
                        OptionsMethod.java
  Log:
  first version of the delta-v prototype (client part). The response of an options may 
be XML!
  
  Revision  Changes    Path
  1.7       +201 -21   
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/OptionsMethod.java
  
  Index: OptionsMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/OptionsMethod.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- OptionsMethod.java        1 May 2001 21:28:01 -0000       1.6
  +++ OptionsMethod.java        2 Jan 2002 15:13:31 -0000       1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/OptionsMethod.java,v
 1.6 2001/05/01 21:28:01 remm Exp $
  - * $Revision: 1.6 $
  - * $Date: 2001/05/01 21:28:01 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/OptionsMethod.java,v
 1.7 2002/01/02 15:13:31 juergen Exp $
  + * $Revision: 1.7 $
  + * $Date: 2002/01/02 15:13:31 $
    *
    * ====================================================================
    *
  @@ -65,6 +65,7 @@
   
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.StringReader;
   
   import java.util.Vector;
   import java.util.Enumeration;
  @@ -75,6 +76,28 @@
   import org.apache.commons.httpclient.State;
   import org.apache.commons.httpclient.Header;
   
  +import org.apache.util.XMLPrinter;
  +
  +import javax.xml.parsers.DocumentBuilderFactory;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.ParserConfigurationException;
  +
  +import org.w3c.dom.Document;
  +import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +import java.util.List;
  +import java.util.ArrayList;
  +
  +import org.apache.util.WebdavStatus;
  +import org.apache.util.DOMUtils;
  +import org.apache.util.DOMWriter;
  +
  +
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.NodeList;
  +
   
   /**
    * OPTIONS Method.
  @@ -82,7 +105,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
    */
   public class OptionsMethod
  -    extends HttpMethodBase {
  +    extends XMLResponseMethodBase {
       
       
       // -------------------------------------------------------------- Constants
  @@ -123,6 +146,17 @@
        */
       public static final String DASL = "6";
       
  +    /**
  +     *
  +     */
  +    public static final int OPTIONS_WORKSPACE = 8;
  +        
  +    /**
  +     *
  +     */
  +    public static final int OPTIONS_VERSION_HISTORY = 9;
  +    
  +        
       
       // ----------------------------------------------------------- Constructors
       
  @@ -143,9 +177,20 @@
           name = "OPTIONS";
       }
       
  +    /**
  +     * Method constructor.
  +     */
  +    public OptionsMethod(String path, int type) {
  +        super(path);
  +        name = "OPTIONS";
  +        this.type = type;
  +    }
       
       // ----------------------------------------------------- Instance Variables
       
  +    private Hashtable responseHashtable = null;
  +        
  +    private Document responseDocument = null;
       
       /**
        * DAV Capabilities.
  @@ -158,6 +203,8 @@
        */
       private Vector methodsAllowed = new Vector();
       
  +    private int type = 0;
  +    
       
       // --------------------------------------------------------- Public Methods
       
  @@ -201,25 +248,8 @@
       // --------------------------------------------------- WebdavMethod Methods
       
       
  -    /**
  -     * Generate the query body.
  -     *
  -     * @return String query
  -     */
  -    public String generateQuery() {
  -        return null;
  -    }
       
       
  -    /**
  -     * Parse response.
  -     *
  -     * @param is Input stream
  -     */
  -    public void parseResponse(InputStream is)
  -        throws IOException {
  -    }
  -    
       
       /**
        * Process response headers. The contract of this method is that it only
  @@ -254,4 +284,154 @@
       }
       
       
  +
  +
  +  
  +     /**
  +     * Generate the query body.
  +     *
  +     * @return String query
  +     */
  +    public String generateQuery() { //return null;
  +    
  +        if (type != 0){
  +            XMLPrinter printer = new XMLPrinter();
  +            printer.writeXMLHeader();
  +            //System.out.println(printer.toString());
  +            if (query != null)
  +                return printer.toString()+ query;
  +            printer.writeElement("D", "DAV:", "options",
  +                                 XMLPrinter.OPENING);
  +            
  +            if (type == OPTIONS_VERSION_HISTORY)
  +                printer.writeElement("D", "version-history-collection-set", 
XMLPrinter.NO_CONTENT);
  +            if (type == OPTIONS_WORKSPACE)
  +                printer.writeElement("D", "workspace-collection-set", 
XMLPrinter.NO_CONTENT);
  +        
  +            printer.writeElement("D", "options", XMLPrinter.CLOSING);
  +
  +            query = printer.toString();
  +            //System.out.println("query: " +query);
  +            return query;
  +}
  +        
  +        return null;
  +    }
  +
  +        
  +        
  +        //get and set header
  +     public void generateHeaders(String host, State state) {
  +         super.generateHeaders(host, state);
  +         
  +         if (type!= 0){
  +            super.setHeader("Content-Type", "text/xml; charset=utf-8");
  +            //System.out.println("Content-Type set" );
  +         }
  +     }
  +
  +/**
  +     * This method returns an enumeration of URL paths.  If the PropFindMethod
  +     * was sent to the URL of a collection, then there will be multiple URLs.
  +     * The URLs are picked out of the <code>&lt;D:href&gt;</code> elements
  +     * of the response.
  +     *
  +     * @return an enumeration of URL paths as Strings
  +     */
  +    public Enumeration getAllResponseURLs() {
  +        checkUsed();
  +        return getResponseHashtable().keys();
  +    }
  +
  +    public Enumeration getResponseProperties(){
  +        Vector result = new Vector();
  +        return (Enumeration) result;
  +    }
  +        
  +    public void parseResponse(InputStream input)
  +        throws IOException{
  +            try{
  +                Document responseDocument = parseResponseContent(input);
  +                this.responseDocument = responseDocument;
  +                
  +        } catch (Exception any){ any.printStackTrace();}
  +            
  +        }
  +        
  +    protected Document parseResponseContent(InputStream is)
  +        throws ParserConfigurationException, SAXException, IOException {
  +
  +        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  +        factory.setNamespaceAware(true);
  +
  +        DocumentBuilder builder = factory.newDocumentBuilder();
  +            
  +        byte[] chunk;
  +        byte[] all;
  +        int chunkLen;
  +        int allLen;
  +        List chunks;
  +        int i;
  +        int max;
  +        int ofs;
  +        
  +        allLen = 0;
  +        chunk = new byte[1024*4];
  +        chunkLen = is.read(chunk);
  +        chunks = new ArrayList();
  +        while (chunkLen != -1) {
  +            chunks.add(new Integer(chunkLen));
  +            chunks.add(chunk);
  +            allLen += chunkLen;
  +            chunk = new byte[1024*4];
  +            chunkLen = is.read(chunk);
  +        }
  +
  +        all = new byte[allLen];
  +        ofs = 0;
  +        max = chunks.size();
  +        for (i = 0; i < max; i += 2) {
  +            chunkLen = ((Integer) chunks.get(i)).intValue();
  +            chunk = (byte[]) chunks.get(i + 1);
  +            System.arraycopy(chunk, 0, all, ofs, chunkLen);
  +            ofs += chunkLen;
  +        }
  +        
  +            
  +        return builder.parse(new InputSource(new StringReader(new String(all))));
  +
  +    }
  +        
  +        protected Hashtable getResponseHashtable() {
  +        checkUsed();
  +        if (responseHashtable == null) {
  +            initResponseHashtable();
  +        }
  +        return responseHashtable;
  +    }
  +
  +
  +    private synchronized void initResponseHashtable() {
  +        if (responseHashtable == null) {
  +
  +            responseHashtable = new Hashtable();
  +            int status = getStatusCode();
  +            
  +        if (responseDocument != null) {
  +            //System.out.println("adding Response");
  +                                    
  +            Response response = new OptionsResponse(responseDocument,
  +                getPath(), status);
  +            responseHashtable.put(response.getHref(), response);
  +            
  +            setDocument(responseDocument);
  +            setResponseHashtable(responseHashtable);
  +            //System.out.println(response);
  +            }
  +        }
  +    }
   }
  +    
  +
  +
  +
  
  
  

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

Reply via email to