You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2002/10/22 17:13:44 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core TestSwitchTag.java testSwitchTag.jelly

rwaldhoff    2002/10/22 08:13:43

  Modified:    jelly    project.xml
               jelly/src/java/org/apache/commons/jelly/tags/core
                        CoreTagLibrary.java
  Added:       jelly/src/java/org/apache/commons/jelly/tags/core
                        CaseTag.java DefaultTag.java SwitchTag.java
               jelly/src/test/org/apache/commons/jelly/core
                        TestSwitchTag.java testSwitchTag.jelly
  Log:
  add switch/case/default tags, and tests
  
  Revision  Changes    Path
  1.82      +5 -0      jakarta-commons-sandbox/jelly/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/project.xml,v
  retrieving revision 1.81
  retrieving revision 1.82
  diff -u -r1.81 -r1.82
  --- project.xml	21 Oct 2002 16:51:54 -0000	1.81
  +++ project.xml	22 Oct 2002 15:13:43 -0000	1.82
  @@ -93,6 +93,11 @@
         <id>morgand</id>
         <email>morgand@apache.org</email>
       </developer>
  +    <developer>
  +      <name>Rodney Waldhoff</name>
  +      <id>rwaldhoff</id>
  +      <email>rwaldhoff@apache.org</email>
  +    </developer>
     </developers>
   
     <contributors>
  
  
  
  1.20      +8 -5      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java
  
  Index: CoreTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- CoreTagLibrary.java	5 Oct 2002 03:37:24 -0000	1.19
  +++ CoreTagLibrary.java	22 Oct 2002 15:13:43 -0000	1.20
  @@ -95,6 +95,9 @@
           registerTag("choose", ChooseTag.class);
           registerTag("when", WhenTag.class);
           registerTag("otherwise", OtherwiseTag.class);
  +        registerTag("switch", SwitchTag.class);
  +        registerTag("case", CaseTag.class);
  +        registerTag("default", DefaultTag.class);
           
           // other tags
           registerTag("include", IncludeTag.class);
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CaseTag.java
  
  Index: CaseTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CaseTag.java,v 1.1 2002/10/22 15:13:43 rwaldhoff Exp $
   * $Revision: 1.1 $
   * $Date: 2002/10/22 15:13:43 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: CaseTag.java,v 1.1 2002/10/22 15:13:43 rwaldhoff Exp $
   */
  package org.apache.commons.jelly.tags.core;
  
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.expression.Expression;
  
  /** 
   * A tag which conditionally evaluates its body if
   * my {@link #setValue value} attribute equals my ancestor
   * {@link SwitchTag &lt;switch&gt;} tag's 
   * {@link SwitchTag#setOn "on"} attribute.
   * 
   * This tag must be contained within the body of some 
   * {@link SwitchTag &lt;switch&gt;} tag.
   * 
   * @see SwitchTag
   * 
   * @author Rodney Waldhoff
   * @version $Revision: 1.1 $ $Date: 2002/10/22 15:13:43 $
   */
  public class CaseTag extends TagSupport {
  
      public CaseTag() {
      }
      
      // Tag interface
      //------------------------------------------------------------------------- 
      public void setValue(Expression value) {
          this.valueExpression = value;
      }
      
      public void setFallThru(boolean fallThru) {
          this.fallThru = fallThru;
      }
      
      public void doTag(XMLOutput output) throws Exception {
          if(null == this.valueExpression) {
              throw new MissingAttributeException("value");
          }        
          SwitchTag tag = (SwitchTag)findAncestorWithClass(SwitchTag.class);
          if(null == tag) {
              throw new JellyException("This tag must be enclosed inside a <switch> tag" );
          }
          Object value = valueExpression.evaluate(context);        
          if(tag.isFallingThru() || 
             (null == tag.getValue() && null == value) || 
             (null != tag.getValue() && tag.getValue().equals(value))) {
              tag.caseMatched();
              tag.setFallingThru(fallThru);
              invokeBody(output);
          }
      }
      
      // Attributes
      //------------------------------------------------------------------------- 
      private Expression valueExpression = null;
      private boolean fallThru = false;
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/DefaultTag.java
  
  Index: DefaultTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/DefaultTag.java,v 1.1 2002/10/22 15:13:43 rwaldhoff Exp $
   * $Revision: 1.1 $
   * $Date: 2002/10/22 15:13:43 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: DefaultTag.java,v 1.1 2002/10/22 15:13:43 rwaldhoff Exp $
   */
  package org.apache.commons.jelly.tags.core;
  
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  
  /** 
   * A tag which conditionally evaluates its body if
   * none of its preceeding sibling {@link CaseTag &lt;case&gt;} 
   * tags have been evaluated.
   * 
   * This tag must be contained within the body of some 
   * {@link SwitchTag &lt;switch&gt;} tag.
   * 
   * @see SwitchTag
   * 
   * @author Rodney Waldhoff
   * @version $Revision: 1.1 $ $Date: 2002/10/22 15:13:43 $
   */
  public class DefaultTag extends TagSupport {
  
      public DefaultTag() {
      }
      
      // Tag interface
      //------------------------------------------------------------------------- 
      
      public void setFallThru(boolean fallThru) {
          this.fallThru = fallThru;
      }
      
      public void doTag(XMLOutput output) throws Exception {
          SwitchTag tag = (SwitchTag)findAncestorWithClass(SwitchTag.class);
          if(null == tag) {
              throw new JellyException("This tag must be enclosed inside a <switch> tag" );
          }
          if(tag.hasDefaultBeenEncountered()) {
              throw new JellyException("Only one <default> tag is allowed per <switch>.");
          }
          if(tag.isFallingThru() || (!tag.hasSomeCaseMatched())) {
              tag.caseMatched();
              tag.setFallingThru(fallThru);
              invokeBody(output);
          }
      }
  
      // Attributes
      //------------------------------------------------------------------------- 
      private boolean fallThru = false;
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/SwitchTag.java
  
  Index: SwitchTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/SwitchTag.java,v 1.1 2002/10/22 15:13:43 rwaldhoff Exp $
   * $Revision: 1.1 $
   * $Date: 2002/10/22 15:13:43 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: SwitchTag.java,v 1.1 2002/10/22 15:13:43 rwaldhoff Exp $
   */
  package org.apache.commons.jelly.tags.core;
  
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.expression.Expression;
  
  import bsh.This;
  
  /** 
   * Executes the child &lt;case&gt; tag whose value equals my on attribute.
   * Executes a child &lt;default&gt; tag when present and no &lt;case&gt; tag has
   * yet matched.
   * 
   * @see CaseTag
   * @see DefaultTag
   * 
   * @author Rodney Waldhoff
   * @version $Revision: 1.1 $ $Date: 2002/10/22 15:13:43 $
   */
  public class SwitchTag extends TagSupport {
  
      public SwitchTag() {
      }
      
      // Tag interface
      //------------------------------------------------------------------------- 
  
      /**
       * Sets the value to switch on.
       * Note that the {@link Expression} is evaluated only once, when the 
       * &lt;switch&gt; tag is evaluated.
       * @param on the value to switch on
       */
      public void setOn(Expression on) {
          this.on = on;
      }
      
      public void doTag(XMLOutput output) throws Exception {
          if(null == on) {
              throw new MissingAttributeException("on");
          } else {
              value = on.evaluate(context);
              invokeBody(output);
          }
      }
      
      // Protected properties
      //------------------------------------------------------------------------- 
      protected boolean hasSomeCaseMatched() {
          return this.someCaseMatched;
      }
      
      protected void caseMatched() {
          this.someCaseMatched = true;
      }
      
      protected boolean isFallingThru() {
          return this.fallingThru;
      }
      
      protected void setFallingThru(boolean fallingThru) {
          this.fallingThru = fallingThru;
      }
      
      protected Object getValue() {
          return value;        
      }
  
      protected boolean hasDefaultBeenEncountered() {
          return defaultEncountered;        
      }
  
      protected void defaultEncountered() {
          this.defaultEncountered = true;
      }
  
      // Attributes
      //------------------------------------------------------------------------- 
      private boolean someCaseMatched = false;
      private boolean fallingThru = false;
      private boolean defaultEncountered = false;
      private Expression on = null;
      private Object value = null;
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/TestSwitchTag.java
  
  Index: TestSwitchTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/TestSwitchTag.java,v 1.1 2002/10/22 15:13:43 rwaldhoff Exp $
   * $Revision: 1.1 $
   * $Date: 2002/10/22 15:13:43 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: TestSwitchTag.java,v 1.1 2002/10/22 15:13:43 rwaldhoff Exp $
   */
  package org.apache.commons.jelly.core;
  
  import java.io.File;
  import java.net.URL;
  
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.jelly.Jelly;
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.TagLibrary;
  import org.apache.commons.jelly.XMLOutput;
  
  /**
   * @author Rodney Waldhoff
   * @version $Revision: 1.1 $ $Date: 2002/10/22 15:13:43 $
   */
  public class TestSwitchTag extends TestCase {
  
      public TestSwitchTag(String name) {
          super(name);
      }
  
      public static TestSuite suite() throws Exception {
          return new TestSuite(TestSwitchTag.class);        
      }
  
      public void setUp() throws Exception {
          super.setUp();
          jelly = new Jelly();
          context = new JellyContext();
          xmlOutput = XMLOutput.createDummyXMLOutput();        
      }    
      
      private void setUpScript(String scriptname) throws Exception {
          URL url = this.getClass().getResource(scriptname);
          if(null == url) {
              throw new Exception( 
                  "Could not find Jelly script: " + scriptname 
                  + " in package of class: " + getClass().getName() 
              );
          }
          jelly.setUrl(url);
  
          String exturl = url.toExternalForm();
          int lastSlash = exturl.lastIndexOf("/");
          String extBase = exturl.substring(0,lastSlash+1);
          URL baseurl = new URL(extBase);
          context.setCurrentURL(baseurl);
      }
      
      public void testSimpleSwitch() throws Exception {
          setUpScript("testSwitchTag.jelly");
          Script script = jelly.compileScript();
          context.setVariable("switch.on.a","two");
          script.run(context,xmlOutput);
          assertNull("should not have 'a.one' variable set",
                     context.getVariable("a.one"));
          assertTrue("should have set 'a.two' variable to 'true'",
                     context.getVariable("a.two").equals("true"));
          assertNull("should not have 'a.three' variable set",
                     context.getVariable("a.three"));
          assertNull("should not have 'a.null' variable set",
                     context.getVariable("a.null"));
          assertNull("should not have 'a.default' variable set",
                     context.getVariable("a.default"));
      }
  
      public void testFallThru() throws Exception {
          setUpScript("testSwitchTag.jelly");
          Script script = jelly.compileScript();
          context.setVariable("switch.on.a","one");
          script.run(context,xmlOutput);
          assertTrue("should have set 'a.one' variable to 'true'",
                     context.getVariable("a.one").equals("true"));
          assertTrue("should have set 'a.two' variable to 'true'",
                     context.getVariable("a.two").equals("true"));
          assertNull("should not have 'a.three' variable set",
                     context.getVariable("a.three"));
          assertNull("should not have 'a.null' variable set",
                     context.getVariable("a.null"));
          assertNull("should not have 'a.default' variable set",
                     context.getVariable("a.default"));
      }
  
      public void testDefault() throws Exception {
          setUpScript("testSwitchTag.jelly");
          Script script = jelly.compileScript();
          context.setVariable("switch.on.a","negative one");
          script.run(context,xmlOutput);
          assertNull("should not have 'a.one' variable set",
                     context.getVariable("a.one"));
          assertNull("should not have 'a.two' variable set",
                     context.getVariable("a.two"));
          assertNull("should not have 'a.three' variable set",
                     context.getVariable("a.three"));
          assertNull("should not have 'a.null' variable set",
                     context.getVariable("a.null"));
          assertTrue("should have set 'a.default' variable to 'true'",
                     context.getVariable("a.default").equals("true"));
      }
  
      public void testNullCase() throws Exception {
          setUpScript("testSwitchTag.jelly");
          Script script = jelly.compileScript();
          context.setVariable("switch.on.a",null);
          script.run(context,xmlOutput);
          assertNull("should not have 'a.one' variable set",
                     context.getVariable("a.one"));
          assertNull("should not have 'a.two' variable set",
                     context.getVariable("a.two"));
          assertNull("should not have 'a.three' variable set",
                     context.getVariable("a.three"));
          assertTrue("should have set 'a.null' variable to 'true'",
                     context.getVariable("a.null").equals("true"));
          assertNull("should not have 'a.default' variable set",
                     context.getVariable("a.default"));
      }
  
      private Jelly jelly = null;
      private JellyContext context = null;
      private XMLOutput xmlOutput = null;
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/testSwitchTag.jelly
  
  Index: testSwitchTag.jelly
  ===================================================================
  <j:jelly xmlns:j="jelly:core">
      <j:switch on="${switch.on.a}">
          <j:case value="one" fallThru="true">
              <j:set var="a.one" value="true"/>
          </j:case>
          <j:case value="two">
              <j:set var="a.two" value="true"/>
          </j:case>
          <j:case value="three">
              <j:set var="a.three" value="true"/>
          </j:case>
          <j:case value="${null}">
              <j:set var="a.null" value="true"/>
          </j:case>
          <j:default>
              <j:set var="a.default" value="true"/>
          </j:default>
      </j:switch>
  </j:jelly>
  
  
  

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