use of com.opensymphony.xwork2.Result in project struts by apache.
the class ServletUrlRenderer method renderUrl.
/**
* {@inheritDoc}
*/
@Override
public void renderUrl(Writer writer, UrlProvider urlComponent) {
String scheme = urlComponent.getHttpServletRequest().getScheme();
if (urlComponent.getScheme() != null) {
ValueStack vs = ActionContext.getContext().getValueStack();
scheme = vs.findString(urlComponent.getScheme());
if (scheme == null) {
scheme = urlComponent.getScheme();
}
}
String result;
ActionInvocation ai = ActionContext.getContext().getActionInvocation();
if (urlComponent.getValue() == null && urlComponent.getAction() != null) {
result = urlComponent.determineActionURL(urlComponent.getAction(), urlComponent.getNamespace(), urlComponent.getMethod(), urlComponent.getHttpServletRequest(), urlComponent.getHttpServletResponse(), urlComponent.getParameters(), scheme, urlComponent.isIncludeContext(), urlComponent.isEncode(), urlComponent.isForceAddSchemeHostAndPort(), urlComponent.isEscapeAmp());
} else if (urlComponent.getValue() == null && urlComponent.getAction() == null && ai != null) {
// both are null, we will default to the current action
final String action = ai.getProxy().getActionName();
final String namespace = ai.getProxy().getNamespace();
final String method = urlComponent.getMethod() != null || !ai.getProxy().isMethodSpecified() ? urlComponent.getMethod() : ai.getProxy().getMethod();
result = urlComponent.determineActionURL(action, namespace, method, urlComponent.getHttpServletRequest(), urlComponent.getHttpServletResponse(), urlComponent.getParameters(), scheme, urlComponent.isIncludeContext(), urlComponent.isEncode(), urlComponent.isForceAddSchemeHostAndPort(), urlComponent.isEscapeAmp());
} else {
String _value = urlComponent.getValue();
// prioritised before this [in start(Writer) method]
if (_value != null && _value.indexOf('?') > 0) {
_value = _value.substring(0, _value.indexOf('?'));
}
result = urlHelper.buildUrl(_value, urlComponent.getHttpServletRequest(), urlComponent.getHttpServletResponse(), urlComponent.getParameters(), scheme, urlComponent.isIncludeContext(), urlComponent.isEncode(), urlComponent.isForceAddSchemeHostAndPort(), urlComponent.isEscapeAmp());
}
String anchor = urlComponent.getAnchor();
if (StringUtils.isNotEmpty(anchor)) {
result += '#' + urlComponent.findString(anchor);
}
if (urlComponent.isPutInContext()) {
String var = urlComponent.getVar();
if (StringUtils.isNotEmpty(var)) {
urlComponent.putInContext(result);
// Note: Old comments stated that var was placed in the page scope, but interactive checks with EL on JSPs prove otherwise.
// Add the var attribute to the request scope as well.
urlComponent.getHttpServletRequest().setAttribute(var, result);
} else {
try {
writer.write(result);
} catch (IOException e) {
throw new StrutsException("IOError: " + e.getMessage(), e);
}
}
} else {
try {
writer.write(result);
} catch (IOException e) {
throw new StrutsException("IOError: " + e.getMessage(), e);
}
}
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class Bean method start.
public boolean start(Writer writer) {
boolean result = super.start(writer);
ValueStack stack = getStack();
try {
String beanName = findString(name, "name", "Bean name is required. Example: com.acme.FooBean or proper Spring bean ID");
bean = objectFactory.buildBean(beanName, stack.getContext(), false);
} catch (Exception e) {
LOG.error("Could not instantiate bean", e);
return false;
}
// push bean on stack
stack.push(bean);
// store for reference later
putInContext(bean);
return result;
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class Push method start.
public boolean start(Writer writer) {
boolean result = super.start(writer);
ValueStack stack = getStack();
if (stack != null) {
stack.push(findValue(value, "value", "You must specify a value to push on the stack. Example: person"));
pushed = true;
} else {
// need to ensure push is assigned, otherwise we may have a leftover value
pushed = false;
}
return result;
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class PortletResultTest method testDoExecute_event_locationIsJsp.
public void testDoExecute_event_locationIsJsp() {
Mock mockRequest = mock(ActionRequest.class);
Mock mockResponse = mock(ActionResponse.class);
Constraint[] params = new Constraint[] { eq(ACTION_PARAM), eq("renderDirect") };
mockResponse.expects(once()).method("setRenderParameter").with(params);
params = new Constraint[] { eq(MODE_PARAM), eq(PortletMode.VIEW.toString()) };
mockResponse.expects(once()).method("setRenderParameter").with(params);
params = new Constraint[] { eq(PortletConstants.RENDER_DIRECT_NAMESPACE), eq("/test") };
mockResponse.expects(once()).method("setRenderParameter").with(params);
mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
ActionContext ctx = ActionContext.getContext();
Map<String, Object> session = new HashMap<>();
ctx.setSession(session);
ctx.put(REQUEST, mockRequest.proxy());
ctx.put(RESPONSE, mockResponse.proxy());
ctx.put(PHASE, PortletPhase.ACTION_PHASE);
PortletResult result = new PortletResult();
try {
result.doExecute("/WEB-INF/pages/testJsp.jsp", (ActionInvocation) mockInvocation.proxy());
} catch (Exception e) {
e.printStackTrace();
fail("Error occurred!");
}
assertEquals("/WEB-INF/pages/testJsp.jsp", session.get(RENDER_DIRECT_LOCATION));
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class PortletResultTest method testDoExecute_render.
public void testDoExecute_render() {
Mock mockRequest = mock(RenderRequest.class);
Mock mockResponse = mock(RenderResponse.class);
Mock mockRd = mock(PortletRequestDispatcher.class);
RenderRequest req = (RenderRequest) mockRequest.proxy();
RenderResponse res = (RenderResponse) mockResponse.proxy();
PortletRequestDispatcher rd = (PortletRequestDispatcher) mockRd.proxy();
PortletContext ctx = (PortletContext) mockCtx.proxy();
ActionInvocation inv = (ActionInvocation) mockInvocation.proxy();
Constraint[] params = new Constraint[] { same(req), same(res) };
mockRd.expects(once()).method("include").with(params);
mockCtx.expects(once()).method("getRequestDispatcher").with(eq("/WEB-INF/pages/testPage.jsp")).will(returnValue(rd));
mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
mockResponse.expects(once()).method("setContentType").with(eq("text/html"));
mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
ActionContext ctxMap = ActionContext.getContext();
ctxMap.put(RESPONSE, res);
ctxMap.put(REQUEST, req);
ctxMap.put(SERVLET_CONTEXT, ctx);
ctxMap.put(PHASE, PortletPhase.RENDER_PHASE);
PortletResult result = new PortletResult();
try {
result.doExecute("/WEB-INF/pages/testPage.jsp", inv);
} catch (Exception e) {
e.printStackTrace();
fail("Error occurred!");
}
}
Aggregations