View Javadoc

1   /*
2       Jameleon - An automation testing tool..
3       Copyright (C) 2003 Christian W. Hargraves (engrean@hotmail.com)
4       
5       This library is free software; you can redistribute it and/or
6       modify it under the terms of the GNU Lesser General Public
7       License as published by the Free Software Foundation; either
8       version 2.1 of the License, or (at your option) any later version.
9   
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13      Lesser General Public License for more details.
14  
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19  package net.sf.jameleon;
20  
21  import net.sf.jameleon.util.JameleonUtility;
22  
23  import org.apache.commons.jelly.MissingAttributeException;
24  import org.apache.commons.jelly.Tag;
25  import org.apache.commons.jelly.JellyTagException;
26  import org.apache.commons.jelly.XMLOutput;
27  
28  /***
29   * used only as a child of <map-variable/>, it allows the ability to map one or more
30   * text values to a variable. The variableType of <map-variable/> can be used to when defining
31   * multiple values.
32   * 
33   * For example:
34   * <pre><source>
35   * &lt;testcase xmlns="jelly:jameleon"&gt;
36   *
37   *   &lt;some-session application="someApp" beginSession="true"&gt;
38   *       &lt;some-tag-that-uses-context-variables
39   *           functionId="Verify successful navigation, using a different variable."&gt;
40   *           &lt;map-variable toVariable="resultsText" variableType="list"&gt;
41   *               &lt;variable-value&gt;value 1&lt;/variable-value&gt;
42   *               &lt;variable-value&gt;value 2&lt;/variable-value&gt;
43   *               &lt;variable-value&gt;value 3&lt;/variable-value&gt;
44   *               &lt;variable-value&gt;value 4&lt;/variable-value&gt;
45   *           &lt;/map-variable/&gt;
46   *       &lt;/some-tag-that-uses-context-variables&gt;
47   *   &lt;/some-session&gt;
48   * &lt;/testcase&gt;
49   * </source></pre>
50   * 
51   * @jameleon.function name="variable-value"
52   */
53  public class VariableValueTag extends VariableTag {
54      private boolean decodeXMLToText;
55  
56      public VariableValueTag(){
57          super();
58      }
59      /***
60       * An implementation of the <code>doTag</code> method provided by the <code>TagSupport</code> class.
61       * Maps the value in the <code>fromVariable</code> over to the original variable name, <code>toVariable</code>.
62       */
63      public void doTag(XMLOutput out) throws MissingAttributeException, JellyTagException{
64          init();
65          VariableMappingTag tag = (VariableMappingTag)getParent();
66          toVariable = tag.getToVariable();
67          variableType = tag.getVariableType();
68          value = (String)getBodyText();
69  
70          if (decodeXMLToText) {
71              value = JameleonUtility.decodeXMLToText(value);
72          }
73          super.doTag(out);
74          tag.setChildExecuted(true);
75      }
76  
77      /***
78       * Used to validate everything is set up correctly.
79       * @throws MissingAttributeException - When a required attribute isn't set.
80       * @throws JellyTagException - When this tag is used out of context.
81       */
82      protected void validate()throws MissingAttributeException, JellyTagException{
83          Tag tag = getParent();
84          if ( ! (tag instanceof VariableMappingTag) ) {
85              throw new JellyTagException("This tag can only be imbedded in a the map-variable tag.");
86          }
87          if (value == null ){
88              throw new MissingAttributeException("value is required as an attribute or the body of the element!");
89          }
90          super.validate();
91      }
92  
93      /***
94       * @return The variable name to be mapped to the <code>fromVariable</code> or the originally supported variable name that has a set method for it
95       * in the function point.
96       */
97      public String getValue(){
98          return this.value;
99      }
100 
101     /***
102      * Sets the variable value.
103      * @param value - the variable value.
104      */
105     public void setValue(String value){
106         this.value = value;
107     }
108 
109     public void setDecodeXMLToText(boolean decodeXMLToText){
110         this.decodeXMLToText = decodeXMLToText;
111     }    
112 }