//Check mode of portal, portlet and permission for viewable
if ((portalMode == UIPortalApplication.NORMAL_MODE || portalMode == UIPortalApplication.APP_VIEW_EDIT_MODE
|| portalMode == UIPortalApplication.CONTAINER_VIEW_EDIT_MODE || uicomponent.getCurrentPortletMode().equals(PortletMode.EDIT))
&& uicomponent.hasPermission())
{
PortletInvocationResponse response = uicomponent.invoke(renderInvocation);
if (response instanceof FragmentResponse)
{
FragmentResponse fragmentResponse = (FragmentResponse)response;
switch (fragmentResponse.getType())
{
case FragmentResponse.TYPE_CHARS:
markup = Text.create(fragmentResponse.getContent());
break;
case FragmentResponse.TYPE_BYTES:
markup = Text.create(fragmentResponse.getBytes(), Charset.forName("UTF-8"));
break;
case FragmentResponse.TYPE_EMPTY:
markup = Text.create("");
break;
}
portletTitle = fragmentResponse.getTitle();
// setup portlet properties
if (fragmentResponse.getProperties() != null)
{
//setup transport headers
if (fragmentResponse.getProperties().getTransportHeaders() != null)
{
MultiValuedPropertyMap<String> transportHeaders =
fragmentResponse.getProperties().getTransportHeaders();
for (String key : transportHeaders.keySet())
{
for (String value : transportHeaders.getValues(key))
{
prcontext.getResponse().setHeader(key, value);
}
}
}
//setup up portlet cookies
if (fragmentResponse.getProperties().getCookies() != null)
{
List<Cookie> cookies = fragmentResponse.getProperties().getCookies();
for (Cookie cookie : cookies)
{
prcontext.getResponse().addCookie(cookie);
}
}
//setup markup headers
if (fragmentResponse.getProperties().getMarkupHeaders() != null)
{
MultiValuedPropertyMap<Element> markupHeaders =
fragmentResponse.getProperties().getMarkupHeaders();
List<Element> markupElements = markupHeaders.getValues(MimeResponse.MARKUP_HEAD_ELEMENT);
if (markupElements != null)
{
for (Element element : markupElements)
{
if ("title".equals(element.getNodeName().toLowerCase()) && element.getFirstChild() != null)
{
String title = element.getFirstChild().getTextContent();
prcontext.getRequest().setAttribute(PortalRequestContext.REQUEST_TITLE, title);
}
else
{
prcontext.addExtraMarkupHeader(element);
}
}
}
}
}
}
else
{
PortletContainerException pcException;
if (response instanceof ErrorResponse)
{
ErrorResponse errorResponse = (ErrorResponse)response;
pcException =
new PortletContainerException(errorResponse.getMessage(), errorResponse.getCause());
}
else
{
pcException =
new PortletContainerException("Unknown invocation response type [" + response.getClass()
+ "]. Expected a FragmentResponse or an ErrorResponse");
}
//
PortletExceptionHandleService portletExceptionService = uicomponent.getApplicationComponent(PortletExceptionHandleService.class);