1 16 package org.apache.cocoon.portal.acting; 17 18 import java.util.Map ; 19 20 import org.apache.avalon.framework.configuration.ConfigurationException; 21 import org.apache.avalon.framework.parameters.Parameters; 22 import org.apache.avalon.framework.service.ServiceException; 23 import org.apache.cocoon.ProcessingException; 24 import org.apache.cocoon.acting.ServiceableAction; 25 import org.apache.cocoon.environment.ObjectModelHelper; 26 import org.apache.cocoon.environment.Redirector; 27 import org.apache.cocoon.environment.SourceResolver; 28 import org.apache.cocoon.portal.Constants; 29 import org.apache.cocoon.portal.PortalService; 30 import org.apache.cocoon.portal.event.Event; 31 import org.apache.cocoon.portal.event.EventManager; 32 import org.apache.cocoon.portal.event.impl.CopletJXPathEvent; 33 34 40 public class CopletSetDataAction 41 extends ServiceableAction { 42 43 46 public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) 47 throws Exception { 48 PortalService portalService = null; 49 try { 50 51 portalService = (PortalService)this.manager.lookup(PortalService.ROLE); 52 53 String copletId = null; 55 Map context = (Map )objectModel.get(ObjectModelHelper.PARENT_CONTEXT); 56 if (context != null) { 57 copletId = (String )context.get(Constants.COPLET_ID_KEY); 58 } else { 59 copletId = (String )objectModel.get(Constants.COPLET_ID_KEY); 60 } 61 62 if (copletId == null) { 63 throw new ConfigurationException("copletId must be passed in the object model either directly (e.g. by using ObjectModelAction) or within the parent context."); 64 } 65 66 final String [] names = parameters.getNames(); 71 if ( names != null ) { 72 final EventManager publisher = portalService.getComponentManager().getEventManager(); 73 for(int i=0; i<names.length; i++) { 74 final String path = names[i]; 75 final String value = parameters.getParameter(path, null ); 76 if ( value != null && value.trim().length() > 0 ) { 77 final Event event = new CopletJXPathEvent(portalService.getComponentManager().getProfileManager().getCopletInstanceData(copletId), 78 path, 79 value); 80 publisher.send(event); 81 } 82 } 83 } 84 85 return EMPTY_MAP; 86 87 } catch (ServiceException e) { 88 throw new ProcessingException("Unable to lookup component.", e); 89 } finally { 90 this.manager.release(portalService); 91 } 92 } 93 } 94 | Popular Tags |