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