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