1 16 package org.apache.cocoon.portal.event.aspect.impl; 17 18 import java.util.Iterator ; 19 20 import org.apache.avalon.framework.logger.AbstractLogEnabled; 21 import org.apache.avalon.framework.thread.ThreadSafe; 22 import org.apache.avalon.framework.activity.Disposable; 23 import org.apache.avalon.framework.service.Serviceable; 24 import org.apache.avalon.framework.service.ServiceManager; 25 import org.apache.avalon.framework.service.ServiceException; 26 import org.apache.cocoon.environment.ObjectModelHelper; 27 import org.apache.cocoon.environment.Request; 28 import org.apache.cocoon.portal.PortalService; 29 import org.apache.cocoon.portal.impl.PageLabelManager; 30 import org.apache.cocoon.portal.event.Event; 31 import org.apache.cocoon.portal.event.EventManager; 32 import org.apache.cocoon.portal.event.aspect.EventAspect; 33 import org.apache.cocoon.portal.event.aspect.EventAspectContext; 34 35 44 public class PageLabelEventAspect 45 extends AbstractLogEnabled 46 implements EventAspect, ThreadSafe, Serviceable, Disposable { 47 48 protected ServiceManager manager; 49 50 protected PageLabelManager labelManager; 51 52 55 public void service(ServiceManager manager) throws ServiceException { 56 this.manager = manager; 57 this.labelManager = (PageLabelManager)manager.lookup(PageLabelManager.ROLE); 58 } 59 60 63 public void dispose() { 64 if (this.manager != null) { 65 if (this.labelManager != null) { 66 this.manager.release(this.labelManager); 67 this.labelManager = null; 68 } 69 this.manager = null; 70 } 71 } 72 73 76 public void process(EventAspectContext context, PortalService service) { 77 if (this.labelManager != null) { 78 final EventManager publisher = service.getComponentManager().getEventManager(); 79 final Request request = ObjectModelHelper.getRequest(context.getObjectModel()); 80 final String parameterName = this.labelManager.getRequestParameterName(); 81 82 String label = request.getParameter(parameterName); 83 if (label != null) { 85 String previous = this.labelManager.getPreviousLabel(); 86 if (previous != null && previous.equals(label)) { 87 } else { 89 Iterator iter = this.labelManager.getPageLabelEvents(label).iterator(); 90 while (iter.hasNext()) { 92 Event event = (Event) iter.next(); 93 publisher.send(event); 94 } 95 } 97 } 98 } 99 100 context.invokeNext( service ); 101 } 102 } 103 | Popular Tags |