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.function.FunctionTag;
22 import java.util.ArrayList;
23
24 import org.apache.commons.jelly.MissingAttributeException;
25 import org.apache.commons.jelly.JellyTagException;
26 import org.apache.commons.jelly.TagSupport;
27 import org.apache.commons.jelly.XMLOutput;
28
29 /***
30 * Used to give a function tag a parameter or a list of parameters.
31 *
32 * For example:
33 * <pre>
34 * <param>
35 * <param-name>someName</param-name>
36 * <param-value>foo</param-value>
37 * <param-type>text</param-type>
38 * </param>
39 * </pre>
40 * This tag adds itself to a list of param tags to the parent FunctionTag.
41 * It's up to the FunctionTag to use the parameters. They can be accessed via
42 * the {@link net.sf.jameleon.function.FunctionTag#getParams()} method.
43 *
44 * @jameleon.function name="param"
45 */
46 public class ParamTag extends TagSupport {
47
48 /***
49 * The value of the param.
50 */
51 protected ArrayList values;
52 /***
53 * The name of param.
54 */
55 protected String name;
56 /***
57 * The input type of the param (text, checkbox, listbox...)
58 */
59 protected String paramType;
60
61 protected String fromVariable;
62
63 public ParamTag(){
64 super();
65 values = new ArrayList();
66 }
67
68 public void doTag(XMLOutput out) throws MissingAttributeException, JellyTagException{
69 values = new ArrayList();
70
71 invokeBody(out);
72 validate();
73
74 FunctionTag tag = (FunctionTag) findAncestorWithClass(FunctionTag.class);
75 tag.addParam(this);
76 }
77
78 /***
79 * Used to validate everything is set up correctly.
80 * @throws MissingAttributeException - When a required attribute isn't set.
81 * @throws JellyTagException - When this tag is used out of context.
82 */
83 protected void validate()throws MissingAttributeException, JellyTagException{
84 if (name == null){
85 throw new MissingAttributeException("name is a required tag!");
86 }
87 }
88
89 /***
90 * @return The param type
91 */
92 public String getParamType(){
93 return this.paramType;
94 }
95
96 /***
97 * @return The first param value from the list of values
98 */
99 public String getValue(){
100 return (String)values.get(0);
101 }
102
103 /***
104 * @return The param values
105 */
106 public ArrayList getParamValues(){
107 return values;
108 }
109
110 /***
111 * Adds a value to the list of values supplied for this parameter.
112 * @param value The param value
113 */
114 public void addParamValue(String value){
115 values.add(value);
116 }
117
118 /***
119 * @return The param name
120 */
121 public String getName(){
122 return this.name;
123 }
124
125 /***
126 * @return The param name
127 */
128 public String getParamName(){
129 return this.name;
130 }
131
132 public void setParamName(String paramName){
133 name = paramName;
134 }
135
136 public void setParamValue(String value){
137 values = new ArrayList();
138 values.add(value);
139 }
140
141 public void setParamType(String paramType){
142 this.paramType = paramType;
143 }
144
145 public String getFromVariable(){
146 return fromVariable;
147 }
148
149 public void setFromVariable(String fromVar){
150 fromVariable = fromVar;
151 }
152
153 }