1 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 ; 44 import org.xml.sax.SAXException ; 45 46 53 public class PortalManagerImpl 54 extends AbstractLogEnabled 55 implements PortalManager, Serviceable, Disposable, ThreadSafe, Contextualizable, PortalManagerAspect, Configurable { 56 57 58 protected ServiceManager manager; 59 60 61 protected PortalService portalService; 62 63 protected PortalManagerAspectChain chain; 64 65 protected ServiceSelector aspectSelector; 66 protected ServiceSelector adapterSelector; 67 68 69 protected Context context; 70 71 72 private boolean fullScreenNav; 73 public static final String FULLSCREEN = "fullScreenNav"; 74 75 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 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 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 121 public void showPortal(ContentHandler contentHandler, Parameters parameters) 122 throws SAXException { 123 DefaultPortalManagerAspectContext aspectContext = 124 new DefaultPortalManagerAspectContext(this.chain, 125 this.portalService, 126 ContextHelper.getObjectModel(this.context)); 127 aspectContext.invokeNext(contentHandler, parameters); 128 } 129 130 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 146 public void contextualize(Context context) throws ContextException { 147 this.context = context; 148 } 149 150 153 public void prepare(PortalManagerAspectPrepareContext context, PortalService service) throws ProcessingException { 154 EventManager eventManager = this.portalService.getComponentManager().getEventManager(); 155 eventManager.processEvents(); 156 } 157 158 161 public void render(PortalManagerAspectRenderContext context, PortalService service, ContentHandler ch, Parameters parameters) throws SAXException { 162 164 Layout portalLayout = null; 165 Boolean renderable = (service.getEntryLayout(null) == null) ? 166 Boolean.TRUE : Boolean.FALSE; 167 if (!this.fullScreenNav) { 168 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 |