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.page;
023:
024: import org.jboss.portal.theme.render.renderer.PageRendererContext;
025: import org.jboss.portal.theme.render.renderer.RegionRendererContext;
026: import org.jboss.portal.theme.render.renderer.WindowRendererContext;
027:
028: import java.util.Collection;
029: import java.util.HashMap;
030: import java.util.Iterator;
031: import java.util.Map;
032: import java.util.Set;
033:
034: /**
035: * Interface to represent the read only information of a rendered portal page. <p>The page result allows access to all
036: * the information needed to generate the final markup.
037: *
038: * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>
039: * @version $Revision: 8784 $
040: */
041: public class PageResult implements PageRendererContext {
042:
043: /** . */
044: protected final Map results;
045:
046: /** . */
047: protected final Map windowContexts;
048:
049: /** . */
050: protected String pageName;
051:
052: /** . */
053: protected Map properties;
054:
055: /** . */
056: protected String layoutState;
057:
058: /** . */
059: final Map regions;
060:
061: public PageResult(String pageName, Map properties) {
062: this .pageName = pageName;
063: this .properties = properties == null ? new HashMap()
064: : properties;
065:
066: this .results = new HashMap(5);
067: this .windowContexts = new HashMap(5);
068: this .regions = new HashMap(5);
069: }
070:
071: public PageResult(String pageName) {
072: this (pageName, new HashMap());
073: }
074:
075: /**
076: * Get a reference to the region object for the provided region name.
077: *
078: * @param regionName the name of the region to get
079: * @return the region for the provided region name
080: */
081: public Region getRegion2(String regionName) {
082: return (Region) regions.get(regionName);
083: }
084:
085: /**
086: * Get the name of the requested page.
087: *
088: * @return the name of the page that is being rendered
089: */
090: public String getPageName() {
091: return pageName;
092: }
093:
094: /**
095: * Get the state string of the layout. <p>The state is used to further sub select a layout uri. One layout can
096: * contain a separate layout uri per state. The state has to match to string version of one of the allowed window
097: * states.<p>
098: *
099: * @return a string representing the current window state to potentially further select a more specific layout uri
100: */
101: public String getLayoutState() {
102: return layoutState;
103: }
104:
105: public void setLayoutState(String layoutState) {
106: this .layoutState = layoutState;
107: }
108:
109: /**
110: * Get a Set of all window ids that are contained in this page.
111: *
112: * @return a set of all window ids on this page
113: */
114: public Set getWindowIds() {
115: return windowContexts.keySet();
116: }
117:
118: public WindowRendererContext getWindow(String windowId) {
119: return getWindowContext(windowId);
120: }
121:
122: /**
123: * Get the <code>WindowContext</code> for the provided window id.
124: *
125: * @param windowId the window id identifying the portlet to get the context for
126: * @return the window context for the provided window id
127: */
128: public WindowContext getWindowContext(String windowId) {
129: return (WindowContext) windowContexts.get(windowId);
130: }
131:
132: /**
133: * Get a map of all <code>PortletContext</code>s on the page keyed by window id
134: *
135: * @return a map of all portlet on the page
136: */
137: public Map getWindowContextMap() {
138: return windowContexts;
139: }
140:
141: public void addWindowContext(WindowContext windowContext) {
142: windowContexts.put(windowContext.getId(), windowContext);
143:
144: //
145: Region region = (Region) regions.get(windowContext
146: .getRegionName());
147:
148: //
149: if (region == null) {
150: region = new Region(this , windowContext.getRegionName());
151: regions.put(region.getId(), region);
152: }
153:
154: //
155: region.addWindowContext(windowContext);
156: }
157:
158: // PageRenderContext implementation *********************************************************************************
159:
160: public String getProperty(String name) {
161: return (String) properties.get(name);
162: }
163:
164: public Map getProperties() {
165: return properties;
166: }
167:
168: public Collection getRegions() {
169: return regions.values();
170: }
171:
172: public RegionRendererContext getRegion(String regionName) {
173: return (RegionRendererContext) regions.get(regionName);
174: }
175:
176: public void rebuild() {
177: // Clear all windows
178: for (Iterator i = regions.values().iterator(); i.hasNext();) {
179: Region region = (Region) i.next();
180: region.windows.clear();
181: }
182:
183: // Readd all windows
184: for (Iterator i = windowContexts.values().iterator(); i
185: .hasNext();) {
186: WindowContext wc = (WindowContext) i.next();
187:
188: //
189: Region region = (Region) regions.get(wc.getRegionName());
190:
191: //
192: if (region == null) {
193: region = new Region(this , wc.getRegionName());
194: regions.put(region.getId(), region);
195: }
196:
197: //
198: region.addWindowContext(wc);
199: }
200: }
201: }
|