Author: chris.laprun(a)jboss.com
Date: 2008-08-06 18:42:48 -0400 (Wed, 06 Aug 2008)
New Revision: 11674
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/content/InternalContentProvider.java
Log:
- JBPORTAL-2114: InternalContentProvider.renderWindow now fails if a window state or mode
that the portlet doesn't support is requested.
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/content/InternalContentProvider.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/content/InternalContentProvider.java 2008-08-06
22:23:49 UTC (rev 11673)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/content/InternalContentProvider.java 2008-08-06
22:42:48 UTC (rev 11674)
@@ -25,6 +25,7 @@
import org.jboss.logging.Logger;
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
+import org.jboss.portal.common.i18n.LocalizedString;
import org.jboss.portal.common.net.media.MediaType;
import org.jboss.portal.common.util.MultiValuedPropertyMap;
import org.jboss.portal.core.aspects.portlet.AjaxInterceptor;
@@ -44,9 +45,11 @@
import org.jboss.portal.core.model.portal.content.ContentRendererContext;
import org.jboss.portal.core.model.portal.content.WindowRendition;
import org.jboss.portal.portlet.NoSuchPortletException;
+import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.controller.state.PortletWindowNavigationalState;
import org.jboss.portal.portlet.info.CapabilitiesInfo;
+import org.jboss.portal.portlet.info.MetaInfo;
import org.jboss.portal.portlet.info.ModeInfo;
import org.jboss.portal.portlet.info.WindowStateInfo;
import org.jboss.portal.portlet.invocation.RenderInvocation;
@@ -63,6 +66,8 @@
import org.w3c.dom.Element;
import javax.portlet.MimeResponse;
+import javax.portlet.PortletModeException;
+import javax.portlet.WindowStateException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -206,13 +211,13 @@
//
return new WindowRendition(windowProps, WindowState.NORMAL, Mode.VIEW, null,
null, cr);
}
-
+
//
PortletWindowNavigationalState windowNS =
rendererContext.getPortletNavigationalState();
-
+
if (windowNS == null)
{
-
+
}
//
@@ -250,7 +255,8 @@
//
try
{
- CapabilitiesInfo capabilitiesInfo =
instance.getPortlet().getInfo().getCapabilities();
+ Portlet portlet = instance.getPortlet();
+ CapabilitiesInfo capabilitiesInfo = portlet.getInfo().getCapabilities();
// Add window states for any media type
Set<WindowStateInfo> windowStatesInfo =
capabilitiesInfo.getAllWindowStates();
@@ -266,7 +272,7 @@
// Get current Media Type
MediaType mediaType = invocation.getContext().getMarkupInfo().getMediaType();
-
+
// Add window states for the current media type
windowStatesInfo = capabilitiesInfo.getWindowStates(mediaType);
supportedWindowStates = new
ArrayList<WindowState>(windowStatesInfo.size());
@@ -279,6 +285,14 @@
}
}
+ // fail fast if we are requesting a window state that is not supported by this
portlet
+ if (!supportedWindowStates.contains(windowState))
+ {
+ String windowStateName = windowState.toString();
+ throw new WindowStateException(windowStateName + " is not supported by
portlet " + getPortletName(portlet),
+ new javax.portlet.WindowState(windowStateName));
+ }
+
// Add modes for any media type
Set<ModeInfo> modesInfo = capabilitiesInfo.getAllModes();
supportedModes = new ArrayList<Mode>(modesInfo.size());
@@ -303,6 +317,14 @@
}
}
+ // fail fast if we are requesting a window state that is not supported by this
portlet
+ if (!supportedModes.contains(mode))
+ {
+ String modeName = mode.toString();
+ throw new PortletModeException(modeName + " is not supported by portlet
" + getPortletName(portlet),
+ new javax.portlet.PortletMode(modeName));
+ }
+
// Remove edit mode if the user is not logged it
if (rendererContext.getUser() == null)
{
@@ -322,7 +344,7 @@
//
response = instance.invoke(invocation);
}
- catch (PortletInvokerException e)
+ catch (Exception e)
{
ControllerResponse cr;
@@ -421,4 +443,20 @@
//
return new WindowRendition(windowProps, windowState, mode, supportedWindowStates,
supportedModes, cr);
}
+
+ private String getPortletName(Portlet portlet) throws PortletInvokerException
+ {
+ LocalizedString displayName =
portlet.getInfo().getMeta().getMetaValue(MetaInfo.DISPLAY_NAME);
+ // if we can't get a display name, default to portlet id...
+ String name;
+ if (displayName == null)
+ {
+ name = portlet.getContext().getId();
+ }
+ else
+ {
+ name = displayName.getDefaultString();
+ }
+ return "'" + name + "'";
+ }
}
Show replies by date