You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by bu...@apache.org on 2002/02/25 18:09:39 UTC

DO NOT REPLY [Bug 6657] New: - CookieMatcher [contribution]

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6657>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6657

CookieMatcher [contribution]

           Summary: CookieMatcher [contribution]
           Product: Cocoon 2
           Version: Current CVS
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: sitemap components
        AssignedTo: cocoon-dev@xml.apache.org
        ReportedBy: maciejka@tiger.com.pl


/* Example of usage:
  <map:match type="cookie" pattern="CURRENT_USER_ID">
      <map:generate src="cocoon://home/{CURRENT_USER_ID}/index.xml"/>
      <map:transform src="xsl/2html/page2html.xsl"/>
      <map:serialize/>      
  </map:match>

*/


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());
                    }
                }
            }
        }
        return result;
    }
}

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