Author: julien(a)jboss.com
Date: 2007-03-06 16:50:33 -0500 (Tue, 06 Mar 2007)
New Revision: 6563
Added:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java
Modified:
trunk/core-cms/src/main/org/jboss/portal/core/cms/CMSConstants.java
trunk/core-cms/src/main/org/jboss/portal/core/cms/CMSObjectCommandFactory.java
trunk/core-cms/src/main/org/jboss/portal/core/cms/content/CMSContentRenderer.java
trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java
trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/PortletContentRenderer.java
Log:
generify the portlet integration for content viewing
Added:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java 2007-03-06
21:50:33 UTC (rev 6563)
@@ -0,0 +1,131 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.impl.model.portal.content;
+
+import org.jboss.portal.core.model.instance.Instance;
+import org.jboss.portal.core.model.instance.InstanceContainer;
+import org.jboss.portal.core.model.portal.command.RenderWindowCommand;
+import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.content.Content;
+import org.jboss.portal.core.controller.ControllerContext;
+import org.jboss.portal.portlet.PortletParametersStateString;
+import org.jboss.portal.Mode;
+import org.jboss.portal.theme.page.WindowResult;
+import org.jboss.portal.theme.navigation.WindowNavigationalState;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GenericPortletContentRenderer extends PortletContentRenderer
+{
+
+ /** . */
+ public static final Mode VIEW_CONTENT_MODE = new Mode("view_content");
+
+ /** . */
+ private String instanceName;
+
+ /** . */
+ private boolean decorateContent;
+
+ public String getInstanceName()
+ {
+ return instanceName;
+ }
+
+ public void setInstanceName(String instanceName)
+ {
+ this.instanceName = instanceName;
+ }
+
+ public boolean isDecorateContent()
+ {
+ return decorateContent;
+ }
+
+ public void setDecorateContent(boolean decorateContent)
+ {
+ this.decorateContent = decorateContent;
+ }
+
+ protected Instance findInstance(RenderWindowCommand cmd)
+ {
+ ControllerContext context = cmd.getControllerContext();
+ InstanceContainer container = context.getController().getInstanceContainer();
+ return container.getDefinition(instanceName);
+ }
+
+ public Object renderWindow(RenderWindowCommand cmd) throws Exception
+ {
+ ControllerContext context = cmd.getControllerContext();
+ Window window = cmd.getWindow();
+ PortalObjectId windowId = window.getId();
+
+ // Initialize the navigational state with the URI when needed
+ PortletParametersStateString navigationalState =
(PortletParametersStateString)context.getAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE,
windowId);
+ if (navigationalState == null)
+ {
+ Content content = window.getContent();
+ String uri = content.getURI();
+ navigationalState = new PortletParametersStateString();
+ navigationalState.setValue("uri", uri);
+ context.setAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE, windowId,
navigationalState);
+ }
+
+ // Set the view content mode
+ String navStateKey = windowId + "_window";
+ WindowNavigationalState windowNavState =
(WindowNavigationalState)context.getAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE,
navStateKey);
+ if (windowNavState == null)
+ {
+ windowNavState = new WindowNavigationalState();
+ context.setAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE, navStateKey,
windowNavState);
+ }
+ windowNavState.setMode(VIEW_CONTENT_MODE);
+
+ //
+ Object o = super.renderWindow(cmd);
+
+ //
+ if (o instanceof WindowResult && decorateContent == false)
+ {
+ WindowResult result = (WindowResult)o;
+
+ //
+ Map props = new HashMap(result.getWindowProperties());
+ props.put("theme.windowRendererId", "emptyRenderer");
+ props.put("theme.decorationRendererId", "emptyRenderer");
+ props.put("theme.portletRendererId", "emptyRenderer");
+
+ //
+ result.setWindowProperties(props);
+ }
+
+ //
+ return o;
+ }
+}
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/PortletContentRenderer.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/PortletContentRenderer.java 2007-03-06
21:46:32 UTC (rev 6562)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/PortletContentRenderer.java 2007-03-06
21:50:33 UTC (rev 6563)
@@ -106,6 +106,11 @@
return customizationManager.getInstance(window, user);
}
+ protected PortletInvocationResponse invoke(Instance instance, PortletInvocation
invocation) throws PortletInvokerException
+ {
+ return instance.invoke(invocation);
+ }
+
public Object renderWindow(RenderWindowCommand cmd) throws Exception
{
Window window = cmd.getWindow();
@@ -114,28 +119,21 @@
ServerConfig cfg =
context.getServerInvocation().getRequest().getServer().getConfig();
PortalObjectId windowId = window.getId();
StateString navigationalState =
(StateString)context.getAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE,
windowId);
-
- // Get mode and window state
String navStateKey = windowId + "_window";
WindowNavigationalState windowNavState =
(WindowNavigationalState)context.getAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE,
navStateKey);
+
+ //
if (windowNavState == null)
{
windowNavState = new WindowNavigationalState();
context.setAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE, navStateKey,
windowNavState);
}
+
+ //
Mode mode = windowNavState.getMode();
WindowState windowState = windowNavState.getWindowState();
//
- RenderInvocation invocation = PortletInvocationFactory.createRender(
- context,
- mode,
- windowState,
- navigationalState,
- window,
- portal);
-
- //
String windowTitle;
String contentChars;
String headerChars = null;
@@ -164,12 +162,20 @@
throw new ResourceNotFoundException(ref);
}
+ // Create invocation
+ RenderInvocation invocation = PortletInvocationFactory.createRender(
+ context,
+ mode,
+ windowState,
+ navigationalState,
+ window,
+ portal);
+
//
PortletInvocationResponse response;
try
{
- before(cmd, invocation);
- response = instance.invoke(invocation);
+ response = invoke(instance, invocation);
}
catch (PortletInvokerException e)
{
@@ -186,10 +192,6 @@
throw new ControllerException(e);
}
}
- finally
- {
- after(cmd, invocation);
- }
//
if (response instanceof FragmentResponse)
@@ -343,14 +345,6 @@
return null;
}
- protected void before(RenderWindowCommand cmd, PortletInvocation invocation)
- {
- }
-
- protected void after(RenderWindowCommand cmd, PortletInvocation invocation)
- {
- }
-
/**
* Create the action URLs for the allowed window states of the rendered portlet window
and add them to the provided
* actionMap.
Modified: trunk/core-cms/src/main/org/jboss/portal/core/cms/CMSConstants.java
===================================================================
--- trunk/core-cms/src/main/org/jboss/portal/core/cms/CMSConstants.java 2007-03-06
21:46:32 UTC (rev 6562)
+++ trunk/core-cms/src/main/org/jboss/portal/core/cms/CMSConstants.java 2007-03-06
21:50:33 UTC (rev 6563)
@@ -28,11 +28,5 @@
*/
public class CMSConstants
{
- /**
- * Property name for the server config which designates the value of the default
window reference for the
- * CMS integration by the command mapper.
- */
- public static final String DEFAULT_CMS_WINDOW_REF_CONFIG_PROPERTY_NAME =
"cms.default_window_ref";
-
public static final String SEARCH_ID = "CMS";
}
Modified: trunk/core-cms/src/main/org/jboss/portal/core/cms/CMSObjectCommandFactory.java
===================================================================
---
trunk/core-cms/src/main/org/jboss/portal/core/cms/CMSObjectCommandFactory.java 2007-03-06
21:46:32 UTC (rev 6562)
+++
trunk/core-cms/src/main/org/jboss/portal/core/cms/CMSObjectCommandFactory.java 2007-03-06
21:50:33 UTC (rev 6563)
@@ -60,6 +60,11 @@
/** . */
protected ServerConfig serverConfig;
+ public PortalObjectId getTargetWindowId()
+ {
+ return targetWindowId;
+ }
+
public CMS getCMSService()
{
return CMSService;
@@ -94,9 +99,6 @@
{
targetWindowId = PortalObjectId.parse(targetWindowRef,
PortalObjectId.LEGACY_FORMAT);
- // Update the config from the configuration
- serverConfig.setProperty(CMSConstants.DEFAULT_CMS_WINDOW_REF_CONFIG_PROPERTY_NAME,
targetWindowRef);
-
//
super.startService();
}
Modified:
trunk/core-cms/src/main/org/jboss/portal/core/cms/content/CMSContentRenderer.java
===================================================================
---
trunk/core-cms/src/main/org/jboss/portal/core/cms/content/CMSContentRenderer.java 2007-03-06
21:46:32 UTC (rev 6562)
+++
trunk/core-cms/src/main/org/jboss/portal/core/cms/content/CMSContentRenderer.java 2007-03-06
21:50:33 UTC (rev 6563)
@@ -22,98 +22,69 @@
******************************************************************************/
package org.jboss.portal.core.cms.content;
-import org.jboss.portal.core.impl.model.portal.content.PortletContentRenderer;
-import org.jboss.portal.core.model.instance.Instance;
-import org.jboss.portal.core.model.instance.InstanceContainer;
-import org.jboss.portal.core.model.portal.Window;
-import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.impl.model.portal.content.GenericPortletContentRenderer;
import org.jboss.portal.core.model.portal.command.RenderWindowCommand;
-import org.jboss.portal.core.cms.CMSConstants;
-import org.jboss.portal.core.cms.ui.CMSPortlet;
-import org.jboss.portal.core.controller.ControllerContext;
-import org.jboss.portal.portlet.PortletParametersStateString;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.server.config.ServerConfig;
-import org.jboss.portal.theme.page.WindowResult;
+import org.jboss.portal.core.model.portal.PortalObjectId;
-import java.util.HashMap;
-import java.util.Map;
+import javax.management.ObjectName;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class CMSContentRenderer extends PortletContentRenderer
+public class CMSContentRenderer extends GenericPortletContentRenderer
{
- protected Instance findInstance(RenderWindowCommand cmd)
+ /** . */
+ private static final ThreadLocal useGlobalURLLocal = new ThreadLocal();
+
+ public static boolean useGlobalURL()
{
- ControllerContext context = cmd.getControllerContext();
+ return Boolean.TRUE.equals(useGlobalURLLocal.get());
+ }
- // The window
- Window window = cmd.getWindow();
- PortalObjectId windowId = window.getId();
+ /** . */
+ private PortalObjectId targetWindowId;
- //
- CMSContent content = (CMSContent)window.getContent();
- String uri = content.getURI();
+ /** . */
+ private ObjectName commandFactory;
- // Initialize the navigational state with the URI when needed
- PortletParametersStateString navigationalState =
(PortletParametersStateString)context.getAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE,
windowId);
- if (navigationalState == null)
- {
- navigationalState = new PortletParametersStateString();
- navigationalState.setValue("path", uri);
- context.setAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE, windowId,
navigationalState);
- }
+ public ObjectName getCommandFactory()
+ {
+ return commandFactory;
+ }
- // Make that configurable
- InstanceContainer container = context.getController().getInstanceContainer();
- return container.getDefinition("CMSPortletInstance");
+ public void setCommandFactory(ObjectName commandFactory)
+ {
+ this.commandFactory = commandFactory;
}
- protected void before(RenderWindowCommand cmd, PortletInvocation invocation)
+ protected void startService() throws Exception
{
- // Find out if we are invoking the content portlet
- ServerConfig cfg =
cmd.getControllerContext().getServerInvocation().getRequest().getServer().getConfig();
+ targetWindowId = (PortalObjectId)server.getAttribute(commandFactory,
"TargetWindowId");
//
- Window window = cmd.getWindow();
-
- // Set the request property for it
- String windowRef =
cfg.getProperty(CMSConstants.DEFAULT_CMS_WINDOW_REF_CONFIG_PROPERTY_NAME);
- if (window.getId().toString(PortalObjectId.LEGACY_FORMAT).equals(windowRef))
- {
- invocation.setAttribute(PortletInvocation.REQUEST_PROPERTIES_SCOPE,
CMSPortlet.REQUEST_PROPERTY_USE_GLOBAL_URLS, "true");
- }
+ super.startService();
}
- protected void after(RenderWindowCommand cmd, PortletInvocation invocation)
- {
- // Cleanup request property
- invocation.removeAttribute(PortletInvocation.REQUEST_PROPERTIES_SCOPE,
CMSPortlet.REQUEST_PROPERTY_USE_GLOBAL_URLS);
- }
-
public Object renderWindow(RenderWindowCommand cmd) throws Exception
{
- Object o = super.renderWindow(cmd);
-
- //
- if (o instanceof WindowResult)
+ try
{
- WindowResult result = (WindowResult)o;
+ PortalObjectId windowId = cmd.getWindow().getId();
//
- Map props = new HashMap(result.getWindowProperties());
- props.put("theme.windowRendererId", "emptyRenderer");
- props.put("theme.decorationRendererId", "emptyRenderer");
- props.put("theme.portletRendererId", "emptyRenderer");
+ if (windowId.equals(targetWindowId))
+ {
+ useGlobalURLLocal.set(Boolean.TRUE);
+ }
//
- result.setWindowProperties(props);
+ return super.renderWindow(cmd);
}
-
- //
- return o;
+ finally
+ {
+ useGlobalURLLocal.set(null);
+ }
}
}
Modified: trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java
===================================================================
--- trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java 2007-03-06
21:46:32 UTC (rev 6562)
+++ trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java 2007-03-06
21:50:33 UTC (rev 6563)
@@ -37,6 +37,7 @@
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import javax.portlet.PortletMode;
import org.apache.log4j.Logger;
import org.jboss.portal.cms.CMS;
@@ -130,9 +131,6 @@
/** . */
private CMS CMSService;
-
- /** . */
- private String indexpage;
public void init() throws PortletException
{
@@ -159,8 +157,42 @@
}
}
- public void doView(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
+
+ protected void doDispatch(RenderRequest req, RenderResponse resp) throws
PortletException, PortletSecurityException, IOException
{
+ PortletMode portletMode = req.getPortletMode();
+ if ("view_content".equals(portletMode.toString()))
+ {
+ doViewContent(req, resp);
+ }
+ else
+ {
+ super.doDispatch(req, resp);
+ }
+ }
+
+ protected void doViewContent(RenderRequest req, RenderResponse resp) throws
PortletException, PortletSecurityException, IOException
+ {
+ String path = req.getParameter(RENDER_PARAMETER_PATH);
+ if (path != null)
+ {
+ display(req, resp, path);
+ }
+ else
+ {
+ doView(req, resp);
+ }
+ }
+
+ protected void doView(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
+ {
+ PortletPreferences prefs = req.getPreferences();
+ String indexpage = prefs.getValue("indexpage",
"/default/index.html");
+ display(req, resp, indexpage);
+ }
+
+ private void display(RenderRequest req, RenderResponse resp, String path) throws
PortletException, PortletSecurityException, IOException
+ {
String useGlobalURLs = req.getProperty(REQUEST_PROPERTY_USE_GLOBAL_URLS);
URLFactory textURLFactory = null;
if ("true".equals(useGlobalURLs))
@@ -175,41 +207,19 @@
URLFactory resourceURLFactory = new
GlobalURLFactory(((JBossRenderRequest)req).getControllerContext());
//
- String path;
- path = req.getParameter(RENDER_PARAMETER_PATH);
- if (path == null)
- {
- PortletPreferences prefs = req.getPreferences();
- indexpage = prefs.getValue("indexpage",
"/default/index.html");
- }
-
- //
try
{
// Get the file from the CMS, localized.
- Command fileGet;
- File file;
- if (path == null)
+ Command fileGet = CMSService.getCommandFactory().createFileGetCommand(path,
req.getLocale());
+ File file = (File)CMSService.execute(fileGet);
+
+ //
+ if (file == null)
{
- fileGet = CMSService.getCommandFactory().createFileGetCommand(indexpage,
req.getLocale());
+ fileGet = CMSService.getCommandFactory().createFileGetCommand(path, new
Locale(CMSService.getDefaultLocale()));
file = (File)CMSService.execute(fileGet);
- if (file == null)
- {
- fileGet = CMSService.getCommandFactory().createFileGetCommand(indexpage,
new Locale(CMSService.getDefaultLocale()));
- file = (File)CMSService.execute(fileGet);
- }
}
- else
- {
- fileGet = CMSService.getCommandFactory().createFileGetCommand(path,
req.getLocale());
- file = (File)CMSService.execute(fileGet);
- if (file == null)
- {
- fileGet = CMSService.getCommandFactory().createFileGetCommand(path, new
Locale(CMSService.getDefaultLocale()));
- file = (File)CMSService.execute(fileGet);
- }
- }
// Translate links to resources.
String sHTML = null;
Modified: trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml 2007-03-06
21:46:32 UTC (rev 6562)
+++ trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml 2007-03-06
21:50:33 UTC (rev 6563)
@@ -702,9 +702,12 @@
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
<attribute name="ContentType">cms</attribute>
+ <attribute name="DecorateContent">false</attribute>
+ <attribute
name="InstanceName">CMSPortletInstance</attribute>
<depends
optional-attribute-name="Registry"
proxy-type="attribute">portal:service=ContentRendererRegistry</depends>
+ <depends
optional-attribute-name="CommandFactory">portal:commandFactory=CMSObject</depends>
</mbean>
<!-- Content handler integration -->