use of com.opensymphony.xwork2.ognl.OgnlValueStack 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.ognl.OgnlValueStack 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.ognl.OgnlValueStack 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.ognl.OgnlValueStack in project struts by apache.
the class ValidateAction method createStubValueStack.
private ValueStack createStubValueStack(final Map<String, Object> actual) {
ValueStack stack = new OgnlValueStack(container.getInstance(XWorkConverter.class), (CompoundRootAccessor) container.getInstance(PropertyAccessor.class, CompoundRoot.class.getName()), container.getInstance(TextProvider.class, "system"), true, true) {
@Override
public void setValue(String expr, Object value) {
actual.put(expr, value);
}
@Override
public void setParameter(String expr, Object value) {
actual.put(expr, value);
}
};
container.inject(stack);
return stack;
}
use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.
the class ValidatorSupportTest method testConditionalParseExpression.
public void testConditionalParseExpression() {
OgnlValueStack stack = (OgnlValueStack) container.getInstance(ValueStackFactory.class).createValueStack();
stack.getContext().put("something", "somevalue");
ActionContext.of(stack.getContext()).withContainer(container).bind();
ValidatorSupport validator = new ValidatorSupport() {
public void validate(Object object) throws ValidationException {
}
};
validator.setValueStack(ActionContext.getContext().getValueStack());
String result1 = validator.parse("${#something}", String.class).toString();
assertEquals(result1, "somevalue");
}
Aggregations