1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 * <testcase xmlns="jelly:jameleon">
36 *
37 * <some-session application="someApp" beginSession="true">
38 * <some-tag-that-uses-context-variables
39 * functionId="Verify successful navigation, using a different variable.">
40 * <map-variable toVariable="resultsText" variableType="list">
41 * <variable-value>value 1</variable-value>
42 * <variable-value>value 2</variable-value>
43 * <variable-value>value 3</variable-value>
44 * <variable-value>value 4</variable-value>
45 * </map-variable/>
46 * </some-tag-that-uses-context-variables>
47 * </some-session>
48 * </testcase>
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 }