KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > chain > web > AbstractSetLocaleCommand


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 JavaDoc;
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: 1.5 $ $Date: 2004/02/25 00:01:06 $
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 JavaDoc 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     public String JavaDoc getLocaleKey() {
51
52     return (this.localeKey);
53
54     }
55
56
57     /**
58      * <p>Set the context attribute key under which we will retrieve
59      * the response <code>Locale</code>.</p>
60      *
61      * @param localeKey The new context attribute key
62      */

63     public void setLocaleKey(String JavaDoc localeKey) {
64
65     this.localeKey = localeKey;
66
67     }
68
69
70     // --------------------------------------------------------- Command Methods
71

72
73     /**
74      * <p>Retrieve the <code>Locale</code> stored under the specified
75      * context attribute key, and establish it on this response.</p>
76      *
77      * @param context The {@link Context} we are operating on
78      *
79      * @return <code>false</code> so that processng will continue
80      */

81     public boolean execute(Context context) throws Exception JavaDoc {
82
83     setLocale(context,
84           (Locale JavaDoc) context.get(getLocaleKey()));
85     return (false);
86
87     }
88
89
90     // ------------------------------------------------------- Protected Methods
91

92
93     /**
94      * <p>Establish the specified <code>Locale</code> for this response.</p>
95      */

96     protected abstract void setLocale(Context context, Locale JavaDoc locale);
97
98
99 }
100
Popular Tags