use of org.apache.struts.action.ActionMapping in project sonarqube 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);
}
use of org.apache.struts.action.ActionMapping in project sonarqube by SonarSource.
the class TestRequestUtils method testCreateActionForm2a.
// Default module -- Standard ActionForm should be created
public void testCreateActionForm2a() {
request.setPathElements("/myapp", "/static.do", null, null);
ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig("/static");
assertNotNull("Found /static mapping", mapping);
assertNotNull("Mapping has non-null name", mapping.getName());
assertEquals("Mapping has correct name", "static", 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 MockFormBean);
}
use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.
the class TestRequestUtilsPopulate method testMultipartVisibility.
/**
* Ensure that the getMultipartRequestHandler cannot be seen in
* a subclass of ActionForm.
*
* The purpose of this test is to ensure that Bug #38534 is fixed.
*/
public void testMultipartVisibility() throws Exception {
String mockMappingName = "mockMapping";
String stringValue = "Test";
MockFormBean mockForm = new MockFormBean();
ActionMapping mapping = new ActionMapping();
mapping.setName(mockMappingName);
// Set up the mock HttpServletRequest
request.setMethod("POST");
request.setContentType("multipart/form-data");
request.setAttribute(Globals.MULTIPART_KEY, MockMultipartRequestHandler.class.getName());
request.setAttribute(Globals.MAPPING_KEY, mapping);
request.addParameter("stringProperty", stringValue);
request.addParameter("multipartRequestHandler.mapping.name", "Bad");
// Check the Mapping/ActionForm before
assertNull("Multipart Handler already set", mockForm.getMultipartRequestHandler());
assertEquals("Mapping name not set correctly", mockMappingName, mapping.getName());
// Try to populate
try {
RequestUtils.populate(mockForm, request);
} catch (ServletException se) {
// Expected BeanUtils.populate() to throw a NestedNullException
// which gets wrapped in RequestUtils in a ServletException
assertEquals("Unexpected type of Exception thrown", "BeanUtils.populate", se.getMessage());
}
// Check the Mapping/ActionForm after
assertNotNull("Multipart Handler Missing", mockForm.getMultipartRequestHandler());
assertEquals("Mapping name has been modified", mockMappingName, mapping.getName());
}
use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.
the class JavascriptValidatorTag method createDynamicJavascript.
/**
* Generates the dynamic JavaScript for the form.
*
* @param config
* @param resources
* @param locale
* @param form
*/
private String createDynamicJavascript(ModuleConfig config, ValidatorResources resources, Locale locale, Form form) throws JspException {
StringBuffer results = new StringBuffer();
MessageResources messages = TagUtils.getInstance().retrieveMessageResources(pageContext, bundle, true);
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
ServletContext application = pageContext.getServletContext();
List actions = this.createActionList(resources, form);
final String methods = this.createMethods(actions, this.stopOnError(config));
String formName = form.getName();
jsFormName = formName;
if (jsFormName.charAt(0) == '/') {
String mappingName = TagUtils.getInstance().getActionMappingName(jsFormName);
ActionMapping mapping = (ActionMapping) config.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;
}
jsFormName = mapping.getAttribute();
}
results.append(this.getJavascriptBegin(methods));
for (Iterator i = actions.iterator(); i.hasNext(); ) {
ValidatorAction va = (ValidatorAction) i.next();
int jscriptVar = 0;
String functionName = null;
if ((va.getJsFunctionName() != null) && (va.getJsFunctionName().length() > 0)) {
functionName = va.getJsFunctionName();
} else {
functionName = va.getName();
}
results.append(" function " + jsFormName + "_" + functionName + " () { \n");
for (Iterator x = form.getFields().iterator(); x.hasNext(); ) {
Field field = (Field) x.next();
// retrieve from scope?))
if (field.isIndexed() || (field.getPage() != page) || !field.isDependency(va.getName())) {
continue;
}
String message = Resources.getMessage(application, request, messages, locale, va, field);
message = (message != null) ? message : "";
// prefix variable with 'a' to make it a legal identifier
results.append(" this.a" + jscriptVar++ + " = new Array(\"" + field.getKey() + "\", \"" + escapeQuotes(message) + "\", ");
results.append("new Function (\"varName\", \"");
Map vars = field.getVars();
// Loop through the field's variables.
Iterator varsIterator = vars.keySet().iterator();
while (varsIterator.hasNext()) {
String varName = (String) varsIterator.next();
Var var = (Var) vars.get(varName);
String varValue = Resources.getVarValue(var, application, request, false);
String jsType = var.getJsType();
// fieldValue
if (varName.startsWith("field")) {
continue;
}
String varValueEscaped = escapeJavascript(varValue);
if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) {
results.append("this." + varName + "=" + varValueEscaped + "; ");
} else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) {
results.append("this." + varName + "=/" + varValueEscaped + "/; ");
} else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) {
results.append("this." + varName + "='" + varValueEscaped + "'; ");
// So everyone using the latest format doesn't need to
// change their xml files immediately.
} else if ("mask".equalsIgnoreCase(varName)) {
results.append("this." + varName + "=/" + varValueEscaped + "/; ");
} else {
results.append("this." + varName + "='" + varValueEscaped + "'; ");
}
}
results.append(" return this[varName];\"));\n");
}
results.append(" } \n\n");
}
return results.toString();
}
use of org.apache.struts.action.ActionMapping in project sonar-java by SonarSource.
the class TestRequestUtils method testCreateActionForm2a.
// Default module -- Standard ActionForm should be created
public void testCreateActionForm2a() {
request.setPathElements("/myapp", "/static.do", null, null);
ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig("/static");
assertNotNull("Found /static mapping", mapping);
assertNotNull("Mapping has non-null name", mapping.getName());
assertEquals("Mapping has correct name", "static", 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 MockFormBean);
}
Aggregations