use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.
the class OgnlValueStackTest method testConvertStringArrayToList.
public void testConvertStringArrayToList() {
Foo foo = new Foo();
OgnlValueStack vs = createValueStack();
vs.push(foo);
vs.setValue("strings", new String[] { "one", "two" });
assertNotNull(foo.getStrings());
assertEquals("one", foo.getStrings().get(0));
assertEquals("two", foo.getStrings().get(1));
}
use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.
the class FreemarkerResult method createModel.
/**
* Build the instance of the ScopesHashModel, including JspTagLib support
* <p>
* Objects added to the model are
* </p>
*
* <ul>
* <li>Application - servlet context attributes hash model
* <li>JspTaglibs - jsp tag lib factory model
* <li>Request - request attributes hash model
* <li>Session - session attributes hash model
* <li>request - the HttpServletRequst object for direct access
* <li>response - the HttpServletResponse object for direct access
* <li>stack - the OgnLValueStack instance for direct access
* <li>ognl - the instance of the OgnlTool
* <li>action - the action itself
* <li>exception - optional : the JSP or Servlet exception as per the servlet spec (for JSP Exception pages)
* <li>struts - instance of the StrutsUtil class
* </ul>
*
* @return TemplateModel returns the created template model
* @throws TemplateModelException in case of errors during creating the model
*/
protected TemplateModel createModel() throws TemplateModelException {
ServletContext servletContext = ServletActionContext.getServletContext();
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
ValueStack stack = ActionContext.getContext().getValueStack();
Object action = null;
// Added for NullPointException
if (invocation != null)
action = invocation.getAction();
return freemarkerManager.buildTemplateModel(stack, action, servletContext, request, response, wrapper);
}
use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.
the class TagModelTest method testGetWriter.
public void testGetWriter() throws Exception {
OgnlValueStack stack = (OgnlValueStack) ActionContext.getContext().getValueStack();
final InternalBean bean = new InternalBean(stack);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
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 bean;
}
};
tagModel.getWriter(new StringWriter(), params);
assertNotNull(bean);
assertEquals(bean.getProperty1(), true);
assertEquals(bean.getProperty2(), false);
assertEquals(bean.getProperty3(), "toby");
assertEquals(bean.getProperty4(), "phil");
assertEquals(bean.getProperty5(), new Integer(10));
assertEquals(bean.getProperty6(), new Float(1.1));
assertNotNull(bean.getProperty7());
assertTrue(bean.getProperty7() instanceof Map);
assertNotNull(bean.getProperty8());
assertTrue(bean.getProperty8() instanceof Collection);
assertNotNull(bean.getProperty9());
assertTrue(bean.getProperty9() instanceof Collection);
assertEquals(bean.getProperty10(), ADAPTER_TEMPLATE_MODEL_CONTAINED_OBJECT);
assertEquals(bean.getProperty11(), WRAPPING_TEMPLATE_MODEL_CONTAINED_OBJECT);
}
use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.
the class OgnlValueStack method readResolve.
private Object readResolve() {
// TODO: this should be done better
ActionContext ac = ActionContext.getContext();
Container cont = ac.getContainer();
XWorkConverter xworkConverter = cont.getInstance(XWorkConverter.class);
CompoundRootAccessor accessor = (CompoundRootAccessor) cont.getInstance(PropertyAccessor.class, CompoundRoot.class.getName());
TextProvider prov = cont.getInstance(TextProvider.class, "system");
final boolean allowStaticMethod = BooleanUtils.toBoolean(cont.getInstance(String.class, StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS));
final boolean allowStaticField = BooleanUtils.toBoolean(cont.getInstance(String.class, StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS));
OgnlValueStack aStack = new OgnlValueStack(xworkConverter, accessor, prov, allowStaticMethod, allowStaticField);
aStack.setOgnlUtil(cont.getInstance(OgnlUtil.class));
aStack.setRoot(xworkConverter, accessor, this.root, allowStaticMethod, allowStaticField);
return aStack;
}
use of com.opensymphony.xwork2.ognl.OgnlValueStack in project struts by apache.
the class PortletFreemarkerResult method createModel.
/**
* <p>
* Build the instance of the ScopesHashModel, including JspTagLib support
* </p>
*
* <p>Objects added to the model are:</p>
*
* <ul>
* <li>Application - servlet context attributes hash model
* <li>JspTaglibs - jsp tag lib factory model
* <li>Request - request attributes hash model
* <li>Session - session attributes hash model
* <li>request - the HttpServletRequst object for direct access
* <li>response - the HttpServletResponse object for direct access
* <li>stack - the OgnLValueStack instance for direct access
* <li>ognl - the instance of the OgnlTool
* <li>action - the action itself
* <li>exception - optional : the JSP or Servlet exception as per the
* servlet spec (for JSP Exception pages)
* <li>struts - instance of the StrutsUtil class
* </ul>
*
* @return freemarker template model
*
* @throws TemplateModelException in case of template model errors
*/
protected TemplateModel createModel() throws TemplateModelException {
ServletContext servletContext = ServletActionContext.getServletContext();
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
ValueStack stack = ServletActionContext.getContext().getValueStack();
return freemarkerManager.buildTemplateModel(stack, invocation.getAction(), servletContext, request, response, wrapper);
}
Aggregations