KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > event > aspect > impl > FullScreenCopletEventAspect


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
38
39 /**
40  *
41  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
42  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
43  *
44  * @version CVS $Id: FullScreenCopletEventAspect.java 219049 2005-07-14 15:11:52Z cziegeler $
45  */

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     /* (non-Javadoc)
58      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
59      */

60     public void service(ServiceManager manager) throws ServiceException {
61         this.manager = manager;
62     }
63
64     /* (non-Javadoc)
65      * @see org.apache.cocoon.portal.event.aspect.EventAspect#process(org.apache.cocoon.portal.event.aspect.EventAspectContext, org.apache.cocoon.portal.PortalService)
66      */

67     public void process(EventAspectContext context, PortalService service) {
68         final String JavaDoc requestParameterName = FullScreenCopletEvent.REQUEST_PARAMETER_NAME;
69         final Request request = ObjectModelHelper.getRequest( context.getObjectModel() );
70         String JavaDoc[] 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 JavaDoc 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 JavaDoc list = (List JavaDoc) 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         // and invoke next one
100
context.invokeNext( service );
101     }
102
103     /**
104      * @see Receiver
105      */

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             // ignore
121
} finally {
122             this.manager.release(portalService);
123         }
124     }
125
126     /* (non-Javadoc)
127      * @see org.apache.avalon.framework.activity.Initializable#initialize()
128      */

129     public void initialize()
130     throws Exception JavaDoc {
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     /**
141      * @see org.apache.avalon.framework.activity.Disposable#dispose()
142      */

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 JavaDoc ignore) {
150                 // ignore this here
151
} finally {
152                 this.manager.release( eventManager );
153             }
154         }
155     }
156 }
157
Popular Tags