KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > servlet > tags > imports > ImportParam


1 package jodd.servlet.tags.imports;
2
3 import javax.servlet.jsp.JspTagException;
4 import javax.servlet.jsp.tagext.BodyContent;
5 import javax.servlet.jsp.tagext.BodyTagSupport;
6
7 /**
8  * Parameters for import tag.
9  *
10  * @see Import
11  */

12 public class ImportParam extends BodyTagSupport {
13
14     private String name = "";
15     /**
16      * Sets parameter name (required).
17      *
18      * @param v parameter name
19      */

20     public void setName(String v) {
21         name = v;
22     }
23     /**
24      * Returns parameter name.
25      *
26      * @return parameter name
27      */

28     protected String getName() {
29         return name;
30     }
31
32
33     private String value = "";
34     /**
35      * Sets value.
36      *
37      * @param v string value
38      */

39     public void setValue(String v) {
40         value = v;
41     }
42     /**
43      * Sets value from an integer.
44      *
45      * @param v int value
46      */

47     public void setValue(int v) {
48         value = Integer.toString(v);
49     }
50     /**
51      * Sets value from a float.
52      *
53      * @param f float value
54      */

55     public void setValue(float f) {
56         value = Float.toString(f);
57     }
58     /**
59      * Sets value from a double.
60      *
61      * @param d double value
62      */

63     public void setValue(double d) {
64         value = Double.toString(d);
65     }
66     /**
67      * Sets value from any obejct.
68      *
69      * @param o object
70      */

71     public void setValue(Object o) {
72         if (o == null) {
73             value = "";
74         } else {
75             value = o.toString();
76         }
77     }
78     /**
79      * Returns parameter value.
80      *
81      * @return parameter value
82      */

83     public String getValue() {
84         return value;
85     }
86
87     private String persist = "";
88
89     /**
90      * Set persistence flag for a parameter.
91      *
92      * @param v parameter persistance
93      */

94     public void setPersist(String v) {
95         persist = v;
96     }
97     /**
98      * Returns parameter persistance.
99      *
100      * @return parameter persistence
101      */

102     public String getPersist() {
103         return persist;
104     }
105     
106     
107     private Import parent = null;
108     
109     private boolean isPersistent = false;
110
111     public int doStartTag() {
112         parent = (Import) findAncestorWithClass(this, Import.class);
113         if (parent == null) {
114             return SKIP_BODY;
115         }
116         if ((persist != null) && (persist.equals("true"))) {
117             isPersistent = true;
118         }
119         if ((value == null) || (value.length() == 0)) {
120             return EVAL_BODY_AGAIN;
121         } else {
122             pageContext.getRequest().setAttribute(name, value);
123             if (isPersistent == false) {
124                 parent.addAttributeName(name);
125             }
126             return SKIP_BODY;
127         }
128     }
129
130
131     public int doAfterBody() throws JspTagException {;
132         BodyContent body = getBodyContent();
133         String bodyValue = body.getString();
134         pageContext.getRequest().setAttribute(name, bodyValue);
135         if (isPersistent == false) {
136             parent.addAttributeName(name);
137         }
138         return SKIP_BODY;
139     }
140
141     public int doEndTag() {
142         return EVAL_PAGE;
143     }
144
145 }
146
147
Popular Tags