Hi Simone, thanks for your contribution! If noone else is integrating your patches in the next days, I would ask you to add these to bugzilla as an enhancement so that they don't get lost. (Unfortunately, I don't have time to look at it).
Carsten > -----Original Message----- > From: Simone Gianni [mailto:[EMAIL PROTECTED]] > Sent: Saturday, October 13, 2001 3:33 AM > To: [EMAIL PROTECTED] > Subject: Cookie matcher > > > Hi all .. > > I've not found a simple way to match against a cookie, it should be > possible with matching the headers, but since it's a bit confusing and > error prone, I've cloned the RequestParamMatcher and modified it in the > RequestCookieMatcher .. I've not tested it too much .. but it > seems to work > .. and since it's 99% copied from the RequestParamMatcher class it should > be ok ... here is the source : > > /***************************************************************** > ************ > * Copyright (C) The Apache Software Foundation. All rights > reserved. * > * > ------------------------------------------------------------------ > ------- * > * This software is published under the terms of the Apache > Software License * > * version 1.1, a copy of which has been included with this > distribution in * > * the LICENSE file. > * > > ****************************************************************** > ***********/ > > /* > * Package definition > */ > package org.apache.cocoon.matching; > > /* > * Standard imports > */ > import org.apache.avalon.framework.parameters.Parameters; > import org.apache.avalon.framework.thread.ThreadSafe; > import org.apache.cocoon.Constants; > import org.apache.cocoon.environment.Request; > import org.apache.cocoon.environment.Cookie; > > import java.util.HashMap; > import java.util.Map; > > /** > * This class allows for matching based on a request cookie. > * If the specified request cookie exists, its value is > retrieved for later > * xpath substitution. > * > * <p><b>Example:</b></p> > * <pre> > * <map:match type="cookie" pattern="skin"> > * <map:redirect-to uri="{1}"/> > * </map:match> > * </pre> > * > * @author <a href="mailto:[EMAIL PROTECTED]">Simone Gianni</a> > * @version CVS $Revision: 1.3.2.3 $ > */ > public class RequestCookieMatcher implements Matcher, ThreadSafe { > /** > * Match method to see if the request cookie exists. If it does > * have a value the parameter is added to the array list for later > * substitution with a xpath attribute. > * > * @param pattern name of request cookie to find > * @param objectModel environment passed through via cocoon > * @returns null or map containing value of request cookie 'pattern' > */ > public Map match(String pattern, Map objectModel, Parameters > parameters) { > Request request = > (Request) objectModel.get(Constants.REQUEST_OBJECT); > Cookie cook = (Cookie)request.getCookieMap().get(pattern); > String param = null; > if (cook != null) { > param = cook.getValue(); > } > > if (param == null) > return null; // no parameter defined > else { > Map map = new HashMap(); > map.put(Integer.toString(1), param); > return map; // parameter defined, return map > } > } > } > > Hope it will be useful ... > > Congratulations from this great piece of software ! > > Simone Gianni > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, email: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]