1 16 package org.apache.cocoon.portal.event.aspect.impl; 17 18 import org.apache.avalon.framework.activity.Disposable; 19 import org.apache.avalon.framework.activity.Initializable; 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.Receiver; 31 import org.apache.cocoon.portal.event.aspect.EventAspect; 32 import org.apache.cocoon.portal.event.aspect.EventAspectContext; 33 import org.apache.cocoon.portal.event.impl.FullScreenCopletEvent; 34 import org.apache.cocoon.portal.layout.Layout; 35 import org.apache.cocoon.portal.layout.impl.CopletLayout; 36 37 import java.util.List ; 38 39 46 public class FullScreenCopletEventAspect 47 extends AbstractLogEnabled 48 implements EventAspect, 49 ThreadSafe, 50 Serviceable, 51 Disposable, 52 Receiver, 53 Initializable { 54 55 protected ServiceManager manager; 56 57 60 public void service(ServiceManager manager) throws ServiceException { 61 this.manager = manager; 62 } 63 64 67 public void process(EventAspectContext context, PortalService service) { 68 final String requestParameterName = FullScreenCopletEvent.REQUEST_PARAMETER_NAME; 69 final Request request = ObjectModelHelper.getRequest( context.getObjectModel() ); 70 String [] values = request.getParameterValues( requestParameterName ); 71 if ( values != null ) { 72 final EventManager publisher = service.getComponentManager().getEventManager(); 73 for(int i=0; i<values.length; i++) { 74 final String current = values[i]; 75 Event e = context.getEventConverter().decode(current); 76 if ( null != e ) { 77 publisher.send(e); 78 FullScreenCopletEvent fsce = (FullScreenCopletEvent)e; 79 if ( fsce.getLayout() != null) { 80 service.getComponentManager().getLinkService().addEventToLink( e ); 81 } 82 } 83 } 84 } else { 85 List list = (List ) request.getAttribute("org.apache.cocoon.portal." + requestParameterName); 86 if (list != null) { 87 FullScreenCopletEvent[] events = 88 (FullScreenCopletEvent[]) list.toArray(new FullScreenCopletEvent[0]); 89 final EventManager publisher = service.getComponentManager().getEventManager(); 90 for (int i = 0; i < events.length; i++) { 91 FullScreenCopletEvent e = events[i]; 92 publisher.send(e); 93 if (e.getLayout() != null) { 94 service.getComponentManager().getLinkService().addEventToLink(e); 95 } 96 } 97 } 98 } 99 context.invokeNext( service ); 101 } 102 103 106 public void inform(FullScreenCopletEvent event, PortalService service) { 107 final Layout startingLayout = (CopletLayout)event.getLayout(); 108 PortalService portalService = null; 109 try { 110 portalService = (PortalService) this.manager.lookup(PortalService.ROLE); 111 final Layout old = portalService.getEntryLayout(null); 112 if ( old != null && old instanceof CopletLayout) { 113 ((CopletLayout)old).getCopletInstanceData().setAspectData("fullScreen", Boolean.FALSE); 114 } 115 portalService.setEntryLayout( null, startingLayout ); 116 if ( startingLayout != null && startingLayout instanceof CopletLayout) { 117 ((CopletLayout)startingLayout).getCopletInstanceData().setAspectData("fullScreen", Boolean.TRUE); 118 } 119 } catch (ServiceException ce) { 120 } finally { 122 this.manager.release(portalService); 123 } 124 } 125 126 129 public void initialize() 130 throws Exception { 131 EventManager eventManager = null; 132 try { 133 eventManager = (EventManager) this.manager.lookup( EventManager.ROLE ); 134 eventManager.subscribe( this ); 135 } finally { 136 this.manager.release( eventManager ); 137 } 138 } 139 140 143 public void dispose() { 144 if ( this.manager != null ) { 145 EventManager eventManager = null; 146 try { 147 eventManager = (EventManager) this.manager.lookup( EventManager.ROLE ); 148 eventManager.unsubscribe( this ); 149 } catch (Exception ignore) { 150 } finally { 152 this.manager.release( eventManager ); 153 } 154 } 155 } 156 } 157 | Popular Tags |