use of org.apache.struts.config.ModuleConfigFactory in project sonarqube by SonarSource.
the class ActionServlet method initModuleConfig.
/**
* <p>Initialize the module configuration information for the specified
* module.</p>
*
* @param prefix Module prefix for this module
* @param paths Comma-separated list of context-relative resource path(s)
* for this modules's configuration resource(s)
* @return The new module configuration instance.
* @throws ServletException if initialization cannot be performed
* @since Struts 1.1
*/
protected ModuleConfig initModuleConfig(String prefix, String paths) throws ServletException {
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + prefix + "' configuration from '" + paths + "'");
}
// Parse the configuration for this module
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
ModuleConfig config = factoryObject.createModuleConfig(prefix);
// Configure the Digester instance we will use
Digester digester = initConfigDigester();
List urls = splitAndResolvePaths(paths);
URL url;
for (Iterator i = urls.iterator(); i.hasNext(); ) {
url = (URL) i.next();
digester.push(config);
this.parseModuleConfigFile(digester, url);
}
getServletContext().setAttribute(Globals.MODULE_KEY + config.getPrefix(), config);
return config;
}
use of org.apache.struts.config.ModuleConfigFactory in project sonarqube by SonarSource.
the class TestMockBase method setUpThirdApp.
// Set up third app for testing URL mapping
protected void setUpThirdApp() {
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
moduleConfig3 = factoryObject.createModuleConfig("/3");
context.setAttribute(Globals.MODULE_KEY + "/3", moduleConfig3);
// Instantiate the controller configuration for this app
ControllerConfig controller = new ControllerConfig();
moduleConfig3.setControllerConfig(controller);
// Configure the properties we will be testing
controller.setForwardPattern("/forwarding$M$P");
controller.setInputForward(true);
controller.setPagePattern("/paging$M$P");
// Configure global forward declarations
moduleConfig3.addForwardConfig(new ForwardConfig("moduleForward", "/module/forward", // No redirect, same module
false));
moduleConfig3.addForwardConfig(new ForwardConfig("moduleRedirect", "/module/redirect", // Redirect, same module
true));
moduleConfig3.addForwardConfig(new ForwardConfig("contextForward", // No redirect
"/forward", // No redirect
false, // Specify module
"/context"));
moduleConfig3.addForwardConfig(new ForwardConfig("contextRedirect", // Redirect
"/redirect", // Redirect
true, // Specify module
"/context"));
moduleConfig3.addForwardConfig(new ForwardConfig("moduleNoslash", "module/noslash", // No redirect, same module
false));
moduleConfig3.addForwardConfig(new ForwardConfig("contextNoslash", // No redirect
"noslash", // No redirect
false, // specify module
"/context"));
}
use of org.apache.struts.config.ModuleConfigFactory in project sonarqube by SonarSource.
the class TestActionServlet method setUp.
// ------------------------------------------------- setUp() and tearDown()
/**
* Set up instance variables required by this test case.
*/
public void setUp() throws Exception {
actionServlet = new ActionServlet();
actionServlet.initInternal();
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
moduleConfig = factoryObject.createModuleConfig("");
// Setup the base form
baseFormBean = new FormBeanConfig();
baseFormBean.setName("baseForm");
baseFormBean.setType("org.apache.struts.action.DynaActionForm");
// Set up id, name, and score
FormPropertyConfig property = new FormPropertyConfig();
property.setName("id");
property.setType("java.lang.String");
baseFormBean.addFormPropertyConfig(property);
property = new FormPropertyConfig();
property.setName("name");
property.setType("java.lang.String");
baseFormBean.addFormPropertyConfig(property);
property = new FormPropertyConfig();
property.setName("score");
property.setType("java.lang.String");
baseFormBean.addFormPropertyConfig(property);
// Setup the exception handler
baseException = new ExceptionConfig();
baseException.setType("java.lang.NullPointerException");
baseException.setKey("msg.exception.npe");
// Setup the forward config
baseForward = new ActionForward("success", "/succes.jsp", false);
// Setup the action config
baseAction = new ActionMapping();
baseAction.setPath("/index");
baseAction.setType("org.apache.struts.actions.DummyAction");
baseAction.setName("someForm");
baseAction.setInput("/input.jsp");
baseAction.addForwardConfig(new ActionForward("next", "/next.jsp", false));
baseAction.addForwardConfig(new ActionForward("prev", "/prev.jsp", false));
ExceptionConfig exceptionConfig = new ExceptionConfig();
exceptionConfig.setType("java.sql.SQLException");
exceptionConfig.setKey("msg.exception.sql");
baseAction.addExceptionConfig(exceptionConfig);
// Nothing is registered to our module config until they are needed
}
use of org.apache.struts.config.ModuleConfigFactory in project sonarqube by SonarSource.
the class TestMockBase method setUpSecondApp.
protected void setUpSecondApp() {
ActionFormBean formBean = null;
ActionMapping mapping = null;
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
moduleConfig2 = factoryObject.createModuleConfig("/2");
context.setAttribute(Globals.MODULE_KEY + "/2", moduleConfig2);
// Forward "external" to "http://jakarta.apache.org/"
moduleConfig2.addForwardConfig(new ActionForward("external", "http://jakarta.apache.org/", false));
// Forward "foo" to "/baz.jsp" (different from default)
moduleConfig2.addForwardConfig(new ActionForward("foo", "/baz.jsp", false));
// Forward "relative1" to "relative.jsp" non-context-relative
moduleConfig2.addForwardConfig(new ActionForward("relative1", "relative.jsp", false));
// Forward "relative2" to "relative.jsp" context-relative
moduleConfig2.addForwardConfig(new ActionForward("relative2", "relative.jsp", false));
// Form Bean "static" is a standard ActionForm subclass (same as default)
formBean = new ActionFormBean("static", "org.apache.struts.mock.MockFormBean");
moduleConfig2.addFormBeanConfig(formBean);
// Action "/static" uses the "static" form bean in request scope (same as default)
mapping = new ActionMapping();
mapping.setInput("/static.jsp");
mapping.setName("static");
mapping.setPath("/static");
mapping.setScope("request");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig2.addActionConfig(mapping);
// Form Bean "dynamic2" is a DynaActionForm with the same properties
formBean = new ActionFormBean("dynamic2", "org.apache.struts.action.DynaActionForm");
formBean.addFormPropertyConfig(new FormPropertyConfig("booleanProperty", "boolean", "false"));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringProperty", "java.lang.String", null));
moduleConfig2.addFormBeanConfig(formBean);
// Action "/dynamic2" uses the "dynamic2" form bean in session scope
mapping = new ActionMapping();
mapping.setInput("/dynamic2.jsp");
mapping.setName("dynamic2");
mapping.setPath("/dynamic2");
mapping.setScope("session");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig2.addActionConfig(mapping);
// Action "/noform" has no form bean associated with it (same as default)
mapping = new ActionMapping();
mapping.setPath("/noform");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig2.addActionConfig(mapping);
// Configure global forward declarations
moduleConfig2.addForwardConfig(new ForwardConfig("moduleForward", "/module/forward", // No redirect, same module
false));
moduleConfig2.addForwardConfig(new ForwardConfig("moduleRedirect", "/module/redirect", // Redirect, same module
true));
moduleConfig2.addForwardConfig(new ForwardConfig("contextForward", // No redirect
"/forward", // No redirect
false, // Specify module
"/context"));
moduleConfig2.addForwardConfig(new ForwardConfig("contextRedirect", // Redirect
"/redirect", // Redirect
true, // Specify module
"/context"));
moduleConfig2.addForwardConfig(new ForwardConfig("moduleNoslash", "module/noslash", // No redirect, same module
false));
moduleConfig2.addForwardConfig(new ForwardConfig("contextNoslash", // No redirect
"noslash", // No redirect
false, // Specify module
"/context"));
}
use of org.apache.struts.config.ModuleConfigFactory in project sonarqube by SonarSource.
the class TestMockBase method setUpDefaultApp.
protected void setUpDefaultApp() {
ActionFormBean formBean = null;
ActionMapping mapping = null;
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
moduleConfig = factoryObject.createModuleConfig("");
context.setAttribute(Globals.MODULE_KEY, moduleConfig);
// Forward "external" to "http://jakarta.apache.org/"
moduleConfig.addForwardConfig(new ActionForward("external", "http://jakarta.apache.org/", false));
// Forward "foo" to "/bar.jsp"
moduleConfig.addForwardConfig(new ActionForward("foo", "/bar.jsp", false));
// Forward "relative1" to "relative.jsp" non-context-relative
moduleConfig.addForwardConfig(new ActionForward("relative1", "relative.jsp", false));
// Forward "relative2" to "relative.jsp" context-relative
moduleConfig.addForwardConfig(new ActionForward("relative2", "relative.jsp", false));
// Form Bean "static" is a standard ActionForm subclass
formBean = new ActionFormBean("static", "org.apache.struts.mock.MockFormBean");
moduleConfig.addFormBeanConfig(formBean);
// Action "/static" uses the "static" form bean in request scope
mapping = new ActionMapping();
mapping.setInput("/static.jsp");
mapping.setName("static");
mapping.setPath("/static");
mapping.setScope("request");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Form Bean "dynamic" is a DynaActionForm with the same properties
formBean = new ActionFormBean("dynamic", "org.apache.struts.action.DynaActionForm");
formBean.addFormPropertyConfig(new FormPropertyConfig("booleanProperty", "boolean", "false"));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringProperty", "java.lang.String", null));
moduleConfig.addFormBeanConfig(formBean);
// Action "/dynamic" uses the "dynamic" form bean in session scope
mapping = new ActionMapping();
mapping.setInput("/dynamic.jsp");
mapping.setName("dynamic");
mapping.setPath("/dynamic");
mapping.setScope("session");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Form Bean "/dynamic0" is a DynaActionForm with initializers
formBean = new ActionFormBean("dynamic0", "org.apache.struts.action.DynaActionForm");
formBean.addFormPropertyConfig(new FormPropertyConfig("booleanProperty", "boolean", "true"));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringProperty", "java.lang.String", "String Property"));
formBean.addFormPropertyConfig(new FormPropertyConfig("intArray1", "int[]", "{1,2,3}", // 4 should be ignored
4));
formBean.addFormPropertyConfig(new FormPropertyConfig("intArray2", "int[]", null, // 5 should be respected
5));
formBean.addFormPropertyConfig(new FormPropertyConfig("principal", "org.apache.struts.mock.MockPrincipal", null));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringArray1", "java.lang.String[]", "{aaa,bbb,ccc}", // 2 should be ignored
2));
formBean.addFormPropertyConfig(new FormPropertyConfig("stringArray2", "java.lang.String[]", null, // 3 should be respected
3));
moduleConfig.addFormBeanConfig(formBean);
// Action "/dynamic0" uses the "dynamic0" form bean in request scope
mapping = new ActionMapping();
mapping.setName("dynamic0");
mapping.setPath("/dynamic0");
mapping.setScope("request");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Action "/noform" has no form bean associated with it
mapping = new ActionMapping();
mapping.setPath("/noform");
mapping.setType("org.apache.struts.mock.MockAction");
moduleConfig.addActionConfig(mapping);
// Configure global forward declarations
moduleConfig.addForwardConfig(new ForwardConfig("moduleForward", "/module/forward", // No redirect, same module
false));
moduleConfig.addForwardConfig(new ForwardConfig("moduleRedirect", "/module/redirect", // Redirect, same module
true));
moduleConfig.addForwardConfig(new ForwardConfig("contextForward", // No redirect
"/forward", // No redirect
false, // Specify module
"/context"));
moduleConfig.addForwardConfig(new ForwardConfig("contextRedirect", // Redirect
"/redirect", // Redirect
true, // Specify module
"/context"));
moduleConfig.addForwardConfig(new ForwardConfig("moduleNoslash", "module/noslash", // No redirect, same module
false));
moduleConfig.addForwardConfig(new ForwardConfig("contextNoslash", // No redirect
"noslash", // No redirect
false, // Specify module
"/context"));
}
Aggregations