cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davanum Srinivas <d...@yahoo.com>
Subject Re: CookieMatcher
Date Tue, 19 Feb 2002 13:13:18 GMT
Maciek,

Is it possible to contribute a small sample that we can test with? If you can please add the
sample as well as the code below at BugZilla (http://nagoya.apache.org/). The sample will
help
people understand how to use the CookieMatcher as well as for testing.

Thanks,
dims

--- Maciek Kaminski <maciejka@tiger.com.pl> wrote:
> Please feel free to add attached CookieMatcher into Cocoon codebase, if You 
> find it useful.
> 
> Maciek Kaminski
> maciejka@tiger.com.pl
> 
> 
> > package org.apache.cocoon.matching;
> 
> import org.apache.avalon.framework.parameters.Parameters;
> import org.apache.avalon.framework.logger.AbstractLoggable;
> 
> import org.apache.cocoon.Constants;
> import org.apache.cocoon.environment.ObjectModelHelper;
> import org.apache.cocoon.environment.Cookie;
> import org.apache.cocoon.environment.Request;
> import org.apache.cocoon.environment.Response;
> import org.apache.cocoon.environment.Cookie;
> import org.apache.cocoon.sitemap.PatternException;
> 
> import java.util.Map;
> import java.util.HashMap;
> 
> /**
>  *
>  * Matches cookies agains given name. Returns name, value pairs for all cookies.
>  * @author <a href="mailto:maciejka@tiger.com.pl">Maciek Kaminski</a>
>  */
> public class CookieMatcher extends AbstractLoggable implements Matcher
> {
>     public Map match (String pattern, Map objectModel, Parameters parameters) throws
> PatternException {
> 
>         if (pattern == null) {
>             throw new PatternException("No cookie name given.");
>         }
> 
>         Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
> 
>         Cookie[] cookies = request.getCookies();
>         HashMap result = null;
> 
>         if (cookies != null) {
>             for ( int i = 0; i < cookies.length; i++) {
>                 Cookie cookie = cookies[i];
>                 if (cookie.getName().equals(pattern)) {
>                     result = new HashMap();
>                     for ( int j = 0; j < cookies.length; j++) {
>                         result.put(cookie.getName(), cookie.getValue());
>                     }
>                 }
>             }
>         }
> 
>         if (result == null) {
>             getLogger().debug("Cookie'" + pattern + "' not set.");
>         }
> 
>         return result;
>     }
> }
> 
> > ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org


=====
Davanum Srinivas - http://jguru.com/dims/

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message