You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by lu...@apache.org on 2004/11/17 15:00:44 UTC

cvs commit: jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods XMLResponseMethodBase.java

luetzkendorf    2004/11/17 06:00:44

  Modified:    webdavclient/clientlib/src/java/org/apache/webdav/lib/methods
                        Tag: SLIDE_2_1_RELEASE_BRANCH
                        XMLResponseMethodBase.java
  Log:
  optional support for early decoding of response hrefs added
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.14.2.2  +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.14.2.1
  retrieving revision 1.14.2.2
  diff -u -r1.14.2.1 -r1.14.2.2
  --- XMLResponseMethodBase.java	26 Sep 2004 14:19:20 -0000	1.14.2.1
  +++ XMLResponseMethodBase.java	17 Nov 2004 14:00:44 -0000	1.14.2.2
  @@ -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: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org