luetzkendorf 2005/02/21 07:13:09
Modified: webdavclient/clientlib/src/java/org/apache/webdav/lib/methods
XMLResponseMethodBase.java
Log:
new parameter assertHrefsArePathes that controlls whether hrefs are
normalized for be pathes only. I.e., if the server returns
<D:href>http://abc.com/files</D:href> in the response it is internally mapped
to /files
Revision Changes Path
1.17 +49 -28
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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- XMLResponseMethodBase.java 18 Nov 2004 16:34:25 -0000 1.16
+++ XMLResponseMethodBase.java 21 Feb 2005 15:13:08 -0000 1.17
@@ -128,6 +128,7 @@
protected Vector responseURLs = null;
protected String decodeResponseHrefs = null;
+ protected boolean assertHrefsArePathes = false;
// -------------------------------------------------------------
Properties
@@ -166,24 +167,34 @@
xo.setDebug((debug > 0));
}
- /**
- * Debug property getter.
- *
- */
- public int getDebug() {
- 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;
- }
+ /**
+ * Debug property getter.
+ */
+ public int getDebug() {
+ 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;
+ }
+
+ /**
+ * Determines whether hrefs of response elements are normalized to
+ * be pathes only.
+ *
+ * <p>If set to <code>true</code> schema, host, port and other infos
+ * before the URL path are removed.
+ */
+ public void setAssertHrefsArePathes(boolean value) {
+ this.assertHrefsArePathes = value;
+ }
/**
* Reset the State of the class to its initial state, so that it can be
@@ -304,8 +315,7 @@
// Also accept OK sent by buggy servers in reply to a PROPFIND or
// REPORT (Xythos, Catacomb, ...?).
if (getStatusCode() == WebdavStatus.SC_MULTI_STATUS
- || (this instanceof PropFindMethod || this instanceof
ReportMethod)
- && getStatusCode() == HttpStatus.SC_OK) {
+ || (this instanceof PropFindMethod || this instanceof
ReportMethod)) {
try {
parseXMLResponse(input);
} catch (IOException e) {
@@ -396,11 +406,9 @@
// Also accept OK sent by buggy servers in reply to a PROPFIND
// or REPORT (Xythos, Catacomb, ...?).
if (status == WebdavStatus.SC_MULTI_STATUS
- || (this instanceof PropFindMethod
- || this instanceof ReportMethod)
+ || (this instanceof PropFindMethod || this instanceof
ReportMethod)
&& status == HttpStatus.SC_OK) {
-
Document rdoc = getResponseDocument();
NodeList list = null;
@@ -445,11 +453,24 @@
try {
href = URIUtil.decode(href, this.decodeResponseHrefs);
}
- catch (URIException e1) {
+ catch (URIException e) {
// TODO Auto-generated catch block
- e1.printStackTrace();
+ e.printStackTrace();
+ }
+ }
+
+ if (this.assertHrefsArePathes) {
+ int pos = href.indexOf("://");
+ if (pos != -1) {
+ pos = href.indexOf('/', pos+3);
+ if (pos != -1) {
+ href = href.substring(pos);
+ } else {
+ href = "/";
+ }
}
}
+
return href;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]