diff --git a/core/src/main/java/org/apache/struts2/components/I18n.java b/core/src/main/java/org/apache/struts2/components/I18n.java index b5f89b99f..a17f99f97 100644 --- a/core/src/main/java/org/apache/struts2/components/I18n.java +++ b/core/src/main/java/org/apache/struts2/components/I18n.java @@ -33,6 +33,8 @@ import org.apache.struts2.dispatcher.Dispatcher; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.LocaleProvider; import com.opensymphony.xwork2.TextProviderFactory; +import com.opensymphony.xwork2.inject.Container; +import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.LocalizedTextUtil; import com.opensymphony.xwork2.util.ValueStack; @@ -86,10 +88,16 @@ import com.opensymphony.xwork2.util.ValueStack; public class I18n extends Component { protected boolean pushed; protected String name; + protected Container container; public I18n(ValueStack stack) { super(stack); } + + @Inject + public void setContainer(Container container) { + this.container = container; + } public boolean start(Writer writer) { boolean result = super.start(writer); @@ -105,7 +113,7 @@ public class I18n extends Component { if (bundle != null) { final Locale locale = (Locale) getStack().getContext().get(ActionContext.LOCALE); TextProviderFactory tpf = new TextProviderFactory(); - Dispatcher.getInstance().getContainer().inject(tpf); + container.inject(tpf); getStack().push(tpf.createInstance(bundle, new LocaleProvider() { public Locale getLocale() { return locale; @@ -129,7 +137,7 @@ public class I18n extends Component { return super.end(writer, body); } - @StrutsTagAttribute(description="Name of ressource bundle to use (eg foo/bar/customBundle)", required=true, defaultValue="String") + @StrutsTagAttribute(description="Name of resource bundle to use (eg foo/bar/customBundle)", required=true, defaultValue="String") public void setName(String name) { this.name = name; } diff --git a/core/src/main/java/org/apache/struts2/views/freemarker/tags/TagModel.java b/core/src/main/java/org/apache/struts2/views/freemarker/tags/TagModel.java index a1f996534..65da06d9a 100644 --- a/core/src/main/java/org/apache/struts2/views/freemarker/tags/TagModel.java +++ b/core/src/main/java/org/apache/struts2/views/freemarker/tags/TagModel.java @@ -34,6 +34,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.struts2.components.Component; import org.apache.struts2.dispatcher.Dispatcher; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.util.ValueStack; @@ -60,7 +61,7 @@ public abstract class TagModel implements TemplateTransformModel { public Writer getWriter(Writer writer, Map params) throws TemplateModelException, IOException { Component bean = getBean(); - Container container = Dispatcher.getInstance().getConfigurationManager().getConfiguration().getContainer(); + Container container = (Container) stack.getContext().get(ActionContext.CONTAINER); container.inject(bean); Map unwrappedParameters = unwrapParameters(params); diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/AbstractDirective.java b/core/src/main/java/org/apache/struts2/views/velocity/components/AbstractDirective.java index fe9f1ff98..3650ea4fb 100644 --- a/core/src/main/java/org/apache/struts2/views/velocity/components/AbstractDirective.java +++ b/core/src/main/java/org/apache/struts2/views/velocity/components/AbstractDirective.java @@ -38,6 +38,7 @@ import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.runtime.directive.Directive; import org.apache.velocity.runtime.parser.node.Node; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.util.ValueStack; @@ -63,7 +64,7 @@ public abstract class AbstractDirective extends Directive { HttpServletRequest req = (HttpServletRequest) stack.getContext().get(ServletActionContext.HTTP_REQUEST); HttpServletResponse res = (HttpServletResponse) stack.getContext().get(ServletActionContext.HTTP_RESPONSE); Component bean = getBean(stack, req, res); - Container container = Dispatcher.getInstance().getConfigurationManager().getConfiguration().getContainer(); + Container container = (Container) stack.getContext().get(ActionContext.CONTAINER); container.inject(bean); // get the parameters Map params = createPropertyMap(ctx, node); diff --git a/core/src/site/resources/tags/i18n.html b/core/src/site/resources/tags/i18n.html index 001f33bb7..5756c4981 100644 --- a/core/src/site/resources/tags/i18n.html +++ b/core/src/site/resources/tags/i18n.html @@ -33,7 +33,7 @@ Please do not edit it directly. String false String - Name of ressource bundle to use (eg foo/bar/customBundle) + Name of resource bundle to use (eg foo/bar/customBundle) diff --git a/plugins/struts1/src/main/java/org/apache/struts2/s1/ActionFormResetInterceptor.java b/plugins/struts1/src/main/java/org/apache/struts2/s1/ActionFormResetInterceptor.java index b6b016fda..9524a7eb3 100644 --- a/plugins/struts1/src/main/java/org/apache/struts2/s1/ActionFormResetInterceptor.java +++ b/plugins/struts1/src/main/java/org/apache/struts2/s1/ActionFormResetInterceptor.java @@ -26,6 +26,8 @@ import org.apache.struts2.ServletActionContext; import org.apache.struts2.dispatcher.Dispatcher; import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.config.Configuration; +import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; import com.opensymphony.xwork2.interceptor.ScopedModelDriven; @@ -34,6 +36,13 @@ import com.opensymphony.xwork2.interceptor.ScopedModelDriven; */ public class ActionFormResetInterceptor extends AbstractInterceptor { + protected Configuration configuration; + + @Inject + public void setConfiguration(Configuration config) { + this.configuration = config; + } + @Override public String intercept(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); @@ -42,7 +51,7 @@ public class ActionFormResetInterceptor extends AbstractInterceptor { ScopedModelDriven modelDriven = (ScopedModelDriven) action; Object model = modelDriven.getModel(); if (model != null && model instanceof ActionForm) { - Struts1Factory factory = new Struts1Factory(Dispatcher.getInstance().getConfigurationManager().getConfiguration()); + Struts1Factory factory = new Struts1Factory(configuration); ActionMapping mapping = factory.createActionMapping(invocation.getProxy().getConfig()); HttpServletRequest req = ServletActionContext.getRequest(); ((ActionForm)model).reset(mapping, req); diff --git a/plugins/struts1/src/main/java/org/apache/struts2/s1/ActionFormValidationInterceptor.java b/plugins/struts1/src/main/java/org/apache/struts2/s1/ActionFormValidationInterceptor.java index 33795f8c3..e5df31812 100644 --- a/plugins/struts1/src/main/java/org/apache/struts2/s1/ActionFormValidationInterceptor.java +++ b/plugins/struts1/src/main/java/org/apache/struts2/s1/ActionFormValidationInterceptor.java @@ -48,6 +48,8 @@ import org.xml.sax.SAXException; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.TextProvider; +import com.opensymphony.xwork2.config.Configuration; +import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; import com.opensymphony.xwork2.interceptor.ScopedModelDriven; @@ -69,6 +71,13 @@ public class ActionFormValidationInterceptor extends AbstractInterceptor { */ private final static String RESOURCE_DELIM = ","; + protected Configuration configuration; + + @Inject + public void setConfiguration(Configuration config) { + this.configuration = config; + } + /** * Initializes the validation resources */ @@ -113,7 +122,7 @@ public class ActionFormValidationInterceptor extends AbstractInterceptor { Object model = modelDriven.getModel(); if (model != null) { HttpServletRequest req = ServletActionContext.getRequest(); - Struts1Factory strutsFactory = new Struts1Factory(Dispatcher.getInstance().getConfigurationManager().getConfiguration()); + Struts1Factory strutsFactory = new Struts1Factory(configuration); ActionMapping mapping = strutsFactory.createActionMapping(invocation.getProxy().getConfig()); ModuleConfig moduleConfig = strutsFactory.createModuleConfig(invocation.getProxy().getConfig().getPackageName()); req.setAttribute(Globals.MODULE_KEY, moduleConfig); diff --git a/plugins/struts1/src/main/java/org/apache/struts2/s1/Struts1Action.java b/plugins/struts1/src/main/java/org/apache/struts2/s1/Struts1Action.java index 25c18e88a..71410b218 100644 --- a/plugins/struts1/src/main/java/org/apache/struts2/s1/Struts1Action.java +++ b/plugins/struts1/src/main/java/org/apache/struts2/s1/Struts1Action.java @@ -37,6 +37,7 @@ import org.apache.struts2.dispatcher.Dispatcher; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ObjectFactory; +import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.entities.ActionConfig; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.interceptor.ScopedModelDriven; @@ -63,12 +64,18 @@ public class Struts1Action extends DefaultActionSupport implements ScopedModelDr private boolean validate; private String scopeKey; private ObjectFactory objectFactory; + private Configuration configuration; @Inject public void setObjectFactory(ObjectFactory fac) { this.objectFactory = fac; } + @Inject + public void setConfiguration(Configuration config) { + this.configuration = config; + } + public String execute() throws Exception { ActionContext ctx = ActionContext.getContext(); ActionConfig actionConfig = ctx.getActionInvocation().getProxy().getConfig(); diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java index 747e4e3fb..a3da57c1b 100644 --- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java +++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java @@ -20,6 +20,7 @@ */ package org.apache.struts2.tiles; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.inject.Container; import org.apache.commons.logging.Log; @@ -102,17 +103,14 @@ public class StrutsTilesRequestContext extends TilesRequestContextWrapper { HttpServletRequest request = (HttpServletRequest) getRequest(); HttpServletResponse response = (HttpServletResponse) getResponse(); - ActionInvocation invocation = - ServletActionContext.getActionContext(request).getActionInvocation(); + ActionContext ctx = ServletActionContext.getActionContext(request); + ActionInvocation invocation = ctx.getActionInvocation(); try { FreemarkerResult result = new FreemarkerResult(); result.setWriter(response.getWriter()); - Container container = Dispatcher.getInstance() - .getConfigurationManager() - .getConfiguration().getContainer(); - + Container container = ctx.getContainer(); container.inject(result); result.doExecute(include, invocation);