1 16 package org.apache.cocoon.portal.event.aspect.impl; 17 18 import java.util.StringTokenizer ; 19 20 import org.apache.avalon.framework.logger.AbstractLogEnabled; 21 import org.apache.avalon.framework.service.ServiceException; 22 import org.apache.avalon.framework.service.ServiceManager; 23 import org.apache.avalon.framework.service.Serviceable; 24 import org.apache.avalon.framework.thread.ThreadSafe; 25 import org.apache.cocoon.environment.ObjectModelHelper; 26 import org.apache.cocoon.environment.Request; 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 import org.apache.cocoon.portal.layout.Layout; 33 34 41 public abstract class AbstractContentEventAspect 42 extends AbstractLogEnabled 43 implements EventAspect, ThreadSafe, Serviceable { 44 45 protected ServiceManager manager; 46 47 50 public void service(ServiceManager manager) throws ServiceException { 51 this.manager = manager; 52 } 53 54 protected abstract String getRequestParameterName(); 55 56 protected abstract int getRequiredValueCount(); 57 58 65 protected abstract void publish(EventManager publisher, Layout layout, String [] values); 66 67 73 protected void publish( PortalService service, EventManager publisher, String [] values) { 74 Layout layout = service.getComponentManager().getProfileManager().getPortalLayout(values[0], values[1] ); 75 if ( layout != null ) { 76 this.publish( publisher, layout, values); 77 } 78 } 79 80 83 public void process(EventAspectContext context, PortalService service) { 84 final Request request = ObjectModelHelper.getRequest(context.getObjectModel()); 85 String [] values = request.getParameterValues(this.getRequestParameterName()); 86 if (values != null) { 87 final EventManager publisher = service.getComponentManager().getEventManager(); 88 for (int i = 0; i < values.length; i++) { 89 final String value = values[i]; 91 Event e = null; 92 try { 93 e = context.getEventConverter().decode(value); 94 if (null != e) { 95 publisher.send(e); 96 } 97 } catch (Exception ignore) { 98 } 100 if (e == null) { 102 StringTokenizer tokenizer = new StringTokenizer (value, "|"); 104 int tokenNumber = 0; 105 int tokenCount = tokenizer.countTokens(); 106 if (tokenCount == this.getRequiredValueCount()-1) { 109 tokenNumber = tokenNumber + 1; 110 tokenCount++; 111 } 112 113 if ( tokenCount == this.getRequiredValueCount() ) { 114 String [] eventValues = new String [tokenCount]; 115 116 while (tokenizer.hasMoreTokens()) { 117 eventValues[tokenNumber] = tokenizer.nextToken(); 118 119 tokenNumber = tokenNumber + 1; 120 } 121 122 this.publish( service, publisher, eventValues ); 123 124 } else { 125 this.getLogger().warn("Data for Event is not set correctly"); 126 } 127 } 128 } 129 } 130 context.invokeNext(service); 132 } 133 134 } 135 | Popular Tags |