Search in sources :

Example 21 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube 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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) ActionConfig(org.apache.struts.config.ActionConfig) FormBeanConfig(org.apache.struts.config.FormBeanConfig)

Example 22 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class TestTagUtils method testString_getActionMappingURL_String_String_PageContext_boolean1.

// use servlet mapping (extension mapping)
public void testString_getActionMappingURL_String_String_PageContext_boolean1() {
    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", null, null);
    assertEquals("Check path /foo", tagutils.getActionMappingURL("/foo", pageContext), "/myapp/foo.do");
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 23 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class TestTagUtils method testString_getActionMappingURL_String_String_PageContext_boolean3.

// use servlet mapping (extension mapping)
//  -- path as "/"
// (this is probably not a realistic use case)
public void testString_getActionMappingURL_String_String_PageContext_boolean3() {
    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("/mycontext", "/baz", null, null);
    assertEquals("Check path /foo", tagutils.getActionMappingURL("/", pageContext), "/mycontext/.do");
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 24 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.

the class TestTagUtils method testString_getActionMappingURL_String_String_PageContext_boolean5.

// use servlet mapping (path mapping)
// -- with params
public void testString_getActionMappingURL_String_String_PageContext_boolean5() {
    pageContext.getServletContext().setAttribute(Globals.SERVLET_KEY, "/myapp/*");
    ActionConfig actionConfig = new ActionConfig();
    actionConfig.setParameter("/foo");
    moduleConfig.addActionConfig(actionConfig);
    request.setAttribute(Globals.MODULE_KEY, moduleConfig);
    request.setPathElements("/mycontext", "/baz?foo=bar", null, null);
    assertEquals("Check path /foo", tagutils.getActionMappingURL("/foo?foo=bar", pageContext), "/mycontext/myapp/foo?foo=bar");
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Example 25 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.

the class TestTagUtils method testString_getActionMappingURL_String_String_PageContext_boolean6.

// use servlet mapping (path mapping)
// -- using "/" as mapping
public void testString_getActionMappingURL_String_String_PageContext_boolean6() {
    pageContext.getServletContext().setAttribute(Globals.SERVLET_KEY, "/");
    ActionConfig actionConfig = new ActionConfig();
    actionConfig.setParameter("/foo");
    moduleConfig.addActionConfig(actionConfig);
    request.setAttribute(Globals.MODULE_KEY, moduleConfig);
    request.setPathElements("/mycontext", "/baz", null, null);
    assertEquals("Check path /foo", tagutils.getActionMappingURL("/", pageContext), "/mycontext/");
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig)

Aggregations

ActionConfig (org.apache.struts.config.ActionConfig)76 ForwardConfig (org.apache.struts.config.ForwardConfig)14 UnavailableException (javax.servlet.UnavailableException)8 ActionForm (org.apache.struts.action.ActionForm)8 ExceptionConfig (org.apache.struts.config.ExceptionConfig)8 FormBeanConfig (org.apache.struts.config.FormBeanConfig)8 ModuleConfig (org.apache.struts.config.ModuleConfig)8 ServletException (javax.servlet.ServletException)6 MalformedURLException (java.net.MalformedURLException)4 Map (java.util.Map)4 Action (org.apache.struts.action.Action)4 UnauthorizedActionException (org.apache.struts.chain.commands.UnauthorizedActionException)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 MissingResourceException (java.util.MissingResourceException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JspException (javax.servlet.jsp.JspException)2 ActionErrors (org.apache.struts.action.ActionErrors)2 MockActionContext (org.apache.struts.chain.contexts.MockActionContext)2 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2