Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 42722 invoked by uid 500); 13 Oct 2001 01:34:56 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 42672 invoked from network); 13 Oct 2001 01:34:54 -0000 Message-Id: <5.0.0.25.0.20011013032848.02bb37d0@pop.bibop.it> X-Sender: simone@discoone.com X-Mailer: QUALCOMM Windows Eudora Version 5.0 Date: Sat, 13 Oct 2001 03:32:33 +0200 To: cocoon-dev@xml.apache.org From: Simone Gianni Subject: Cookie matcher Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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. * *

Example:

*
  * <map:match type="cookie" pattern="skin">
  *     <map:redirect-to uri="{1}"/>
  * </map:match>
  * 
* * @author Simone Gianni * @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: cocoon-dev-unsubscribe@xml.apache.org For additional commands, email: cocoon-dev-help@xml.apache.org