use of org.apache.struts.config.FormPropertyConfig in project sonarqube by SonarSource.
the class ActionServlet method processFormBeanConfigClass.
/**
* <p>Checks if the current beanConfig is using the correct class based on
* the class of its ancestor form bean config.</p>
*
* @param beanConfig The form bean to check.
* @param moduleConfig The config for the current module.
* @return The form bean config using the correct class as determined by
* the config's ancestor and its own overridden value.
* @throws UnavailableException if an instance of the form bean config
* class cannot be created.
* @throws ServletException on class creation error
*/
protected FormBeanConfig processFormBeanConfigClass(FormBeanConfig beanConfig, ModuleConfig moduleConfig) throws ServletException {
String ancestor = beanConfig.getExtends();
if (ancestor == null) {
// Nothing to do, then
return beanConfig;
}
// Make sure that this bean is of the right class
FormBeanConfig baseConfig = moduleConfig.findFormBeanConfig(ancestor);
if (baseConfig == null) {
throw new UnavailableException("Unable to find " + "form bean '" + ancestor + "' to extend.");
}
// Was our bean's class overridden already?
if (beanConfig.getClass().equals(FormBeanConfig.class)) {
// Ensure that our bean is using the correct class
if (!baseConfig.getClass().equals(beanConfig.getClass())) {
// Replace the bean with an instance of the correct class
FormBeanConfig newBeanConfig = null;
String baseConfigClassName = baseConfig.getClass().getName();
try {
newBeanConfig = (FormBeanConfig) RequestUtils.applicationInstance(baseConfigClassName);
// copy the values
BeanUtils.copyProperties(newBeanConfig, beanConfig);
FormPropertyConfig[] fpc = beanConfig.findFormPropertyConfigs();
for (int i = 0; i < fpc.length; i++) {
newBeanConfig.addFormPropertyConfig(fpc[i]);
}
} catch (Exception e) {
handleCreationException(baseConfigClassName, e);
}
// replace beanConfig with newBeanConfig
moduleConfig.removeFormBeanConfig(beanConfig);
moduleConfig.addFormBeanConfig(newBeanConfig);
beanConfig = newBeanConfig;
}
}
return beanConfig;
}
use of org.apache.struts.config.FormPropertyConfig in project sonarqube by SonarSource.
the class ActionServlet method initModuleFormBeans.
/**
* <p>Initialize the form beans for the specified module.</p>
*
* @param config ModuleConfig information for this module
* @throws ServletException if initialization cannot be performed
* @since Struts 1.3
*/
protected void initModuleFormBeans(ModuleConfig config) throws ServletException {
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + config.getPrefix() + "' form beans");
}
// Process form bean extensions.
FormBeanConfig[] formBeans = config.findFormBeanConfigs();
for (int i = 0; i < formBeans.length; i++) {
FormBeanConfig beanConfig = formBeans[i];
processFormBeanExtension(beanConfig, config);
}
for (int i = 0; i < formBeans.length; i++) {
FormBeanConfig formBean = formBeans[i];
// Verify that required fields are all present for the form config
if (formBean.getType() == null) {
handleValueRequiredException("type", formBean.getName(), "form bean");
}
// ... and the property configs
FormPropertyConfig[] fpcs = formBean.findFormPropertyConfigs();
for (int j = 0; j < fpcs.length; j++) {
FormPropertyConfig property = fpcs[j];
if (property.getType() == null) {
handleValueRequiredException("type", property.getName(), "form property");
}
}
// for all dynamic form beans
if (formBean.getDynamic()) {
formBean.getDynaActionFormClass();
}
}
}
use of org.apache.struts.config.FormPropertyConfig 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.FormPropertyConfig in project sonarqube by SonarSource.
the class TestDynaActionFormClass method testConfigRemove.
// Check for ability to remove a property before and after freezing
public void testConfigRemove() {
FormPropertyConfig prop = null;
// Before freezing
prop = beanConfig.findFormPropertyConfig("booleanProperty");
assertNotNull("booleanProperty found", prop);
beanConfig.removeFormPropertyConfig(prop);
prop = beanConfig.findFormPropertyConfig("booleanProperty");
assertNull("booleanProperty not deleted", prop);
// after freezing
beanConfig.freeze();
prop = beanConfig.findFormPropertyConfig("booleanSecond");
assertNotNull("booleanSecond found", prop);
try {
beanConfig.removeFormPropertyConfig(prop);
fail("booleanSecond remove not prevented");
} catch (IllegalStateException e) {
// Expected result
;
}
}
use of org.apache.struts.config.FormPropertyConfig in project sonarqube by SonarSource.
the class TestCopyFormToContext method setUp.
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
context = new MockActionContext();
ModuleConfigImpl moduleConfig = new ModuleConfigImpl("/");
context.setModuleConfig(moduleConfig);
FormBeanConfig fooFBC = new FormBeanConfig();
fooFBC.setName("foo");
fooFBC.setType("org.apache.struts.mock.MockFormBean");
moduleConfig.addFormBeanConfig(fooFBC);
FormBeanConfig barFBC = new FormBeanConfig();
barFBC.setName("bar");
// use a different type so we can verify lookups better
barFBC.setType("org.apache.struts.action.DynaActionForm");
FormPropertyConfig fpc = new FormPropertyConfig();
fpc.setName("property");
fpc.setType("java.lang.String");
fpc.setInitial("test");
barFBC.addFormPropertyConfig(fpc);
moduleConfig.addFormBeanConfig(barFBC);
ActionConfig testActionConfig = new ActionConfig();
testActionConfig.setPath("/Test");
testActionConfig.setName("foo");
testActionConfig.setScope("request");
moduleConfig.addActionConfig(testActionConfig);
// otherwise, ActionConfigMatcher will be null and we'll get an NPE...
moduleConfig.freeze();
}
Aggregations