001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.event.aspect.impl;
018:
019: import org.apache.avalon.framework.activity.Disposable;
020: import org.apache.avalon.framework.activity.Initializable;
021: import org.apache.avalon.framework.logger.AbstractLogEnabled;
022: import org.apache.avalon.framework.service.ServiceException;
023: import org.apache.avalon.framework.service.ServiceManager;
024: import org.apache.avalon.framework.service.Serviceable;
025: import org.apache.avalon.framework.thread.ThreadSafe;
026: import org.apache.cocoon.environment.ObjectModelHelper;
027: import org.apache.cocoon.environment.Request;
028: import org.apache.cocoon.portal.PortalService;
029: import org.apache.cocoon.portal.event.Event;
030: import org.apache.cocoon.portal.event.EventManager;
031: import org.apache.cocoon.portal.event.Receiver;
032: import org.apache.cocoon.portal.event.aspect.EventAspect;
033: import org.apache.cocoon.portal.event.aspect.EventAspectContext;
034: import org.apache.cocoon.portal.event.impl.FullScreenCopletEvent;
035: import org.apache.cocoon.portal.layout.Layout;
036: import org.apache.cocoon.portal.layout.impl.CopletLayout;
037:
038: import java.util.List;
039:
040: /**
041: *
042: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
043: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
044: *
045: * @version CVS $Id: FullScreenCopletEventAspect.java 433543 2006-08-22 06:22:54Z crossley $
046: */
047: public class FullScreenCopletEventAspect extends AbstractLogEnabled
048: implements EventAspect, ThreadSafe, Serviceable, Disposable,
049: Receiver, Initializable {
050:
051: protected ServiceManager manager;
052:
053: /* (non-Javadoc)
054: * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
055: */
056: public void service(ServiceManager manager) throws ServiceException {
057: this .manager = manager;
058: }
059:
060: /* (non-Javadoc)
061: * @see org.apache.cocoon.portal.event.aspect.EventAspect#process(org.apache.cocoon.portal.event.aspect.EventAspectContext, org.apache.cocoon.portal.PortalService)
062: */
063: public void process(EventAspectContext context,
064: PortalService service) {
065: final String requestParameterName = FullScreenCopletEvent.REQUEST_PARAMETER_NAME;
066: final Request request = ObjectModelHelper.getRequest(context
067: .getObjectModel());
068: String[] values = request
069: .getParameterValues(requestParameterName);
070: if (values != null) {
071: final EventManager publisher = service
072: .getComponentManager().getEventManager();
073: for (int i = 0; i < values.length; i++) {
074: final String current = values[i];
075: Event e = context.getEventConverter().decode(current);
076: if (null != e) {
077: publisher.send(e);
078: FullScreenCopletEvent fsce = (FullScreenCopletEvent) e;
079: if (fsce.getLayout() != null) {
080: service.getComponentManager().getLinkService()
081: .addEventToLink(e);
082: }
083: }
084: }
085: } else {
086: List list = (List) request
087: .getAttribute("org.apache.cocoon.portal."
088: + requestParameterName);
089: if (list != null) {
090: FullScreenCopletEvent[] events = (FullScreenCopletEvent[]) list
091: .toArray(new FullScreenCopletEvent[0]);
092: final EventManager publisher = service
093: .getComponentManager().getEventManager();
094: for (int i = 0; i < events.length; i++) {
095: FullScreenCopletEvent e = events[i];
096: publisher.send(e);
097: if (e.getLayout() != null) {
098: service.getComponentManager().getLinkService()
099: .addEventToLink(e);
100: }
101: }
102: }
103: }
104: // and invoke next one
105: context.invokeNext(service);
106: }
107:
108: /**
109: * @see Receiver
110: */
111: public void inform(FullScreenCopletEvent event,
112: PortalService service) {
113: final Layout startingLayout = event.getLayout();
114: PortalService portalService = null;
115: try {
116: portalService = (PortalService) this .manager
117: .lookup(PortalService.ROLE);
118: final Layout old = portalService.getEntryLayout(null);
119: if (old != null && old instanceof CopletLayout) {
120: ((CopletLayout) old).getCopletInstanceData()
121: .setAspectData("fullScreen", Boolean.FALSE);
122: }
123: portalService.setEntryLayout(null, startingLayout);
124: if (startingLayout != null
125: && startingLayout instanceof CopletLayout) {
126: ((CopletLayout) startingLayout).getCopletInstanceData()
127: .setAspectData("fullScreen", Boolean.TRUE);
128: }
129: } catch (ServiceException ce) {
130: // ignore
131: } finally {
132: this .manager.release(portalService);
133: }
134: }
135:
136: /* (non-Javadoc)
137: * @see org.apache.avalon.framework.activity.Initializable#initialize()
138: */
139: public void initialize() throws Exception {
140: EventManager eventManager = null;
141: try {
142: eventManager = (EventManager) this .manager
143: .lookup(EventManager.ROLE);
144: eventManager.subscribe(this );
145: } finally {
146: this .manager.release(eventManager);
147: }
148: }
149:
150: /**
151: * @see org.apache.avalon.framework.activity.Disposable#dispose()
152: */
153: public void dispose() {
154: if (this .manager != null) {
155: EventManager eventManager = null;
156: try {
157: eventManager = (EventManager) this .manager
158: .lookup(EventManager.ROLE);
159: eventManager.unsubscribe(this );
160: } catch (Exception ignore) {
161: // ignore this here
162: } finally {
163: this.manager.release(eventManager);
164: }
165: }
166: }
167: }
|