use of com.opensymphony.xwork2.Result in project struts by apache.
the class DefaultActionInvocation method invoke.
/**
* @throws ConfigurationException If no result can be found with the returned code
*/
public String invoke() throws Exception {
if (executed) {
throw new IllegalStateException("Action has already executed");
}
if (asyncManager == null || !asyncManager.hasAsyncActionResult()) {
if (interceptors.hasNext()) {
final InterceptorMapping interceptorMapping = interceptors.next();
Interceptor interceptor = interceptorMapping.getInterceptor();
if (interceptor instanceof WithLazyParams) {
interceptor = lazyParamInjector.injectParams(interceptor, interceptorMapping.getParams(), invocationContext);
}
resultCode = interceptor.intercept(DefaultActionInvocation.this);
} else {
resultCode = invokeActionOnly();
}
} else {
Object asyncActionResult = asyncManager.getAsyncActionResult();
if (asyncActionResult instanceof Throwable) {
throw new Exception((Throwable) asyncActionResult);
}
asyncAction = null;
resultCode = saveResult(proxy.getConfig(), asyncActionResult);
}
if (asyncManager == null || asyncAction == null) {
// return above and flow through again
if (!executed) {
if (preResultListeners != null) {
LOG.trace("Executing PreResultListeners for result [{}]", result);
for (Object preResultListener : preResultListeners) {
PreResultListener listener = (PreResultListener) preResultListener;
listener.beforeResult(this, resultCode);
}
}
// now execute the result, if we're supposed to
if (proxy.getExecuteResult()) {
executeResult();
}
executed = true;
}
} else {
asyncManager.invokeAsyncAction(asyncAction);
}
return resultCode;
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class TagModelTest method testUnwrapMap.
public void testUnwrapMap() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
OgnlValueStack stack = (OgnlValueStack) ActionContext.getContext().getValueStack();
Map params = new LinkedHashMap();
// Try to test out the commons Freemarker's Template Model
// TemplateBooleanModel
params.put("property1", new TemplateBooleanModel() {
public boolean getAsBoolean() throws TemplateModelException {
return true;
}
});
params.put("property2", new TemplateBooleanModel() {
public boolean getAsBoolean() throws TemplateModelException {
return false;
}
});
// TemplateScalarModel
params.put("property3", new TemplateScalarModel() {
public String getAsString() throws TemplateModelException {
return "toby";
}
});
params.put("property4", new TemplateScalarModel() {
public String getAsString() throws TemplateModelException {
return "phil";
}
});
// TemplateNumberModel
params.put("property5", new TemplateNumberModel() {
public Number getAsNumber() throws TemplateModelException {
return new Integer("10");
}
});
params.put("property6", new TemplateNumberModel() {
public Number getAsNumber() throws TemplateModelException {
return new Float("1.1");
}
});
// TemplateHashModel
params.put("property7", new TemplateHashModel() {
public TemplateModel get(String arg0) throws TemplateModelException {
return null;
}
public boolean isEmpty() throws TemplateModelException {
return true;
}
});
// TemplateSequenceModel
params.put("property8", new TemplateSequenceModel() {
public TemplateModel get(int arg0) throws TemplateModelException {
return null;
}
public int size() throws TemplateModelException {
return 0;
}
});
// TemplateCollectionModel
params.put("property9", new TemplateCollectionModel() {
public TemplateModelIterator iterator() throws TemplateModelException {
return new TemplateModelIterator() {
private Iterator i;
{
i = Collections.EMPTY_LIST.iterator();
}
public boolean hasNext() throws TemplateModelException {
return i.hasNext();
}
public TemplateModel next() throws TemplateModelException {
return (TemplateModel) i.next();
}
};
}
});
// AdapterTemplateModel
params.put("property10", new AdapterTemplateModel() {
public Object getAdaptedObject(Class arg0) {
return ADAPTER_TEMPLATE_MODEL_CONTAINED_OBJECT;
}
});
// WrapperTemplateModel
params.put("property11", new WrapperTemplateModel() {
public Object getWrappedObject() {
return WRAPPING_TEMPLATE_MODEL_CONTAINED_OBJECT;
}
});
TagModel tagModel = new TagModel(stack, request, response) {
protected Component getBean() {
return null;
}
};
Map result = tagModel.unwrapParameters(params);
assertNotNull(result);
assertEquals(result.size(), 11);
assertEquals(result.get("property1"), Boolean.TRUE);
assertEquals(result.get("property2"), Boolean.FALSE);
assertEquals(result.get("property3"), "toby");
assertEquals(result.get("property4"), "phil");
assertEquals(result.get("property5"), new Integer(10));
assertEquals(result.get("property6"), new Float(1.1));
assertNotNull(result.get("property7"));
assertTrue(result.get("property7") instanceof Map);
assertNotNull(result.get("property8"));
assertTrue(result.get("property8") instanceof Collection);
assertNotNull(result.get("property9"));
assertTrue(result.get("property9") instanceof Collection);
assertEquals(result.get("property10"), ADAPTER_TEMPLATE_MODEL_CONTAINED_OBJECT);
assertEquals(result.get("property11"), WRAPPING_TEMPLATE_MODEL_CONTAINED_OBJECT);
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class I18n method start.
public boolean start(Writer writer) {
boolean result = super.start(writer);
try {
String name = this.findString(this.name, "name", "Resource bundle name is required. Example: foo or foo_en");
ResourceBundle bundle = defaultTextProvider.getTexts(name);
if (bundle == null) {
LocaleProvider localeProvider = localeProviderFactory.createLocaleProvider();
bundle = localizedTextProvider.findResourceBundle(name, localeProvider.getLocale());
}
if (bundle != null) {
textProvider = textProviderFactory.createInstance(bundle);
getStack().push(textProvider);
pushed = true;
}
} catch (Exception e) {
throw new StrutsException("Could not find the bundle " + name, e);
}
return result;
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class Debug method start.
public boolean start(Writer writer) {
boolean result = super.start(writer);
if (showDebug()) {
ValueStack stack = getStack();
Iterator iter = stack.getRoot().iterator();
List stackValues = new ArrayList(stack.getRoot().size());
while (iter.hasNext()) {
Object o = iter.next();
Map values;
try {
values = reflectionProvider.getBeanMap(o);
} catch (Exception e) {
throw new StrutsException("Caught an exception while getting the property values of " + o, e);
}
stackValues.add(new DebugMapEntry(o.getClass().getName(), values));
}
addParameter("stackValues", stackValues);
}
return result;
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class XmlConfigurationProviderExceptionMappingsTest method testActions.
public void testActions() throws ConfigurationException {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-exception-mappings.xml";
ConfigurationProvider provider = buildConfigurationProvider(filename);
List<ExceptionMappingConfig> exceptionMappings = new ArrayList<>();
HashMap<String, String> parameters = new HashMap<>();
HashMap<String, ResultConfig> results = new HashMap<>();
exceptionMappings.add(new ExceptionMappingConfig.Builder("spooky-result", "com.opensymphony.xwork2.SpookyException", "spooky-result").build());
results.put("spooky-result", new ResultConfig.Builder("spooky-result", MockResult.class.getName()).build());
Map<String, String> resultParams = new HashMap<>();
resultParams.put("actionName", "bar.vm");
results.put("specificLocationResult", new ResultConfig.Builder("specificLocationResult", ActionChainResult.class.getName()).addParams(resultParams).build());
ActionConfig expectedAction = new ActionConfig.Builder("default", "Bar", SimpleAction.class.getName()).addParams(parameters).addResultConfigs(results).addExceptionMappings(exceptionMappings).build();
// execute the configuration
provider.init(configuration);
provider.loadPackages();
PackageConfig pkg = configuration.getPackageConfig("default");
Map actionConfigs = pkg.getActionConfigs();
// assertions
assertEquals(1, actionConfigs.size());
ActionConfig action = (ActionConfig) actionConfigs.get("Bar");
assertEquals(expectedAction, action);
}
Aggregations