// save the original response
MimeResponse originalResponse = (MimeResponse) extContext.getResponse();
// see whether the portlet wants to use a writeBehindResponse(Wrapper)
Class<? extends BridgeWriteBehindResponse> writeBehindResponseWrapperClass = (Class<? extends BridgeWriteBehindResponse>) extContext.getRequestMap().get(BridgeImpl.WRITE_BEHIND_RESPONSE);
BridgeWriteBehindResponse wrapped = null;
if (writeBehindResponseWrapperClass != null)
{
try
{
wrapped = writeBehindResponseWrapperClass.newInstance();
if ((BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RENDER_PHASE && wrapped instanceof RenderResponse) ||
(BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RESOURCE_PHASE && wrapped instanceof ResourceResponse))
{
extContext.setResponse(wrapped);
}
else
{
// warn and don't use
wrapped = null;
extContext.log("Unable to use configured BridgeWriteBehindResponse instance because its not the appropriate PortletResponseWrapper for the associated phase.");
}
} catch (Exception e)
{
// Just warn and don't use;
extContext.log("Unable to instantiate configured BridgeWriteBehindResponse instance: ", e);
}
}
else
{
// Use the generic (non-writeBehindResponse) wrapper
if (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RENDER_PHASE)
{
wrapped = new BridgeViewHandlerRenderResponseWrapper();
}
else
{
wrapped = new BridgeViewHandlerResourceResponseWrapper();
}
extContext.setResponse(wrapped);
// don't set write behind as this one doesn't support the Faces specific implementation dependent interfaces
}
// set request attribute indicating we can deal with content
// that is supposed to be delayed until after JSF tree is ouput.
extContext.getRequestMap().put(Bridge.RENDER_CONTENT_AFTER_VIEW, Boolean.TRUE);
// build the view by executing the page
extContext.dispatch(viewURI);
if (wrapped != null)
{
// replace the original response
extContext.setResponse(originalResponse);
// Check whether our wrapper participated in the the writeBehind mechanism and/or
// something else already did (servlet filter)
if (wrapped.hasFacesWriteBehindMarkup() && extContext.getRequestMap().get(Bridge.AFTER_VIEW_CONTENT) == null)
{
// Put the AFTER_VIEW_CONTENT into request scope
// temporarily
Object o = (wrapped.isChars()) ? (Object) wrapped.getChars() : (Object) wrapped.getBytes();
if (o != null)
{
extContext.getRequestMap().put(Bridge.AFTER_VIEW_CONTENT, o);
}
}
else
{
// write ahead -- just write this to the restored response
wrapped.flushMarkupToWrappedResponse();
}
}
}