1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.common.ui.server.messages; |
17 | |
|
18 | |
|
19 | |
import java.lang.reflect.Method; |
20 | |
import java.util.Arrays; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import org.apache.log4j.Logger; |
25 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
26 | |
import org.kuali.student.common.ui.server.gwt.MessagesRpcGwtServlet; |
27 | |
import org.kuali.student.common.ui.server.serialization.KSSerializationPolicy; |
28 | |
import org.kuali.student.common.ui.server.serialization.SerializationUtils; |
29 | |
import org.kuali.student.core.messages.dto.Message; |
30 | |
import org.kuali.student.core.messages.dto.MessageGroupKeyList; |
31 | |
import org.kuali.student.core.messages.dto.MessageList; |
32 | |
import org.kuali.student.core.messages.service.MessageService; |
33 | |
|
34 | |
import com.google.gwt.user.server.rpc.RPC; |
35 | |
|
36 | |
public class MessageRPCPreloader { |
37 | 0 | final Logger LOG = Logger.getLogger(MessageRPCPreloader.class); |
38 | 0 | private final String MESSAGE_SERVICE_MOCK = "ks.messageServiceMock"; |
39 | 0 | private final String MESSAGE_SERVICE = "{http://student.kuali.org/wsdl/messages}MessageService"; |
40 | |
|
41 | |
MessageService messageService; |
42 | |
|
43 | 0 | public MessageRPCPreloader(){ |
44 | |
|
45 | 0 | } |
46 | |
|
47 | |
public MessageService getMessageService() { |
48 | 0 | if (messageService == null){ |
49 | 0 | setMessageService((MessageService)GlobalResourceLoader.getService(MESSAGE_SERVICE_MOCK)); |
50 | 0 | if (messageService == null){ |
51 | 0 | setMessageService((MessageService)GlobalResourceLoader.getService(MESSAGE_SERVICE)); |
52 | |
} |
53 | |
} |
54 | 0 | return messageService; |
55 | |
} |
56 | |
|
57 | |
public void setMessageService(MessageService serviceImpl) { |
58 | 0 | this.messageService = serviceImpl; |
59 | 0 | } |
60 | |
|
61 | |
public String getMessagesByGroupsEncodingString(String locale, String[] keys){ |
62 | |
Method serviceMethod; |
63 | |
try { |
64 | 0 | serviceMethod = MessagesRpcGwtServlet.class.getMethod("getMessagesByGroups", String.class,MessageGroupKeyList.class); |
65 | |
|
66 | 0 | MessageGroupKeyList messageGroupKeyList = new MessageGroupKeyList(); |
67 | 0 | messageGroupKeyList.setMessageGroupKeys(Arrays.asList(keys)); |
68 | |
|
69 | 0 | MessageList messageList = getMessageService().getMessagesByGroups(locale,messageGroupKeyList); |
70 | |
|
71 | 0 | Map<Class<?>, Boolean> whitelist = new HashMap<Class<?>, Boolean>(); |
72 | 0 | whitelist.put(MessageService.class, true); |
73 | 0 | whitelist.put(MessageList.class, true); |
74 | 0 | whitelist.put(MessageGroupKeyList.class,true); |
75 | 0 | whitelist.put(Message.class,true); |
76 | 0 | whitelist.put(MessageGroupKeyList.class,true); |
77 | |
|
78 | 0 | KSSerializationPolicy myPolicy = new KSSerializationPolicy(whitelist); |
79 | |
|
80 | |
|
81 | 0 | String serializedData = RPC.encodeResponseForSuccess(serviceMethod, messageList,myPolicy); |
82 | |
|
83 | |
|
84 | 0 | return SerializationUtils.escapeForSingleQuotedJavaScriptString(serializedData); |
85 | 0 | } catch (Exception e) { |
86 | 0 | LOG.error(e); |
87 | 0 | return ""; |
88 | |
} |
89 | |
|
90 | |
} |
91 | |
|
92 | |
} |