Search in sources :

Example 6 with ActionMapping

use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.

the class TestActionConfigMatcher method buildActionConfig.

private ActionConfig buildActionConfig(String path) {
    ActionMapping mapping = new ActionMapping();
    mapping.setName("name,{1}");
    mapping.setPath(path);
    mapping.setScope("request");
    mapping.setUnknown(false);
    mapping.setValidate(true);
    mapping.setPrefix("foo,{1}");
    mapping.setSuffix("bar,{1}");
    mapping.setType("foo.bar.{1}Action");
    mapping.setRoles("public,{1}");
    mapping.setParameter("param,{1}");
    mapping.setAttribute("attrib,{1}");
    mapping.setForward("fwd,{1}");
    mapping.setInclude("include,{1}");
    mapping.setInput("input,{1}");
    ForwardConfig cfg = new ActionForward();
    cfg.setName("name");
    cfg.setPath("path,{1}");
    cfg.setModule("mod{1}");
    cfg.setProperty("foo", "bar,{1}");
    mapping.addForwardConfig(cfg);
    cfg = new ActionForward();
    cfg.setName("name2");
    cfg.setPath("path2");
    cfg.setModule("mod{1}");
    mapping.addForwardConfig(cfg);
    ExceptionConfig excfg = new ExceptionConfig();
    excfg.setKey("foo");
    excfg.setType("foo.Bar");
    excfg.setPath("path");
    mapping.addExceptionConfig(excfg);
    excfg = new ExceptionConfig();
    excfg.setKey("foo2");
    excfg.setType("foo.Bar2");
    excfg.setPath("path2");
    mapping.addExceptionConfig(excfg);
    mapping.setProperty("testprop", "testval");
    mapping.setProperty("testprop2", "test{1}");
    mapping.freeze();
    return mapping;
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) ActionForward(org.apache.struts.action.ActionForward)

Example 7 with ActionMapping

use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.

the class TestRequestUtils method testCreateActionForm3a.

// Default module -- Dynamic ActionForm should be created
public void testCreateActionForm3a() {
    request.setPathElements("/myapp", "/dynamic.do", null, null);
    ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig("/dynamic");
    assertNotNull("Found /dynamic mapping", mapping);
    assertNotNull("Mapping has non-null name", mapping.getName());
    assertEquals("Mapping has correct name", "dynamic", mapping.getName());
    assertNotNull("AppConfig has form bean " + mapping.getName(), moduleConfig.findFormBeanConfig(mapping.getName()));
    ActionForm form = RequestUtils.createActionForm(request, mapping, moduleConfig, null);
    assertNotNull("ActionForm returned", form);
    assertTrue("ActionForm of correct type", form instanceof DynaActionForm);
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) DynaActionForm(org.apache.struts.action.DynaActionForm) ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm)

Example 8 with ActionMapping

use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.

the class TestRequestUtils method testCreateActionForm3b.

// Second module -- Dynamic ActionForm should be created
public void testCreateActionForm3b() {
    request.setPathElements("/myapp", "/2/dynamic2.do", null, null);
    ActionMapping mapping = (ActionMapping) moduleConfig2.findActionConfig("/dynamic2");
    assertNotNull("Found /dynamic2 mapping", mapping);
    assertNotNull("Mapping has non-null name", mapping.getName());
    assertEquals("Mapping has correct name", "dynamic2", mapping.getName());
    assertNotNull("AppConfig has form bean " + mapping.getName(), moduleConfig2.findFormBeanConfig(mapping.getName()));
    ActionForm form = RequestUtils.createActionForm(request, mapping, moduleConfig2, null);
    assertNotNull("ActionForm returned", form);
    assertTrue("ActionForm of correct type", form instanceof DynaActionForm);
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) DynaActionForm(org.apache.struts.action.DynaActionForm) ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm)

Example 9 with ActionMapping

use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.

the class TestRequestUtils method testCreateActionForm1a.

// ----------------------------------------------------- createActionForm()
// Default module -- No ActionForm should be created
public void testCreateActionForm1a() {
    request.setPathElements("/myapp", "/noform.do", null, null);
    ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig("/noform");
    assertNotNull("Found /noform mapping", mapping);
    ActionForm form = RequestUtils.createActionForm(request, mapping, moduleConfig, null);
    assertNull("No ActionForm returned", form);
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm)

Example 10 with ActionMapping

use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.

the class ConfigHelper method getActionForm.

/*
     * <p>
     * Retrieve and return the <code>ActionForm</code> bean associated with
     * this mapping, creating and stashing one if necessary.  If there is no
     * form bean associated with this mapping, return <code>null</code>.
     * </p>
     */
public ActionForm getActionForm() {
    // Is there a mapping associated with this request?
    ActionMapping mapping = getMapping();
    if (mapping == null) {
        return (null);
    }
    // Is there a form bean associated with this mapping?
    String attribute = mapping.getAttribute();
    if (attribute == null) {
        return (null);
    }
    // Look up the existing form bean, if any
    ActionForm instance;
    if ("request".equals(mapping.getScope())) {
        instance = (ActionForm) this.request.getAttribute(attribute);
    } else {
        instance = (ActionForm) this.session.getAttribute(attribute);
    }
    return instance;
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) ActionForm(org.apache.struts.action.ActionForm)

Aggregations

ActionMapping (org.apache.struts.action.ActionMapping)32 ActionForm (org.apache.struts.action.ActionForm)18 DynaActionForm (org.apache.struts.action.DynaActionForm)14 ActionForward (org.apache.struts.action.ActionForward)6 MockFormBean (org.apache.struts.mock.MockFormBean)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 ActionFormBean (org.apache.struts.action.ActionFormBean)4 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)4 FormPropertyConfig (org.apache.struts.config.FormPropertyConfig)4 ForwardConfig (org.apache.struts.config.ForwardConfig)4 ModuleConfigFactory (org.apache.struts.config.ModuleConfigFactory)4 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 JspException (javax.servlet.jsp.JspException)2 Field (org.apache.commons.validator.Field)2