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.theme.impl;
023:
024: import org.jboss.portal.WindowState;
025: import org.jboss.portal.common.util.MarkupInfo;
026: import org.jboss.portal.theme.LayoutDispatcher;
027: import org.jboss.portal.theme.PortalLayout;
028: import org.jboss.portal.theme.impl.render.dynamic.DynaRenderOptions;
029: import org.jboss.portal.theme.page.PageResult;
030: import org.jboss.portal.theme.page.WindowContext;
031: import org.jboss.portal.theme.page.WindowResult;
032: import org.jboss.portal.theme.render.ObjectRendererContext;
033: import org.jboss.portal.theme.render.RenderException;
034: import org.jboss.portal.theme.render.RendererContext;
035: import org.jboss.portal.theme.render.RendererFactory;
036: import org.jboss.portal.theme.render.ThemeContext;
037: import org.jboss.portal.theme.render.renderer.PageRenderer;
038: import org.jboss.portal.theme.render.renderer.PageRendererContext;
039: import org.jboss.portal.theme.render.renderer.RegionRendererContext;
040: import org.jboss.portal.web.ServletContextDispatcher;
041:
042: import javax.servlet.ServletException;
043: import java.io.IOException;
044: import java.io.PrintWriter;
045: import java.io.Writer;
046: import java.util.Iterator;
047: import java.util.Map;
048:
049: /**
050: * Layout implementation that uses JSPs (and tags) to render the response back to the client.
051: *
052: * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>
053: * @version $Revision: 8784 $
054: * @see LayoutDispatcher
055: */
056: public final class JSPLayout extends PortalLayout implements
057: PageRenderer {
058:
059: public RendererContext getRenderContext(ThemeContext themeContext,
060: MarkupInfo markupInfo, ServletContextDispatcher dispatcher) {
061: RendererFactory factory = new RendererFactoryImpl(this ,
062: serviceInfo, info);
063:
064: //
065: return new JSPRendererContext(themeContext, factory,
066: dispatcher, markupInfo);
067: }
068:
069: public RendererContext getRenderContext(ThemeContext themeContext,
070: MarkupInfo markupInfo, ServletContextDispatcher dispatcher,
071: Writer writer) {
072: RendererFactory factory = new RendererFactoryImpl(this ,
073: serviceInfo, info);
074:
075: //
076: return new WriterRendererContext(themeContext, factory,
077: dispatcher, markupInfo, new PrintWriter(writer));
078: }
079:
080: public void startContext(RendererContext rendererContext,
081: ObjectRendererContext objectRenderContext) {
082: }
083:
084: public void endContext(RendererContext rendererContext,
085: ObjectRendererContext objectRenderContext) {
086: }
087:
088: public void render(RendererContext rendererContext,
089: PageRendererContext prc) throws RenderException {
090: PageResult pageResult = (PageResult) prc;
091:
092: // Take care of maximized window
093: // if one window is maximized then we do chose the maximized layout for the rendition
094: // and put that window on the maximized region of this layout
095: for (Iterator i = pageResult.getWindowIds().iterator(); i
096: .hasNext();) {
097: String windowId = (String) i.next();
098: WindowContext wc = pageResult.getWindowContext(windowId);
099: WindowResult res = wc.getResult();
100: if (WindowState.MAXIMIZED.equals(res.getWindowState())) {
101: // // TODO: Deep clone instead ?
102: // PageResult newRes = new PageResult(
103: // pageResult.getPageName(),
104: // pageResult.getPageProperties(),
105: // pageResult.getPortalProperties());
106: //
107: // //
108: // newRes.setLayoutState("maximized");
109: // newRes.setLayoutURI(getLayoutInfo().getURI("maximized"));
110: // newRes.setThemeResult(pageResult.getThemeResult());
111: //
112: // //
113: // for (Iterator j = pageResult.getWindowContextMap().values().iterator();j.hasNext();)
114: // {
115: // WindowContext windowContext = (WindowContext)j.next();
116: //
117: // //
118: // if (windowContext == wc)
119: // {
120: // newRes.addWindowContext(new WindowContext(wc.getName(), wc.getId(), "maximized", 0, res));
121: // }
122: // else
123: // {
124: // newRes.addWindowContext(windowContext);
125: // }
126: // }
127: //
128: // //
129: // pageResult = newRes;
130:
131: // Get src region
132: RegionRendererContext srcRegion = pageResult
133: .getRegion(wc.getRegionName());
134: Map srcProps = srcRegion.getProperties();
135:
136: //
137: pageResult.setLayoutState("maximized");
138: wc.setRegionName("maximized");
139: wc.setOrder("0");
140:
141: // Yes it is ugly
142: pageResult.rebuild();
143:
144: // New destination region
145: RegionRendererContext dstRegion = pageResult
146: .getRegion("maximized");
147: Map dstProps = dstRegion.getProperties();
148:
149: // Copy properties
150: dstProps.putAll(srcProps);
151:
152: // Disable DnD
153: DynaRenderOptions options = DynaRenderOptions
154: .getOptions(Boolean.FALSE, null);
155: options.setOptions(dstProps);
156:
157: //
158: break;
159: }
160: }
161:
162: try {
163: String layoutState = pageResult.getLayoutState();
164: String layoutURI = getLayoutInfo().getURI(layoutState);
165: LayoutDispatcher dispatcher = new LayoutDispatcher(
166: rendererContext, prc, layoutURI, getLayoutInfo());
167: dispatcher.include();
168: } catch (IOException e) {
169: e.printStackTrace();
170: } catch (ServletException e) {
171: e.printStackTrace();
172: }
173: }
174: }
|