1 16 package org.apache.cocoon.portal.generation; 17 18 import java.util.Map ; 19 20 import org.apache.avalon.framework.parameters.ParameterException; 21 import org.apache.avalon.framework.service.ServiceException; 22 import org.apache.avalon.framework.service.ServiceManager; 23 import org.apache.cocoon.environment.ObjectModelHelper; 24 import org.apache.cocoon.generation.ServiceableGenerator; 25 import org.apache.cocoon.portal.Constants; 26 import org.apache.cocoon.portal.PortalService; 27 import org.apache.cocoon.portal.coplet.CopletInstanceData; 28 import org.xml.sax.SAXException ; 29 30 47 public abstract class AbstractCopletGenerator 48 extends ServiceableGenerator { 49 50 53 public static final String COPLET_ID_PARAM = "copletId"; 54 55 58 public static final String PORTAL_NAME_PARAM = "portalName"; 59 60 61 protected PortalService portalService; 62 63 68 protected CopletInstanceData getCopletInstanceData() 69 throws SAXException { 70 CopletInstanceData cid = this.getCopletInstanceData(null); 71 if ( cid == null ) { 72 throw new SAXException ("Could not find coplet instance data for the current pipeline."); 73 } 74 return cid; 75 } 76 77 78 81 protected PortalService getPortalService() { 82 return this.portalService; 83 } 84 85 86 93 protected CopletInstanceData getCopletInstanceData(String copletId) 94 throws SAXException { 95 final Map context = (Map )objectModel.get(ObjectModelHelper.PARENT_CONTEXT); 96 97 if ( copletId == null ) { 98 if (context != null) { 100 copletId = (String )context.get(Constants.COPLET_ID_KEY); 101 } else { 102 copletId = (String )objectModel.get(Constants.COPLET_ID_KEY); 103 if ( copletId == null ) { 104 try { 105 copletId = this.parameters.getParameter(COPLET_ID_PARAM); 106 107 } catch (ParameterException e) { 108 throw new SAXException ("copletId must be passed as parameter or in the object model within the parent context."); 109 } 110 } 111 } 112 } 113 if (copletId == null) { 114 throw new SAXException ("copletId must be passed as parameter or in the object model within the parent context."); 115 } 116 117 CopletInstanceData object = this.getPortalService().getComponentManager().getProfileManager().getCopletInstanceData( copletId ); 118 119 return object; 120 } 121 122 125 public void dispose() { 126 if ( this.manager != null ) { 127 this.manager.release(this.portalService); 128 this.portalService = null; 129 } 130 super.dispose(); 131 } 132 133 136 public void service(ServiceManager manager) throws ServiceException { 137 super.service(manager); 138 this.portalService = (PortalService)this.manager.lookup(PortalService.ROLE); 139 } 140 } 141 | Popular Tags |