use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.
the class TestTagUtils method testString_getActionMappingURL_String_PageContext.
public void testString_getActionMappingURL_String_PageContext() {
ActionConfig actionConfig = new ActionConfig();
actionConfig.setParameter("/foo");
moduleConfig.addActionConfig(actionConfig);
request.setAttribute(Globals.MODULE_KEY, moduleConfig);
request.setPathElements("/myapp", "/foo.do", null, null);
assertEquals("Check path /foo", tagutils.getActionMappingURL("/foo", pageContext), "/myapp/foo");
}
use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.
the class TestTagUtils method testString_getActionMappingURL_String_String_PageContext_boolean2.
// use servlet mapping (extension mapping)
// -- with params
public void testString_getActionMappingURL_String_String_PageContext_boolean2() {
pageContext.getServletContext().setAttribute(Globals.SERVLET_KEY, "*.do");
ActionConfig actionConfig = new ActionConfig();
actionConfig.setParameter("/foo");
moduleConfig.addActionConfig(actionConfig);
request.setAttribute(Globals.MODULE_KEY, moduleConfig);
request.setPathElements("/myapp", "/baz.do?foo=bar", null, null);
assertEquals("Check path /foo", tagutils.getActionMappingURL("/foo?foo=bar", pageContext), "/myapp/foo.do?foo=bar");
}
use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.
the class FormTag method lookup.
// ------------------------------------------------------ Protected Methods
/**
* Look up values for the <code>name</code>, <code>scope</code>, and
* <code>type</code> properties if necessary.
*
* @throws JspException if a required value cannot be looked up
*/
protected void lookup() throws JspException {
// Look up the module configuration information we need
moduleConfig = TagUtils.getInstance().getModuleConfig(pageContext);
if (moduleConfig == null) {
JspException e = new JspException(messages.getMessage("formTag.collections"));
pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
throw e;
}
String calcAction = this.action;
// If the action is not specified, use the original request uri
if (this.action == null) {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
postbackAction = (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
String prefix = moduleConfig.getPrefix();
if (postbackAction != null && prefix.length() > 0 && postbackAction.startsWith(prefix)) {
postbackAction = postbackAction.substring(prefix.length());
}
calcAction = postbackAction;
} else {
// Translate the action if it is an actionId
ActionConfig actionConfig = moduleConfig.findActionConfigId(this.action);
if (actionConfig != null) {
this.action = actionConfig.getPath();
calcAction = this.action;
}
}
servlet = (ActionServlet) pageContext.getServletContext().getAttribute(Globals.ACTION_SERVLET_KEY);
// Look up the action mapping we will be submitting to
String mappingName = TagUtils.getInstance().getActionMappingName(calcAction);
mapping = (ActionMapping) moduleConfig.findActionConfig(mappingName);
if (mapping == null) {
JspException e = new JspException(messages.getMessage("formTag.mapping", mappingName));
pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
throw e;
}
// Look up the form bean definition
FormBeanConfig formBeanConfig = moduleConfig.findFormBeanConfig(mapping.getName());
if (formBeanConfig == null) {
JspException e = null;
if (mapping.getName() == null) {
e = new JspException(messages.getMessage("formTag.name", calcAction));
} else {
e = new JspException(messages.getMessage("formTag.formBean", mapping.getName(), calcAction));
}
pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
throw e;
}
// Calculate the required values
beanName = mapping.getAttribute();
beanScope = mapping.getScope();
beanType = formBeanConfig.getType();
}
use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.
the class CreateActionForm method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Create (if necessary) and cache a form bean for this request.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> so that processing continues
* @throws Exception on any error
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Is there a form bean associated with this ActionConfig?
ActionConfig actionConfig = actionCtx.getActionConfig();
String name = actionConfig.getName();
if (name == null) {
actionCtx.setActionForm(null);
return (false);
}
if (LOG.isTraceEnabled()) {
LOG.trace("Look up form-bean " + name);
}
// Look up the corresponding FormBeanConfig (if any)
FormBeanConfig formBeanConfig = actionConfig.getModuleConfig().findFormBeanConfig(name);
if (formBeanConfig == null) {
LOG.warn("No FormBeanConfig found in module " + actionConfig.getModuleConfig().getPrefix() + " under name " + name);
actionCtx.setActionForm(null);
return (false);
}
Map scope = actionCtx.getScope(actionConfig.getScope());
ActionForm instance;
instance = (ActionForm) scope.get(actionConfig.getAttribute());
// Can we recycle the existing instance (if any)?
if (!formBeanConfig.canReuse(instance)) {
instance = formBeanConfig.createActionForm(actionCtx);
}
// directly depends on ActionServlet
if (actionCtx instanceof ServletActionContext) {
// The servlet property of ActionForm is transient, so
// ActionForms which are restored from a serialized state
// need to have their servlet restored.
ServletActionContext sac = (ServletActionContext) actionCtx;
instance.setServlet(sac.getActionServlet());
}
actionCtx.setActionForm(instance);
scope.put(actionConfig.getAttribute(), instance);
return (false);
}
use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.
the class ExecuteCommand method getCommand.
/**
* <p>Find the <code>ActionConfig</code> in the current context and, if it
* is properly configured, lookup the appropriate <code>commons-chain</code>
* command.</p>
*
* @param context A valid ActionContext
* @return a <code>Command</code> to execute, or null if none is specified
* or if the specified command cannot be found.
*/
protected Command getCommand(ActionContext context) {
ActionConfig actionConfig = context.getActionConfig();
String commandName = actionConfig.getCommand();
if (commandName == null) {
return null;
}
String catalogName = actionConfig.getCatalog();
return getCommand(commandName, catalogName);
}
Aggregations