KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > chain > AbstractSelectLocale


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.struts.chain;
18
19
20 import java.util.Locale JavaDoc;
21 import org.apache.commons.chain.Command;
22 import org.apache.commons.chain.Context;
23 import org.apache.struts.chain.Constants;
24 import org.apache.struts.config.ModuleConfig;
25
26
27 /**
28  * <p>Select the <code>Locale</code> to be used for this request.</p>
29  *
30  * @author Craig R. McClanahan
31  * @version $Rev: 54933 $ $Date: 2004-10-16 18:04:52 +0100 (Sat, 16 Oct 2004) $
32  */

33
34 public abstract class AbstractSelectLocale implements Command {
35
36
37     // ------------------------------------------------------ Instance Variables
38

39
40     private String JavaDoc localeKey = Constants.LOCALE_KEY;
41     private String JavaDoc moduleConfigKey = Constants.MODULE_CONFIG_KEY;
42
43
44     // -------------------------------------------------------------- Properties
45

46
47     /**
48      * <p>Return the context attribute key under which the
49      * <code>Locale</code> for the current request is stored.</p>
50      */

51     public String JavaDoc getLocaleKey() {
52
53         return (this.localeKey);
54
55     }
56
57
58     /**
59      * <p>Set the context attribute key under which the
60      * <code>Locale</code> for the current request is stored.</p>
61      *
62      * @param localeKey The new context attribute key
63      */

64     public void setLocaleKey(String JavaDoc localeKey) {
65
66         this.localeKey = localeKey;
67
68     }
69
70
71     /**
72      * <p>Return the context attribute key under which the
73      * <code>ModuleConfig</code> for the currently selected application
74      * module will be stored.</p>
75      */

76     public String JavaDoc getModuleConfigKey() {
77
78         return (this.moduleConfigKey);
79
80     }
81
82
83     /**
84      * <p>Set the context attribute key under which the
85      * <code>ModuleConfig</code> for the currently selected application
86      * module will be stored.</p>
87      *
88      * @param moduleConfigKey The new context attribute key
89      */

90     public void setModuleConfigKey(String JavaDoc moduleConfigKey) {
91
92         this.moduleConfigKey = moduleConfigKey;
93
94     }
95
96
97     // ---------------------------------------------------------- Public Methods
98

99
100     /**
101      * <p>Select the <code>Locale</code> to be used for this request.</p>
102      *
103      * @param context The <code>Context</code> for the current request
104      *
105      * @return <code>false</code> so that processing continues
106      */

107     public boolean execute(Context context) throws Exception JavaDoc {
108
109         // Are we configured to select Locale automatically?
110
ModuleConfig moduleConfig = (ModuleConfig)
111             context.get(getModuleConfigKey());
112         if (!moduleConfig.getControllerConfig().getLocale()) {
113             return (false);
114         }
115
116         // Retrieve and cache appropriate Locale for this request
117
Locale JavaDoc locale = getLocale(context);
118         context.put(getLocaleKey(), locale);
119
120         return (false);
121
122     }
123
124
125     // ------------------------------------------------------- Protected Methods
126

127
128     /**
129      * <p>Return the <code>Locale</code> to be used for this request.</p>
130      *
131      * @param context The <code>Context</code> for this request
132      */

133     protected abstract Locale JavaDoc getLocale(Context context);
134
135
136 }
137
Popular Tags