Cleaning up unnecessary dispatcher.getInstance calls, spelling cleanups

WW-1715


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@579186 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2007-09-25 10:39:07 +00:00
parent f88c1e7dcb
commit 0be14bb564
8 changed files with 46 additions and 13 deletions
@@ -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;
}
@@ -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);
@@ -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);
+1 -1
View File
@@ -33,7 +33,7 @@ Please do not edit it directly.
<td align="left" valign="top">String</td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">String</td>
<td align="left" valign="top">Name of ressource bundle to use (eg foo/bar/customBundle)</td>
<td align="left" valign="top">Name of resource bundle to use (eg foo/bar/customBundle)</td>
</tr>
</table>
<!-- END SNIPPET: tagattributes -->
@@ -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);
@@ -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);
@@ -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();
@@ -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);