View Javadoc

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