Here is the promised patch to the ParameterParser. It now hides
the underlying Hashtable and added a getKeys method.
I tested it by compiling, please test it in a real environment.
Since the signature changed it requires rebuilding the whole turbine.
Please let me know if one of the CVS masters applied the
patch, or if I should send my patched file directly to you
as an attachment.
A patch for RunData.getTemp() will follow tomorrow.
:) Christoph
------------------------- cut here ------------------------
--- Apache-Turbine-20001109/src/java/org/apache/turbine/util/ParameterParser.java
Wed Oct 18 20:59:47 2000
+++ Apache-Turbine/src/java/org/apache/turbine/util/ParameterParser.java Thu Nov 9
+19:06:54 2000
@@ -97,8 +97,12 @@
* @version $Id: ParameterParser.java,v 1.10 2000/10/18 18:59:47 nissim Exp $
*/
public class ParameterParser
- extends Hashtable
{
+ /**
+ * Random access storage for parameter data.
+ */
+ protected Hashtable parameters;
+
private HttpServletRequest req = null;
public static final String URL_CASE_FOLDING = "url.case.folding";
@@ -109,13 +113,12 @@
/**
* Create a new instance of ParameterParser. This requires a
* valid HttpServletRequest object. It will attempt to parse out
- * the GET/POST/PATH_INFO data and place the data into itself
- * which is an extension of Hashtable. There are convenience
- * methods for retrieving the data as a number of different
- * datatypes. The PATH_INFO data must be a URLEncoded() string.
+ * the GET/POST/PATH_INFO data and store the data into a Hashtable.
+ * There are convenience methods for retrieving the data as a
+ * number of different datatypes. The PATH_INFO data must be a
+ * URLEncoded() string.
*
- * <p>To add things into this object, use the add() method and not
- * the Hashtable.put() method.
+ * <p>To add things into this object, use the add() methods.
*
* @param req An HttpServletRequest.
*/
@@ -123,6 +126,8 @@
{
this.req = req;
+ parameters = new Hashtable();
+
// String object re-use at its best.
String tmp = null;
@@ -147,7 +152,7 @@
while(names.hasMoreElements())
{
tmp = (String) names.nextElement();
- this.put( convert(tmp), (Object) req.getParameterValues(tmp) );
+ parameters.put( convert(tmp), (Object) req.getParameterValues(tmp) );
}
}
@@ -186,9 +191,7 @@
}
/**
- * Add a name/value pair into this object. The reason for using
- * an add() method instead of Hashtable.put is because things must
- * be in a String[].
+ * Add a name/value pair into this object.
*
* @param name A String with the name.
* @param value A double with the value.
@@ -200,9 +203,7 @@
}
/**
- * Add a name/value pair into this object. The reason for using
- * an add() method instead of Hashtable.put is because things must
- * be in a String[].
+ * Add a name/value pair into this object.
*
* @param name A String with the name.
* @param value An int with the value.
@@ -214,9 +215,7 @@
}
/**
- * Add a name/value pair into this object. The reason for using
- * an add() method instead of Hashtable.put is because things must
- * be in a String[].
+ * Add a name/value pair into this object.
*
* @param name A String with the name.
* @param value An Integer with the value.
@@ -228,9 +227,7 @@
}
/**
- * Add a name/value pair into this object. The reason for using
- * an add() method instead of Hashtable.put is because things must
- * be in a String[].
+ * Add a name/value pair into this object.
*
* @param name A String with the name.
* @param value A long with the value.
@@ -242,9 +239,7 @@
}
/**
- * Add a name/value pair into this object. The reason for using
- * an add() method instead of Hashtable.put is because things must
- * be in a String[].
+ * Add a name/value pair into this object.
*
* @param name A String with the name.
* @param value A String with the value.
@@ -254,11 +249,11 @@
{
String[] strtmp = new String[1];
strtmp[0] = value;
- this.put ( convert(name), (String[]) strtmp);
+ parameters.put ( convert(name), (String[]) strtmp);
}
/**
- * Add a String parameter. If there are any Strings already
+ * Add a String parameters. If there are any Strings already
* associated with the name, append to the array. This is used
* for handling parameters from mulitipart POST requests.
*
@@ -273,19 +268,19 @@
{
items = new String[1];
items[0] = value;
- this.put( convert(name), items );
+ parameters.put( convert(name), items );
}
else
{
String[] newItems = new String[items.length+1];
System.arraycopy(items, 0, newItems, 0, items.length);
newItems[items.length] = value;
- this.put( convert(name), newItems );
+ parameters.put( convert(name), newItems );
}
}
/**
- * Add a FileItem object as a parameter. If there are any
+ * Add a FileItem object as a parameters. If there are any
* FileItems already associated with the name, append to the
* array. The reason for this is that RFC 1867 allows multiple
* files to be associated with single HTML input element.
@@ -301,14 +296,14 @@
{
items = new FileItem[1];
items[0] = value;
- this.put( convert(name), items );
+ parameters.put( convert(name), items );
}
else
{
FileItem[] newItems = new FileItem[items.length+1];
System.arraycopy(items, 0, newItems, 0, items.length);
newItems[items.length] = value;
- this.put( convert(name), newItems );
+ parameters.put( convert(name), newItems );
}
}
@@ -346,7 +341,7 @@
*/
public boolean containsKey( Object key )
{
- return super.containsKey(convert((String)key));
+ return parameters.containsKey(convert((String)key));
}
/**
@@ -363,6 +358,16 @@
containsKey(key + DateSelector.YEAR_SUFFIX));
}
+ /*
+ * Get all the keys for the values in the context
+ *
+ * @return A object array with the keys.
+ */
+ public Object[] getKeys()
+ {
+ return parameters.keySet().toArray();
+ }
+
/**
* Return a boolean for the given name. If the name does not
* exist, return defaultValue.
@@ -375,7 +380,7 @@
boolean defaultValue)
{
boolean value = defaultValue;
- Object object = this.get(convert(name));
+ Object object = parameters.get(convert(name));
if (object != null)
{
String tmp = getString(name);
@@ -446,7 +451,7 @@
double value = defaultValue;
try
{
- Object object = this.get(convert(name));
+ Object object = parameters.get(convert(name));
if (object != null)
value = Double.valueOf(((String[])object)[0]).doubleValue();
}
@@ -482,7 +487,7 @@
int value = defaultValue;
try
{
- Object object = this.get(convert(name));
+ Object object = parameters.get(convert(name));
if (object != null)
value = Integer.valueOf(((String[])object)[0]).intValue();
}
@@ -601,7 +606,7 @@
long value = defaultValue;
try
{
- Object object = this.get(convert(name));
+ Object object = parameters.get(convert(name));
if (object != null)
value = Long.valueOf(((String[])object)[0]).longValue();
}
@@ -679,7 +684,7 @@
byte value = defaultValue;
try
{
- Object object = this.get(convert(name));
+ Object object = parameters.get(convert(name));
if (object != null)
value = Byte.valueOf(((String[])object)[0]).byteValue();
}
@@ -731,7 +736,7 @@
try
{
String value = null;
- Object object = this.get(convert(name));
+ Object object = parameters.get(convert(name));
if (object != null)
value = ((String[])object)[0];
return value;
@@ -772,7 +777,7 @@
public String[] getStrings(String name)
{
String[] value = null;
- Object object = this.get(convert(name));
+ Object object = parameters.get(convert(name));
if (object != null)
value = ((String[])object);
return value;
@@ -809,7 +814,7 @@
try
{
Object value = null;
- Object object = this.get(convert(name));
+ Object object = parameters.get(convert(name));
if (object != null)
value = ((Object[])object)[0];
return value;
@@ -831,7 +836,7 @@
{
try
{
- return (Object[])this.get(convert(name));
+ return (Object[])parameters.get(convert(name));
}
catch ( ClassCastException e )
{
@@ -941,7 +946,7 @@
try
{
FileItem value = null;
- Object object = this.get(convert(name));
+ Object object = parameters.get(convert(name));
if (object != null)
value = ((FileItem[])object)[0];
return value;
@@ -964,7 +969,7 @@
{
try
{
- return (FileItem[])this.get(convert(name));
+ return (FileItem[])parameters.get(convert(name));
}
catch ( ClassCastException e )
{
@@ -1002,7 +1007,7 @@
/**
* Set the property 'prop' in the bean to the value of the
- * corresponding parameter. Supports all types supported by
+ * corresponding parameters. Supports all types supported by
* getXXX methods plus a few more that come for free because
* primitives have to be wrapped before being passed to invoke
* anyway.
@@ -1071,7 +1076,7 @@
public String toString()
{
StringBuffer sb = new StringBuffer();
- for (Enumeration e = this.keys() ; e.hasMoreElements() ;)
+ for (Enumeration e = parameters.keys() ; e.hasMoreElements() ;)
{
String name = (String) e.nextElement();
try
------------------------- cut here ------------------------
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]