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.apache.commons.beanutils.PropertyUtils;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 import org.dbforms.config.Field;
31 import org.dbforms.config.FieldValue;
32 import org.dbforms.config.ResultSetVector;
33
34 import org.dbforms.util.Util;
35
36 import javax.servlet.jsp.JspException;
37
38
39
40 /***
41 * Special class for TextFormatting
42 *
43 * @author hkk
44 */
45 public class TextFormatTag extends AbstractDbBaseHandlerTag
46 implements javax.servlet.jsp.tagext.TryCatchFinally {
47 private static Log logCat = LogFactory.getLog(TextFormatTag.class);
48 private Object fieldObject;
49 private String contextVar;
50 private String type;
51 private String value;
52
53 /***
54 * DOCUMENT ME!
55 *
56 * @param contextVar DOCUMENT ME!
57 */
58 public void setContextVar(String contextVar) {
59 this.contextVar = contextVar;
60 }
61
62
63 /***
64 * DOCUMENT ME!
65 *
66 * @return DOCUMENT ME!
67 */
68 public String getContextVar() {
69 return contextVar;
70 }
71
72
73 /***
74 * DOCUMENT ME!
75 *
76 * @return
77 */
78 public Object getFieldObject() {
79 return fieldObject;
80 }
81
82
83 /***
84 * DOCUMENT ME!
85 *
86 * @param type The type to set.
87 */
88 public void setType(String type) {
89 this.type = type;
90 }
91
92
93 /***
94 * DOCUMENT ME!
95 *
96 * @return Returns the type.
97 */
98 public String getType() {
99 return type;
100 }
101
102
103 /***
104 * DOCUMENT ME!
105 *
106 * @param value The value to set.
107 */
108 public void setValue(String value) {
109 this.value = value;
110 }
111
112
113 /***
114 * DOCUMENT ME!
115 *
116 * @return Returns the value.
117 */
118 public String getValue() {
119 return value;
120 }
121
122 /***
123 * Description of the Method
124 *
125 * @return Description of the Return Value
126 *
127 * @exception javax.servlet.jsp.JspException Description of the Exception
128 * @throws JspException DOCUMENT ME!
129 */
130 public int doEndTag() throws javax.servlet.jsp.JspException {
131 if (Util.isNull(getContextVar()) && Util.isNull(getValue())) {
132 throw new JspException("either var or value must be setted!");
133 }
134
135 Field field = new Field();
136
137 if (!Util.isNull(getValue())) {
138 if (Util.isNull(getType())) {
139 throw new JspException("value setted - type must be setted too!");
140 }
141
142 field.setFieldType(getType());
143
144 FieldValue fv = new FieldValue(field, getValue());
145 fv.setPattern(getPattern());
146 fieldObject = fv.getFieldValueAsObject();
147 } else {
148 String search = getContextVar();
149 int pos = search.indexOf(".");
150
151 ResultSetVector rsv = null;
152
153 if (getParentForm() != null) {
154 rsv = getParentForm()
155 .getResultSetVector();
156 }
157
158 if (pos == -1) {
159 if (rsv != null) {
160 fieldObject = rsv.getAttribute(search);
161 }
162
163 if (fieldObject == null) {
164
165 fieldObject = pageContext.findAttribute(search);
166 }
167 } else {
168 try {
169
170 String search_bean = search.substring(0, pos);
171 search = search.substring(pos + 1);
172
173 Object bean = null;
174
175 if (rsv != null) {
176 bean = rsv.getAttribute(search_bean);
177 }
178
179 if (bean == null) {
180
181 bean = pageContext.findAttribute(search_bean);
182 }
183
184 if (bean != null) {
185 logCat.debug("calling PropertyUtils.getProperty "
186 + search_bean + " " + search);
187 fieldObject = PropertyUtils.getProperty(bean, search);
188 }
189 } catch (Exception e) {
190 throw new JspException(e.getMessage());
191 }
192 }
193
194 if (fieldObject == null) {
195 throw new JspException("object not found in context!");
196 }
197
198 field.setTypeByObject(fieldObject);
199 }
200
201 this.setField(field);
202
203 String fieldValue = getFormattedFieldValue();
204 fieldValue = escapeHTML(fieldValue);
205
206 try {
207 pageContext.getOut()
208 .write(fieldValue);
209 } catch (java.io.IOException ioe) {
210
211 throw new JspException("IO Error: " + ioe.getMessage());
212 }
213
214 return EVAL_PAGE;
215 }
216
217
218 /***
219 * DOCUMENT ME!
220 */
221 public void doFinally() {
222 type = null;
223 value = null;
224 contextVar = null;
225 super.doFinally();
226 }
227
228
229 /***
230 * DOCUMENT ME!
231 *
232 * @param fieldObject DOCUMENT ME!
233 */
234 protected void setFieldObject(Object fieldObject) {
235 this.fieldObject = fieldObject;
236 }
237 }