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 retrieving the
24: * requested Locale from our {@link Context}, and storing it under the
25: * context attribute key returned by the <code>localeKey</code> property.</p>
26: *
27: * @author Craig R. McClanahan
28: * @version $Revision: 411876 $ $Date: 2006-06-05 19:02:19 +0100 (Mon, 05 Jun 2006) $
29: */
30:
31: public abstract class AbstractGetLocaleCommand implements Command {
32:
33: // -------------------------------------------------------------- Properties
34:
35: /**
36: * <p>The context attribute key used to store the <code>Locale</code>.</p>
37: */
38: private String localeKey = "locale";
39:
40: /**
41: * <p>Return the context attribute key under which we will store
42: * the request <code>Locale</code>.</p>
43: *
44: * @return The context attribute key of the request <code>Locale</code>.
45: */
46: public String getLocaleKey() {
47:
48: return (this .localeKey);
49:
50: }
51:
52: /**
53: * <p>Set the context attribute key under which we will store
54: * the request <code>Locale</code>.</p>
55: *
56: * @param localeKey The new context attribute key
57: */
58: public void setLocaleKey(String localeKey) {
59:
60: this .localeKey = localeKey;
61:
62: }
63:
64: // --------------------------------------------------------- Command Methods
65:
66: /**
67: * <p>Retrieve the <code>Locale</code> for this request, and store it
68: * under the specified context attribute.</p>
69: *
70: * @param context The {@link Context} we are operating on
71: *
72: * @return <code>false</code> so that processng will continue
73: * @throws Exception If an error occurs during execution.
74: */
75: public boolean execute(Context context) throws Exception {
76:
77: context.put(getLocaleKey(), getLocale(context));
78: return (false);
79:
80: }
81:
82: // ------------------------------------------------------- Protected Methods
83:
84: /**
85: * <p>Retrieve and return the <code>Locale</code> for this request.</p>
86: * @param context The {@link Context} we are operating on.
87: * @return The Locale for the request.
88: */
89: protected abstract Locale getLocale(Context context);
90:
91: }
|