super.doView(request, response);
return;
}
// view the current page in the history
WebContentHistoryList history = (WebContentHistoryList)PortletMessaging.receive(request, HISTORY);
if (history == null)
history = new WebContentHistoryList();
WebContentHistoryPage currentPage = history.getCurrentPage();
if (currentPage == null)
{
String sourceURL = request.getPreferences().getValue("SRC", "");
if (sourceURL == null)
{
// BOZO - switch to edit mode automatically here, instead of throwing exception!
throw new PortletException("WebContent source not specified. Go to edit mode and specify an URL.");
}
currentPage = new WebContentHistoryPage(sourceURL);
}
// Initialize the controller if it's not already done
if (rewriteController == null)
{
PortletContext portletApplication = getPortletContext();
String path = portletApplication.getRealPath("/WEB-INF");
String contextPath = path + "/";
try
{
// Create rewriter adaptor
rewriteController = getController(contextPath);
}
catch (Exception e)
{
// Failed to create rewriter controller
String msg = "WebContentPortlet failed to create rewriter controller.";
log.error(msg,e);
throw new PortletException(e.getMessage());
}
}
// get content from current page
response.setContentType("text/html");
byte[] content = doWebContent(currentPage.getUrl(), currentPage.getParams(), currentPage.isPost(), request, response);
// System.out.println("Rewritten content is\n..."+new String(content));
// write the meta-control navigation header
PrintWriter writer = response.getWriter();
writer.print("<block>");
if (history.hasPreviousPage())
{
PortletURL prevAction = response.createActionURL() ;
prevAction.setParameter(BROWSER_ACTION_PARAM, BROWSER_ACTION_PREVIOUS_PAGE);
writer.print(" [<a href=\"" + prevAction.toString() +"\">Previous Page</a>] ");
}
PortletURL refreshAction = response.createActionURL() ;
refreshAction.setParameter(BROWSER_ACTION_PARAM, BROWSER_ACTION_REFRESH_PAGE);
writer.print(" [<a href=\"" + refreshAction.toString() +"\">Refresh Page</a>] ");
if (history.hasNextPage())
{
PortletURL nextAction = response.createActionURL() ;
nextAction.setParameter(BROWSER_ACTION_PARAM, BROWSER_ACTION_NEXT_PAGE);
writer.print(" [<a href=\"" + nextAction.toString() +"\">Next Page</a>] ");
}
writer.print("</block><hr/>");
// drain the stream to the portlet window
ByteArrayInputStream bais = new ByteArrayInputStream(content);
drain(new InputStreamReader(bais, WebContentPortlet.defaultEncoding), writer);
bais.close();
// done, cache results in the history and save the history
history.visitPage(currentPage);
PortletMessaging.publish(request, HISTORY, history);
}