juergen 02/01/03 02:51:03
Modified: src/webdav/server/org/apache/slide/webdav WebdavUtils.java
src/webdav/server/org/apache/slide/webdav/method
PropFindMethod.java
AbstractMultistatusResponseMethod.java
Log:
I18N URL encoding fixes. Please see seperate e-mail for details.
Revision Changes Path
1.8 +125 -11
jakarta-slide/src/webdav/server/org/apache/slide/webdav/WebdavUtils.java
Index: WebdavUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/WebdavUtils.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- WebdavUtils.java 11 Oct 2001 05:04:25 -0000 1.7
+++ WebdavUtils.java 3 Jan 2002 10:51:03 -0000 1.8
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/WebdavUtils.java,v
1.7 2001/10/11 05:04:25 msmith Exp $
- * $Revision: 1.7 $
- * $Date: 2001/10/11 05:04:25 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/WebdavUtils.java,v
1.8 2002/01/03 10:51:03 juergen Exp $
+ * $Revision: 1.8 $
+ * $Date: 2002/01/03 10:51:03 $
*
* ====================================================================
*
@@ -82,13 +82,14 @@
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.structure.ObjectNotFoundException;
+import org.apache.slide.util.Configuration;
/**
* A collection of various utility and convenience methods.
*
*
* @author Christopher Lenz (cmlenz at apache.org)
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
**/
public class WebdavUtils {
@@ -99,6 +100,52 @@
// --------------------------------------------------------- Public Methods
+ static private void printHexString(String path, String enc) {
+ try {
+ byte[] ba;
+ if (enc == null) ba = path.getBytes();
+ else ba = path.getBytes("ISO-8859-1");
+ System.out.print("@@@@ bytes= " + enc + " " );
+ for(int i=0; i < ba.length; i++) {
+ System.out.print(convertHexDigit(ba[i]));
+ if( i < ba.length-1 )
+ System.out.print(" ");
+ else {
+ String s;
+ if (enc == null) s = new String(ba);
+ else s = new String(ba, enc);
+ System.out.print(" ( " + s + " )"+ "\n");
+ }
+ }
+ }
+ catch( Exception x ) {
+ x.printStackTrace();
+ }
+ }
+
+
+
+ static private void printString(String path) {
+ System.out.println("");
+ System.out.println("@@@@ string="+path);
+ printHexString(path, Configuration.urlEncoding());
+ printHexString(path, "UTF-8");
+ printHexString(path, "SHIFT_JIS");
+ printHexString(path, null);
+ }
+
+ protected static final String[] hexadecimal =
+ {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
+ "A", "B", "C", "D", "E", "F"};
+
+
+ private static String convertHexDigit( byte toEncode ) {
+ String result;
+ int low = (int) (toEncode & 0x0f);
+ int high = (int) ((toEncode & 0xf0) >> 4);
+ result = hexadecimal[high] + hexadecimal[low];
+ return result;
+ }
/**
* Return a context-relative path, beginning with a "/", that represents
@@ -110,6 +157,35 @@
* @param path the path to be normalized
**/
public static String decodeURL(String path) {
+ return decodeURL(path, Configuration.urlEncoding());
+ }
+
+ /**
+ * Return a context-relative path, beginning with a "/", that represents
+ * the canonical version of the specified path after ".." and "." elements
+ * are resolved out. If the specified path attempts to go outside the
+ * boundaries of the current context (i.e. too many ".." path elements
+ * are present), return <code>null</code> instead.
+ *
+ * @param path the path to be normalized
+ **/
+ public static String decodeURL(String path, String enc) {
+
+ // @@@@@@@@@ TEMP START @@@@@@@@@@@@@@@@@
+ //System.out.println("BEFORE ENCODING");
+ // printString(path);
+ // @@@@@@@@@ TEMP END @@@@@@@@@@@@@@@@@
+
+
+ // @@@@@@@@@ TEMP START @@@@@@@@@@@@@@@@@
+// System.out.println("After ENCODING");
+// printString(path);
+// System.out.println("");
+// System.out.println("");
+ // @@@@@@@@@ TEMP END @@@@@@@@@@@@@@@@@
+
+
+
if (path == null)
return null;
@@ -118,7 +194,7 @@
// which also handles encoded spaces so we can skip that later.
// Placed at the beginning of the chain so that encoded
// bad stuff(tm) can be caught by the later checks
- String normalized = URLUtil.URLDecode(path, "UTF8");
+ String normalized = URLUtil.URLDecode(path, enc);
if (normalized == null)
return (null);
@@ -135,7 +211,7 @@
if (index < 0)
break;
normalized = normalized.substring(0, index) +
- normalized.substring(index + 1);
+ normalized.substring(index + 1);
}
// Resolve occurrences of "/./" in the normalized path
@@ -144,7 +220,7 @@
if (index < 0)
break;
normalized = normalized.substring(0, index) +
- normalized.substring(index + 2);
+ normalized.substring(index + 2);
}
// Resolve occurrences of "/../" in the normalized path
@@ -156,9 +232,14 @@
return (null); // Trying to go outside our context
int index2 = normalized.lastIndexOf('/', index - 1);
normalized = normalized.substring(0, index2) +
- normalized.substring(index + 3);
+ normalized.substring(index + 3);
}
+ // @@@@@@@@@ TEMP START @@@@@@@@@@@@@@@@@
+ //printString(normalized);
+ // @@@@@@@@@ TEMP END @@@@@@@@@@@@@@@@@
+
+
// Return the normalized path that we have completed
return (normalized);
}
@@ -170,7 +251,18 @@
* @param path the path to be rewritten
**/
public static String encodeURL(String path) {
- return URLUtil.URLEncode(path, "UTF8");
+ return URLUtil.URLEncode(path, Configuration.urlEncoding());
+ }
+
+
+ /**
+ * URL rewriter.
+ *
+ * @param path the path to be rewritten
+ * @param enc the encoding
+ **/
+ public static String encodeURL(String path, String enc) {
+ return URLUtil.URLEncode(path, enc);
}
@@ -202,8 +294,10 @@
// prefix the URI with the configured scope
result = config.getScope() + result;
+
+
- return decodeURL(result);
+ return decodeURL(fixTomcatURL(result));
}
@@ -215,6 +309,26 @@
*
* @return a new SlideToken instance
**/
+ public static String fixTomcatURL(String input) {
+ String result = null;
+ try {
+ result = new String(input.getBytes("ISO-8859-1"),
Configuration.urlEncoding());
+ } catch (Exception e) { e.printStackTrace(); }
+ return result;
+ }
+
+
+
+
+
+ /**
+ * Returns a SlideToken using the authentication information of an HTTP
+ * request.
+ *
+ * @param req the HTTP request
+ *
+ * @return a new SlideToken instance
+ **/
public static SlideToken getSlideToken
(HttpServletRequest req) {
@@ -275,7 +389,7 @@
public static boolean isCollection
(NamespaceAccessToken token, SlideToken slideToken,
String path) {
-
+
slideToken = new SlideTokenWrapper(slideToken, false); // check only, no
enlistment
try {
1.42 +47 -30
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java
Index: PropFindMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- PropFindMethod.java 20 Dec 2001 23:03:08 -0000 1.41
+++ PropFindMethod.java 3 Jan 2002 10:51:03 -0000 1.42
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
1.41 2001/12/20 23:03:08 dirkv Exp $
- * $Revision: 1.41 $
- * $Date: 2001/12/20 23:03:08 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
1.42 2002/01/03 10:51:03 juergen Exp $
+ * $Revision: 1.42 $
+ * $Date: 2002/01/03 10:51:03 $
*
* ====================================================================
*
@@ -565,23 +565,35 @@
String path = object.getUri();
- String absoluteUri =
- WebdavUtils.decodeURL(req.getRequestURI());
- String relativePath = requestUri;
- String toAppend = "";
- if (relativePath.length() <= path.length()) {
- toAppend = path.substring(relativePath.length());
- if ((!absoluteUri.endsWith("/")) &&
- (!toAppend.startsWith("/"))) {
- toAppend = "/" + toAppend;
- }
- if (toAppend.equals("/")) {
- toAppend = "";
- }
- }
+// String absoluteUri =
+// req.getRequestURI();
+//
+// System.out.println("getContextPath "+req.getContextPath());
+// System.out.println("getRequestURI "+req.getRequestURI());
+// System.out.println("getPathInfo "+req.getPathInfo());
+// System.out.println("getPathTranslated "+req.getPathTranslated());
+// System.out.println("getRealPath "+req.getRealPath("xx"));
+// System.out.println("getRemoteAddr "+req.getRemoteAddr());
+// System.out.println("getRemoteHost "+req.getRemoteHost());
+// System.out.println("getServerName "+req.getServerName());
+// System.out.println("getServletPath "+req.getServletPath());
+//
+// String relativePath = requestUri;
+// String toAppend = "";
+// if (relativePath.length() <= path.length()) {
+// toAppend = path.substring(relativePath.length());
+// if ((!absoluteUri.endsWith("/")) &&
+// (!toAppend.startsWith("/"))) {
+// toAppend = "/" + toAppend;
+// }
+// if (toAppend.equals("/")) {
+// toAppend = "";
+// }
+// }
generatedXML.writeText(
- WebdavUtils.encodeURL(absoluteUri + toAppend));
+ WebdavUtils.encodeURL(req.getContextPath() + path, "UTF-8"));
+// generatedXML.writeText(absoluteUri + toAppend);
} catch (RevisionDescriptorNotFoundException e) {
@@ -598,20 +610,25 @@
String path = object.getUri();
- String absoluteUri =
- WebdavUtils.decodeURL(req.getRequestURI());
- String relativePath = requestUri;
- String toAppend = "";
- if (relativePath.length() <= path.length()) {
- toAppend = path.substring(relativePath.length());
- if ((!absoluteUri.endsWith("/"))
- && (!toAppend.startsWith("/"))) {
- toAppend = "/" + toAppend;
- }
- }
+// String absoluteUri =
+// WebdavUtils.getRelativePath(req, getConfig());
+// String relativePath = requestUri;
+// String toAppend = "";
+// if (relativePath.length() <= path.length()) {
+// toAppend = path.substring(relativePath.length());
+// if ((!absoluteUri.endsWith("/"))
+// && (!toAppend.startsWith("/"))) {
+// toAppend = "/" + toAppend;
+// }
+// }
+//
generatedXML.writeText(
- WebdavUtils.encodeURL(absoluteUri + toAppend));
+ WebdavUtils.encodeURL(req.getContextPath() + path, "UTF-8"));
+
+// generatedXML.writeText(
+// WebdavUtils.encodeURL(absoluteUri + toAppend, "UTF-8"));
+// generatedXML.writeText(absoluteUri + toAppend);
}
1.12 +4 -4
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractMultistatusResponseMethod.java
Index: AbstractMultistatusResponseMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractMultistatusResponseMethod.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AbstractMultistatusResponseMethod.java 4 Sep 2001 12:04:25 -0000 1.11
+++ AbstractMultistatusResponseMethod.java 3 Jan 2002 10:51:03 -0000 1.12
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractMultistatusResponseMethod.java,v
1.11 2001/09/04 12:04:25 juergen Exp $
- * $Revision: 1.11 $
- * $Date: 2001/09/04 12:04:25 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractMultistatusResponseMethod.java,v
1.12 2002/01/03 10:51:03 juergen Exp $
+ * $Revision: 1.12 $
+ * $Date: 2002/01/03 10:51:03 $
*
* ====================================================================
*
@@ -178,7 +178,7 @@
}
}
- destinationUri = WebdavUtils.decodeURL(destinationUri);
+ destinationUri =
WebdavUtils.decodeURL(WebdavUtils.fixTomcatURL(destinationUri));
String contextPath = req.getContextPath();
if ((contextPath != null) &&
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>