1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.lifecycle;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.messages.MessageService;
20 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21 import org.kuali.rice.krad.uif.UifConstants;
22 import org.kuali.rice.krad.uif.component.Component;
23 import org.kuali.rice.krad.uif.util.ScriptUtils;
24 import org.kuali.rice.krad.uif.view.View;
25 import org.kuali.rice.krad.uif.view.ViewModel;
26 import org.kuali.rice.krad.util.ErrorMessage;
27 import org.kuali.rice.krad.util.GlobalVariables;
28 import org.kuali.rice.krad.util.GrowlMessage;
29 import org.kuali.rice.krad.util.KRADConstants;
30 import org.kuali.rice.krad.util.MessageMap;
31
32 import java.io.Serializable;
33 import java.text.MessageFormat;
34 import java.util.Set;
35
36
37
38
39 public class LifecycleBase implements Serializable {
40 private static final long serialVersionUID = 9150578453981086356L;
41
42 public static void performPostLifecycleProcessing(View view, Object model, ViewPostMetadata viewPostMetadata) {
43 String growlScript = buildGrowlScript(view.isGrowlMessagingEnabled());
44 ((ViewModel) model).setGrowlScript(growlScript);
45
46 }
47
48
49
50
51
52
53
54
55
56
57
58 protected static String buildGrowlScript(boolean growlMessagingEnabled) {
59 StringBuilder growlScript = new StringBuilder();
60
61 MessageService messageService = KRADServiceLocatorWeb.getMessageService();
62
63 MessageMap messageMap = GlobalVariables.getMessageMap();
64 for (GrowlMessage growl : messageMap.getGrowlMessages()) {
65 if (growlMessagingEnabled) {
66 String message = messageService.getMessageText(growl.getNamespaceCode(), growl.getComponentCode(),
67 growl.getMessageKey());
68
69 if (StringUtils.isBlank(message)) {
70 continue;
71 }
72
73 if (growl.getMessageParameters() != null) {
74 message = message.replace("'", "''");
75 message = MessageFormat.format(message, (Object[]) growl.getMessageParameters());
76 }
77
78
79 message = message.replace("'", "\\'");
80
81 String title = growl.getTitle();
82 if (StringUtils.isNotBlank(growl.getTitleKey())) {
83 title = messageService.getMessageText(growl.getNamespaceCode(), growl.getComponentCode(),
84 growl.getTitleKey());
85 }
86 title = title.replace("'", "\\'");
87
88 growlScript.append(ScriptUtils.buildFunctionCall(UifConstants.JsFunctions.SHOW_GROWL, message, title,
89 growl.getTheme()));
90
91 } else {
92 ErrorMessage infoMessage = new ErrorMessage(growl.getMessageKey(), growl.getMessageParameters());
93 infoMessage.setNamespaceCode(growl.getNamespaceCode());
94 infoMessage.setComponentCode(growl.getComponentCode());
95
96 messageMap.putInfoForSectionId(KRADConstants.GLOBAL_INFO, infoMessage);
97 }
98 }
99
100 return growlScript.toString();
101 }
102
103 }