You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2002/03/03 02:03:48 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/matching CookieMatcher.java HeaderMatcher.java ParameterMatcher.java

vgritsenko    02/03/02 17:03:48

  Modified:    src/webapp sitemap.xmap
  Added:       src/java/org/apache/cocoon/matching CookieMatcher.java
                        HeaderMatcher.java ParameterMatcher.java
  Log:
  Add new matchers
  
  Revision  Changes    Path
  1.34      +9 -0      xml-cocoon2/src/webapp/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/webapp/sitemap.xmap,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- sitemap.xmap	28 Feb 2002 21:41:24 -0000	1.33
  +++ sitemap.xmap	3 Mar 2002 01:03:47 -0000	1.34
  @@ -157,6 +157,15 @@
      <map:matcher name="request-parameter" logger="sitemap.matcher.request-parameter"
                   src="org.apache.cocoon.matching.RequestParameterMatcher"/>
   
  +   <map:matcher name="cookie" logger="sitemap.matcher.cookie"
  +                src="org.apache.cocoon.matching.CookieMatcher"/>
  +
  +   <map:matcher name="header" logger="sitemap.matcher.header"
  +                src="org.apache.cocoon.matching.HeaderMatcher"/>
  +
  +   <map:matcher name="parameter" logger="sitemap.matcher.parameter"
  +                src="org.apache.cocoon.matching.ParameterMatcher"/>
  +
      <map:matcher name="sessionstate"  logger="sitemap.matcher.sessionstate"
                   src="org.apache.cocoon.matching.WildcardSessionAttributeMatcher">
         <attribute-name>org.apache.cocoon.SessionState</attribute-name>
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/matching/CookieMatcher.java
  
  Index: CookieMatcher.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.matching;
  
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.Constants;
  import org.apache.cocoon.environment.Cookie;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.sitemap.PatternException;
  
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * 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();
                      result.put("1", cookie.getValue());
                      break;
                  }
              }
          }
  
          return result;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/matching/HeaderMatcher.java
  
  Index: HeaderMatcher.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.matching;
  
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * This class allows for matching based on a request header.
   * If the specified request header parameter exists, its value is 
   * retrieved for later xpath substitution.
   *
   * <p><b>Example:</b></p>
   * <pre>
   * &lt;map:match type="header" pattern="referer"&gt;
   *     &lt;map:redirect-to uri="{1}"/&gt;
   * &lt;/map:match&gt;
   * </pre>
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @version CVS $Id: HeaderMatcher.java,v 1.1 2002/03/03 01:03:48 vgritsenko Exp $
   */
  public class HeaderMatcher implements Matcher, ThreadSafe
  {
      /**
       * Match method to see if the request header exists. If it does
       * have a value the header added to the array list for later
       * substitution with an xpath attribute.
       *
       * @param pattern name of request header to find
       * @param objectModel environment passed through via cocoon
       * @returns null or map containing value of request header 'pattern'
       */
      public Map match(String pattern, Map objectModel, Parameters parameters) {
          Request request = ObjectModelHelper.getRequest(objectModel);
  
          String value = request.getHeader(pattern);
          if (value == null) {
              return null; // no request header defined
          } else {
              Map map = new HashMap();
              map.put("1", value);
              return map; // request header defined, return map
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/matching/ParameterMatcher.java
  
  Index: ParameterMatcher.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.matching;
  
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * This class allows for matching based on a parameter provided from the sitemap.
   * If the specified sitemap parameter exists, its value is retrieved for later
   * xpath substitution.
   *
   * <p><b>Example:</b></p>
   * <pre>
   * &lt;map:match type="parameter" pattern="dest"&gt;
   *     &lt;map:redirect-to uri="{1}"/&gt;
   * &lt;/map:match&gt;
   * </pre>
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @version CVS $Id: ParameterMatcher.java,v 1.1 2002/03/03 01:03:48 vgritsenko Exp $
   */
  public class ParameterMatcher implements Matcher, ThreadSafe
  {
      /**
       * Match method to see if the sitemap parameter exists. If it does
       * have a value the parameter added to the array list for later
       * substitution with an xpath attribute.
       *
       * @param pattern name of sitemap parameter to find
       * @param objectModel environment passed through via cocoon
       * @returns null or map containing value of sitemap parameter 'pattern'
       */
      public Map match(String pattern, Map objectModel, Parameters parameters) {
  
          String parameter = parameters.getParameter(pattern, null);
          if (parameter == null) {
              return null; // no parameter defined
          } else {
              Map map = new HashMap();
              map.put("1", parameter);
              return map; // parameter defined, return map
          }
      }
  }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org