KickJava   Java API By Example, From Geeks To Geeks.

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


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.StringTokenizer JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.apache.avalon.framework.logger.AbstractLogEnabled;
22 import org.apache.avalon.framework.parameters.Parameters;
23 import org.apache.avalon.framework.thread.ThreadSafe;
24 import org.apache.cocoon.environment.ObjectModelHelper;
25 import org.apache.cocoon.environment.Request;
26 import org.apache.cocoon.portal.LinkService;
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.aspect.EventAspect;
31 import org.apache.cocoon.portal.event.aspect.EventAspectContext;
32
33 /**
34  *
35  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
36  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
37  *
38  * @version CVS $Id: RequestParameterEventAspect.java 219049 2005-07-14 15:11:52Z cziegeler $
39  */

40 public class RequestParameterEventAspect
41     extends AbstractLogEnabled
42     implements EventAspect, ThreadSafe {
43
44     protected void process(EventAspectContext context,
45                            PortalService service,
46                            Request request,
47                            String JavaDoc parameterName) {
48         String JavaDoc[] values = request.getParameterValues( parameterName );
49         final EventManager publisher = service.getComponentManager().getEventManager();
50         if ( values != null ) {
51             for(int i=0; i<values.length; i++) {
52                 final String JavaDoc current = values[i];
53                 final Event e = context.getEventConverter().decode(current);
54                 if ( null != e) {
55                     publisher.send(e);
56                 }
57             }
58         } else {
59             List JavaDoc list = (List JavaDoc) request.getAttribute("org.apache.cocoon.portal." + parameterName);
60             if (list != null) {
61                 Event[] events = (Event[]) list.toArray(new Event[0]);
62                 for (int i = 0; i < events.length; i++) {
63                     publisher.send(events[i]);
64                 }
65             }
66         }
67     }
68     
69     /* (non-Javadoc)
70      * @see org.apache.cocoon.portal.event.aspect.EventAspect#process(org.apache.cocoon.portal.event.aspect.EventAspectContext, org.apache.cocoon.portal.PortalService)
71      */

72     public void process(EventAspectContext context, PortalService service) {
73         final Request request = ObjectModelHelper.getRequest( context.getObjectModel() );
74         final Parameters config = context.getAspectParameters();
75         final String JavaDoc requestParameterNames = config.getParameter("parameter-name", LinkService.DEFAULT_REQUEST_EVENT_PARAMETER_NAME);
76         boolean processedDefault = false;
77         
78         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(requestParameterNames, ", ");
79         while ( tokenizer.hasMoreTokens() ) {
80             final String JavaDoc currentName = tokenizer.nextToken();
81             this.process(context, service, request, currentName);
82             if ( LinkService.DEFAULT_REQUEST_EVENT_PARAMETER_NAME.equals(currentName) ) {
83                 processedDefault = true;
84             }
85         }
86         if ( !processedDefault ) {
87             this.process( context, service, request, LinkService.DEFAULT_REQUEST_EVENT_PARAMETER_NAME );
88         }
89         context.invokeNext( service );
90     }
91
92 }
93
Popular Tags