View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.chain.web;
18  
19  
20  import java.util.Locale;
21  import org.apache.commons.chain.Command;
22  import org.apache.commons.chain.Context;
23  
24  
25  /**
26   * <p>Abstract base {@link Command} implementation for retrieving the
27   * requested Locale from our {@link Context}, and storing it under the
28   * context attribute key returned by the <code>localeKey</code> property.</p>
29   *
30   * @author Craig R. McClanahan
31   * @version $Revision: 480477 $ $Date: 2006-11-29 08:34:52 +0000 (Wed, 29 Nov 2006) $
32   */
33  
34  public abstract class AbstractGetLocaleCommand implements Command {
35  
36  
37      // -------------------------------------------------------------- Properties
38  
39  
40      /**
41       * <p>The context attribute key used to store the <code>Locale</code>.</p>
42       */
43      private String localeKey = "locale";
44  
45  
46      /**
47       * <p>Return the context attribute key under which we will store
48       * the request <code>Locale</code>.</p>
49       *
50       * @return The context attribute key of the request <code>Locale</code>.
51       */
52      public String getLocaleKey() {
53  
54      return (this.localeKey);
55  
56      }
57  
58  
59      /**
60       * <p>Set the context attribute key under which we will store
61       * the request <code>Locale</code>.</p>
62       *
63       * @param localeKey The new context attribute key
64       */
65      public void setLocaleKey(String localeKey) {
66  
67      this.localeKey = localeKey;
68  
69      }
70  
71  
72      // --------------------------------------------------------- Command Methods
73  
74  
75      /**
76       * <p>Retrieve the <code>Locale</code> for this request, and store it
77       * under the specified context attribute.</p>
78       *
79       * @param context The {@link Context} we are operating on
80       *
81       * @return <code>false</code> so that processng will continue
82       * @throws Exception If an error occurs during execution.
83       */
84      public boolean execute(Context context) throws Exception {
85  
86      context.put(getLocaleKey(), getLocale(context));
87      return (false);
88  
89      }
90  
91  
92      // ------------------------------------------------------- Protected Methods
93  
94  
95      /**
96       * <p>Retrieve and return the <code>Locale</code> for this request.</p>
97       * @param context The {@link Context} we are operating on.
98       * @return The Locale for the request.
99       */
100     protected abstract Locale getLocale(Context context);
101 
102 
103 }