01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.injection.handler;
16:
17: import java.util.Locale;
18:
19: import javax.servlet.http.HttpServletRequest;
20:
21: import org.apache.struts.Globals;
22: import org.apache.struts.util.MessageResources;
23: import org.strecks.context.ActionContext;
24: import org.strecks.exceptions.ApplicationConfigurationException;
25: import org.strecks.message.MessageResourcesHelperImpl;
26:
27: /**
28: * Injection handler for obtaining <code>MessageResourceHelper</code> from
29: * <code>ActionContext</code>. The <code>MessageResourceHelper</code> is configured with the
30: * message resources for the given bundle as well as the current request <code>Locale</code>
31: * @author Phil Zoio
32: */
33: public class MessageResourcesHelperInjectionHandler extends
34: MessageResourcesInjectionHandler {
35:
36: public MessageResourcesHelperInjectionHandler(String bundle) {
37: super (bundle);
38: }
39:
40: @Override
41: public Object getValue(ActionContext injectionContext) {
42:
43: MessageResources messageResources = getMessageResources(injectionContext);
44:
45: if (messageResources == null) {
46: throw new ApplicationConfigurationException("test me");
47: }
48:
49: HttpServletRequest request = injectionContext.getRequest();
50: Locale locale = (Locale) request
51: .getAttribute(Globals.LOCALE_KEY);
52:
53: return new MessageResourcesHelperImpl(locale, messageResources);
54:
55: }
56:
57: }
|