1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.taglib;
25
26 import org.dbforms.interfaces.IDataContainer;
27 import org.dbforms.interfaces.IStaticDataList;
28 import org.dbforms.interfaces.StaticData;
29
30 import java.sql.Connection;
31
32 import java.util.Collection;
33 import java.util.Vector;
34
35 import javax.servlet.jsp.JspException;
36 import javax.servlet.jsp.PageContext;
37
38
39
40 /***
41 * DOCUMENT ME!
42 *
43 * @author $author$
44 * @version $Revision: 1.2 $
45 */
46 public class StaticDataTag extends AbstractScriptHandlerTag
47 implements javax.servlet.jsp.tagext.TryCatchFinally, IStaticDataList {
48 private String name;
49 private Vector data;
50
51 /***
52 * set the name of the embedded data. every embedded data entity on a jsp
53 * page has to have a unique name. this name is used for storing (caching)
54 * and retrieving data in Page-Scope. this is useful if a tag gets
55 * evaluated many times -> we do not the tag get parsed more than once
56 * #fixme: encode name in order to avoid naming conficts!
57 *
58 * @param name DOCUMENT ME!
59 */
60 public void setName(String name) {
61 this.name = name;
62 }
63
64
65 /***
66 * returns the unique name of the embedded data
67 *
68 * @return DOCUMENT ME!
69 */
70 public String getName() {
71 return name;
72 }
73
74
75 /***
76 * DOCUMENT ME!
77 *
78 * @param pair DOCUMENT ME!
79 */
80 public void addElement(StaticData pair) {
81 data.add(pair);
82 }
83
84
85 /***
86 * DOCUMENT ME!
87 *
88 * @return DOCUMENT ME!
89 *
90 * @throws JspException DOCUMENT ME!
91 */
92 public int doAfterBody() throws JspException {
93
94 pageContext.setAttribute(name, data, PageContext.PAGE_SCOPE);
95
96 return SKIP_BODY;
97 }
98
99
100 /***
101 * DOCUMENT ME!
102 *
103 * @return DOCUMENT ME!
104 *
105 * @throws JspException DOCUMENT ME!
106 */
107 public int doEndTag() throws JspException {
108 ((IDataContainer) getParent()).setEmbeddedData(data);
109
110 return EVAL_PAGE;
111 }
112
113
114 /***
115 * DOCUMENT ME!
116 */
117 public void doFinally() {
118 name = null;
119 data = null;
120 }
121
122
123 /***
124 * DOCUMENT ME!
125 *
126 * @return DOCUMENT ME!
127 *
128 * @throws JspException DOCUMENT ME!
129 */
130 public int doStartTag() throws JspException {
131
132 data = (Vector) pageContext.getAttribute(name, PageContext.PAGE_SCOPE);
133
134
135
136 if (data == null) {
137 data = new Vector();
138
139 return EVAL_BODY_BUFFERED;
140 } else {
141 return SKIP_BODY;
142 }
143 }
144
145
146 /***
147 * for use from parent element [radio, select, etc.]
148 *
149 * @param con DOCUMENT ME!
150 *
151 * @return DOCUMENT ME!
152 */
153 protected Collection fetchData(Connection con) {
154 return data;
155 }
156 }