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.impl.model.content.generic;
023:
024: import org.jboss.portal.Mode;
025: import org.jboss.portal.common.i18n.LocalizedString;
026: import org.jboss.portal.core.impl.model.content.InternalContentProvider;
027: import org.jboss.portal.core.model.content.Content;
028: import org.jboss.portal.core.model.content.ContentType;
029: import org.jboss.portal.core.model.content.spi.ContentProvider;
030: import org.jboss.portal.core.model.content.spi.handler.ContentHandler;
031: import org.jboss.portal.core.model.content.spi.handler.ContentState;
032: import org.jboss.portal.core.model.content.spi.portlet.ContentPortlet;
033: import org.jboss.portal.core.model.instance.Instance;
034: import org.jboss.portal.core.model.instance.InstanceContainer;
035: import org.jboss.portal.core.model.portal.PortalObjectId;
036: import org.jboss.portal.core.model.portal.Window;
037: import org.jboss.portal.core.model.portal.command.response.MarkupResponse;
038: import org.jboss.portal.core.model.portal.content.WindowRendition;
039: import org.jboss.portal.core.model.portal.content.ContentRendererContext;
040: import org.jboss.portal.core.model.portal.navstate.WindowNavigationalState;
041: import org.jboss.portal.portlet.PortletParametersStateString;
042:
043: import java.util.Iterator;
044: import java.util.Map;
045:
046: /**
047: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
048: * @version $Revision: 9006 $
049: */
050: public class InternalGenericContentProvider extends
051: InternalContentProvider implements ContentHandler {
052:
053: /** . */
054: protected InstanceContainer instanceContainer;
055:
056: /** . */
057: protected boolean decorateContent;
058:
059: /** . */
060: protected ContentPortlet contentPortlet;
061:
062: public InstanceContainer getInstanceContainer() {
063: return instanceContainer;
064: }
065:
066: public void setInstanceContainer(InstanceContainer instanceContainer) {
067: this .instanceContainer = instanceContainer;
068: }
069:
070: public ContentPortlet getContentPortletInfo() {
071: return contentPortlet;
072: }
073:
074: public void setContentPortletInfo(ContentPortlet contentPortlet) {
075: this .contentPortlet = contentPortlet;
076: }
077:
078: public boolean getDecorateContent() {
079: return decorateContent;
080: }
081:
082: public void setDecorateContent(boolean decorateContent) {
083: this .decorateContent = decorateContent;
084: }
085:
086: protected ContentProvider createProvider() {
087: return new ContentProvider() {
088: public ContentType getContentType() {
089: return getRegisteredContentType();
090: }
091:
092: public LocalizedString getDisplayName() {
093: return null;
094: }
095:
096: public LocalizedString getDescription() {
097: return null;
098: }
099:
100: public ContentHandler getHandler() {
101: return InternalGenericContentProvider.this ;
102: }
103:
104: public ContentPortlet getPortletInfo() {
105: return contentPortlet;
106: }
107: };
108: }
109:
110: public Content newContent(String contextId, ContentState state) {
111: return new GenericContent(state);
112: }
113:
114: protected Instance getPortletInstance(
115: ContentRendererContext rendererContext) {
116: String id = contentPortlet.getPortletName(Mode.VIEW);
117:
118: //
119: if (id != null) {
120: return instanceContainer.getDefinition(id);
121: } else {
122: return null;
123: }
124: }
125:
126: public void contentCreated(String contextId, ContentState state) {
127: }
128:
129: public void contentDestroyed(String contextId, ContentState state) {
130: }
131:
132: public WindowRendition renderWindow(
133: ContentRendererContext rendererContext) {
134: Window window = rendererContext.getWindow();
135: PortalObjectId windowId = window.getId();
136:
137: // No content
138: Content content = window.getContent();
139: if (content == null) {
140: return null;
141: }
142:
143: //
144:
145: // Initialize the navigational state with the URI when needed
146: WindowNavigationalState navigationalState = rendererContext
147: .getNavigationalState();
148:
149: //
150: // boolean update = true;
151: // if (navigationalState != null && navigationalState.getState() instanceof PortletParametersStateString)
152: // {
153: // PortletParametersStateString state = (PortletParametersStateString)navigationalState.getState();
154: // if (content.getURI().equals(state.getValue("uri")))
155: // {
156: // update = false;
157: // }
158: // }
159:
160: //
161: if (navigationalState == null) {
162: PortletParametersStateString state = new PortletParametersStateString();
163:
164: //
165: for (Iterator i = content.getParameterNames(); i.hasNext();) {
166: String paramName = (String) i.next();
167: String paramValue = content.getParameter(paramName);
168: state.setValue(paramName, paramValue);
169: }
170:
171: //
172: String uri = content.getURI();
173: state.setValue("uri", uri);
174:
175: //
176: rendererContext
177: .setNavigationalState(WindowNavigationalState
178: .bilto(navigationalState, null, null, state));
179: }
180:
181: //
182: WindowRendition rendition = super .renderWindow(rendererContext);
183:
184: //
185: if (rendition != null
186: && rendition.getControllerResponse() instanceof MarkupResponse
187: && !getDecorateContent()) {
188: Map props = rendition.getProperties();
189: if (props.get("theme.windowRendererId") == null) {
190: props.put("theme.windowRendererId", "emptyRenderer");
191: }
192: if (props.get("theme.decorationRendererId") == null) {
193: props
194: .put("theme.decorationRendererId",
195: "emptyRenderer");
196: }
197: if (props.get("theme.portletRendererId") == null) {
198: props.put("theme.portletRendererId", "emptyRenderer");
199: }
200: }
201:
202: //
203: return rendition;
204: }
205: }
|