/*
* Copyright 2005-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.strecks.injection.handler;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.Globals;
import org.apache.struts.util.MessageResources;
import org.strecks.context.ActionContext;
import org.strecks.exceptions.ApplicationConfigurationException;
import org.strecks.message.MessageResourcesHelperImpl;
/**
* Injection handler for obtaining <code>MessageResourceHelper</code> from
* <code>ActionContext</code>. The <code>MessageResourceHelper</code> is configured with the
* message resources for the given bundle as well as the current request <code>Locale</code>
* @author Phil Zoio
*/
public class MessageResourcesHelperInjectionHandler extends MessageResourcesInjectionHandler
{
public MessageResourcesHelperInjectionHandler(String bundle)
{
super(bundle);
}
@Override
public Object getValue(ActionContext injectionContext)
{
MessageResources messageResources = getMessageResources(injectionContext);
if (messageResources == null)
{
throw new ApplicationConfigurationException("test me");
}
HttpServletRequest request = injectionContext.getRequest();
Locale locale = (Locale) request.getAttribute(Globals.LOCALE_KEY);
return new MessageResourcesHelperImpl(locale, messageResources);
}
}