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.instance.command.render;
023:
024: import org.jboss.portal.Mode;
025: import org.jboss.portal.WindowState;
026: import org.jboss.portal.common.NotYetImplemented;
027: import org.jboss.portal.core.controller.ControllerException;
028: import org.jboss.portal.core.controller.ControllerResponse;
029: import org.jboss.portal.core.controller.command.info.CommandInfo;
030: import org.jboss.portal.core.controller.portlet.InvokePortletCommandFactory;
031: import org.jboss.portal.core.controller.portlet.PortletContextFactory;
032: import org.jboss.portal.core.controller.portlet.PortletInvocationFactory;
033: import org.jboss.portal.core.model.instance.InvokePortletInstanceCommandFactory;
034: import org.jboss.portal.core.model.instance.command.PortletInstanceCommand;
035: import org.jboss.portal.core.theme.PageRendition;
036: import org.jboss.portal.portlet.PortletInvokerException;
037: import org.jboss.portal.portlet.StateString;
038: import org.jboss.portal.portlet.invocation.RenderInvocation;
039: import org.jboss.portal.portlet.invocation.response.ErrorResponse;
040: import org.jboss.portal.portlet.invocation.response.FragmentResponse;
041: import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
042: import org.jboss.portal.theme.LayoutService;
043: import org.jboss.portal.theme.PageService;
044: import org.jboss.portal.theme.PortalLayout;
045: import org.jboss.portal.theme.ThemeConstants;
046: import org.jboss.portal.theme.page.PageResult;
047: import org.jboss.portal.theme.page.WindowContext;
048: import org.jboss.portal.theme.page.WindowResult;
049:
050: import java.util.Collections;
051: import java.util.HashMap;
052: import java.util.Map;
053:
054: /**
055: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
056: * @version $Revision: 8786 $
057: */
058: public class RenderPortletInstanceCommand extends
059: PortletInstanceCommand {
060:
061: public RenderPortletInstanceCommand(String instanceId,
062: StateString navigationalState) {
063: super (instanceId, navigationalState);
064: }
065:
066: public CommandInfo getInfo() {
067: return null;
068: }
069:
070: public ControllerResponse execute() throws ControllerException {
071:
072: try {
073: PortletContextFactory pcf1 = new PortletContextFactory(
074: context);
075: InvokePortletCommandFactory pcf2 = new InvokePortletInstanceCommandFactory(
076: instanceId);
077: RenderInvocation render = PortletInvocationFactory
078: .createRender(context, Mode.VIEW,
079: WindowState.MAXIMIZED, navigationalState,
080: pcf1, pcf2);
081: PortletInvocationResponse response = instance
082: .invoke(render);
083:
084: // For now let the controller handle non fragment response
085: String content;
086: String header = "";
087: if (response instanceof FragmentResponse) {
088: FragmentResponse fragment = (FragmentResponse) response;
089: content = fragment.getContent();
090: header = fragment.getHeader();
091: } else if (response instanceof ErrorResponse) {
092: content = ((ErrorResponse) response).toHTML();
093: } else {
094: throw new NotYetImplemented();
095: }
096:
097: //
098: PageService ps = context.getController().getPageService();
099: LayoutService ls = ps.getLayoutService();
100: PortalLayout layout = ls.getLayout("generic", true);
101: Map pageProperties = new HashMap();
102: pageProperties.put("theme.renderSetId", "divRenderer");
103: pageProperties.put("theme.id", "renaissance");
104: PageResult result = new PageResult("BILTO", pageProperties);
105:
106: //
107: Map windowProps = new HashMap();
108: windowProps.put(ThemeConstants.PORTAL_PROP_WINDOW_RENDERER,
109: "emptyRenderer");
110: windowProps.put(
111: ThemeConstants.PORTAL_PROP_DECORATION_RENDERER,
112: "emptyRenderer");
113: windowProps.put(
114: ThemeConstants.PORTAL_PROP_PORTLET_RENDERER,
115: "emptyRenderer");
116:
117: //
118: WindowResult res = new WindowResult("", content,
119: Collections.EMPTY_MAP, windowProps, header,
120: WindowState.MAXIMIZED, Mode.VIEW);
121: WindowContext blah = new WindowContext("BILTO",
122: "maximized", "0", res);
123: result.addWindowContext(blah);
124:
125: //
126: return new PageRendition(layout, null, result, ps);
127: } catch (PortletInvokerException e) {
128: throw new ControllerException(e);
129: }
130: }
131: }
|