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 setting the 027 * response locale for this response to the <code>Locale</code> stored 028 * under the context attribute key returned by the <code>localeKey</code> 029 * property.</p> 030 * 031 * @author Craig R. McClanahan 032 * @version $Revision: 480477 $ $Date: 2006-11-29 08:34:52 +0000 (Wed, 29 Nov 2006) $ 033 */ 034 035 public abstract class AbstractSetLocaleCommand implements Command { 036 037 038 // -------------------------------------------------------------- Properties 039 040 041 /** 042 * <p>The context attribute key used to retrieve the <code>Locale</code>.</p> 043 */ 044 private String localeKey = "locale"; 045 046 047 /** 048 * <p>Return the context attribute key under which we will retrieve 049 * the response <code>Locale</code>.</p> 050 * 051 * @return The context attribute key of the request <code>Locale</code>. 052 */ 053 public String getLocaleKey() { 054 055 return (this.localeKey); 056 057 } 058 059 060 /** 061 * <p>Set the context attribute key under which we will retrieve 062 * the response <code>Locale</code>.</p> 063 * 064 * @param localeKey The new context attribute key 065 */ 066 public void setLocaleKey(String localeKey) { 067 068 this.localeKey = localeKey; 069 070 } 071 072 073 // --------------------------------------------------------- Command Methods 074 075 076 /** 077 * <p>Retrieve the <code>Locale</code> stored under the specified 078 * context attribute key, and establish it on this response.</p> 079 * 080 * @param context The {@link Context} we are operating on 081 * 082 * @return <code>false</code> so that processng will continue 083 * @throws Exception If an error occurs during execution. 084 */ 085 public boolean execute(Context context) throws Exception { 086 087 setLocale(context, 088 (Locale) context.get(getLocaleKey())); 089 return (false); 090 091 } 092 093 094 // ------------------------------------------------------- Protected Methods 095 096 097 /** 098 * <p>Establish the specified <code>Locale</code> for this response.</p> 099 * 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 }