1 16 package org.apache.cocoon.portal.transformation; 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.portal.Constants; 25 import org.apache.cocoon.portal.PortalService; 26 import org.apache.cocoon.portal.coplet.CopletInstanceData; 27 import org.apache.cocoon.transformation.AbstractSAXTransformer; 28 import org.xml.sax.SAXException ; 29 30 53 public abstract class AbstractCopletTransformer 54 extends AbstractSAXTransformer { 55 56 59 public static final String COPLET_ID_PARAM = "copletId"; 60 61 62 protected PortalService portalService; 63 64 69 protected CopletInstanceData getCopletInstanceData() 70 throws SAXException { 71 CopletInstanceData cid = this.getCopletInstanceData(null); 72 if ( cid == null ) { 73 throw new SAXException ("Could not find coplet instance data for the current pipeline."); 74 } 75 return cid; 76 } 77 78 79 83 protected PortalService getPortalService() 84 throws SAXException { 85 return this.portalService; 86 } 87 88 89 96 protected CopletInstanceData getCopletInstanceData(String copletId) 97 throws SAXException { 98 final Map context = (Map )objectModel.get(ObjectModelHelper.PARENT_CONTEXT); 99 100 if ( copletId == null ) { 101 if (context != null) { 103 copletId = (String )context.get(Constants.COPLET_ID_KEY); 104 } else { 105 copletId = (String )objectModel.get(Constants.COPLET_ID_KEY); 106 if ( copletId == null ) { 107 try { 108 copletId = this.parameters.getParameter(COPLET_ID_PARAM); 109 110 } catch (ParameterException e) { 111 throw new SAXException ("copletId must be passed as parameter or in the object model within the parent context."); 112 } 113 } 114 } 115 } 116 if (copletId == null) { 117 throw new SAXException ("copletId must be passed as parameter or in the object model within the parent context."); 118 } 119 120 CopletInstanceData object = this.portalService.getComponentManager().getProfileManager().getCopletInstanceData( copletId ); 121 122 return object; 123 } 124 125 128 public void service(ServiceManager manager) throws ServiceException { 129 super.service(manager); 130 this.portalService = (PortalService)this.manager.lookup(PortalService.ROLE); 131 } 132 133 136 public void dispose() { 137 if ( this.portalService != null ) { 138 this.manager.release( this.portalService ); 139 this.portalService = null; 140 } 141 super.dispose(); 142 } 143 } 144 | Popular Tags |