You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by "Henning P. Schmiedehausen" <ma...@hometree.net> on 2001/05/14 15:24:53 UTC

[PATCH] Iterating over parameters

Hi,

for debugging purposes, I needed to display all the values parsed by
the ParameterParser. I found no way to do this but adding an accessor
function to the iterator of the keys of the internal hash table.

Now you can do:

Iterator it = data.getParameters().iterator();
while(it.hasNext())
{
   String key = (String)it.next();
   System.err.println("Key: "+key+" -> "+pp.get(key));
}

Patch against Turbine-HEAD attached.

	Regards
		Henning

diff -urb jakarta-turbine.orig/src/java/org/apache/turbine/util/ParameterParser.java jakarta-turbine/src/java/org/apache/turbine/util/ParameterParser.java
--- jakarta-turbine.orig/src/java/org/apache/turbine/util/ParameterParser.java	Sun May  6 19:06:40 2001
+++ jakarta-turbine/src/java/org/apache/turbine/util/ParameterParser.java	Mon May 14 15:20:53 2001
@@ -54,6 +54,7 @@
  * <http://www.apache.org/>.
  */
 
+import java.util.Iterator;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.turbine.util.upload.FileItem;
@@ -79,6 +80,7 @@
  * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
  * @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
  * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
+ * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
  * @version $Id: ParameterParser.java,v 1.30 2001/05/06 17:06:40 jvanzyl Exp $
  */
 public interface ParameterParser
@@ -152,4 +154,14 @@
      * @return A FileItem[].
      */
     public FileItem[] getFileItems(String name);
+
+  /**
+   * Returns an iterator over the 
+   * available parameters in this Parser
+   *
+   * @return an Iterator object
+   */
+
+  public Iterator iterator();
+
 }
diff -urb jakarta-turbine.orig/src/java/org/apache/turbine/util/parser/DefaultParameterParser.java jakarta-turbine/src/java/org/apache/turbine/util/parser/DefaultParameterParser.java
--- jakarta-turbine.orig/src/java/org/apache/turbine/util/parser/DefaultParameterParser.java	Sun May  6 19:06:46 2001
+++ jakarta-turbine/src/java/org/apache/turbine/util/parser/DefaultParameterParser.java	Mon May 14 15:20:57 2001
@@ -55,6 +55,7 @@
  */
 
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.StringTokenizer;
 
 import javax.servlet.http.HttpServletRequest;
@@ -90,6 +91,7 @@
  * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
  * @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
  * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
+ * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
  * @version $Id: DefaultParameterParser.java,v 1.2 2001/05/06 17:06:46 jvanzyl Exp $
  */
 public class DefaultParameterParser
@@ -332,5 +334,17 @@
             return null;
         }
     }
+
+  /**
+   * Returns an iterator over the 
+   * available parameters in this Parser
+   *
+   * @return an Iterator object
+   */
+
+  public Iterator iterator()
+  {
+    return parameters.keySet().iterator();
+  }
 
 }

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
D-91054 Buckenhof     Fax.: 09131 / 50654-20   

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: [PATCH] Iterating over parameters

Posted by John McNally <jm...@collab.net>.
I have no problem with the patch, but would like to point out a simple
method for getting the parameter information.  The toString method
returns a decent view of the parameters, so you can just
add

<p>Debugging:</p>
[ $data.Parameters ]

or something similar to a bottom navigation template.

john mcnally

"Henning P. Schmiedehausen" wrote:
> 
> me wrote:
> 
> >Hi,
> 
> >for debugging purposes, I needed to display all the values parsed by
> >the ParameterParser. I found no way to do this but adding an accessor
> >function to the iterator of the keys of the internal hash table.
> 
> >Now you can do:
> 
> >Iterator it = data.getParameters().iterator();
> >while(it.hasNext())
> >{
> >   String key = (String)it.next();
> >   System.err.println("Key: "+key+" -> "+pp.get(key));
> >}
> 
> >Patch against Turbine-HEAD attached.
> 
> Ok, in the meantime (thanks to all that told me), I learned that there
> is already
> 
> ValueParser::keys() and
> 
> Enumeration e = pp.keys();
> while(e.hasMoreElements())
> {
>    String key = (String)e.nextElement();
> 
>   System.out.println("Key: "+key+" -> "+pp.get(key));
> }
> 
> so strictly spoken, this patch is not necessary. However, I'd still
> like to apply this patch as the Iterator is IMHO the "newer" interface
> in the Sun Collections Stuff.
> 
>         Regards
>                 Henning
> 
> --
> Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
> INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de
> 
> Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
> D-91054 Buckenhof     Fax.: 09131 / 50654-20
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: [PATCH] Iterating over parameters

Posted by "Henning P. Schmiedehausen" <ma...@hometree.net>.
me wrote:

>Hi,

>for debugging purposes, I needed to display all the values parsed by
>the ParameterParser. I found no way to do this but adding an accessor
>function to the iterator of the keys of the internal hash table.

>Now you can do:

>Iterator it = data.getParameters().iterator();
>while(it.hasNext())
>{
>   String key = (String)it.next();
>   System.err.println("Key: "+key+" -> "+pp.get(key));
>}

>Patch against Turbine-HEAD attached.

Ok, in the meantime (thanks to all that told me), I learned that there
is already

ValueParser::keys() and

Enumeration e = pp.keys();
while(e.hasMoreElements())
{
   String key = (String)e.nextElement();

  System.out.println("Key: "+key+" -> "+pp.get(key));
}

so strictly spoken, this patch is not necessary. However, I'd still
like to apply this patch as the Iterator is IMHO the "newer" interface
in the Sun Collections Stuff.

	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
D-91054 Buckenhof     Fax.: 09131 / 50654-20   

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: [PATCH] Iterating over parameters

Posted by Jon Stevens <jo...@latchkey.com>.
on 5/14/01 6:24 AM, "Henning P. Schmiedehausen" <ma...@hometree.net>
wrote:

> for debugging purposes, I needed to display all the values parsed by
> the ParameterParser. I found no way to do this but adding an accessor
> function to the iterator of the keys of the internal hash table.

There is a way...take a look at BaseValueParser.

    .toString() will also achieve what you want.

:-)

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org