001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.core.model.portal.command.render;
023:
024: import org.jboss.portal.core.controller.ControllerContext;
025: import org.jboss.portal.core.controller.ControllerException;
026: import org.jboss.portal.core.controller.ControllerResponse;
027: import org.jboss.portal.core.controller.portlet.PortletInvocationFactory;
028: import org.jboss.portal.core.controller.command.info.CommandInfo;
029: import org.jboss.portal.core.controller.command.info.ViewCommandInfo;
030: import org.jboss.portal.core.model.content.ContentType;
031: import org.jboss.portal.core.model.portal.PortalObjectId;
032: import org.jboss.portal.core.model.portal.navstate.WindowNavigationalState;
033: import org.jboss.portal.core.model.portal.command.WindowCommand;
034: import org.jboss.portal.core.model.portal.content.ContentRenderer;
035: import org.jboss.portal.core.model.portal.content.ContentRendererRegistry;
036: import org.jboss.portal.core.model.portal.content.WindowRendition;
037: import org.jboss.portal.core.model.portal.content.ContentRendererContext;
038: import org.jboss.portal.core.model.portal.control.page.PageControlContext;
039: import org.jboss.portal.core.navstate.NavigationalStateKey;
040: import org.jboss.portal.common.invocation.AttributeResolver;
041: import org.jboss.portal.identity.User;
042: import org.jboss.portal.portlet.invocation.RenderInvocation;
043:
044: /**
045: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
046: * @version $Revision: 9006 $
047: */
048: public class RenderWindowCommand extends WindowCommand implements
049: ContentRendererContext {
050:
051: /** . */
052: private static final CommandInfo info = new ViewCommandInfo();
053:
054: /** . */
055: private WindowRendition rendition;
056:
057: public RenderWindowCommand(PortalObjectId windowId)
058: throws IllegalArgumentException {
059: super (windowId);
060: }
061:
062: public CommandInfo getInfo() {
063: return info;
064: }
065:
066: /** Hack the command system. */
067: public WindowRendition render(ControllerContext ctx)
068: throws ControllerException {
069: ctx.execute(this );
070:
071: //
072: return rendition;
073: }
074:
075: public ControllerResponse execute() throws ControllerException {
076: // Find the appropriate content renderer
077: ContentRendererRegistry registry = context.getController()
078: .getContentRendererRegistry();
079: ContentType contentType = window.getContentType();
080: ContentRenderer renderer = registry.getRenderer(contentType);
081:
082: //
083: if (renderer == null) {
084: // Return the appropriate result
085: } else {
086: rendition = renderer.renderWindow(this );
087:
088: // Apply policy behavior here
089: if (rendition != null) {
090: PageControlContext wcc = new PageControlContext(
091: context, targetId, rendition);
092: context.getController().getPageControlPolicy()
093: .doControl(wcc);
094: }
095: }
096:
097: //
098: return null;
099: }
100:
101: public WindowNavigationalState getNavigationalState() {
102: AttributeResolver nsResolver = context
103: .getAttributeResolver(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE);
104: NavigationalStateKey nsKey = new NavigationalStateKey(
105: WindowNavigationalState.class, window.getId());
106: return (WindowNavigationalState) nsResolver.getAttribute(nsKey);
107: }
108:
109: public void setNavigationalState(
110: WindowNavigationalState navigationalState) {
111: AttributeResolver nsResolver = context
112: .getAttributeResolver(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE);
113: NavigationalStateKey nsKey = new NavigationalStateKey(
114: WindowNavigationalState.class, window.getId());
115: nsResolver.setAttribute(nsKey, navigationalState);
116: }
117:
118: public User getUser() {
119: return context.getUser();
120: }
121:
122: public RenderInvocation createRenderInvocation(
123: WindowNavigationalState navigationalState) {
124: return PortletInvocationFactory.createRender(context,
125: navigationalState.getMode(), navigationalState
126: .getWindowState(), navigationalState
127: .getContentState(), window, portal);
128: }
129: }
|