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();
}
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;
}
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);
}
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();
}
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 }));
}
Aggregations