jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From morg...@apache.org
Subject cvs commit: jakarta-taglibs-sandbox/latka-taglib/xml latka-taglib.xml
Date Fri, 31 Aug 2001 20:08:25 GMT
morgand     01/08/31 13:08:25

  Modified:    latka-taglib/xml latka-taglib.xml
  Added:       latka-taglib/src/org/apache/taglibs/latka
                        SetPropertiesFromRequestTag.java
  Log:
  added tag for reading Latka properties from Request parameters
  
  Revision  Changes    Path
  1.1                  jakarta-taglibs-sandbox/latka-taglib/src/org/apache/taglibs/latka/SetPropertiesFromRequestTag.java
  
  Index: SetPropertiesFromRequestTag.java
  ===================================================================
  package org.apache.taglibs.latka;
  
  import java.util.Enumeration;
  import java.util.Properties;
  
  import javax.servlet.ServletRequest;
  import javax.servlet.jsp.tagext.BodyTagSupport;
  
  /**
   * This is a utility tag that can parse the Request
   * for properties to add to a Properties object (such
   * as those generated by the SessionPropertiesTag).
   * Any request paramters with the prefix "latka.property."
   * will have the prefix trimmed and set the name and value
   * as a property to the designated Properties object.
   *
   * This Tag assumes that there is only one value per
   * request parameter name.
   * 
   * @see SessionPropertiesTag
   */
  public class SetPropertiesFromRequestTag extends BodyTagSupport {
  
    protected Properties _prop = null;
  
    /**
     * Finds a Property servlet attribute of the given name.
     * Any request paramters with the "latka.property." will
     * be parsed for a property name and value, and this
     * value will be added to the Property object.
     * 
     * @param propAtttribute
     *               Name of the Property attribute.
     */
    public void setProperties(String propAttribute) {
      _prop = (Properties) pageContext.findAttribute(propAttribute);
    }
  
    public int doStartTag() {
  
      ServletRequest req = pageContext.getRequest();
  
      Enumeration parameters = req.getParameterNames();
      // why, oh why doesn't the Servlet API use Java 2 collections?
      while (parameters.hasMoreElements()) {
        String parameter = (String) parameters.nextElement();
        if (parameter.startsWith("latka.property.")) {
          _prop.setProperty(parameter.substring(15),
                            req.getParameter(parameter));
        }
      }
  
      return SKIP_BODY;
  
    }
  
  }
  
  
  
  1.5       +45 -0     jakarta-taglibs-sandbox/latka-taglib/xml/latka-taglib.xml
  
  Index: latka-taglib.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs-sandbox/latka-taglib/xml/latka-taglib.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- latka-taglib.xml	2001/08/31 18:15:49	1.4
  +++ latka-taglib.xml	2001/08/31 20:08:25	1.5
  @@ -259,6 +259,51 @@
           </usage>
         </example>
       </tag>
  +
  +    <tag>
  +      <name>setPropertiesFromRequest</name>
  +      <tag-class>org.apache.taglibs.latka.SetPropertiesFromRequestTag</tag-class>
  +      <body-content>empty</body-content>
  +
  +      <description>
  +        This is a utility tag that can parse the Request
  +        for properties to add to a Properties object (such
  +        as those generated by the SessionPropertiesTag).
  +        Any request paramters with the prefix "latka.property."
  +        will have the prefix trimmed and set the name and value
  +        as a property to the designated Properties object.
  + 
  +        This Tag assumes that there is only one value per
  +        request parameter name.
  +      </description>
  +      <availability>1.0</availability>
  +
  +      <attribute>
  +        <name>properties</name>
  +        <required>yes</required>
  +        <rtexprvalue>yes</rtexprvalue>
  +        <description>
  +          Name of a Properties Servlet attribute. 
  +        </description>
  +        <availability>1.0</availability>
  +      </attribute>
  +            
  +      <example>
  +        <usage>
  +          <comment>
  +            Using sessionProperties and setPropertiesFromRequest
  +            cooperatively.
  +          </comment>
  +          <code>
  +<![CDATA[
  +<latka:sessionProperties id="props"/>
  +
  +<latka.setPropertiesFromRequest properties="props"/>
  +]]>
  +          </code>
  +        </usage>
  +      </example>
  +    </tag>
               
     </tagtoc>
   
  
  
  

Mime
View raw message