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 setting the
26   * response locale for this response to the <code>Locale</code> stored
27   * under the context attribute key returned by the <code>localeKey</code>
28   * property.</p>
29   *
30   * @author Craig R. McClanahan
31   * @version $Revision: 411876 $ $Date: 2006-06-05 19:02:19 +0100 (Mon, 05 Jun 2006) $
32   */
33  
34  public abstract class AbstractSetLocaleCommand implements Command {
35  
36  
37      // -------------------------------------------------------------- Properties
38  
39  
40      /***
41       * <p>The context attribute key used to retrieve 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 retrieve
48       * the response <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 retrieve
61       * the response <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> stored under the specified
77       * context attribute key, and establish it on this response.</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      setLocale(context,
87            (Locale) context.get(getLocaleKey()));
88      return (false);
89  
90      }
91  
92  
93      // ------------------------------------------------------- Protected Methods
94  
95  
96      /***
97       * <p>Establish the specified <code>Locale</code> for this response.</p>
98       *
99       * @param context The {@link Context} we are operating on.
100      * @param locale The Locale for the request.
101      */
102     protected abstract void setLocale(Context context, Locale locale);
103 
104 
105 }