1 16 package org.apache.cocoon.portal.layout.renderer.aspect.impl; 17 18 import org.apache.avalon.framework.service.ServiceException; 19 import org.apache.avalon.framework.service.ServiceSelector; 20 import org.apache.cocoon.portal.PortalService; 21 import org.apache.cocoon.portal.coplet.CopletInstanceData; 22 import org.apache.cocoon.portal.coplet.adapter.CopletAdapter; 23 import org.apache.cocoon.portal.layout.Layout; 24 import org.apache.cocoon.portal.layout.impl.CopletLayout; 25 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext; 26 import org.apache.cocoon.xml.IncludeXMLConsumer; 27 import org.apache.cocoon.xml.XMLUtils; 28 import org.xml.sax.ContentHandler ; 29 import org.xml.sax.SAXException ; 30 31 55 public class DefaultCopletAspect extends AbstractAspect { 56 57 60 public void toSAX(RendererAspectContext context, 61 Layout layout, 62 PortalService service, 63 ContentHandler handler) 64 throws SAXException { 65 66 if (!(context.isRendering())) { 67 context.invokeNext(layout, service, handler); 68 return; 69 } 70 71 XMLUtils.startElement(handler, "content"); 72 CopletInstanceData cid = ((CopletLayout)layout).getCopletInstanceData(); 73 74 final String adapterName = cid.getCopletData().getCopletBaseData().getCopletAdapterName(); 75 CopletAdapter copletAdapter = null; 76 ServiceSelector adapterSelector = null; 77 try { 78 adapterSelector = (ServiceSelector) this.manager.lookup(CopletAdapter.ROLE + "Selector"); 79 copletAdapter = (CopletAdapter) adapterSelector.select(adapterName); 80 copletAdapter.toSAX(cid, new IncludeXMLConsumer(handler)); 81 } catch (ServiceException ce) { 82 throw new SAXException ("Unable to lookup component.", ce); 83 } finally { 84 if (null != copletAdapter) { 85 adapterSelector.release(copletAdapter); 86 } 87 this.manager.release(adapterSelector); 88 } 89 90 XMLUtils.endElement(handler, "content"); 91 context.invokeNext(layout, service, handler); 92 } 93 94 } 95 | Popular Tags |