Search in sources :

Example 1 with OgnlValueStack

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();
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack)

Example 2 with OgnlValueStack

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();
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack)

Example 3 with OgnlValueStack

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);
}
Also used : OgnlValueStack(com.opensymphony.xwork2.ognl.OgnlValueStack) TemplateModelException(freemarker.template.TemplateModelException) TemplateSequenceModel(freemarker.template.TemplateSequenceModel) TemplateModelIterator(freemarker.template.TemplateModelIterator) WrapperTemplateModel(freemarker.ext.util.WrapperTemplateModel) AdapterTemplateModel(freemarker.template.AdapterTemplateModel) TemplateModel(freemarker.template.TemplateModel) LinkedHashMap(java.util.LinkedHashMap) TemplateHashModel(freemarker.template.TemplateHashModel) Iterator(java.util.Iterator) TemplateModelIterator(freemarker.template.TemplateModelIterator) TemplateCollectionModel(freemarker.template.TemplateCollectionModel) WrapperTemplateModel(freemarker.ext.util.WrapperTemplateModel) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) TemplateBooleanModel(freemarker.template.TemplateBooleanModel) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TemplateNumberModel(freemarker.template.TemplateNumberModel) AdapterTemplateModel(freemarker.template.AdapterTemplateModel) Collection(java.util.Collection) TemplateScalarModel(freemarker.template.TemplateScalarModel) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with OgnlValueStack

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;
}
Also used : OgnlValueStack(com.opensymphony.xwork2.ognl.OgnlValueStack) OgnlValueStack(com.opensymphony.xwork2.ognl.OgnlValueStack) ValueStack(com.opensymphony.xwork2.util.ValueStack) XWorkConverter(com.opensymphony.xwork2.conversion.impl.XWorkConverter) CompoundRoot(com.opensymphony.xwork2.util.CompoundRoot) TextProvider(com.opensymphony.xwork2.TextProvider)

Example 5 with OgnlValueStack

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");
}
Also used : OgnlValueStack(com.opensymphony.xwork2.ognl.OgnlValueStack)

Aggregations

Foo (com.opensymphony.xwork2.util.Foo)14 ValueStack (com.opensymphony.xwork2.util.ValueStack)6 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)5 OgnlException (ognl.OgnlException)5 StrutsException (org.apache.struts2.StrutsException)5 OgnlValueStack (com.opensymphony.xwork2.ognl.OgnlValueStack)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 ParseException (ognl.ParseException)4 TextProvider (com.opensymphony.xwork2.TextProvider)2 XWorkConverter (com.opensymphony.xwork2.conversion.impl.XWorkConverter)2 WrapperTemplateModel (freemarker.ext.util.WrapperTemplateModel)2 AdapterTemplateModel (freemarker.template.AdapterTemplateModel)2 TemplateBooleanModel (freemarker.template.TemplateBooleanModel)2 TemplateCollectionModel (freemarker.template.TemplateCollectionModel)2 TemplateHashModel (freemarker.template.TemplateHashModel)2 TemplateModel (freemarker.template.TemplateModel)2 TemplateModelException (freemarker.template.TemplateModelException)2 TemplateModelIterator (freemarker.template.TemplateModelIterator)2 TemplateNumberModel (freemarker.template.TemplateNumberModel)2