use of com.opensymphony.xwork2.conversion.impl.XWorkConverter 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.conversion.impl.XWorkConverter in project struts by apache.
the class OgnlValueStackFactory method createValueStack.
public ValueStack createValueStack() {
ValueStack stack = new OgnlValueStack(xworkConverter, compoundRootAccessor, textProvider, containerAllowsStaticMethodAccess(), containerAllowsStaticFieldAccess());
container.inject(stack);
return stack.getActionContext().withContainer(container).withValueStack(stack).getValueStack();
}
use of com.opensymphony.xwork2.conversion.impl.XWorkConverter 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.conversion.impl.XWorkConverter in project struts by apache.
the class AbstractTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
scriptingAttrs.put("onclick", "onclick_");
scriptingAttrs.put("ondblclick", "ondblclick_");
scriptingAttrs.put("onmousedown", "onmousedown_");
scriptingAttrs.put("onmouseup", "onmouseup_");
scriptingAttrs.put("onmouseover", "onmouseover_");
scriptingAttrs.put("onmousemove", "onmousemove_");
scriptingAttrs.put("onmouseout", "onmouseout_");
scriptingAttrs.put("onfocus", "onfocus_");
scriptingAttrs.put("onblur", "onblur_");
scriptingAttrs.put("onkeypress", "onkeypress_");
scriptingAttrs.put("onkeydown", "onkeydown_");
scriptingAttrs.put("onkeyup", "onkeyup_");
scriptingAttrs.put("onselect", "onselect_");
scriptingAttrs.put("onchange", "onchange_");
commonAttrs.put("accesskey", "accesskey_");
dynamicAttrs.put("data-remote", "data-remote_");
dynamicAttrs.put("data-label", "data-label_");
theme = new SimpleTheme();
writer = new StringWriter();
map = new HashMap<>();
template = createMock(Template.class);
stack = createNiceMock(ValueStack.class);
setUpStack();
stackContext = new HashMap<>();
context = new TemplateRenderingContext(template, writer, stack, map, null);
stackContext.put(Component.COMPONENT_STACK, new Stack<>());
ActionContext actionContext = ActionContext.of(stackContext).bind();
request = createNiceMock(HttpServletRequest.class);
expect(request.getContextPath()).andReturn("/some/path").anyTimes();
response = createNiceMock(HttpServletResponse.class);
expect(stack.getActionContext()).andReturn(actionContext).anyTimes();
expect(stack.getContext()).andReturn(stackContext).anyTimes();
Container container = createNiceMock(Container.class);
XWorkConverter converter = new ConverterEx();
expect(container.getInstance(XWorkConverter.class)).andReturn(converter).anyTimes();
TextParser parser = new OgnlTextParser();
expect(container.getInstance(TextParser.class)).andReturn(parser).anyTimes();
replay(request);
replay(stack);
replay(container);
actionContext.withContainer(container).withServletRequest(request);
}
use of com.opensymphony.xwork2.conversion.impl.XWorkConverter in project struts by apache.
the class SetPropertiesTest method testSetCollectionByConverterFromArray.
public void testSetCollectionByConverterFromArray() {
Foo foo = new Foo();
ValueStack vs = ActionContext.getContext().getValueStack();
vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
XWorkConverter c = (XWorkConverter) ((OgnlTypeConverterWrapper) Ognl.getTypeConverter(vs.getContext())).getTarget();
c.registerConverter(Cat.class.getName(), new FooBarConverter());
vs.push(foo);
vs.setValue("cats", new String[] { "1", "2" });
assertNotNull(foo.getCats());
assertEquals(2, foo.getCats().size());
assertEquals(Cat.class, foo.getCats().get(0).getClass());
assertEquals(Cat.class, foo.getCats().get(1).getClass());
}
Aggregations