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: 1.5 $ $Date: 2004/02/25 00:01:06 $
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      public String getLocaleKey() {
50  
51      return (this.localeKey);
52  
53      }
54  
55  
56      /***
57       * <p>Set the context attribute key under which we will store
58       * the request <code>Locale</code>.</p>
59       *
60       * @param localeKey The new context attribute key
61       */
62      public void setLocaleKey(String localeKey) {
63  
64      this.localeKey = localeKey;
65  
66      }
67  
68  
69      // --------------------------------------------------------- Command Methods
70  
71  
72      /***
73       * <p>Retrieve the <code>Locale</code> for this request, and store it
74       * under the specified context attribute.</p>
75       *
76       * @param context The {@link Context} we are operating on
77       *
78       * @return <code>false</code> so that processng will continue
79       */
80      public boolean execute(Context context) throws Exception {
81  
82      context.put(getLocaleKey(), getLocale(context));
83      return (false);
84  
85      }
86  
87  
88      // ------------------------------------------------------- Protected Methods
89  
90  
91      /***
92       * <p>Retrieve and return the <code>Locale</code> for this request.</p>
93       */
94      protected abstract Locale getLocale(Context context);
95  
96  
97  }