KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > impl > PortalManagerImpl


1 /*
2  * Copyright 1999-2002,2004-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.impl;
17
18 import org.apache.avalon.framework.activity.Disposable;
19 import org.apache.avalon.framework.configuration.Configurable;
20 import org.apache.avalon.framework.configuration.Configuration;
21 import org.apache.avalon.framework.configuration.ConfigurationException;
22 import org.apache.avalon.framework.context.Context;
23 import org.apache.avalon.framework.context.ContextException;
24 import org.apache.avalon.framework.context.Contextualizable;
25 import org.apache.avalon.framework.logger.AbstractLogEnabled;
26 import org.apache.avalon.framework.parameters.Parameters;
27 import org.apache.avalon.framework.service.ServiceException;
28 import org.apache.avalon.framework.service.ServiceManager;
29 import org.apache.avalon.framework.service.ServiceSelector;
30 import org.apache.avalon.framework.service.Serviceable;
31 import org.apache.avalon.framework.thread.ThreadSafe;
32 import org.apache.cocoon.ProcessingException;
33 import org.apache.cocoon.components.ContextHelper;
34 import org.apache.cocoon.portal.PortalManager;
35 import org.apache.cocoon.portal.PortalManagerAspect;
36 import org.apache.cocoon.portal.PortalManagerAspectPrepareContext;
37 import org.apache.cocoon.portal.PortalManagerAspectRenderContext;
38 import org.apache.cocoon.portal.PortalService;
39 import org.apache.cocoon.portal.coplet.adapter.CopletAdapter;
40 import org.apache.cocoon.portal.event.EventManager;
41 import org.apache.cocoon.portal.layout.Layout;
42 import org.apache.cocoon.portal.layout.renderer.Renderer;
43 import org.xml.sax.ContentHandler JavaDoc;
44 import org.xml.sax.SAXException JavaDoc;
45
46 /**
47  *
48  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
49  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
50  *
51  * @version CVS $Id: PortalManagerImpl.java 330865 2005-11-04 18:54:05Z rgoers $
52  */

53 public class PortalManagerImpl
54     extends AbstractLogEnabled
55     implements PortalManager, Serviceable, Disposable, ThreadSafe, Contextualizable, PortalManagerAspect, Configurable {
56
57     /** The service manager */
58     protected ServiceManager manager;
59
60     /** The portal service */
61     protected PortalService portalService;
62
63     protected PortalManagerAspectChain chain;
64
65     protected ServiceSelector aspectSelector;
66     protected ServiceSelector adapterSelector;
67
68     /** The component context. */
69     protected Context context;
70
71     /** Indicates whether navigation appears on full screen portlets */
72     private boolean fullScreenNav;
73     public static final String JavaDoc FULLSCREEN = "fullScreenNav";
74
75     /**
76      * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
77      */

78     public void service(ServiceManager serviceManager)
79     throws ServiceException {
80         this.manager = serviceManager;
81         this.portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
82         if ( this.manager.hasService(PortalManagerAspect.ROLE+"Selector") ) {
83             this.aspectSelector = (ServiceSelector) this.manager.lookup( PortalManagerAspect.ROLE+"Selector");
84         }
85         this.adapterSelector = (ServiceSelector)this.manager.lookup(CopletAdapter.ROLE+"Selector");
86     }
87
88     /**
89      * @see org.apache.avalon.framework.activity.Disposable#dispose()
90      */

91     public void dispose() {
92         if ( this.manager != null ) {
93             this.manager.release(this.portalService);
94             this.portalService = null;
95             if ( this.chain != null) {
96                 this.chain.dispose( this.aspectSelector, this.adapterSelector );
97             }
98             this.manager.release( this.aspectSelector );
99             this.aspectSelector = null;
100             this.manager.release( this.adapterSelector );
101             this.adapterSelector = null;
102             this.manager = null;
103         }
104     }
105
106     /**
107      * @see org.apache.cocoon.portal.PortalManager#process()
108      */

109     public void process()
110     throws ProcessingException {
111         DefaultPortalManagerAspectContext aspectContext =
112             new DefaultPortalManagerAspectContext(this.chain,
113                                                   this.portalService,
114                                                   ContextHelper.getObjectModel(this.context));
115         aspectContext.invokeNext();
116     }
117
118     /**
119      * @see PortalManager#showPortal(ContentHandler, Parameters)
120      */

121     public void showPortal(ContentHandler JavaDoc contentHandler, Parameters parameters)
122     throws SAXException JavaDoc {
123         DefaultPortalManagerAspectContext aspectContext =
124             new DefaultPortalManagerAspectContext(this.chain,
125                                                   this.portalService,
126                                                   ContextHelper.getObjectModel(this.context));
127         aspectContext.invokeNext(contentHandler, parameters);
128     }
129
130     /**
131      * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
132      */

133     public void configure(Configuration conf) throws ConfigurationException {
134         this.chain = new PortalManagerAspectChain();
135         this.chain.configure(this.aspectSelector,
136                              this.adapterSelector,
137                              conf.getChild("aspects"),
138                              this,
139                              new Parameters());
140         this.fullScreenNav = conf.getChild(FULLSCREEN, true).getValueAsBoolean(false);
141     }
142
143     /**
144      * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
145      */

146     public void contextualize(Context context) throws ContextException {
147         this.context = context;
148     }
149
150     /**
151      * @see org.apache.cocoon.portal.PortalManagerAspect#prepare(org.apache.cocoon.portal.PortalManagerAspectPrepareContext, org.apache.cocoon.portal.PortalService)
152      */

153     public void prepare(PortalManagerAspectPrepareContext context, PortalService service) throws ProcessingException {
154         EventManager eventManager = this.portalService.getComponentManager().getEventManager();
155         eventManager.processEvents();
156     }
157
158     /**
159      * @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)
160      */

161     public void render(PortalManagerAspectRenderContext context, PortalService service, ContentHandler JavaDoc ch, Parameters parameters) throws SAXException JavaDoc {
162         // first check for a full screen layout
163

164         Layout portalLayout = null;
165         Boolean JavaDoc renderable = (service.getEntryLayout(null) == null) ?
166                 Boolean.TRUE : Boolean.FALSE;
167         if (!this.fullScreenNav) {
168             // If fullscreen mode - otherwise the aspects will deal with the layout
169
portalLayout = service.getEntryLayout(null);
170             renderable = Boolean.TRUE;
171         }
172         if ( portalLayout == null ) {
173             portalLayout = service.getComponentManager().getProfileManager().getPortalLayout(null, null);
174         }
175         service.setRenderable(renderable);
176
177         Renderer portalLayoutRenderer = this.portalService.getComponentManager().getRenderer( portalLayout.getRendererName());
178
179         ch.startDocument();
180         portalLayoutRenderer.toSAX(portalLayout, this.portalService, ch);
181         ch.endDocument();
182         service.setRenderable(null);
183     }
184 }
185
Popular Tags