001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.chain.web;
018
019
020 import java.util.Locale;
021 import org.apache.commons.chain.Command;
022 import org.apache.commons.chain.Context;
023
024
025 /**
026 * <p>Abstract base {@link Command} implementation for retrieving the
027 * requested Locale from our {@link Context}, and storing it under the
028 * context attribute key returned by the <code>localeKey</code> property.</p>
029 *
030 * @author Craig R. McClanahan
031 * @version $Revision: 480477 $ $Date: 2006-11-29 08:34:52 +0000 (Wed, 29 Nov 2006) $
032 */
033
034 public abstract class AbstractGetLocaleCommand implements Command {
035
036
037 // -------------------------------------------------------------- Properties
038
039
040 /**
041 * <p>The context attribute key used to store the <code>Locale</code>.</p>
042 */
043 private String localeKey = "locale";
044
045
046 /**
047 * <p>Return the context attribute key under which we will store
048 * the request <code>Locale</code>.</p>
049 *
050 * @return The context attribute key of the request <code>Locale</code>.
051 */
052 public String getLocaleKey() {
053
054 return (this.localeKey);
055
056 }
057
058
059 /**
060 * <p>Set the context attribute key under which we will store
061 * the request <code>Locale</code>.</p>
062 *
063 * @param localeKey The new context attribute key
064 */
065 public void setLocaleKey(String localeKey) {
066
067 this.localeKey = localeKey;
068
069 }
070
071
072 // --------------------------------------------------------- Command Methods
073
074
075 /**
076 * <p>Retrieve the <code>Locale</code> for this request, and store it
077 * under the specified context attribute.</p>
078 *
079 * @param context The {@link Context} we are operating on
080 *
081 * @return <code>false</code> so that processng will continue
082 * @throws Exception If an error occurs during execution.
083 */
084 public boolean execute(Context context) throws Exception {
085
086 context.put(getLocaleKey(), getLocale(context));
087 return (false);
088
089 }
090
091
092 // ------------------------------------------------------- Protected Methods
093
094
095 /**
096 * <p>Retrieve and return the <code>Locale</code> for this request.</p>
097 * @param context The {@link Context} we are operating on.
098 * @return The Locale for the request.
099 */
100 protected abstract Locale getLocale(Context context);
101
102
103 }