Method from org.apache.struts2.portlet.result.PortletResult Detail: |
protected static void convertQueryParamsToRenderParams(ActionResponse response,
String queryParams) {
StringTokenizer tok = new StringTokenizer(queryParams, "&");
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
String key = token.substring(0, token.indexOf('='));
String value = token.substring(token.indexOf('=') + 1);
response.setRenderParameter(key, value);
}
}
Converts the query params to render params. |
public void doExecute(String finalLocation,
ActionInvocation actionInvocation) throws Exception {
if (PortletActionContext.isRender()) {
executeRenderResult(finalLocation);
} else if (PortletActionContext.isEvent()) {
executeActionResult(finalLocation, actionInvocation);
} else {
executeRegularServletResult(finalLocation, actionInvocation);
}
}
|
protected void executeActionResult(String finalLocation,
ActionInvocation invocation) throws Exception {
LOG.debug("Executing result in Event phase");
ActionResponse res = PortletActionContext.getActionResponse();
Map sessionMap = invocation.getInvocationContext().getSession();
LOG.debug("Setting event render parameter: " + finalLocation);
if (finalLocation.indexOf('?') != -1) {
convertQueryParamsToRenderParams(res, finalLocation.substring(finalLocation.indexOf('?') + 1));
finalLocation = finalLocation.substring(0, finalLocation.indexOf('?'));
}
if (finalLocation.endsWith(".action")) {
// View is rendered with a view action...luckily...
finalLocation = finalLocation.substring(0, finalLocation.lastIndexOf("."));
res.setRenderParameter(ACTION_PARAM, finalLocation);
} else {
// View is rendered outside an action...uh oh...
String namespace = invocation.getProxy().getNamespace();
if ( namespace != null && namespace.length() > 0 && !namespace.endsWith("/")) {
namespace += "/";
}
res.setRenderParameter(ACTION_PARAM, namespace + "renderDirect");
sessionMap.put(RENDER_DIRECT_LOCATION, finalLocation);
}
if(portletMode != null) {
res.setPortletMode(portletMode);
res.setRenderParameter(PortletActionConstants.MODE_PARAM, portletMode.toString());
}
else {
res.setRenderParameter(PortletActionConstants.MODE_PARAM, PortletActionContext.getRequest().getPortletMode()
.toString());
}
}
Executes the action result. |
protected void executeRenderResult(String finalLocation) throws PortletException, IOException {
LOG.debug("Executing result in Render phase");
PortletContext ctx = PortletActionContext.getPortletContext();
RenderRequest req = PortletActionContext.getRenderRequest();
RenderResponse res = PortletActionContext.getRenderResponse();
res.setContentType(contentType);
if (StringUtils.isNotEmpty(title)) {
res.setTitle(title);
}
LOG.debug("Location: " + finalLocation);
if (useDispatcherServlet) {
req.setAttribute(DISPATCH_TO, finalLocation);
PortletRequestDispatcher dispatcher = ctx.getNamedDispatcher(dispatcherServletName);
if(dispatcher == null) {
throw new PortletException("Could not locate dispatcher servlet \"" + dispatcherServletName + "\". Please configure it in your web.xml file");
}
dispatcher.include(req, res);
} else {
PortletRequestDispatcher dispatcher = ctx.getRequestDispatcher(finalLocation);
if (dispatcher == null) {
throw new PortletException("Could not locate dispatcher for '" + finalLocation + "'");
}
dispatcher.include(req, res);
}
}
Executes the render result. |
public void setContentType(String contentType) {
this.contentType = contentType;
}
|
public void setDispatcherServletName(String dispatcherServletName) {
this.dispatcherServletName = dispatcherServletName;
}
|
public void setPortletMode(String portletMode) {
if(portletMode != null) {
this.portletMode = new PortletMode(portletMode);
}
}
|
public void setTitle(String title) {
this.title = title;
}
|
public void setUseDispatcherServlet(String useDispatcherServlet) {
this.useDispatcherServlet = "true".equalsIgnoreCase(useDispatcherServlet);
}
|