dgraham 2003/03/01 16:22:40
Modified: src/share/org/apache/struts/util RequestUtils.java
Log:
Change encodeURL to not use reflection on every call.
Revision Changes Path
1.91 +26 -15
jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java
Index: RequestUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -r1.90 -r1.91
--- RequestUtils.java 26 Feb 2003 04:48:56 -0000 1.90
+++ RequestUtils.java 2 Mar 2003 00:22:40 -0000 1.91
@@ -142,6 +142,24 @@
* The context attribute under which we store our prefixes list.
*/
private static final String PREFIXES_KEY = "org.apache.struts.util.PREFIXES";
+
+ /**
+ * Java 1.4 encode method to use instead of deprecated 1.3 version.
+ */
+ private static Method encode = null;
+
+ /**
+ * Initialize the encode variable with the 1.4 method if available
+ */
+ static {
+ try {
+ // get version of encode method with two String args
+ Class[] args = new Class[] { String.class, String.class };
+ encode = URLEncoder.class.getMethod("encode", args);
+ } catch (NoSuchMethodException e) {
+ log.debug("Could not find Java 1.4 encode method. Using deprecated
version.", e);
+ }
+ }
// --------------------------------------------------------- Public Methods
@@ -1904,27 +1922,20 @@
* @return String - the encoded url.
*/
public static String encodeURL(String url) {
- // default to old version
- String encodedURL = URLEncoder.encode(url);
- Class encoderClass = URLEncoder.class;
-
try {
- // get version of encode method with two String args
- Class[] args = new Class[] { String.class, String.class };
- Method encode = encoderClass.getMethod("encode", args);
// encode url with new 1.4 method and UTF-8 encoding
- encodedURL = (String) encode.invoke(null, new Object[] { url, "UTF-8"
});
+ if (encode != null) {
+ return (String) encode.invoke(null, new Object[] { url, "UTF-8" });
+ }
} catch (IllegalAccessException e) {
log.debug("Could not find Java 1.4 encode method. Using deprecated
version.", e);
} catch (InvocationTargetException e) {
log.debug("Could not find Java 1.4 encode method. Using deprecated
version.", e);
- } catch (NoSuchMethodException e) {
- log.debug("Could not find Java 1.4 encode method. Using deprecated
version.", e);
}
- return encodedURL;
+ return URLEncoder.encode(url);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]