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.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.config.ResultSetVector;
30 import org.dbforms.interfaces.IDataContainer;
31 import org.dbforms.interfaces.StaticData;
32
33 import org.dbforms.util.Util;
34
35 import java.util.List;
36
37 import javax.servlet.jsp.JspException;
38
39
40
41 /***
42 * this tag renders a dabase-datadriven LABEL, which is a passive element (it
43 * can't be changed by the user) - it is predestinated for use with read-only
44 * data (i.e. primary keys you don't want the user to change, etc) so far it
45 * is equivalent to DbLabelTag. But this tag may have a body containing any
46 * kind of EmbeddedData - tag. i put this feature into a seperate class for
47 * performance reasons (we do not want the overhead of pushing and poping the
48 * jsp writer to and off the stack
49 *
50 * @author Joachim Peer
51 */
52 public class DbDataContainerLabelTag extends AbstractDbBaseHandlerTag
53 implements IDataContainer, javax.servlet.jsp.tagext.TryCatchFinally {
54
55 private List embeddedData = null;
56 private static Log logCat = LogFactory.getLog(DbDataContainerLabelTag.class);
57 private String strict = "false";
58
59 /***
60 * This method is a "hookup" for EmbeddedData - Tags which can assign the
61 * lines of data they loaded (by querying a database, or by rendering
62 * data-subelements, etc. etc.) and make the data available to this tag.
63 * [this method is defined in Interface DataContainer]
64 *
65 * @param embeddedData DOCUMENT ME!
66 */
67 public void setEmbeddedData(List embeddedData) {
68 this.embeddedData = embeddedData;
69 }
70
71
72 /***
73 * DOCUMENT ME!
74 *
75 * @param string
76 */
77 public void setStrict(String string) {
78 strict = string;
79 }
80
81
82 /***
83 * DOCUMENT ME!
84 *
85 * @return
86 */
87 public String getStrict() {
88 return strict;
89 }
90
91
92
93 /***
94 * DOCUMENT ME!
95 *
96 * @return DOCUMENT ME!
97 *
98 * @throws javax.servlet.jsp.JspException DOCUMENT ME!
99 * @throws JspException DOCUMENT ME!
100 */
101 public int doEndTag() throws javax.servlet.jsp.JspException {
102 try {
103 String fieldValue = "";
104
105 if (!Util.getTrue(strict)) {
106 fieldValue = this.getFormattedFieldValue();
107 }
108
109 String compareValue = this.getFieldValue();
110
111
112 if (!ResultSetVector.isNull(getParentForm().getResultSetVector())) {
113 if (embeddedData != null) {
114
115 int embeddedDataSize = embeddedData.size();
116 int i = 0;
117 String embeddedDataValue = null;
118
119 while (i < embeddedDataSize) {
120 StaticData aKeyValuePair = (StaticData) embeddedData.get(i);
121
122 if (aKeyValuePair.getKey()
123 .equals(compareValue)) {
124 embeddedDataValue = aKeyValuePair.getValue();
125
126 break;
127 }
128
129 i++;
130 }
131
132 if (embeddedDataValue != null) {
133 fieldValue = embeddedDataValue;
134
135
136 }
137 }
138 }
139
140
141
142 String size = null;
143
144 if (((size = this.getMaxlength()) != null)
145 && (size.trim()
146 .length() > 0)) {
147
148 int count = Integer.parseInt(size);
149
150
151 if (count < fieldValue.length()) {
152 fieldValue = fieldValue.substring(0, count);
153 fieldValue += "...";
154 }
155 }
156
157
158
159 String s = prepareStyles();
160
161 if (Util.isNull(s)) {
162 pageContext.getOut()
163 .write(fieldValue);
164 } else {
165 pageContext.getOut()
166 .write("<span " + s + ">" + fieldValue + "</span>");
167 }
168 } catch (java.io.IOException ioe) {
169 logCat.error(ioe);
170 throw new JspException("IO Error: " + ioe.getMessage());
171 } catch (Exception e) {
172 logCat.error(e);
173 throw new JspException("Error: " + e.getMessage());
174 }
175
176 return EVAL_PAGE;
177 }
178
179
180 /***
181 * DOCUMENT ME!
182 */
183 public void doFinally() {
184 embeddedData = null;
185 super.doFinally();
186 }
187 }