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 java.util.StringTokenizer;
020: import java.util.List;
021:
022: import org.apache.avalon.framework.logger.AbstractLogEnabled;
023: import org.apache.avalon.framework.parameters.Parameters;
024: import org.apache.avalon.framework.thread.ThreadSafe;
025: import org.apache.cocoon.environment.ObjectModelHelper;
026: import org.apache.cocoon.environment.Request;
027: import org.apache.cocoon.portal.LinkService;
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.aspect.EventAspect;
032: import org.apache.cocoon.portal.event.aspect.EventAspectContext;
033:
034: /**
035: *
036: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
037: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
038: *
039: * @version CVS $Id: RequestParameterEventAspect.java 433543 2006-08-22 06:22:54Z crossley $
040: */
041: public class RequestParameterEventAspect extends AbstractLogEnabled
042: implements EventAspect, ThreadSafe {
043:
044: protected void process(EventAspectContext context,
045: PortalService service, Request request, String parameterName) {
046: String[] values = request.getParameterValues(parameterName);
047: final EventManager publisher = service.getComponentManager()
048: .getEventManager();
049: if (values != null) {
050: for (int i = 0; i < values.length; i++) {
051: final String current = values[i];
052: final Event e = context.getEventConverter().decode(
053: current);
054: if (null != e) {
055: publisher.send(e);
056: }
057: }
058: } else {
059: List list = (List) request
060: .getAttribute("org.apache.cocoon.portal."
061: + parameterName);
062: if (list != null) {
063: Event[] events = (Event[]) list.toArray(new Event[0]);
064: for (int i = 0; i < events.length; i++) {
065: publisher.send(events[i]);
066: }
067: }
068: }
069: }
070:
071: /* (non-Javadoc)
072: * @see org.apache.cocoon.portal.event.aspect.EventAspect#process(org.apache.cocoon.portal.event.aspect.EventAspectContext, org.apache.cocoon.portal.PortalService)
073: */
074: public void process(EventAspectContext context,
075: PortalService service) {
076: final Request request = ObjectModelHelper.getRequest(context
077: .getObjectModel());
078: final Parameters config = context.getAspectParameters();
079: final String requestParameterNames = config.getParameter(
080: "parameter-name",
081: LinkService.DEFAULT_REQUEST_EVENT_PARAMETER_NAME);
082: boolean processedDefault = false;
083:
084: StringTokenizer tokenizer = new StringTokenizer(
085: requestParameterNames, ", ");
086: while (tokenizer.hasMoreTokens()) {
087: final String currentName = tokenizer.nextToken();
088: this .process(context, service, request, currentName);
089: if (LinkService.DEFAULT_REQUEST_EVENT_PARAMETER_NAME
090: .equals(currentName)) {
091: processedDefault = true;
092: }
093: }
094: if (!processedDefault) {
095: this.process(context, service, request,
096: LinkService.DEFAULT_REQUEST_EVENT_PARAMETER_NAME);
097: }
098: context.invokeNext(service);
099: }
100:
101: }
|