commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hus...@apache.org
Subject cvs commit: jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/text ConvertUtils.java
Date Mon, 28 Oct 2002 15:19:07 GMT
husted      2002/10/28 07:19:07

  Modified:    scaffold/src/java/org/apache/commons/scaffold/text
                        ConvertUtils.java
  Log:
  + ConvertUtils.addParams: intial version, makes query attributes from Map.
  
  Revision  Changes    Path
  1.4       +78 -5     jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/text/ConvertUtils.java
  
  Index: ConvertUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/text/ConvertUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConvertUtils.java	27 Sep 2002 19:11:20 -0000	1.3
  +++ ConvertUtils.java	28 Oct 2002 15:19:07 -0000	1.4
  @@ -9,7 +9,11 @@
   import java.text.SimpleDateFormat;
   
   import java.util.Date;
  +import java.util.Iterator;
   import java.util.Locale;
  +import java.util.Map;
  +import java.util.Map.Entry;
  +import java.util.Set;
   
   import java.sql.Timestamp;
   
  @@ -20,6 +24,7 @@
    *
    * @author Ted Husted
    * @author OK State DEQ
  + * @author WXXI Public Broadcasting Council
    * @version $Revision$ $Date$
    */
   public class ConvertUtils {
  @@ -173,19 +178,87 @@
   
   
       /**
  +     * The token that signifies the begnning of a query string ["?"].
  +     */
  +    public static String QS_START = "?";
  +
  +
  +    /**
  +     * The token that delimits two or more attributes of a query string ["&"].
  +     */
  +    public static String QS_DELIM = "&";
  +
  +
  +    /**
  +     * The token that seperates an attribute name and value.
  +     */
  +    public static String QS_SEP = "=";
  +
  +
  +    /**
        * Appends name=value parameter.
        */
       public static String addParam(String path, String name, String value) {
           StringBuffer uri = new StringBuffer(path);
  -        boolean isQuery = (path.indexOf("?")>=0);
  +        boolean isQuery = (path.indexOf(QS_START)>=0);
           if (isQuery)
  -            uri.append("&");
  +            uri.append(QS_DELIM);
           else
  -            uri.append("?");
  +            uri.append(QS_START);
           uri.append(name);
  -        uri.append("=");
  +        uri.append(QS_SEP);
           uri.append(value);
           return uri.toString();
  +
  +     }
  +
  +
  +    /**
  +     * Appends name=value parameters to path from Map.
  +     */
  +    public static String addParams(String path, Map parameters) {
  +
  +        if (null==path) path = new String();
  +
  +        if ((null==parameters) || (parameters.isEmpty())) return path;
  +
  +        StringBuffer uri = new StringBuffer(path);
  +        boolean isQuery = (path.indexOf(QS_START)>=0);
  +        if (isQuery)
  +            uri.append(QS_DELIM);
  +        else
  +            uri.append(QS_START);
  +
  +        Set entries = parameters.entrySet();
  +        for (Iterator i = entries.iterator(); i.hasNext(); ) {
  +            Entry e = (Entry) i.next();
  +            uri.append(e.getKey());
  +            uri.append(QS_SEP);
  +            uri.append(e.getValue());
  +        }
  +        return uri.toString();
  +
  +     }
  +
  +
  +    /**
  +     * Returns parameters as a series of hidden HTML fields.
  +     */
  +    public static String renderHiddenFields(Map parameters) {
  +
  +        if ((null==parameters) || (parameters.isEmpty())) return new String();
  +
  +        StringBuffer html = new StringBuffer();
  +        Set entries = parameters.entrySet();
  +        for (Iterator i = entries.iterator(); i.hasNext(); ) {
  +            html.append("<input type='hidden' name='");
  +            Entry e = (Entry) i.next();
  +            html.append(e.getKey());
  +            html.append("' value='");
  +            html.append(e.getValue());
  +            html.append("' />");
  +        }
  +        return html.toString();
   
        }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message