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 <[EMAIL PROTECTED]> wrote:
> Please feel free to add attached CookieMatcher into Cocoon codebase, if You 
> find it useful.
> 
> Maciek Kaminski
> [EMAIL PROTECTED]
> 
> 
> > 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:[EMAIL PROTECTED]";>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: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]


=====
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: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to