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 setting the
27   * response locale for this response to the <code>Locale</code> stored
28   * under the context attribute key returned by the <code>localeKey</code>
29   * property.</p>
30   *
31   * @author Craig R. McClanahan
32   * @version $Revision: 480477 $ $Date: 2006-11-29 08:34:52 +0000 (Wed, 29 Nov 2006) $
33   */
34  
35  public abstract class AbstractSetLocaleCommand implements Command {
36  
37  
38      // -------------------------------------------------------------- Properties
39  
40  
41      /**
42       * <p>The context attribute key used to retrieve the <code>Locale</code>.</p>
43       */
44      private String localeKey = "locale";
45  
46  
47      /**
48       * <p>Return the context attribute key under which we will retrieve
49       * the response <code>Locale</code>.</p>
50       *
51       * @return The context attribute key of the request <code>Locale</code>.
52       */
53      public String getLocaleKey() {
54  
55      return (this.localeKey);
56  
57      }
58  
59  
60      /**
61       * <p>Set the context attribute key under which we will retrieve
62       * the response <code>Locale</code>.</p>
63       *
64       * @param localeKey The new context attribute key
65       */
66      public void setLocaleKey(String localeKey) {
67  
68      this.localeKey = localeKey;
69  
70      }
71  
72  
73      // --------------------------------------------------------- Command Methods
74  
75  
76      /**
77       * <p>Retrieve the <code>Locale</code> stored under the specified
78       * context attribute key, and establish it on this response.</p>
79       *
80       * @param context The {@link Context} we are operating on
81       *
82       * @return <code>false</code> so that processng will continue
83       * @throws Exception If an error occurs during execution.
84       */
85      public boolean execute(Context context) throws Exception {
86  
87      setLocale(context,
88            (Locale) context.get(getLocaleKey()));
89      return (false);
90  
91      }
92  
93  
94      // ------------------------------------------------------- Protected Methods
95  
96  
97      /**
98       * <p>Establish the specified <code>Locale</code> for this response.</p>
99       *
100      * @param context The {@link Context} we are operating on.
101      * @param locale The Locale for the request.
102      */
103     protected abstract void setLocale(Context context, Locale locale);
104 
105 
106 }