1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.chain.commands;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.struts.chain.contexts.ActionContext;
23 import org.apache.struts.config.ModuleConfig;
24
25 import java.util.Locale;
26
27 /***
28 * <p>Select the <code>Locale</code> to be used for this request.</p>
29 *
30 * @version $Rev: 421119 $ $Date: 2005-11-12 13:01:44 -0500 (Sat, 12 Nov 2005)
31 * $
32 */
33 public abstract class AbstractSelectLocale extends ActionCommandBase {
34
35
36 /***
37 * <p> Provide Commons Logging instance for this class. </p>
38 */
39 private static final Log LOG =
40 LogFactory.getLog(AbstractSelectLocale.class);
41
42
43
44 /***
45 * <p>Select the <code>Locale</code> to be used for this request.</p>
46 *
47 * @param actionCtx The <code>Context</code> for the current request
48 * @return <code>false</code> so that processing continues
49 * @throws Exception if thrown by the Action class
50 */
51 public boolean execute(ActionContext actionCtx)
52 throws Exception {
53
54 LOG.trace("retrieve config...");
55
56 ModuleConfig moduleConfig = actionCtx.getModuleConfig();
57
58 if (!moduleConfig.getControllerConfig().getLocale()) {
59 if (LOG.isDebugEnabled()) {
60 LOG.debug("module is not configured for a specific locale; "
61 + "nothing to do");
62 }
63
64 return (false);
65 }
66
67
68 Locale locale = getLocale(actionCtx);
69
70 if (LOG.isDebugEnabled()) {
71 LOG.debug("set context locale to " + locale);
72 }
73
74 actionCtx.setLocale(locale);
75
76 return (false);
77 }
78
79
80
81 /***
82 * <p>Return the <code>Locale</code> to be used for this request.</p>
83 *
84 * @param context The <code>Context</code> for this request
85 * @return The Locale to be used for this request
86 */
87 protected abstract Locale getLocale(ActionContext context);
88 }