dgraham 2003/08/02 13:35:28
Modified: src/share/org/apache/struts/taglib/html ImgTag.java
src/share/org/apache/struts/util RequestUtils.java
src/share/org/apache/struts/taglib TagUtils.java
Log:
Moved encodeURL() to TagUtils.
Revision Changes Path
1.32 +7 -8
jakarta-struts/src/share/org/apache/struts/taglib/html/ImgTag.java
Index: ImgTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ImgTag.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- ImgTag.java 31 Jul 2003 00:19:04 -0000 1.31
+++ ImgTag.java 2 Aug 2003 20:35:28 -0000 1.32
@@ -72,7 +72,6 @@
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.taglib.TagUtils;
import org.apache.struts.util.MessageResources;
-import org.apache.struts.util.RequestUtils;
/**
* Generate an IMG tag to the specified image URI.
@@ -615,7 +614,7 @@
src.append('=');
Object value = TagUtils.getInstance().lookup(pageContext, paramName,
paramProperty, paramScope);
if (value != null)
- src.append(RequestUtils.encodeURL(value.toString()));
+ src.append(TagUtils.getInstance().encodeURL(value.toString()));
}
// Just return the URL if there is no bean to look up
@@ -666,7 +665,7 @@
}
src.append(key);
src.append('=');
- src.append(RequestUtils.encodeURL(values[i]));
+ src.append(TagUtils.getInstance().encodeURL(values[i]));
}
} else {
@@ -678,7 +677,7 @@
}
src.append(key);
src.append('=');
- src.append(RequestUtils.encodeURL(value.toString()));
+ src.append(TagUtils.getInstance().encodeURL(value.toString()));
}
}
1.130 +7 -35
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.129
retrieving revision 1.130
diff -u -r1.129 -r1.130
--- RequestUtils.java 30 Jul 2003 23:55:50 -0000 1.129
+++ RequestUtils.java 2 Aug 2003 20:35:28 -0000 1.130
@@ -128,23 +128,6 @@
private static MessageResources messages =
MessageResources.getMessageResources("org.apache.struts.util.LocalStrings");
- /**
- * 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
@@ -1505,22 +1488,11 @@
* method; if the reflection operations throw exceptions, this will return the
url
* encoded with the old URLEncoder.encode() method.
* @return String - the encoded url.
+ * @deprecated Use TagUtils.encodeURL() instead. This will be removed
+ * after Struts 1.2.
*/
public static String encodeURL(String url) {
- try {
-
- // encode url with new 1.4 method and UTF-8 encoding
- 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);
- }
-
- return URLEncoder.encode(url);
+ return TagUtils.getInstance().encodeURL(url);
}
/**
1.18 +55 -14 jakarta-struts/src/share/org/apache/struts/taglib/TagUtils.java
Index: TagUtils.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/TagUtils.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- TagUtils.java 31 Jul 2003 00:30:21 -0000 1.17
+++ TagUtils.java 2 Aug 2003 20:35:28 -0000 1.18
@@ -63,7 +63,9 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.MalformedURLException;
+import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
@@ -122,15 +124,30 @@
MessageResources.getMessageResources("org.apache.struts.util.LocalStrings");
/**
+ * Java 1.4 encode method to use instead of deprecated 1.3 version.
+ */
+ private static Method encode = null;
+
+ /**
* Maps lowercase JSP scope names to their PageContext integer constant
* values.
*/
private static final Map scopes = new HashMap();
/**
- * Initialize the scope names map.
+ * Initialize the scope names map and the encode variable with the
+ * Java 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);
+ }
+
scopes.put("page", new Integer(PageContext.PAGE_SCOPE));
scopes.put("request", new Integer(PageContext.REQUEST_SCOPE));
scopes.put("session", new Integer(PageContext.SESSION_SCOPE));
@@ -432,7 +449,7 @@
url.setLength(hash);
}
url.append('#');
- url.append(RequestUtils.encodeURL(anchor));
+ url.append(this.encodeURL(anchor));
}
// Add dynamic parameters if requested
@@ -472,7 +489,7 @@
} else {
url.append(separator);
}
- url.append(RequestUtils.encodeURL(key));
+ url.append(this.encodeURL(key));
url.append('='); // Interpret null as "no value"
} else if (value instanceof String) {
if (!question) {
@@ -481,9 +498,9 @@
} else {
url.append(separator);
}
- url.append(RequestUtils.encodeURL(key));
+ url.append(this.encodeURL(key));
url.append('=');
- url.append(RequestUtils.encodeURL((String) value));
+ url.append(this.encodeURL((String) value));
} else if (value instanceof String[]) {
String values[] = (String[]) value;
for (int i = 0; i < values.length; i++) {
@@ -493,9 +510,9 @@
} else {
url.append(separator);
}
- url.append(RequestUtils.encodeURL(key));
+ url.append(this.encodeURL(key));
url.append('=');
- url.append(RequestUtils.encodeURL(values[i]));
+ url.append(this.encodeURL(values[i]));
}
} else /* Convert other objects to a string */ {
if (!question) {
@@ -504,16 +521,16 @@
} else {
url.append(separator);
}
- url.append(RequestUtils.encodeURL(key));
+ url.append(this.encodeURL(key));
url.append('=');
- url.append(RequestUtils.encodeURL(value.toString()));
+ url.append(this.encodeURL(value.toString()));
}
}
// Re-add the saved anchor (if any)
if (anchor != null) {
url.append('#');
- url.append(RequestUtils.encodeURL(anchor));
+ url.append(this.encodeURL(anchor));
}
}
@@ -530,6 +547,30 @@
return (url.toString());
}
+ }
+
+ /**
+ * Use the new URLEncoder.encode() method from Java 1.4 if available, else
+ * use the old deprecated version. This method uses reflection to find the
+ * appropriate method; if the reflection operations throw exceptions, this
+ * will return the url encoded with the old URLEncoder.encode() method.
+ * @return String The encoded url.
+ */
+ public String encodeURL(String url) {
+ try {
+
+ // encode url with new 1.4 method and UTF-8 encoding
+ 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);
+ }
+
+ return URLEncoder.encode(url);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]