1 16 package org.apache.cocoon.portal.event.aspect.impl; 17 18 import java.util.StringTokenizer ; 19 import java.util.List ; 20 21 import org.apache.avalon.framework.logger.AbstractLogEnabled; 22 import org.apache.avalon.framework.parameters.Parameters; 23 import org.apache.avalon.framework.thread.ThreadSafe; 24 import org.apache.cocoon.environment.ObjectModelHelper; 25 import org.apache.cocoon.environment.Request; 26 import org.apache.cocoon.portal.LinkService; 27 import org.apache.cocoon.portal.PortalService; 28 import org.apache.cocoon.portal.event.Event; 29 import org.apache.cocoon.portal.event.EventManager; 30 import org.apache.cocoon.portal.event.aspect.EventAspect; 31 import org.apache.cocoon.portal.event.aspect.EventAspectContext; 32 33 40 public class RequestParameterEventAspect 41 extends AbstractLogEnabled 42 implements EventAspect, ThreadSafe { 43 44 protected void process(EventAspectContext context, 45 PortalService service, 46 Request request, 47 String parameterName) { 48 String [] values = request.getParameterValues( parameterName ); 49 final EventManager publisher = service.getComponentManager().getEventManager(); 50 if ( values != null ) { 51 for(int i=0; i<values.length; i++) { 52 final String current = values[i]; 53 final Event e = context.getEventConverter().decode(current); 54 if ( null != e) { 55 publisher.send(e); 56 } 57 } 58 } else { 59 List list = (List ) request.getAttribute("org.apache.cocoon.portal." + parameterName); 60 if (list != null) { 61 Event[] events = (Event[]) list.toArray(new Event[0]); 62 for (int i = 0; i < events.length; i++) { 63 publisher.send(events[i]); 64 } 65 } 66 } 67 } 68 69 72 public void process(EventAspectContext context, PortalService service) { 73 final Request request = ObjectModelHelper.getRequest( context.getObjectModel() ); 74 final Parameters config = context.getAspectParameters(); 75 final String requestParameterNames = config.getParameter("parameter-name", LinkService.DEFAULT_REQUEST_EVENT_PARAMETER_NAME); 76 boolean processedDefault = false; 77 78 StringTokenizer tokenizer = new StringTokenizer (requestParameterNames, ", "); 79 while ( tokenizer.hasMoreTokens() ) { 80 final String currentName = tokenizer.nextToken(); 81 this.process(context, service, request, currentName); 82 if ( LinkService.DEFAULT_REQUEST_EVENT_PARAMETER_NAME.equals(currentName) ) { 83 processedDefault = true; 84 } 85 } 86 if ( !processedDefault ) { 87 this.process( context, service, request, LinkService.DEFAULT_REQUEST_EVENT_PARAMETER_NAME ); 88 } 89 context.invokeNext( service ); 90 } 91 92 } 93 | Popular Tags |