PortletResultpublic class PortletResult extends org.apache.struts2.dispatcher.StrutsResultSupport Result type that includes a JSP to render. |
Fields Summary |
---|
private static final long | serialVersionUID | private static final Log | LOGLogger instance. | private String | contentType | private String | title |
Constructors Summary |
---|
public PortletResult()
super();
| public PortletResult(String location)
super(location);
|
Methods Summary |
---|
protected static void | convertQueryParamsToRenderParams(javax.portlet.ActionResponse response, java.lang.String queryParams)Converts the query params to render params.
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);
}
| public void | doExecute(java.lang.String finalLocation, com.opensymphony.xwork2.ActionInvocation actionInvocation)Execute the result. Obtains the
{@link javax.portlet.PortletRequestDispatcher}from the
{@link PortletActionContext}and includes the JSP.
if (PortletActionContext.isRender()) {
executeRenderResult(finalLocation);
} else if (PortletActionContext.isEvent()) {
executeActionResult(finalLocation, actionInvocation);
} else {
executeRegularServletResult(finalLocation, actionInvocation);
}
| protected void | executeActionResult(java.lang.String finalLocation, com.opensymphony.xwork2.ActionInvocation invocation)Executes the action result.
LOG.debug("Executing result in Event phase");
ActionResponse res = PortletActionContext.getActionResponse();
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(PortletActionConstants.ACTION_PARAM, finalLocation);
} else {
// View is rendered outside an action...uh oh...
res.setRenderParameter(PortletActionConstants.ACTION_PARAM, "renderDirect");
res.setRenderParameter("location", finalLocation);
}
res.setRenderParameter(PortletActionConstants.MODE_PARAM, PortletActionContext
.getRequest().getPortletMode().toString());
| private void | executeRegularServletResult(java.lang.String finalLocation, com.opensymphony.xwork2.ActionInvocation actionInvocation)Executes the regular servlet result.
ServletContext ctx = ServletActionContext.getServletContext();
HttpServletRequest req = ServletActionContext.getRequest();
HttpServletResponse res = ServletActionContext.getResponse();
try {
ctx.getRequestDispatcher(finalLocation).include(req, res);
} catch (ServletException e) {
LOG.error("ServletException including " + finalLocation, e);
throw e;
} catch (IOException e) {
LOG.error("IOException while including result '" + finalLocation + "'", e);
throw e;
}
| protected void | executeRenderResult(java.lang.String finalLocation)Executes the render result.
LOG.debug("Executing result in Render phase");
PortletConfig cfg = PortletActionContext.getPortletConfig();
RenderRequest req = PortletActionContext.getRenderRequest();
RenderResponse res = PortletActionContext.getRenderResponse();
LOG.debug("PortletConfig: " + cfg);
LOG.debug("RenderRequest: " + req);
LOG.debug("RenderResponse: " + res);
res.setContentType(contentType);
if (TextUtils.stringSet(title)) {
res.setTitle(title);
}
LOG.debug("Location: " + finalLocation);
PortletRequestDispatcher preparator = cfg.getPortletContext()
.getNamedDispatcher("preparator");
if(preparator == null) {
throw new PortletException("Cannot look up 'preparator' servlet. Make sure that you" +
"have configured it correctly in the web.xml file.");
}
new IncludeTemplate() {
protected void when(PortletException e) {
LOG.error("PortletException while dispatching to 'preparator' servlet", e);
}
protected void when(IOException e) {
LOG.error("IOException while dispatching to 'preparator' servlet", e);
}
}.include(preparator, req, res);
PortletRequestDispatcher dispatcher = cfg.getPortletContext().getRequestDispatcher(finalLocation);
if(dispatcher == null) {
throw new PortletException("Could not locate dispatcher for '" + finalLocation + "'");
}
new IncludeTemplate() {
protected void when(PortletException e) {
LOG.error("PortletException while dispatching to '" + finalLocation + "'");
}
protected void when(IOException e) {
LOG.error("IOException while dispatching to '" + finalLocation + "'");
}
}.include(dispatcher, req, res);
| public void | setContentType(java.lang.String contentType)Sets the content type.
this.contentType = contentType;
| public void | setTitle(java.lang.String title)Sets the title.
this.title = title;
|
|