[jboss-svn-commits] JBoss Portal SVN: r5342 - in trunk/core/src/main/org/jboss/portal/core: aspects/controller controller/command
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Oct 6 13:31:26 EDT 2006
Author: julien at jboss.com
Date: 2006-10-06 13:31:22 -0400 (Fri, 06 Oct 2006)
New Revision: 5342
Removed:
trunk/core/src/main/org/jboss/portal/core/controller/command/MarkupCommand.java
Modified:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageNavigationInterceptor.java
trunk/core/src/main/org/jboss/portal/core/controller/command/RenderPageCommand.java
Log:
bilto simplification
Modified: trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageNavigationInterceptor.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageNavigationInterceptor.java 2006-10-06 17:18:48 UTC (rev 5341)
+++ trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageNavigationInterceptor.java 2006-10-06 17:31:22 UTC (rev 5342)
@@ -8,8 +8,8 @@
import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.controller.ControllerInterceptor;
import org.jboss.portal.core.controller.ControllerCommand;
-import org.jboss.portal.core.controller.command.MarkupCommand;
import org.jboss.portal.core.controller.command.PortalObjectCommand;
+import org.jboss.portal.core.controller.command.RenderPageCommand;
import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.Portal;
import org.jboss.portal.core.model.portal.PortalObject;
@@ -156,7 +156,7 @@
private static PortalLayout getLayout(LayoutService layoutService, Page page)
{
- return MarkupCommand.getLayout(layoutService, page);
+ return RenderPageCommand.getLayout(layoutService, page);
}
private static void processResponse(AttributeResolver navCtx, PageNavigationalState pageNavState, StrategyResponse strategyResponse, PortalLayout layout)
Deleted: trunk/core/src/main/org/jboss/portal/core/controller/command/MarkupCommand.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/command/MarkupCommand.java 2006-10-06 17:18:48 UTC (rev 5341)
+++ trunk/core/src/main/org/jboss/portal/core/controller/command/MarkupCommand.java 2006-10-06 17:31:22 UTC (rev 5342)
@@ -1,691 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., 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.controller.command;
-
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-import org.jboss.portal.common.invocation.AttributeResolver;
-import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.portal.common.util.Exceptions;
-import org.jboss.portal.core.controller.command.info.CommandInfo;
-import org.jboss.portal.core.controller.command.info.ViewCommandInfo;
-import org.jboss.portal.core.controller.ControllerException;
-import org.jboss.portal.core.controller.ResourceNotFoundException;
-import org.jboss.portal.core.controller.ControllerSecurityException;
-import org.jboss.portal.core.controller.ControllerCommand;
-import org.jboss.portal.core.controller.ControllerContext;
-import org.jboss.portal.core.controller.InsufficientTransportGuaranteeException;
-import org.jboss.portal.core.controller.ResourceAccessDeniedException;
-import org.jboss.portal.core.model.instance.Instance;
-import org.jboss.portal.core.model.portal.Page;
-import org.jboss.portal.core.model.portal.PortalObject;
-import org.jboss.portal.core.model.portal.PortalObjectPermission;
-import org.jboss.portal.core.model.portal.Window;
-import org.jboss.portal.core.model.portal.Portal;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.portlet.Properties;
-import org.jboss.portal.portlet.info.ModeInfo;
-import org.jboss.portal.portlet.info.WindowStateInfo;
-import org.jboss.portal.portlet.result.ErrorResult;
-import org.jboss.portal.portlet.result.FragmentResult;
-import org.jboss.portal.portlet.result.InsufficientPrivilegesResult;
-import org.jboss.portal.portlet.result.InsufficientTransportGuaranteeResult;
-import org.jboss.portal.portlet.result.Result;
-import org.jboss.portal.portlet.result.UnavailableResult;
-import org.jboss.portal.security.PortalSecurityException;
-import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
-import org.jboss.portal.server.ServerInvocation;
-import org.jboss.portal.server.ServerInvocationContext;
-import org.jboss.portal.server.request.URLContext;
-import org.jboss.portal.server.request.URLFormat;
-import org.jboss.portal.server.config.ServerConfig;
-import org.jboss.portal.theme.LayoutService;
-import org.jboss.portal.theme.PortalLayout;
-import org.jboss.portal.theme.PortalTheme;
-import org.jboss.portal.theme.ServerRegistrationID;
-import org.jboss.portal.theme.ThemeConstants;
-import org.jboss.portal.theme.ThemeResult;
-import org.jboss.portal.theme.ThemeService;
-import org.jboss.portal.theme.PageRendition;
-import org.jboss.portal.theme.navigation.PageNavigationalState;
-import org.jboss.portal.theme.navigation.WindowNavigationalState;
-import org.jboss.portal.theme.page.ModifiableWindowResult;
-import org.jboss.portal.theme.page.PageService;
-import org.jboss.portal.theme.page.WindowResult;
-import org.jboss.portal.theme.render.MarkupResult;
-
-import javax.servlet.http.HttpServletRequest;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-/**
- * Abstract base class for portal object commands that produce markup (of a page, region, window). <p>This command
- * contains all the shared functionality amongst all commands that create page , or page fragment markup, like the
- * RenderPageCommand and the RenderRegionCommand.</p>
- *
- * @author <a href="mailto:mholzner at novell.com">Martin Holzner</a>
- * @version $Revision$
- */
-public abstract class MarkupCommand extends PortalObjectCommand
-{
-
- /** . */
- private static String WINDOW_ACCESS_DENIED = "core.render.window_access_denied";
-
- /** . */
- private static String WINDOW_UNAVAILABLE = "core.render.window_unavailable";
-
- /** . */
- private static String WINDOW_ERROR = "core.render.window_error";
-
- /** . */
- private static String WINDOW_INTERNAL_ERROR = "core.render.window_internal_error";
-
- /** . */
- private static String WINDOW_NOT_FOUND = "core.render.window_not_found";
-
- /** . */
- private static String HIDE = "hide";
-
- /** . */
- private static String SHOW = "show";
-
- /** . */
- private static final CommandInfo info = new ViewCommandInfo(false, "view");
-
- /** . */
- private final String pageRef;
-
- /** . */
- private final Object markupContainer;
-
- /** . */
- private Portal portal;
-
- /** . */
- private Page page;
-
- /** . */
- private PortalLayout layout;
-
- /** . */
- private boolean personalizable;
-
- /** . */
- private PageRendition result;
-
- /**
- * render the entire page
- *
- * @param pageRef the page idenitifier of the page to render
- */
- public MarkupCommand(String pageRef)
- {
- this(pageRef, null);
- }
-
- /**
- * render a fragment on the page (a region or a window on the page)
- *
- * @param pageRef the page idenitifier of the page to render
- * @param markupContainer the fragment to render (the region or the window); if the argument is null, the entire page
- * will be rendered
- */
- public MarkupCommand(String pageRef, Object markupContainer)
- {
- if (pageRef == null)
- {
- throw new IllegalArgumentException();
- }
- this.pageRef = pageRef;
- this.markupContainer = markupContainer;
- }
-
- /**
- * call the component invocation(s) to create the markup fragment(s) for this request
- *
- * @param cfg the server config to get config information (for error behaviour )
- * @param navCtx the navigational state context to get to the window navigational state
- * @return a markup result containing the fragments rendered by the portlets in this command
- * @throws InvocationException
- */
- public abstract MarkupResult renderFragments(ServerConfig cfg, AttributeResolver navCtx) throws ControllerException;
-
- /**
- * for security checks and navigational state, return the page of the requested MarkupContainer
- *
- * @return the requested page (or the page of the requested region or window)
- */
- public PortalObject getTarget()
- {
- return page;
- }
-
- /**
- * Get the command info (runtime info about the command)
- *
- * @return info about the command
- */
- public CommandInfo getInfo()
- {
- return info;
- }
-
- /**
- * Get the identifier of the requeste page
- *
- * @return the identifier of the requeste page
- */
- public String getPageRef()
- {
- return pageRef;
- }
-
- /**
- * Get the requeste page
- *
- * @return the requested page
- */
- public Page getPage()
- {
- return page;
- }
-
- /**
- * Get the layout that was determined for this request (based on portal and page properties)
- *
- * @return the layout to use for this request
- */
- public PortalLayout getLayout()
- {
- return layout;
- }
-
- /**
- * Get the fragment identifier of the page fragment that was requested
- *
- * @return the region or window to render as part of this request
- */
- public Object getMarkupContainer()
- {
- return markupContainer;
- }
-
- public PageRendition getResult()
- {
- return result;
- }
-
- /**
- * initialize the command
- *
- * @throws InvocationException
- */
- public void create() throws ControllerException
- {
- // Get page
- page = (Page)context.getController().getPortalObjectContainer().getObject(pageRef);
- if (page == null)
- {
- throw new ResourceNotFoundException(pageRef);
- }
-
- // Get nearest portal ancestor
- portal = page.getPortal();
- if (portal == null)
- {
- throw new ResourceNotFoundException("Portal for " + pageRef);
- }
-
- //
- LayoutService layoutService = context.getController().getPageService().getLayoutService();
- layout = getLayout(layoutService, page);
- }
-
- public void enforceSecurity(PortalAuthorizationManager pam) throws ControllerSecurityException, PortalSecurityException
- {
- //
- super.enforceSecurity(pam);
-
- // Check if the user can personalize the page
- String uri = page.getId();
- PortalObjectPermission perm = new PortalObjectPermission(uri, PortalObjectPermission.PERSONALIZE_MASK);
- personalizable = pam.checkPermission(perm);
- }
-
- /**
- * execute the command
- *
- * @throws InvocationException
- */
- public final void execute() throws ControllerException, InvocationException
- {
- ServerInvocation sinv = context.getServerInvocation();
- HttpServletRequest request = sinv.getServerContext().getClientRequest();
- try
- {
- // Ensure that the page nav state is in place
- AttributeResolver navCtx = sinv.getContext().getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE);
- PageNavigationalState pageNavState = (PageNavigationalState)navCtx.getAttribute(page.getId());
-
- if (pageNavState == null)
- {
- throw new InvocationException("PageNavigationalState not available in NavigationalStateContext");
- }
-
- //
- PageService pageService = context.getController().getPageService();
- PortalTheme theme = null;
-
- if (personalizable)
- {
- ControllerContext controllerCtx = (ControllerContext)getContext();
- User user = (User)controllerCtx.getServerInvocation().getRequest().getUser();
- if (user != null)
- {
- String themeId = user.getTheme();
- if (themeId != null)
- {
- theme = getTheme(themeId);
- }
- }
- }
-
- // If nothing get it from the object properties
- if (theme == null)
- {
- String themeId = page.getProperty(ThemeConstants.PORTAL_PROP_THEME);
- theme = getTheme(themeId);
- }
-
- // Call the portlet container to create the markup fragment(s) for each portlet that needs to render itself
- ServerConfig cfg = sinv.getRequest().getServer().getConfig();
- MarkupResult renderResult = renderFragments(cfg, navCtx);
-
- // Make the theme available as servlet request attribute (needed for CM)
- if(theme != null)
- {
- // render the theme markup and place it into the request so that the markup assembler (theme tag) can pick it up there
- ThemeResult themeResult = theme.assembleResponse(sinv.getRequest(), sinv.getResponse());
-// request.setAttribute(ThemeConstants.ATTR_THEMERESULT, themeResult);
-// request.setAttribute(ThemeConstants.ATTR_THEME, theme);
- renderResult.setTheme(theme);
- renderResult.setThemeResult(themeResult);
-
- //
- result = new PageRendition(layout, pageNavState, renderResult, pageService);
- }
- }
- catch (Exception e)
- {
- ControllerCommand.rethrow(e);
- }
- finally
- {
- request.removeAttribute(ThemeConstants.ATTR_THEMESERVER);
- request.removeAttribute(ThemeConstants.ATTR_THEME);
- request.removeAttribute(ThemeConstants.ATTR_THEMERESULT);
- }
- }
-
- private PortalTheme getTheme(String themeIdString)
- {
- //
- ThemeService service = context.getController().getPageService().getThemeService();
-
- // If the id is provided in the form of context.name then look up the theme via a registration id
- if (themeIdString.lastIndexOf(".") > 0)
- {
- ServerRegistrationID themeId = ServerRegistrationID.createID(ServerRegistrationID.TYPE_THEME, parseID(themeIdString));
- return service.getTheme(themeId, true);
- }
- else
- {
- // Otherwise use the ordinary theme name provided and lookup the theme via the name
- return service.getTheme(themeIdString, true);
- }
- }
-
- /**
- * Get the portal layout to use for the provided page. <p>The name of the layout to use can be defined as a property
- * in the portal, or the individual page. The page property overwrites the portal property. If no property was set, a
- * default layout with the name "nodesk" is assumed.</p>
- *
- * @param layoutService the layout service that allows access to the layout
- * @param page the page that hosts the markup container to render (the page, region, window,...)
- * @return a <code>PortalLayout</code> for the defined layout name
- */
- public static PortalLayout getLayout(LayoutService layoutService, Page page)
- {
- String layoutIDString = page.getProperty(ThemeConstants.PORTAL_PROP_LAYOUT);
-
- // Last resort: use the nodesk layout
- if (layoutIDString == null)
- {
- layoutIDString = "nodesk";
- }
-
- //
- PortalLayout layout = null;
- if (layoutIDString.lastIndexOf(".") > 0)
- {
- // if the id is provided in the form of context.name then look up the layout via a registration id
- ServerRegistrationID layoutID = ServerRegistrationID.createID(ServerRegistrationID.TYPE_LAYOUT, parseID(layoutIDString));
- layout = layoutService.getLayout(layoutID, true);
- }
- else
- {
- // otherwise use the ordinary layout name provided and lookup the layout via the name
- layout = layoutService.getLayout(layoutIDString, true);
- }
-
- // We don't like that situation
- if (layout == null)
- {
- throw new IllegalStateException("NO LAYOUT FOUND FOR " + layoutIDString);
- }
-
- //
- return layout;
- }
-
- /**
- * Call the component container to render the markup fragment of a window
- *
- * @param cfg the server config to get information about the error behaviour
- * @param window the window to render
- * @return a result containing markup, or other result information (redirect url, etc.)
- * @throws InvocationException
- */
- protected MarkupResult renderPortletWindow(ServerConfig cfg, Window window) throws ControllerException
- {
- // Execute render command
- String windowRef = window.getId();
-
- //
- String windowTitle;
- String contentChars = "";
- String headerChars = null;
- Map actionMap = new HashMap();
- Properties responseProps;
- Map windowProps = window.getDeclaredProperties();
- WindowNavigationalState windowNavState = (WindowNavigationalState)this.context.getAttribute(ControllerCommand.NAVIGATIONAL_STATE_SCOPE, window.getId() + "_window");
-
- try
- {
- RenderWindowCommand renderCmd = new RenderWindowCommand(windowRef);
-
- //
- context.execute(renderCmd);
- Result result = renderCmd.getResult();
-
- //
- if (result instanceof InsufficientTransportGuaranteeResult)
- {
- throw new InsufficientTransportGuaranteeException();
- }
-
- //
- if (result instanceof FragmentResult)
- {
- FragmentResult fragment = (FragmentResult)result;
- windowTitle = fragment.getTitle();
- if (windowTitle == null)
- {
- windowTitle = window.getName();
- }
- headerChars = fragment.getHeader();
- responseProps = fragment.getProperties();
-
- //
- Instance instance = renderCmd.getInstance();
-
- //
- List supportedWindowStates = new ArrayList();
- for (Iterator i = instance.getPortlet().getInfo().getCapabilities().getAllWindowStates().iterator(); i.hasNext();)
- {
- WindowStateInfo windowStateInfo = (WindowStateInfo)i.next();
- WindowState windowState = windowStateInfo.getWindowState();
- if (portal.getSupportedWindowStates().contains(windowState))
- {
- supportedWindowStates.add(windowState);
- }
- }
-
- //
- List supportedModes = new ArrayList();
- for (Iterator i = instance.getPortlet().getInfo().getCapabilities().getAllModes().iterator(); i.hasNext();)
- {
- ModeInfo modeInfo = (ModeInfo)i.next();
- Mode mode = modeInfo.getMode();
- if (portal.getSupportedModes().contains(mode))
- {
- supportedModes.add(mode);
- }
- }
-
- // Remove edit mode if the user is not logged it
- // commenting out for now since it breaks the tests
- if (getControllerContext().getServerInvocation().getServerContext().getClientRequest().getUserPrincipal() == null)
- {
- supportedModes.remove(Mode.EDIT);
- }
-
- //
- addModeActions(window, actionMap, windowNavState.getMode(), supportedModes);
-
- //
- addStateActions(window, actionMap, windowNavState.getWindowState(), supportedWindowStates);
-
- switch (fragment.getType())
- {
- case FragmentResult.TYPE_CHARS:
- contentChars = fragment.getChars().toString();
- break;
- case FragmentResult.TYPE_BYTES:
- // Funny for now we don't know how to interpret that or we should not
- // because it is for some kind of flash portal ?
- contentChars = fragment.getBytes().toString();
- break;
- case FragmentResult.TYPE_EMPTY:
- // Do nothing, the contentChars is already empty string
- break;
- }
- return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
- }
- else if (result instanceof ErrorResult)
- {
- ErrorResult errorResult = (ErrorResult)result;
- String logMessage = "Rendering portlet window " + windowRef + " triggered the following error :";
- errorResult.logErrorTo(ControllerCommand.log, logMessage);
- String property = cfg.getProperty(WINDOW_ERROR);
- if (!HIDE.equals(property))
- {
- windowTitle = "An error occured while rendering window '" + windowRef + "'";
- responseProps = new Properties();
- contentChars = errorResult.getMessage();
- Throwable t = errorResult.getThrowable();
- if (t != null && SHOW.equals(property))
- {
- contentChars = Exceptions.toHTML(t, true);
- }
- return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
- }
- }
- else if (result instanceof UnavailableResult)
- {
- if (SHOW.equals(cfg.getProperty(WINDOW_UNAVAILABLE)))
- {
- windowTitle = "Portlet unavailable";
- contentChars = "Portlet unavailable";
- actionMap = new HashMap();
- actionMap.put(WindowResult.MODES_KEY, Collections.EMPTY_LIST);
- actionMap.put(WindowResult.WINDOWSTATES_KEY, Collections.EMPTY_LIST);
- responseProps = new Properties();
- return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
- }
- }
- else if (result instanceof InsufficientPrivilegesResult)
- {
- // Julien : go to the section below, I know it is very ugly
- throw new ResourceAccessDeniedException(windowRef);
- }
- else
- {
- ControllerCommand.log.error("Unexpected result from a portlet invocation " + result);
- return null;
- }
- }
- catch (ResourceAccessDeniedException e)
- {
- if (ControllerCommand.log.isTraceEnabled())
- {
- ControllerCommand.log.trace("Window access denied", e);
- }
- if (SHOW.equals(cfg.getProperty(WINDOW_ACCESS_DENIED)))
- {
- actionMap.put(WindowResult.MODES_KEY, Collections.EMPTY_LIST);
- actionMap.put(WindowResult.WINDOWSTATES_KEY, Collections.EMPTY_LIST);
- windowTitle = "Access denied";
- contentChars = "Access denied";
- responseProps = new Properties();
- return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
- }
- }
- catch (ResourceNotFoundException e)
- {
- if (ControllerCommand.log.isTraceEnabled())
- {
- ControllerCommand.log.trace("Window not found", e);
- }
- if (SHOW.equals(cfg.getProperty(WINDOW_NOT_FOUND)))
- {
- actionMap.put(WindowResult.MODES_KEY, Collections.EMPTY_LIST);
- actionMap.put(WindowResult.WINDOWSTATES_KEY, Collections.EMPTY_LIST);
- windowTitle = "Cannot render";
- contentChars = "Object not found " + e.getRef();
- responseProps = new Properties();
- return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
- }
- }
- catch (ControllerException e)
- {
- // It's a CommandException that we rethrow
- throw e;
- }
- catch (Exception e)
- {
- ControllerCommand.log.error("Rendering portlet window " + windowRef + " produced an internal error", e);
- String property = cfg.getProperty(WINDOW_INTERNAL_ERROR);
- if (SHOW.equals(property))
- {
- windowTitle = "An internal error occured while rendering window '" + window + "'";
- responseProps = new Properties();
- contentChars = Exceptions.toHTML(e, true);
- return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
- }
- }
-
- return null;
- }
-
- /**
- * parse the provided String for '.' as a separator. For each token, add an entry to a String[] that will be returned
- * as the result
- *
- * @param layoutIDString the string to be examined
- * @return an array of Strings
- */
- private static String[] parseID(String layoutIDString)
- {
- List names = new ArrayList();
- StringTokenizer tokens = new StringTokenizer(layoutIDString, ".");
- if (tokens.countTokens() > 1)
- {
- while (tokens.hasMoreElements())
- {
- names.add(tokens.nextToken());
- }
- }
- else
- {
- names.add(layoutIDString);
- }
-
- String[] id = new String[names.size()];
- names.toArray(id);
- return id;
- }
-
- /**
- * Create the action URLs for the allowed window states of the rendered portlet window and add them to the provided
- * actionMap.
- */
- private void addStateActions(Window window, Map actionMap, WindowState currentWindowState, List supportedWindowStates)
- {
- List windowStates = new ArrayList(supportedWindowStates.size());
- for (Iterator j = supportedWindowStates.iterator(); j.hasNext();)
- {
- WindowState windowState = (WindowState)j.next();
- String url = createUpdateNavigationalStateURL(window, null, windowState);
- boolean disabled = windowState.equals(currentWindowState);
- WindowResult.Action action = new WindowResult.Action(windowState, url, !disabled);
- windowStates.add(action);
- }
- actionMap.put(WindowResult.WINDOWSTATES_KEY, windowStates);
- }
-
- /**
- * Create the action URLs for the allowed portlet modes of the rendered portlet window and add them to the provided
- * actionMap.
- */
- private void addModeActions(Window window, Map actionMap, Mode currentMode, List supportedModes)
- {
- List modes = new ArrayList(supportedModes.size());
- for (Iterator j = supportedModes.iterator(); j.hasNext();)
- {
- Mode mode = (Mode)j.next();
- String url = createUpdateNavigationalStateURL(window, mode, null);
- boolean disabled = mode.equals(currentMode);
- WindowResult.Action action = new WindowResult.Action(mode, url, !disabled);
- modes.add(action);
- }
- actionMap.put(WindowResult.MODES_KEY, modes);
- }
-
- public String createUpdateNavigationalStateURL(Window window, Mode mode, WindowState windowState)
- {
- InvokeWindowRenderCommand cmd = new InvokeWindowRenderCommand(window.getId(), mode, windowState);
- ControllerContext controllerContext = getControllerContext();
- ServerInvocationContext serverContext = controllerContext.getServerInvocation().getServerContext();
- boolean secure = serverContext.getURLContext().getSecure();
- boolean authenticated = serverContext.getURLContext().isAuthenticated();
- URLContext urlContext = URLContext.newInstance(secure, authenticated);
- return controllerContext.encodeURL(cmd, urlContext, URLFormat.newInstance(true, true));
- }
-
-}
Modified: trunk/core/src/main/org/jboss/portal/core/controller/command/RenderPageCommand.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/command/RenderPageCommand.java 2006-10-06 17:18:48 UTC (rev 5341)
+++ trunk/core/src/main/org/jboss/portal/core/controller/command/RenderPageCommand.java 2006-10-06 17:31:22 UTC (rev 5342)
@@ -23,17 +23,66 @@
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.common.invocation.AttributeResolver;
+import org.jboss.portal.common.util.Exceptions;
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.model.portal.Portal;
+import org.jboss.portal.core.model.portal.Page;
+import org.jboss.portal.core.model.portal.PortalObjectPermission;
+import org.jboss.portal.core.model.instance.Instance;
import org.jboss.portal.core.controller.ControllerException;
+import org.jboss.portal.core.controller.ResourceNotFoundException;
+import org.jboss.portal.core.controller.ControllerSecurityException;
+import org.jboss.portal.core.controller.ControllerCommand;
+import org.jboss.portal.core.controller.ControllerContext;
+import org.jboss.portal.core.controller.InsufficientTransportGuaranteeException;
+import org.jboss.portal.core.controller.ResourceAccessDeniedException;
+import org.jboss.portal.core.controller.command.info.CommandInfo;
+import org.jboss.portal.core.controller.command.info.ViewCommandInfo;
import org.jboss.portal.server.config.ServerConfig;
+import org.jboss.portal.server.ServerInvocation;
+import org.jboss.portal.server.ServerInvocationContext;
+import org.jboss.portal.server.request.URLContext;
+import org.jboss.portal.server.request.URLFormat;
import org.jboss.portal.theme.navigation.PageNavigationalState;
+import org.jboss.portal.theme.navigation.WindowNavigationalState;
import org.jboss.portal.theme.page.ModifiablePageResult;
import org.jboss.portal.theme.page.WindowResult;
+import org.jboss.portal.theme.page.PageService;
+import org.jboss.portal.theme.page.ModifiableWindowResult;
import org.jboss.portal.theme.render.MarkupResult;
+import org.jboss.portal.theme.PortalLayout;
+import org.jboss.portal.theme.PageRendition;
+import org.jboss.portal.theme.LayoutService;
+import org.jboss.portal.theme.PortalTheme;
+import org.jboss.portal.theme.ThemeConstants;
+import org.jboss.portal.theme.ThemeResult;
+import org.jboss.portal.theme.ThemeService;
+import org.jboss.portal.theme.ServerRegistrationID;
+import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
+import org.jboss.portal.security.PortalSecurityException;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.portlet.Properties;
+import org.jboss.portal.portlet.info.WindowStateInfo;
+import org.jboss.portal.portlet.info.ModeInfo;
+import org.jboss.portal.portlet.result.Result;
+import org.jboss.portal.portlet.result.InsufficientTransportGuaranteeResult;
+import org.jboss.portal.portlet.result.FragmentResult;
+import org.jboss.portal.portlet.result.ErrorResult;
+import org.jboss.portal.portlet.result.UnavailableResult;
+import org.jboss.portal.portlet.result.InsufficientPrivilegesResult;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
+import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.Iterator;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.StringTokenizer;
/**
* Render a full page.
@@ -41,14 +90,62 @@
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision$
*/
-public final class RenderPageCommand extends MarkupCommand
+public final class RenderPageCommand extends PortalObjectCommand
{
+
+ /** . */
+ private static String WINDOW_ACCESS_DENIED = "core.render.window_access_denied";
+
+ /** . */
+ private static String WINDOW_UNAVAILABLE = "core.render.window_unavailable";
+
+ /** . */
+ private static String WINDOW_ERROR = "core.render.window_error";
+
+ /** . */
+ private static String WINDOW_INTERNAL_ERROR = "core.render.window_internal_error";
+
+ /** . */
+ private static String WINDOW_NOT_FOUND = "core.render.window_not_found";
+
+ /** . */
+ private static String HIDE = "hide";
+
+ /** . */
+ private static String SHOW = "show";
+
+ /** . */
+ private static final CommandInfo info = new ViewCommandInfo(false, "view");
+
+ /** . */
+ private final String pageRef;
+
+ /** . */
+ private Portal portal;
+
+ /** . */
+ private Page page;
+
+ /** . */
+ private PortalLayout layout;
+
+ /** . */
+ private boolean personalizable;
+
+ /** . */
+ private PageRendition result;
+
public RenderPageCommand(String pageRef)
{
- super(pageRef);
+ if (pageRef == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.pageRef = pageRef;
}
/**
+ * Call the component invocation(s) to create the markup fragment(s) for this request
* Call the component / portlet invocation for each window on the page, and create a markup result with the resulting markup fragments in it
*
* @param cfg the server configuration to get access to customizable error behaviour
@@ -89,4 +186,507 @@
return pageResult;
}
+
+ /**
+ * for security checks and navigational state, return the page of the requested MarkupContainer
+ *
+ * @return the requested page (or the page of the requested region or window)
+ */
+ public PortalObject getTarget()
+ {
+ return page;
+ }
+
+ /**
+ * Get the command info (runtime info about the command)
+ *
+ * @return info about the command
+ */
+ public CommandInfo getInfo()
+ {
+ return info;
+ }
+
+ /**
+ * Get the identifier of the requeste page
+ *
+ * @return the identifier of the requeste page
+ */
+ public String getPageRef()
+ {
+ return pageRef;
+ }
+
+ /**
+ * Get the requeste page
+ *
+ * @return the requested page
+ */
+ public Page getPage()
+ {
+ return page;
+ }
+
+ /**
+ * Get the layout that was determined for this request (based on portal and page properties)
+ *
+ * @return the layout to use for this request
+ */
+ public PortalLayout getLayout()
+ {
+ return layout;
+ }
+
+ public PageRendition getResult()
+ {
+ return result;
+ }
+
+ /**
+ * initialize the command
+ *
+ * @throws InvocationException
+ */
+ public void create() throws ControllerException
+ {
+ // Get page
+ page = (Page)context.getController().getPortalObjectContainer().getObject(pageRef);
+ if (page == null)
+ {
+ throw new ResourceNotFoundException(pageRef);
+ }
+
+ // Get nearest portal ancestor
+ portal = page.getPortal();
+ if (portal == null)
+ {
+ throw new ResourceNotFoundException("Portal for " + pageRef);
+ }
+
+ //
+ LayoutService layoutService = context.getController().getPageService().getLayoutService();
+ layout = getLayout(layoutService, page);
+ }
+
+ public void enforceSecurity(PortalAuthorizationManager pam) throws ControllerSecurityException, PortalSecurityException
+ {
+ //
+ super.enforceSecurity(pam);
+
+ // Check if the user can personalize the page
+ String uri = page.getId();
+ PortalObjectPermission perm = new PortalObjectPermission(uri, PortalObjectPermission.PERSONALIZE_MASK);
+ personalizable = pam.checkPermission(perm);
+ }
+
+ /**
+ * execute the command
+ *
+ * @throws InvocationException
+ */
+ public final void execute() throws ControllerException, InvocationException
+ {
+ ServerInvocation sinv = context.getServerInvocation();
+ HttpServletRequest request = sinv.getServerContext().getClientRequest();
+ try
+ {
+ // Ensure that the page nav state is in place
+ AttributeResolver navCtx = sinv.getContext().getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE);
+ PageNavigationalState pageNavState = (PageNavigationalState)navCtx.getAttribute(page.getId());
+
+ if (pageNavState == null)
+ {
+ throw new InvocationException("PageNavigationalState not available in NavigationalStateContext");
+ }
+
+ //
+ PageService pageService = context.getController().getPageService();
+ PortalTheme theme = null;
+
+ if (personalizable)
+ {
+ ControllerContext controllerCtx = (ControllerContext)getContext();
+ User user = (User)controllerCtx.getServerInvocation().getRequest().getUser();
+ if (user != null)
+ {
+ String themeId = user.getTheme();
+ if (themeId != null)
+ {
+ theme = getTheme(themeId);
+ }
+ }
+ }
+
+ // If nothing get it from the object properties
+ if (theme == null)
+ {
+ String themeId = page.getProperty(ThemeConstants.PORTAL_PROP_THEME);
+ theme = getTheme(themeId);
+ }
+
+ // Call the portlet container to create the markup fragment(s) for each portlet that needs to render itself
+ ServerConfig cfg = sinv.getRequest().getServer().getConfig();
+ MarkupResult renderResult = renderFragments(cfg, navCtx);
+
+ // Make the theme available as servlet request attribute (needed for CM)
+ if(theme != null)
+ {
+ // render the theme markup and place it into the request so that the markup assembler (theme tag) can pick it up there
+ ThemeResult themeResult = theme.assembleResponse(sinv.getRequest(), sinv.getResponse());
+// request.setAttribute(ThemeConstants.ATTR_THEMERESULT, themeResult);
+// request.setAttribute(ThemeConstants.ATTR_THEME, theme);
+ renderResult.setTheme(theme);
+ renderResult.setThemeResult(themeResult);
+
+ //
+ result = new PageRendition(layout, pageNavState, renderResult, pageService);
+ }
+ }
+ catch (Exception e)
+ {
+ ControllerCommand.rethrow(e);
+ }
+ finally
+ {
+ request.removeAttribute(ThemeConstants.ATTR_THEMESERVER);
+ request.removeAttribute(ThemeConstants.ATTR_THEME);
+ request.removeAttribute(ThemeConstants.ATTR_THEMERESULT);
+ }
+ }
+
+ private PortalTheme getTheme(String themeIdString)
+ {
+ //
+ ThemeService service = context.getController().getPageService().getThemeService();
+
+ // If the id is provided in the form of context.name then look up the theme via a registration id
+ if (themeIdString.lastIndexOf(".") > 0)
+ {
+ ServerRegistrationID themeId = ServerRegistrationID.createID(ServerRegistrationID.TYPE_THEME, parseID(themeIdString));
+ return service.getTheme(themeId, true);
+ }
+ else
+ {
+ // Otherwise use the ordinary theme name provided and lookup the theme via the name
+ return service.getTheme(themeIdString, true);
+ }
+ }
+
+ /**
+ * Get the portal layout to use for the provided page. <p>The name of the layout to use can be defined as a property
+ * in the portal, or the individual page. The page property overwrites the portal property. If no property was set, a
+ * default layout with the name "nodesk" is assumed.</p>
+ *
+ * @param layoutService the layout service that allows access to the layout
+ * @param page the page that hosts the markup container to render (the page, region, window,...)
+ * @return a <code>PortalLayout</code> for the defined layout name
+ */
+ public static PortalLayout getLayout(LayoutService layoutService, Page page)
+ {
+ String layoutIDString = page.getProperty(ThemeConstants.PORTAL_PROP_LAYOUT);
+
+ // Last resort: use the nodesk layout
+ if (layoutIDString == null)
+ {
+ layoutIDString = "nodesk";
+ }
+
+ //
+ PortalLayout layout = null;
+ if (layoutIDString.lastIndexOf(".") > 0)
+ {
+ // if the id is provided in the form of context.name then look up the layout via a registration id
+ ServerRegistrationID layoutID = ServerRegistrationID.createID(ServerRegistrationID.TYPE_LAYOUT, parseID(layoutIDString));
+ layout = layoutService.getLayout(layoutID, true);
+ }
+ else
+ {
+ // otherwise use the ordinary layout name provided and lookup the layout via the name
+ layout = layoutService.getLayout(layoutIDString, true);
+ }
+
+ // We don't like that situation
+ if (layout == null)
+ {
+ throw new IllegalStateException("NO LAYOUT FOUND FOR " + layoutIDString);
+ }
+
+ //
+ return layout;
+ }
+
+ /**
+ * Call the component container to render the markup fragment of a window
+ *
+ * @param cfg the server config to get information about the error behaviour
+ * @param window the window to render
+ * @return a result containing markup, or other result information (redirect url, etc.)
+ * @throws InvocationException
+ */
+ protected MarkupResult renderPortletWindow(ServerConfig cfg, Window window) throws ControllerException
+ {
+ // Execute render command
+ String windowRef = window.getId();
+
+ //
+ String windowTitle;
+ String contentChars = "";
+ String headerChars = null;
+ Map actionMap = new HashMap();
+ Properties responseProps;
+ Map windowProps = window.getDeclaredProperties();
+ WindowNavigationalState windowNavState = (WindowNavigationalState)this.context.getAttribute(ControllerCommand.NAVIGATIONAL_STATE_SCOPE, window.getId() + "_window");
+
+ try
+ {
+ RenderWindowCommand renderCmd = new RenderWindowCommand(windowRef);
+
+ //
+ context.execute(renderCmd);
+ Result result = renderCmd.getResult();
+
+ //
+ if (result instanceof InsufficientTransportGuaranteeResult)
+ {
+ throw new InsufficientTransportGuaranteeException();
+ }
+
+ //
+ if (result instanceof FragmentResult)
+ {
+ FragmentResult fragment = (FragmentResult)result;
+ windowTitle = fragment.getTitle();
+ if (windowTitle == null)
+ {
+ windowTitle = window.getName();
+ }
+ headerChars = fragment.getHeader();
+ responseProps = fragment.getProperties();
+
+ //
+ Instance instance = renderCmd.getInstance();
+
+ //
+ List supportedWindowStates = new ArrayList();
+ for (Iterator i = instance.getPortlet().getInfo().getCapabilities().getAllWindowStates().iterator(); i.hasNext();)
+ {
+ WindowStateInfo windowStateInfo = (WindowStateInfo)i.next();
+ WindowState windowState = windowStateInfo.getWindowState();
+ if (portal.getSupportedWindowStates().contains(windowState))
+ {
+ supportedWindowStates.add(windowState);
+ }
+ }
+
+ //
+ List supportedModes = new ArrayList();
+ for (Iterator i = instance.getPortlet().getInfo().getCapabilities().getAllModes().iterator(); i.hasNext();)
+ {
+ ModeInfo modeInfo = (ModeInfo)i.next();
+ Mode mode = modeInfo.getMode();
+ if (portal.getSupportedModes().contains(mode))
+ {
+ supportedModes.add(mode);
+ }
+ }
+
+ // Remove edit mode if the user is not logged it
+ // commenting out for now since it breaks the tests
+ if (getControllerContext().getServerInvocation().getServerContext().getClientRequest().getUserPrincipal() == null)
+ {
+ supportedModes.remove(Mode.EDIT);
+ }
+
+ //
+ addModeActions(window, actionMap, windowNavState.getMode(), supportedModes);
+
+ //
+ addStateActions(window, actionMap, windowNavState.getWindowState(), supportedWindowStates);
+
+ switch (fragment.getType())
+ {
+ case FragmentResult.TYPE_CHARS:
+ contentChars = fragment.getChars().toString();
+ break;
+ case FragmentResult.TYPE_BYTES:
+ // Funny for now we don't know how to interpret that or we should not
+ // because it is for some kind of flash portal ?
+ contentChars = fragment.getBytes().toString();
+ break;
+ case FragmentResult.TYPE_EMPTY:
+ // Do nothing, the contentChars is already empty string
+ break;
+ }
+ return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
+ }
+ else if (result instanceof ErrorResult)
+ {
+ ErrorResult errorResult = (ErrorResult)result;
+ String logMessage = "Rendering portlet window " + windowRef + " triggered the following error :";
+ errorResult.logErrorTo(ControllerCommand.log, logMessage);
+ String property = cfg.getProperty(WINDOW_ERROR);
+ if (!HIDE.equals(property))
+ {
+ windowTitle = "An error occured while rendering window '" + windowRef + "'";
+ responseProps = new Properties();
+ contentChars = errorResult.getMessage();
+ Throwable t = errorResult.getThrowable();
+ if (t != null && SHOW.equals(property))
+ {
+ contentChars = Exceptions.toHTML(t, true);
+ }
+ return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
+ }
+ }
+ else if (result instanceof UnavailableResult)
+ {
+ if (SHOW.equals(cfg.getProperty(WINDOW_UNAVAILABLE)))
+ {
+ windowTitle = "Portlet unavailable";
+ contentChars = "Portlet unavailable";
+ actionMap = new HashMap();
+ actionMap.put(WindowResult.MODES_KEY, Collections.EMPTY_LIST);
+ actionMap.put(WindowResult.WINDOWSTATES_KEY, Collections.EMPTY_LIST);
+ responseProps = new Properties();
+ return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
+ }
+ }
+ else if (result instanceof InsufficientPrivilegesResult)
+ {
+ // Julien : go to the section below, I know it is very ugly
+ throw new ResourceAccessDeniedException(windowRef);
+ }
+ else
+ {
+ ControllerCommand.log.error("Unexpected result from a portlet invocation " + result);
+ return null;
+ }
+ }
+ catch (ResourceAccessDeniedException e)
+ {
+ if (ControllerCommand.log.isTraceEnabled())
+ {
+ ControllerCommand.log.trace("Window access denied", e);
+ }
+ if (SHOW.equals(cfg.getProperty(WINDOW_ACCESS_DENIED)))
+ {
+ actionMap.put(WindowResult.MODES_KEY, Collections.EMPTY_LIST);
+ actionMap.put(WindowResult.WINDOWSTATES_KEY, Collections.EMPTY_LIST);
+ windowTitle = "Access denied";
+ contentChars = "Access denied";
+ responseProps = new Properties();
+ return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
+ }
+ }
+ catch (ResourceNotFoundException e)
+ {
+ if (ControllerCommand.log.isTraceEnabled())
+ {
+ ControllerCommand.log.trace("Window not found", e);
+ }
+ if (SHOW.equals(cfg.getProperty(WINDOW_NOT_FOUND)))
+ {
+ actionMap.put(WindowResult.MODES_KEY, Collections.EMPTY_LIST);
+ actionMap.put(WindowResult.WINDOWSTATES_KEY, Collections.EMPTY_LIST);
+ windowTitle = "Cannot render";
+ contentChars = "Object not found " + e.getRef();
+ responseProps = new Properties();
+ return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
+ }
+ }
+ catch (ControllerException e)
+ {
+ // It's a CommandException that we rethrow
+ throw e;
+ }
+ catch (Exception e)
+ {
+ ControllerCommand.log.error("Rendering portlet window " + windowRef + " produced an internal error", e);
+ String property = cfg.getProperty(WINDOW_INTERNAL_ERROR);
+ if (SHOW.equals(property))
+ {
+ windowTitle = "An internal error occured while rendering window '" + window + "'";
+ responseProps = new Properties();
+ contentChars = Exceptions.toHTML(e, true);
+ return new ModifiableWindowResult(windowTitle, contentChars, actionMap, windowProps, responseProps, headerChars, windowNavState.getWindowState(), windowNavState.getMode());
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * parse the provided String for '.' as a separator. For each token, add an entry to a String[] that will be returned
+ * as the result
+ *
+ * @param layoutIDString the string to be examined
+ * @return an array of Strings
+ */
+ private static String[] parseID(String layoutIDString)
+ {
+ List names = new ArrayList();
+ StringTokenizer tokens = new StringTokenizer(layoutIDString, ".");
+ if (tokens.countTokens() > 1)
+ {
+ while (tokens.hasMoreElements())
+ {
+ names.add(tokens.nextToken());
+ }
+ }
+ else
+ {
+ names.add(layoutIDString);
+ }
+
+ String[] id = new String[names.size()];
+ names.toArray(id);
+ return id;
+ }
+
+ /**
+ * Create the action URLs for the allowed window states of the rendered portlet window and add them to the provided
+ * actionMap.
+ */
+ private void addStateActions(Window window, Map actionMap, WindowState currentWindowState, List supportedWindowStates)
+ {
+ List windowStates = new ArrayList(supportedWindowStates.size());
+ for (Iterator j = supportedWindowStates.iterator(); j.hasNext();)
+ {
+ WindowState windowState = (WindowState)j.next();
+ String url = createUpdateNavigationalStateURL(window, null, windowState);
+ boolean disabled = windowState.equals(currentWindowState);
+ WindowResult.Action action = new WindowResult.Action(windowState, url, !disabled);
+ windowStates.add(action);
+ }
+ actionMap.put(WindowResult.WINDOWSTATES_KEY, windowStates);
+ }
+
+ /**
+ * Create the action URLs for the allowed portlet modes of the rendered portlet window and add them to the provided
+ * actionMap.
+ */
+ private void addModeActions(Window window, Map actionMap, Mode currentMode, List supportedModes)
+ {
+ List modes = new ArrayList(supportedModes.size());
+ for (Iterator j = supportedModes.iterator(); j.hasNext();)
+ {
+ Mode mode = (Mode)j.next();
+ String url = createUpdateNavigationalStateURL(window, mode, null);
+ boolean disabled = mode.equals(currentMode);
+ WindowResult.Action action = new WindowResult.Action(mode, url, !disabled);
+ modes.add(action);
+ }
+ actionMap.put(WindowResult.MODES_KEY, modes);
+ }
+
+ public String createUpdateNavigationalStateURL(Window window, Mode mode, WindowState windowState)
+ {
+ InvokeWindowRenderCommand cmd = new InvokeWindowRenderCommand(window.getId(), mode, windowState);
+ ControllerContext controllerContext = getControllerContext();
+ ServerInvocationContext serverContext = controllerContext.getServerInvocation().getServerContext();
+ boolean secure = serverContext.getURLContext().getSecure();
+ boolean authenticated = serverContext.getURLContext().isAuthenticated();
+ URLContext urlContext = URLContext.newInstance(secure, authenticated);
+ return controllerContext.encodeURL(cmd, urlContext, URLFormat.newInstance(true, true));
+ }
}
More information about the jboss-svn-commits
mailing list