luetzkendorf    2004/11/18 08:34:25

  Modified:    webdavclient/clientlib/src/java/org/apache/webdav/lib/methods
                        XMLResponseMethodBase.java
  Log:
  optional support for early decoding of response hrefs added
  
  Revision  Changes    Path
  1.16      +37 -19    
jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/XMLResponseMethodBase.java
  
  Index: XMLResponseMethodBase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/XMLResponseMethodBase.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XMLResponseMethodBase.java        26 Sep 2004 14:32:23 -0000      1.15
  +++ XMLResponseMethodBase.java        18 Nov 2004 16:34:25 -0000      1.16
  @@ -40,6 +40,8 @@
   import org.apache.commons.httpclient.HttpException;
   import org.apache.commons.httpclient.HttpState;
   import org.apache.commons.httpclient.HttpStatus;
  +import org.apache.commons.httpclient.URIException;
  +import org.apache.commons.httpclient.util.URIUtil;
   
   import org.apache.webdav.lib.Property;
   import org.apache.webdav.lib.ResponseEntity;
  @@ -125,6 +127,7 @@
        */
       protected Vector responseURLs = null;
   
  +    protected String decodeResponseHrefs = null;
   
       // ------------------------------------------------------------- 
Properties
   
  @@ -149,10 +152,6 @@
           return getResponseHashtable().elements();
       }
   
  -    /*protected HttpState getState() {
  -        return state;
  -    }*/
  -
   
       // --------------------------------------------------- WebdavMethod 
Methods
   
  @@ -175,7 +174,16 @@
                return this.debug;
        }
   
  -
  +     /**
  +      * Sets whether the href in responses are decoded, as early as possible.
  +      * The <code>href</code> data in responses is often url-encoded, but 
not 
  +      * alwyas in a comparable way. Set this to a non-null value to decode 
the 
  +      * hrefs as early as possible.
  +      * @param encoding The encoding used in while decoding (UTF-8 is 
recommended)
  +      */
  +     public void setDecodeResponseHrefs(String encoding) {
  +         this.decodeResponseHrefs = encoding;
  +     }
   
       /**
        * Reset the State of the class to its initial state, so that it can be
  @@ -412,12 +420,9 @@
                                   "DAV:".equals(namespace)) {
                                   Response response =
                                       new ResponseWithinMultistatus(child);
  -                                responseHashtable.put(response.getHref(),
  -                                                      response);
  -                                responseURLs.add(response.getHref());
  -                                /*if (debug>10)
  -                                    System.out.println(response); */
  -                                //log.debug(response);
  +                                String href = getHref(response);
  +                                responseHashtable.put(href,response);
  +                                responseURLs.add(href);
                               }
                           } catch (ClassCastException e) {
                           }
  @@ -426,13 +431,26 @@
               } else if (responseDocument != null) {
                   Response response = new SingleResponse(responseDocument,
                       getPath(), status);
  -                responseHashtable.put(response.getHref(), response);
  -                responseURLs.add(response.getHref());
  -                /*if (debug>10)
  -                    System.out.println(response); */
  -                //log.debug(response);
  +                String href = getHref(response);
  +                responseHashtable.put(href, response);
  +                responseURLs.add(href);
  +            }
  +        }
  +    }
  +
  +
  +    private String getHref(Response response) {
  +        String href = response.getHref();
  +        if (this.decodeResponseHrefs != null) {
  +            try {
  +                href = URIUtil.decode(href, this.decodeResponseHrefs);
  +            }
  +            catch (URIException e1) {
  +                // TODO Auto-generated catch block
  +                e1.printStackTrace();
               }
           }
  +        return href;
       }
   
   
  
  
  

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

Reply via email to