1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.element;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
22 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
23 import org.kuali.rice.krad.datadictionary.validator.Validator;
24 import org.kuali.rice.krad.uif.component.Component;
25 import org.kuali.rice.krad.uif.util.MessageStructureUtils;
26 import org.kuali.rice.krad.uif.view.View;
27 import org.kuali.rice.krad.util.KRADConstants;
28
29 import java.util.List;
30
31
32
33
34
35
36
37
38
39
40
41 @BeanTags({@BeanTag(name = "message-bean", parent = "Uif-Message"),
42 @BeanTag(name = "instructionalMessage-bean", parent = "Uif-InstructionalMessage"),
43 @BeanTag(name = "constraintMessage-bean", parent = "Uif-ConstraintMessage"),
44 @BeanTag(name = "requiredMessage-bean", parent = "Uif-RequiredMessage"),
45 @BeanTag(name = "requiredInstructionsMessage-bean", parent = "Uif-RequiredInstructionsMessage"),
46 @BeanTag(name = "stateBased-requiredInstructionsMessage-bean",
47 parent = "Uif-StateBased-RequiredInstructionsMessage"),
48 @BeanTag(name = "dialogPrompt-bean", parent = "Uif-DialogPrompt"),
49 @BeanTag(name = "imageCutineMessage-bean", parent = "Uif-ImageCutineMessage")})
50 public class Message extends ContentElementBase {
51 private static final long serialVersionUID = 4090058533452450395L;
52
53 private String messageText;
54 private boolean generateSpan;
55
56 private List<Component> inlineComponents;
57 private List<Component> messageComponentStructure;
58
59 private boolean parseComponents;
60
61 public Message() {
62 super();
63
64 generateSpan = true;
65 parseComponents = true;
66 }
67
68
69
70
71
72
73
74 @Override
75 public void performApplyModel(View view, Object model, Component parent) {
76 super.performApplyModel(view, model, parent);
77
78
79
80 if (messageText != null && messageText.contains(KRADConstants.MessageParsing.LEFT_TOKEN) &&
81 messageText.contains(KRADConstants.MessageParsing.RIGHT_TOKEN) &&
82 (messageComponentStructure == null || messageComponentStructure.isEmpty())) {
83
84 messageComponentStructure = MessageStructureUtils.parseMessage(this.getId(), this.getMessageText(),
85 this.getInlineComponents(), view, parseComponents);
86
87 if (messageComponentStructure != null) {
88 for (Component component : messageComponentStructure) {
89 view.getViewHelperService().performComponentInitialization(view, model, component);
90 }
91 }
92 }
93
94 }
95
96
97
98
99 @Override
100 public void performFinalize(View view, Object model, Component parent) {
101 super.performFinalize(view, model, parent);
102
103 this.addDataAttribute("parent", parent.getId());
104 }
105
106
107
108
109 @Override
110 public List<Component> getComponentsForLifecycle() {
111 List<Component> components = super.getComponentsForLifecycle();
112
113 if (messageComponentStructure != null) {
114 for (Component component : messageComponentStructure) {
115 components.add(component);
116 }
117 }
118
119 return components;
120 }
121
122
123
124
125
126
127
128 @Override
129 public boolean isRender() {
130 boolean render = super.isRender();
131
132 if (render) {
133 render = getPropertyExpressions().containsKey("messageText") || (StringUtils.isNotBlank(messageText)
134 && !StringUtils.equals(messageText, " "));
135 }
136
137 return render;
138 }
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162 @BeanTagAttribute(name = "messageText")
163 public String getMessageText() {
164 return this.messageText;
165 }
166
167
168
169
170
171
172 public void setMessageText(String messageText) {
173 this.messageText = messageText;
174 }
175
176
177
178
179
180
181
182 @BeanTagAttribute(name = "generateSpan")
183 public boolean isGenerateSpan() {
184 return generateSpan;
185 }
186
187
188
189
190
191
192 public void setGenerateSpan(boolean generateSpan) {
193 this.generateSpan = generateSpan;
194 }
195
196
197
198
199
200
201
202
203
204
205 public List<Component> getMessageComponentStructure() {
206 return messageComponentStructure;
207 }
208
209
210
211
212
213
214
215 public void setMessageComponentStructure(List<Component> messageComponentStructure) {
216 this.messageComponentStructure = messageComponentStructure;
217 }
218
219
220
221
222
223
224
225
226
227
228
229 @BeanTagAttribute(name = "inlineComponents", type = BeanTagAttribute.AttributeType.LISTBEAN)
230 public List<Component> getInlineComponents() {
231 return inlineComponents;
232 }
233
234
235
236
237
238
239 public void setInlineComponents(List<Component> inlineComponents) {
240 this.inlineComponents = inlineComponents;
241 }
242
243
244
245
246 @Override
247 public void completeValidation(ValidationTrace tracer) {
248 tracer.addBean(this);
249
250
251 if (getMessageText() == null) {
252 if (Validator.checkExpressions(this, "messageText")) {
253 String currentValues[] = {"messageText =" + getMessageText()};
254 tracer.createWarning("MessageText should be set", currentValues);
255 }
256 }
257
258 super.completeValidation(tracer.getCopy());
259 }
260
261
262
263
264
265
266 @BeanTagAttribute(name = "parseComponents")
267 public boolean isParseComponents() {
268 return parseComponents;
269 }
270
271
272
273
274
275
276 public void setParseComponents(boolean parseComponents) {
277 this.parseComponents = parseComponents;
278 }
279 }