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.logger.AbstractLogEnabled;
020: import org.apache.avalon.framework.parameters.ParameterException;
021: import org.apache.avalon.framework.parameters.Parameterizable;
022: import org.apache.avalon.framework.parameters.Parameters;
023: import org.apache.avalon.framework.thread.ThreadSafe;
024: import org.apache.cocoon.environment.ObjectModelHelper;
025: import org.apache.cocoon.environment.Request;
026: import org.apache.cocoon.environment.Response;
027: import org.apache.cocoon.portal.PortalService;
028: import org.apache.cocoon.portal.event.aspect.EventAspect;
029: import org.apache.cocoon.portal.event.aspect.EventAspectContext;
030:
031: /**
032: * This aspect "disables" the back button of the browser and tries to avoid
033: * problems with the user browsing in multiple windows.
034: * This event attaches a unique number to each request. For each user only the
035: * current number is "active". Every request comming in containing an older
036: * number is disregarded and therefore ignored.
037: * WARNING: This aspect solves some problems while introducing new ones. Some
038: * features of the portal do NOT work when this aspect is used.
039: *
040: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
041: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
042: *
043: * @version CVS $Id: ActionCounterEventAspect.java 433543 2006-08-22 06:22:54Z crossley $
044: */
045: public class ActionCounterEventAspect extends AbstractLogEnabled
046: implements EventAspect, ThreadSafe, Parameterizable {
047:
048: protected final static String ATTRIBUTE_NAME = ActionCounterEventAspect.class
049: .getName();
050:
051: /** The name of the parameter to check */
052: protected String parameterName;
053:
054: /* (non-Javadoc)
055: * @see org.apache.cocoon.portal.event.aspect.EventAspect#process(org.apache.cocoon.portal.event.aspect.EventAspectContext, org.apache.cocoon.portal.PortalService)
056: */
057: public void process(EventAspectContext context,
058: PortalService service) {
059: final String requestParameterName = context
060: .getAspectParameters().getParameter("parameter-name",
061: this .parameterName);
062:
063: int actionCount;
064:
065: Integer actionValue = (Integer) service
066: .getAttribute(ATTRIBUTE_NAME);
067: if (null == actionValue) {
068: actionValue = new Integer(0);
069: service.setAttribute(ATTRIBUTE_NAME, actionValue);
070: actionCount = 0;
071: } else {
072: actionCount = actionValue.intValue() + 1;
073: service.setAttribute(ATTRIBUTE_NAME, new Integer(
074: actionCount));
075: }
076:
077: final Request request = ObjectModelHelper.getRequest(context
078: .getObjectModel());
079: String value = request.getParameter(requestParameterName);
080: if (value != null && actionCount > 0) {
081: // get number
082: int number = 0;
083: try {
084: number = Integer.parseInt(value);
085: } catch (Exception ignore) {
086: number = -1;
087: }
088:
089: if (number == actionCount - 1) {
090: // and invoke next one
091: context.invokeNext(service);
092: }
093: }
094: service.getComponentManager().getLinkService()
095: .addUniqueParameterToLink(requestParameterName,
096: String.valueOf(actionCount));
097:
098: final Response response = ObjectModelHelper.getResponse(context
099: .getObjectModel());
100: response.setHeader("Cache-Control", "no-cache");
101: response.addHeader("Cache-Control", "no-store");
102: response.setHeader("Pragma", "no-cache");
103: response.setHeader("Expires", "Thu, 01 Jan 2000 00:00:00 GMT");
104: }
105:
106: /* (non-Javadoc)
107: * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
108: */
109: public void parameterize(Parameters parameters)
110: throws ParameterException {
111: this .parameterName = parameters.getParameter("parameter-name",
112: "cocoon-portal-action");
113: }
114: }
|