use of com.opensymphony.xwork2.Result in project struts by apache.
the class ArrayConverter method convertValue.
@Override
public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) {
Object result = null;
Class componentType = toType.getComponentType();
if (componentType != null) {
TypeConverter converter = getTypeConverter(context);
if (value.getClass().isArray()) {
int length = Array.getLength(value);
result = Array.newInstance(componentType, length);
for (int i = 0; i < length; i++) {
Object valueItem = Array.get(value, i);
Array.set(result, i, converter.convertValue(context, target, member, propertyName, valueItem, componentType));
}
} else {
result = Array.newInstance(componentType, 1);
Array.set(result, 0, converter.convertValue(context, target, member, propertyName, value, componentType));
}
}
return result;
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class DefaultWorkflowInterceptor method processInputConfig.
/**
* Process {@link InputConfig} annotation applied to method
* @param action action object
* @param method method
* @param currentResultName current result name
*
* @return result name
*
* @throws Exception in case of any errors
*/
protected String processInputConfig(final Object action, final String method, final String currentResultName) throws Exception {
String resultName = currentResultName;
InputConfig annotation = MethodUtils.getAnnotation(action.getClass().getMethod(method, EMPTY_CLASS_ARRAY), InputConfig.class, true, true);
if (annotation != null) {
if (StringUtils.isNotEmpty(annotation.methodName())) {
resultName = (String) MethodUtils.invokeMethod(action, true, annotation.methodName());
} else {
resultName = annotation.resultName();
}
LOG.debug("Changing result name from [{}] to [{}] because of processing annotation [{}] on action [{}]", currentResultName, resultName, InputConfig.class.getSimpleName(), action);
}
return resultName;
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class OgnlValueStackFactory method createValueStack.
public ValueStack createValueStack(ValueStack stack) {
ValueStack result = new OgnlValueStack(stack, xworkConverter, compoundRootAccessor, containerAllowsStaticMethodAccess(), containerAllowsStaticFieldAccess());
container.inject(result);
return result.getActionContext().withContainer(container).withValueStack(result).getValueStack();
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class TextParseUtil method translateVariablesCollection.
/**
* Resolves given expression on given ValueStack. If found element is a
* collection each element will be converted to String. If just a single
* object is found it is converted to String and wrapped in a collection.
*
* @param openChars open character array
* @param expression expression string
* @param stack value stack
* @param evaluator value evaluator
* @param excludeEmptyElements Whether empty elements shall be excluded.
* @param maxLoopCount max loop count
* @return converted objects
*/
public static Collection<String> translateVariablesCollection(char[] openChars, String expression, final ValueStack stack, boolean excludeEmptyElements, final ParsedValueEvaluator evaluator, int maxLoopCount) {
ParsedValueEvaluator ognlEval = new ParsedValueEvaluator() {
public Object evaluate(String parsedValue) {
// no asType !!!
return stack.findValue(parsedValue);
}
};
ActionContext actionContext = stack.getActionContext();
TextParser parser = actionContext.getContainer().getInstance(TextParser.class);
Object result = parser.evaluate(openChars, expression, ognlEval, maxLoopCount);
Collection<String> resultCol;
if (result instanceof Collection) {
@SuppressWarnings("unchecked") Collection<Object> casted = (Collection<Object>) result;
resultCol = new ArrayList<>();
XWorkConverter conv = actionContext.getContainer().getInstance(XWorkConverter.class);
for (Object element : casted) {
String stringElement = (String) conv.convertValue(actionContext.getContextMap(), element, String.class);
if (shallBeIncluded(stringElement, excludeEmptyElements)) {
if (evaluator != null) {
stringElement = evaluator.evaluate(stringElement).toString();
}
resultCol.add(stringElement);
}
}
} else {
resultCol = new ArrayList<>();
String resultStr = translateVariables(expression, stack, evaluator);
if (shallBeIncluded(resultStr, excludeEmptyElements)) {
resultCol.add(resultStr);
}
}
return resultCol;
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class DefaultActionInvocation method createResult.
public Result createResult() throws Exception {
LOG.trace("Creating result related to resultCode [{}]", resultCode);
if (explicitResult != null) {
Result ret = explicitResult;
explicitResult = null;
return ret;
}
ActionConfig config = proxy.getConfig();
Map<String, ResultConfig> results = config.getResults();
ResultConfig resultConfig = null;
try {
resultConfig = results.get(resultCode);
} catch (NullPointerException e) {
LOG.debug("Got NPE trying to read result configuration for resultCode [{}]", resultCode);
}
if (resultConfig == null) {
// If no result is found for the given resultCode, try to get a wildcard '*' match.
resultConfig = results.get("*");
}
if (resultConfig != null) {
try {
return objectFactory.buildResult(resultConfig, invocationContext.getContextMap());
} catch (Exception e) {
LOG.error("There was an exception while instantiating the result of type {}", resultConfig.getClassName(), e);
throw new StrutsException(e, resultConfig);
}
} else if (resultCode != null && !Action.NONE.equals(resultCode) && unknownHandlerManager.hasUnknownHandlers()) {
return unknownHandlerManager.handleUnknownResult(invocationContext, proxy.getActionName(), proxy.getConfig(), resultCode);
}
return null;
}
Aggregations