You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2003/01/31 15:16:25 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core SetTag.java

jstrachan    2003/01/31 06:16:25

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/core
                        SetTag.java
  Log:
  Applied Knut's patch to fail fast if invalid arguments are used in the <j:set> tag
  
  Revision  Changes    Path
  1.14      +20 -11    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/SetTag.java
  
  Index: SetTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/SetTag.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SetTag.java	29 Jan 2003 15:45:36 -0000	1.13
  +++ SetTag.java	31 Jan 2003 14:16:25 -0000	1.14
  @@ -107,6 +107,21 @@
       // Tag interface
       //------------------------------------------------------------------------- 
       public void doTag(XMLOutput output) throws JellyTagException {
  +        // perform validation up front to fail fast
  +        if ( var != null ) {
  +            if ( target != null || property != null ) {
  +                throw new JellyTagException( "The 'target' and 'property' attributes cannot be used in combination with the 'var' attribute" );
  +            }
  +        }
  +        else {
  +            if ( target == null ) {
  +                throw new JellyTagException( "Either a 'var' or a 'target' attribute must be defined for this tag" );
  +            }
  +            if ( property == null ) {
  +                throw new JellyTagException( "The 'target' attribute requires the 'property' attribute" );
  +            }
  +        }
  +
           Object answer = null;
           if ( value != null ) {
               answer = value.evaluate(context);
  @@ -124,12 +139,6 @@
               }
           }
           else {
  -            if ( target == null ) {
  -                throw new JellyTagException( "Either a 'var' or a 'target' attribute must be defined for this tag" );
  -            }
  -            if ( property == null ) {
  -                throw new JellyTagException( "You must define a 'property' attribute if you specify a 'target'" );
  -            }
               setPropertyValue( target, property, answer );
           }
       }
  
  
  

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