You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by sh...@apache.org on 2002/04/17 16:53:26 UTC

cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/core SetTag.java

shawn       02/04/17 07:53:26

  Modified:    standard/conf c-rt.tld c.tld
               standard/src/org/apache/taglibs/standard/tag/el/core
                        SetTag.java
  Log:
  New attributes for <c:set>, plus inclusion of <c:set> in RT library.
  
  Revision  Changes    Path
  1.15      +34 -0     jakarta-taglibs/standard/conf/c-rt.tld
  
  Index: c-rt.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/conf/c-rt.tld,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- c-rt.tld	17 Apr 2002 13:56:41 -0000	1.14
  +++ c-rt.tld	17 Apr 2002 14:53:26 -0000	1.15
  @@ -286,6 +286,40 @@
       </attribute>
     </tag>
   
  + <tag>
  +    <name>set</name>
  +    <tag-class>org.apache.taglibs.standard.tag.rt.core.SetTag</tag-class>
  +    <body-content>JSP</body-content>
  +    <description>
  +        Sets the result of an expression evaluation in a 'scope'
  +    </description>
  +    <attribute>
  +        <name>var</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>value</name>
  +        <required>false</required>
  +        <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>target</name>
  +        <required>false</required>
  +        <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>property</name>
  +        <required>false</required>
  +        <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>scope</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +  </tag>
  +
     <tag>
       <name>url</name>
       <tag-class>org.apache.taglibs.standard.tag.rt.core.UrlTag</tag-class>
  
  
  
  1.17      +13 -1     jakarta-taglibs/standard/conf/c.tld
  
  Index: c.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/conf/c.tld,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- c.tld	17 Apr 2002 13:56:41 -0000	1.16
  +++ c.tld	17 Apr 2002 14:53:26 -0000	1.17
  @@ -36,6 +36,8 @@
   	    param:value
               redirect:context
               redirect:url
  +	    set:property
  +	    set:target
   	    set:value
   	    url:context
   	    url:value
  @@ -343,11 +345,21 @@
       </description>
       <attribute>
           <name>var</name>
  -        <required>true</required>
  +        <required>false</required>
           <rtexprvalue>false</rtexprvalue>
       </attribute>
       <attribute>
           <name>value</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>target</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>property</name>
           <required>false</required>
           <rtexprvalue>false</rtexprvalue>
       </attribute>
  
  
  
  1.4       +57 -62    jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/core/SetTag.java
  
  Index: SetTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/core/SetTag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SetTag.java	18 Mar 2002 23:01:10 -0000	1.3
  +++ SetTag.java	17 Apr 2002 14:53:26 -0000	1.4
  @@ -58,44 +58,47 @@
   import javax.servlet.jsp.*;
   import javax.servlet.jsp.tagext.*;
   import org.apache.taglibs.standard.tag.common.core.*;
  -import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
  -import org.apache.taglibs.standard.resources.Resources;
   
   /**
  - * <p>A handler for the &lt;set&gt; tag, which evaluates an expression
  - * -- or its body -- and stores the resulting value in the 'scoped'
  - * attribute specified by the 'var' and 'scope' attributes.</p>
  + * <p>A handler for &lt;sett&gt;, which redirects the browser to a
  + * new URL.
    *
    * @author Shawn Bayern
    */
  -public class SetTag extends BodyTagSupport {
  +
  +public class SetTag extends SetSupport {
   
       //*********************************************************************
  -    // Internal state
  +    // 'Private' state (implementation details)
  +
  +    private String value_;			// stores EL-based property
  +    private String target_;			// stores EL-based property
  +    private String property_;			// stores EL-based property
   
  -    private String value;                               // tag attribute
  -    private int scope;					// tag attribute
  -    private String var;					// tag attribute
   
       //*********************************************************************
  -    // Construction and initialization
  +    // Constructor
   
  -    /**
  -     * Constructs a new handler.  As with TagSupport, subclasses should
  -     * not provide other constructors and are expected to call the
  -     * superclass constructor.
  -     */
       public SetTag() {
           super();
           init();
       }
   
  -    // resets local state
  -    private void init() {
  -        value = var = null;
  -	scope = PageContext.PAGE_SCOPE;
  +
  +    //*********************************************************************
  +    // Tag logic
  +
  +    // evaluates expression and chains to parent
  +    public int doStartTag() throws JspException {
  +
  +        // evaluate any expressions we were passed, once per invocation
  +        evaluateExpressions();
  +
  +	// chain to the parent implementation
  +	return super.doStartTag();
       }
   
  +
       // Releases any resources we may have (or inherit)
       public void release() {
           super.release();
  @@ -104,58 +107,50 @@
   
   
       //*********************************************************************
  -    // Tag logic
  -
  -    // evaluates the expression and stores it appropriately
  -    public int doEndTag() throws JspException {
  +    // Accessor methods
   
  -	Object result;			// what we'll store in scope:var
  +    public void setValue(String value_) {
  +        this.value_ = value_;
  +    }
   
  -	// determine the value by...
  -	if (value != null) {
  -            // ... evaluating our expression
  -            result = ExpressionEvaluatorManager.evaluate(
  -                "value", value, Object.class, this, pageContext);
  -	    if (result == null) {
  -		// throw new NullAttributeException("set", "value");
  -		pageContext.removeAttribute(var, scope);
  -		return EVAL_PAGE;
  -	    }
  -	} else {
  -	    // ... retrieving and trimming our body
  -	    if (bodyContent == null || bodyContent.getString() == null)
  -		result = "";
  -	    else
  -		result = bodyContent.getString().trim();
  -	}
  -
  -	/*
  -         * Store the result, letting an IllegalArgumentException
  -         * propagate back if the scope is invalid (e.g., if an attempt
  -         * is made to store something in the session without any
  -	 * HttpSession existing).
  -         */
  -	pageContext.setAttribute(var, result, scope);
  +    public void setTarget(String target_) {
  +        this.target_ = target_;
  +    }
   
  -	return EVAL_PAGE;
  +    public void setProperty(String property_) {
  +        this.property_ = property_;
       }
   
   
       //*********************************************************************
  -    // Accessor methods
  +    // Private (utility) methods
   
  -    // for tag attribute
  -    public void setVar(String var) {
  -	this.var = var;
  +    // (re)initializes state (during release() or construction)
  +    private void init() {
  +        // null implies "no expression"
  +	value_ = target_ = property_ = null;
       }
   
  -    // for tag attribute
  -    public void setValue(String value) {
  -        this.value = value;
  -    }
  +    /* Evaluates expressions as necessary */
  +    private void evaluateExpressions() throws JspException {
  +        /* 
  +         * Note: we don't check for type mismatches here; we assume
  +         * the expression evaluator will return the expected type
  +         * (by virtue of knowledge we give it about what that type is).
  +         * A ClassCastException here is truly unexpected, so we let it
  +         * propagate up.
  +         */
   
  -    // for tag attribute
  -    public void setScope(String scope) {
  -        this.scope = Util.getScope(scope);
  +	value = (String) ExpressionUtil.evalNotNull(
  +	    "set", "value", value_, String.class, this, pageContext);
  +	target = ExpressionUtil.evalNotNull(
  +	    "set", "target", target_, Object.class, this, pageContext);
  +	try {
  +	    property = (String) ExpressionUtil.evalNotNull(
  +	         "set", "property", property_, String.class, this, pageContext);
  +        } catch (NullAttributeException ex) {
  +            // explicitly let 'property' be null
  +            property = null;
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>