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