001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.impl;
018:
019: import org.apache.avalon.framework.activity.Disposable;
020: import org.apache.avalon.framework.configuration.Configurable;
021: import org.apache.avalon.framework.configuration.Configuration;
022: import org.apache.avalon.framework.configuration.ConfigurationException;
023: import org.apache.avalon.framework.context.Context;
024: import org.apache.avalon.framework.context.ContextException;
025: import org.apache.avalon.framework.context.Contextualizable;
026: import org.apache.avalon.framework.logger.AbstractLogEnabled;
027: import org.apache.avalon.framework.parameters.Parameters;
028: import org.apache.avalon.framework.service.ServiceException;
029: import org.apache.avalon.framework.service.ServiceManager;
030: import org.apache.avalon.framework.service.ServiceSelector;
031: import org.apache.avalon.framework.service.Serviceable;
032: import org.apache.avalon.framework.thread.ThreadSafe;
033: import org.apache.cocoon.ProcessingException;
034: import org.apache.cocoon.components.ContextHelper;
035: import org.apache.cocoon.portal.PortalManager;
036: import org.apache.cocoon.portal.PortalManagerAspect;
037: import org.apache.cocoon.portal.PortalManagerAspectPrepareContext;
038: import org.apache.cocoon.portal.PortalManagerAspectRenderContext;
039: import org.apache.cocoon.portal.PortalService;
040: import org.apache.cocoon.portal.coplet.adapter.CopletAdapter;
041: import org.apache.cocoon.portal.event.EventManager;
042: import org.apache.cocoon.portal.layout.Layout;
043: import org.apache.cocoon.portal.layout.renderer.Renderer;
044: import org.xml.sax.ContentHandler;
045: import org.xml.sax.SAXException;
046:
047: /**
048: *
049: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
050: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
051: *
052: * @version CVS $Id: PortalManagerImpl.java 433543 2006-08-22 06:22:54Z crossley $
053: */
054: public class PortalManagerImpl extends AbstractLogEnabled implements
055: PortalManager, Serviceable, Disposable, ThreadSafe,
056: Contextualizable, PortalManagerAspect, Configurable {
057:
058: /** The service manager */
059: protected ServiceManager manager;
060:
061: /** The portal service */
062: protected PortalService portalService;
063:
064: protected PortalManagerAspectChain chain;
065:
066: protected ServiceSelector aspectSelector;
067: protected ServiceSelector adapterSelector;
068:
069: /** The component context. */
070: protected Context context;
071:
072: /** Indicates whether navigation appears on full screen portlets */
073: private boolean fullScreenNav;
074: public static final String FULLSCREEN = "fullScreenNav";
075:
076: /**
077: * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
078: */
079: public void service(ServiceManager serviceManager)
080: throws ServiceException {
081: this .manager = serviceManager;
082: this .portalService = (PortalService) this .manager
083: .lookup(PortalService.ROLE);
084: if (this .manager.hasService(PortalManagerAspect.ROLE
085: + "Selector")) {
086: this .aspectSelector = (ServiceSelector) this .manager
087: .lookup(PortalManagerAspect.ROLE + "Selector");
088: }
089: this .adapterSelector = (ServiceSelector) this .manager
090: .lookup(CopletAdapter.ROLE + "Selector");
091: }
092:
093: /**
094: * @see org.apache.avalon.framework.activity.Disposable#dispose()
095: */
096: public void dispose() {
097: if (this .manager != null) {
098: this .manager.release(this .portalService);
099: this .portalService = null;
100: if (this .chain != null) {
101: this .chain.dispose(this .aspectSelector,
102: this .adapterSelector);
103: }
104: this .manager.release(this .aspectSelector);
105: this .aspectSelector = null;
106: this .manager.release(this .adapterSelector);
107: this .adapterSelector = null;
108: this .manager = null;
109: }
110: }
111:
112: /**
113: * @see org.apache.cocoon.portal.PortalManager#process()
114: */
115: public void process() throws ProcessingException {
116: DefaultPortalManagerAspectContext aspectContext = new DefaultPortalManagerAspectContext(
117: this .chain, this .portalService, ContextHelper
118: .getObjectModel(this .context));
119: aspectContext.invokeNext();
120: }
121:
122: /**
123: * @see PortalManager#showPortal(ContentHandler, Parameters)
124: */
125: public void showPortal(ContentHandler contentHandler,
126: Parameters parameters) throws SAXException {
127: DefaultPortalManagerAspectContext aspectContext = new DefaultPortalManagerAspectContext(
128: this .chain, this .portalService, ContextHelper
129: .getObjectModel(this .context));
130: aspectContext.invokeNext(contentHandler, parameters);
131: }
132:
133: /**
134: * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
135: */
136: public void configure(Configuration conf)
137: throws ConfigurationException {
138: this .chain = new PortalManagerAspectChain();
139: this .chain.configure(this .aspectSelector, this .adapterSelector,
140: conf.getChild("aspects"), this , new Parameters());
141: this .fullScreenNav = conf.getChild(FULLSCREEN, true)
142: .getValueAsBoolean(false);
143: }
144:
145: /**
146: * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
147: */
148: public void contextualize(Context context) throws ContextException {
149: this .context = context;
150: }
151:
152: /**
153: * @see org.apache.cocoon.portal.PortalManagerAspect#prepare(org.apache.cocoon.portal.PortalManagerAspectPrepareContext, org.apache.cocoon.portal.PortalService)
154: */
155: public void prepare(PortalManagerAspectPrepareContext context,
156: PortalService service) throws ProcessingException {
157: EventManager eventManager = this .portalService
158: .getComponentManager().getEventManager();
159: eventManager.processEvents();
160: }
161:
162: /**
163: * @see org.apache.cocoon.portal.PortalManagerAspect#render(org.apache.cocoon.portal.PortalManagerAspectRenderContext, org.apache.cocoon.portal.PortalService, org.xml.sax.ContentHandler, org.apache.avalon.framework.parameters.Parameters)
164: */
165: public void render(PortalManagerAspectRenderContext context,
166: PortalService service, ContentHandler ch,
167: Parameters parameters) throws SAXException {
168: // first check for a full screen layout
169:
170: Layout portalLayout = null;
171: Boolean renderable = (service.getEntryLayout(null) == null) ? Boolean.TRUE
172: : Boolean.FALSE;
173: if (!this .fullScreenNav) {
174: // If fullscreen mode - otherwise the aspects will deal with the layout
175: portalLayout = service.getEntryLayout(null);
176: renderable = Boolean.TRUE;
177: }
178: if (portalLayout == null) {
179: portalLayout = service.getComponentManager()
180: .getProfileManager().getPortalLayout(null, null);
181: }
182: service.setRenderable(renderable);
183:
184: Renderer portalLayoutRenderer = this.portalService
185: .getComponentManager().getRenderer(
186: portalLayout.getRendererName());
187:
188: ch.startDocument();
189: portalLayoutRenderer
190: .toSAX(portalLayout, this.portalService, ch);
191: ch.endDocument();
192: service.setRenderable(null);
193: }
194: }
|