1 16 package org.apache.cocoon.portal.event.aspect.impl; 17 18 import org.apache.avalon.framework.logger.AbstractLogEnabled; 19 import org.apache.avalon.framework.parameters.ParameterException; 20 import org.apache.avalon.framework.parameters.Parameterizable; 21 import org.apache.avalon.framework.parameters.Parameters; 22 import org.apache.avalon.framework.thread.ThreadSafe; 23 import org.apache.cocoon.environment.ObjectModelHelper; 24 import org.apache.cocoon.environment.Request; 25 import org.apache.cocoon.environment.Response; 26 import org.apache.cocoon.portal.PortalService; 27 import org.apache.cocoon.portal.event.aspect.EventAspect; 28 import org.apache.cocoon.portal.event.aspect.EventAspectContext; 29 30 44 public class ActionCounterEventAspect 45 extends AbstractLogEnabled 46 implements EventAspect, 47 ThreadSafe, 48 Parameterizable { 49 50 protected final static String ATTRIBUTE_NAME = ActionCounterEventAspect.class.getName(); 51 52 53 protected String parameterName; 54 55 58 public void process(EventAspectContext context, PortalService service) { 59 final String requestParameterName = context.getAspectParameters().getParameter("parameter-name", this.parameterName); 60 61 int actionCount; 62 63 Integer actionValue = (Integer ) service.getAttribute(ATTRIBUTE_NAME); 64 if (null == actionValue) { 65 actionValue = new Integer (0); 66 service.setAttribute(ATTRIBUTE_NAME, actionValue); 67 actionCount = 0; 68 } else { 69 actionCount = actionValue.intValue() + 1; 70 service.setAttribute(ATTRIBUTE_NAME, new Integer (actionCount)); 71 } 72 73 final Request request = ObjectModelHelper.getRequest( context.getObjectModel() ); 74 String value = request.getParameter( requestParameterName ); 75 if ( value != null && actionCount > 0) { 76 int number = 0; 78 try { 79 number = Integer.parseInt( value ); 80 } catch (Exception ignore) { 81 number = -1; 82 } 83 84 if ( number == actionCount - 1) { 85 context.invokeNext( service ); 87 } 88 } 89 service.getComponentManager().getLinkService().addUniqueParameterToLink( requestParameterName, String.valueOf(actionCount)); 90 91 final Response response = ObjectModelHelper.getResponse( context.getObjectModel() ); 92 response.setHeader("Cache-Control", "no-cache"); 93 response.addHeader("Cache-Control", "no-store"); 94 response.setHeader("Pragma", "no-cache"); 95 response.setHeader("Expires", "Thu, 01 Jan 2000 00:00:00 GMT"); 96 } 97 98 101 public void parameterize(Parameters parameters) 102 throws ParameterException { 103 this.parameterName = parameters.getParameter("parameter-name", "cocoon-portal-action"); 104 } 105 } 106 | Popular Tags |