1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.oness.common.webapp.controller.struts;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.StringTokenizer;
21
22 import javax.servlet.ServletException;
23
24 import org.apache.struts.config.MessageResourcesConfig;
25 import org.apache.struts.config.ModuleConfig;
26
27 /***
28 * Customized ActionServlet to use CustomMessageResources
29 *
30 * @todo improve this class
31 *
32 * @author Carlos Sanchez
33 * @version $Revision: 1.1 $
34 */
35 public class ActionServlet extends org.apache.struts.action.ActionServlet {
36
37 /***
38 * This is the overridden method to load multiple resource bundle files. The
39 * resource bundle files are expected to be defined in the struts-config.xml
40 * file in a comma separated fashion. For example, this is a typical struts
41 * config file declaring multiple resource files <message-resources
42 * null="false" parameter="centaur-event-resources, centaur-page-resources,
43 * centaur-nominal-resources, centaur-error-resources"/>
44 *
45 * This method makes use of CentaurMessageResource class and passed the list
46 * of resource files to handle.Finally, it puts the CentaurMessageResources
47 * object in the ServletContext against the key specified in the
48 * configuration. As is the case, if no "key" is specified in the
49 * configuration (in our example config), it constructs a default key.
50 *
51 * @param config
52 * The ModuleConfig object.
53 * @throws ServletException
54 * is thrown in case of initialisation problem.
55 */
56 protected void initModuleMessageResources(ModuleConfig config)
57 throws ServletException {
58
59 List fileNames = new ArrayList();
60
61
62
63
64
65
66 MessageResourcesConfig resourceConfig = config
67 .findMessageResourcesConfigs()[0];
68
69
70
71
72
73
74 if (resourceConfig.getFactory() == null
75 || resourceConfig.getParameter() == null) {
76 super.log
77 .error("Error in message resource configuration. No parameter defined.");
78
79 return;
80
81 }
82
83
84 String configParam = resourceConfig.getParameter();
85 if (configParam.indexOf(",") != -1) {
86
87 StringTokenizer tokenizer = new StringTokenizer(configParam, ",");
88
89 while (tokenizer.hasMoreTokens()) {
90 String token = tokenizer.nextToken();
91
92 fileNames.add(token.trim());
93
94 }
95 } else {
96
97 fileNames.add(configParam);
98 }
99
100
101
102
103
104 CustomMessageResources resources = new CustomMessageResources(fileNames);
105
106
107
108
109
110
111
112
113 getServletContext().setAttribute(
114 resourceConfig.getKey() + config.getPrefix(), resources);
115
116 }
117
118 }