KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
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 /**
36  * Converts links generated by the PageLabelLinkService into events and publishes them.
37  * Used in conjunction with the PageLabelLinkService, links generated from the layout
38  * portal.xml will be based upon the names of the named items.
39  *
40  * @author Ralph Goers
41  *
42  * @version CVS $Id: $
43  */

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     /**
53      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
54      */

55     public void service(ServiceManager manager) throws ServiceException {
56         this.manager = manager;
57         this.labelManager = (PageLabelManager)manager.lookup(PageLabelManager.ROLE);
58     }
59
60     /**
61      * @see org.apache.avalon.framework.activity.Disposable#dispose()
62      */

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     /**
74      * @see org.apache.cocoon.portal.event.aspect.EventAspect#process(org.apache.cocoon.portal.event.aspect.EventAspectContext, org.apache.cocoon.portal.PortalService)
75      */

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 JavaDoc parameterName = this.labelManager.getRequestParameterName();
81
82             String JavaDoc label = request.getParameter(parameterName);
83             // The pageLabel must be single valued
84
if (label != null) {
85                 String JavaDoc previous = this.labelManager.getPreviousLabel();
86                 if (previous != null && previous.equals(label)) {
87                     // Already on this page. Don't publish the pageLabel events
88
} else {
89                     Iterator JavaDoc iter = this.labelManager.getPageLabelEvents(label).iterator();
90                     // Publish all the events for this page label.
91
while (iter.hasNext()) {
92                         Event event = (Event) iter.next();
93                         publisher.send(event);
94                     }
95             // return;
96
}
97             }
98         }
99
100         context.invokeNext( service );
101     }
102 }
103
Popular Tags