Search in sources :

Example 1 with ModelDriven

use of com.opensymphony.xwork2.ModelDriven in project struts by apache.

the class ModelDrivenInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    Object action = invocation.getAction();
    if (action instanceof ModelDriven) {
        ModelDriven modelDriven = (ModelDriven) action;
        ValueStack stack = invocation.getStack();
        Object model = modelDriven.getModel();
        if (model != null) {
            stack.push(model);
        }
        if (refreshModelBeforeResult) {
            invocation.addPreResultListener(new RefreshModelBeforeResult(modelDriven, model));
        }
    }
    return invocation.invoke();
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) ModelDriven(com.opensymphony.xwork2.ModelDriven)

Example 2 with ModelDriven

use of com.opensymphony.xwork2.ModelDriven in project struts by apache.

the class JSONResult method findRootObject.

protected Object findRootObject(ActionInvocation invocation) {
    ValueStack stack = invocation.getStack();
    Object rootObject;
    if (this.root != null) {
        LOG.debug("Root was defined as [{}], searching stack for it", this.root);
        rootObject = stack.findValue(root);
    } else {
        LOG.debug("Root was not defined, searching for #action");
        rootObject = stack.findValue("#action");
        if (rootObject instanceof ModelDriven) {
            LOG.debug("Action is an instance of ModelDriven, assuming model is on the top of the stack and using it");
            rootObject = stack.peek();
        } else if (rootObject == null) {
            LOG.debug("Neither #action nor ModelDriven, peeking up object from the top of the stack");
            rootObject = stack.peek();
        }
    }
    return rootObject;
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) ModelDriven(com.opensymphony.xwork2.ModelDriven)

Example 3 with ModelDriven

use of com.opensymphony.xwork2.ModelDriven in project struts by apache.

the class StrutsLocalizedTextProviderTest method testFindTextInChildProperty.

public void testFindTextInChildProperty() throws Exception {
    ModelDriven action = new ModelDrivenAction2();
    TestBean2 bean = (TestBean2) action.getModel();
    Bar bar = new Bar();
    bean.setBarObj(bar);
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("hashCode", 0);
    mockActionInvocation.expectAndReturn("getAction", action);
    ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy());
    ActionContext.getContext().getValueStack().push(action);
    ActionContext.getContext().getValueStack().push(action.getModel());
    String message = localizedTextProvider.findText(ModelDrivenAction2.class, "invalid.fieldvalue.barObj.title", Locale.getDefault());
    assertEquals("Title is invalid!", message);
}
Also used : ModelDrivenAction2(com.opensymphony.xwork2.test.ModelDrivenAction2) ModelDriven(com.opensymphony.xwork2.ModelDriven) TestBean2(com.opensymphony.xwork2.test.TestBean2) Mock(com.mockobjects.dynamic.Mock)

Example 4 with ModelDriven

use of com.opensymphony.xwork2.ModelDriven in project struts by apache.

the class ContentTypeInterceptor method intercept.

public String intercept(ActionInvocation invocation) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    ContentTypeHandler handler = selector.getHandlerForRequest(request);
    Object target = invocation.getAction();
    if (target instanceof ModelDriven) {
        target = ((ModelDriven<?>) target).getModel();
    }
    if (request.getContentLength() > 0) {
        InputStream is = request.getInputStream();
        InputStreamReader reader = new InputStreamReader(is);
        handler.toObject(invocation, reader, target);
    }
    return invocation.invoke();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ContentTypeHandler(org.apache.struts2.rest.handler.ContentTypeHandler) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ModelDriven(com.opensymphony.xwork2.ModelDriven)

Example 5 with ModelDriven

use of com.opensymphony.xwork2.ModelDriven in project struts by apache.

the class XStreamHandler method addDefaultPermissions.

protected void addDefaultPermissions(ActionInvocation invocation, XStream stream) {
    stream.addPermission(new ExplicitTypePermission(new Class[] { invocation.getAction().getClass() }));
    if (invocation.getAction() instanceof ModelDriven) {
        stream.addPermission(new ExplicitTypePermission(new Class[] { ((ModelDriven) invocation.getAction()).getModel().getClass() }));
    }
    stream.addPermission(NullPermission.NULL);
    stream.addPermission(PrimitiveTypePermission.PRIMITIVES);
    stream.addPermission(ArrayTypePermission.ARRAYS);
    stream.addPermission(CollectionTypePermission.COLLECTIONS);
    stream.addPermission(new ExplicitTypePermission(new Class[] { Date.class }));
}
Also used : ModelDriven(com.opensymphony.xwork2.ModelDriven) Date(java.util.Date) ExplicitTypePermission(com.thoughtworks.xstream.security.ExplicitTypePermission)

Aggregations

ModelDriven (com.opensymphony.xwork2.ModelDriven)8 Mock (com.mockobjects.dynamic.Mock)2 ActionContext (com.opensymphony.xwork2.ActionContext)2 ModelDrivenAction2 (com.opensymphony.xwork2.test.ModelDrivenAction2)2 ValueStack (com.opensymphony.xwork2.util.ValueStack)2 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)1 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)1 ValidationAware (com.opensymphony.xwork2.interceptor.ValidationAware)1 TestBean2 (com.opensymphony.xwork2.test.TestBean2)1 DelegatingValidatorContext (com.opensymphony.xwork2.validator.DelegatingValidatorContext)1 ValidatorContext (com.opensymphony.xwork2.validator.ValidatorContext)1 ExplicitTypePermission (com.thoughtworks.xstream.security.ExplicitTypePermission)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1