01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.apache.commons.chain.web;
17:
18: import java.util.Locale;
19: import org.apache.commons.chain.Command;
20: import org.apache.commons.chain.Context;
21:
22: /**
23: * <p>Abstract base {@link Command} implementation for setting the
24: * response locale for this response to the <code>Locale</code> stored
25: * under the context attribute key returned by the <code>localeKey</code>
26: * property.</p>
27: *
28: * @author Craig R. McClanahan
29: * @version $Revision: 411876 $ $Date: 2006-06-05 19:02:19 +0100 (Mon, 05 Jun 2006) $
30: */
31:
32: public abstract class AbstractSetLocaleCommand implements Command {
33:
34: // -------------------------------------------------------------- Properties
35:
36: /**
37: * <p>The context attribute key used to retrieve the <code>Locale</code>.</p>
38: */
39: private String localeKey = "locale";
40:
41: /**
42: * <p>Return the context attribute key under which we will retrieve
43: * the response <code>Locale</code>.</p>
44: *
45: * @return The context attribute key of the request <code>Locale</code>.
46: */
47: public String getLocaleKey() {
48:
49: return (this .localeKey);
50:
51: }
52:
53: /**
54: * <p>Set the context attribute key under which we will retrieve
55: * the response <code>Locale</code>.</p>
56: *
57: * @param localeKey The new context attribute key
58: */
59: public void setLocaleKey(String localeKey) {
60:
61: this .localeKey = localeKey;
62:
63: }
64:
65: // --------------------------------------------------------- Command Methods
66:
67: /**
68: * <p>Retrieve the <code>Locale</code> stored under the specified
69: * context attribute key, and establish it on this response.</p>
70: *
71: * @param context The {@link Context} we are operating on
72: *
73: * @return <code>false</code> so that processng will continue
74: * @throws Exception If an error occurs during execution.
75: */
76: public boolean execute(Context context) throws Exception {
77:
78: setLocale(context, (Locale) context.get(getLocaleKey()));
79: return (false);
80:
81: }
82:
83: // ------------------------------------------------------- Protected Methods
84:
85: /**
86: * <p>Establish the specified <code>Locale</code> for this response.</p>
87: *
88: * @param context The {@link Context} we are operating on.
89: * @param locale The Locale for the request.
90: */
91: protected abstract void setLocale(Context context, Locale locale);
92:
93: }
|