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/05 02:09:20 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/matching RegexpParameterMatcher.java WildcardParameterMatcher.java

vgritsenko    02/03/04 17:09:20

  Added:       src/java/org/apache/cocoon/selection CookieSelector.java
               src/java/org/apache/cocoon/matching
                        RegexpParameterMatcher.java
                        WildcardParameterMatcher.java
  Log:
  new matchers/selectors
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/selection/CookieSelector.java
  
  Index: CookieSelector.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.selection;
  
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.environment.Cookie;
  import org.apache.cocoon.environment.ObjectModelHelper;
  
  import java.util.Map;
  
  /**
   * A <code>Selector</code> that matches a string against a configurable cookie's value.
   *
   * <p><b>Global and local configuration</b></p>
   * <table border="1">
   * <tr>
   *	<td><code>cookie-name</code></td>
   *	<td>Name of the cookie whose value to match against</td>
   *	</tr>
   * </table>
   *
   * @author <a href="mailto:matteodg@infinito.it">Matteo Di Giovinazzo</a>
   */
  public class CookieSelector extends AbstractLoggable
          implements Configurable, Selector, ThreadSafe {
  
      protected String defaultName;
  
      public void configure(Configuration config) throws ConfigurationException {
          this.defaultName = config.getChild("cookie-name").getValue(null);
      }
  
      public boolean select(String expression, Map objectModel, Parameters parameters) {
  
          String name = parameters.getParameter("cookie-name", this.defaultName);
          if (name == null) {
              getLogger().warn("No cookie name given -- failing.");
              return false;
          }
  
          Cookie[] cookies = ObjectModelHelper.getRequest(objectModel).getCookies();
          if (cookies == null) {
              getLogger().debug("Cookie '" + name + "' not set -- failing");
              return false;
          }
  
          // TODO: this is not optimized
          String value = null;
          for (int i = 0; i < cookies.length; i++) {
              if (cookies[i].getName().equals(name)) {
                  value = cookies[i].getValue();
                  break;
              }
          }
  
          if (value == null) {
              getLogger().debug("Cookie '" + name + "' not set -- failing");
              return false;
          }
  
          return value.equals(expression);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/matching/RegexpParameterMatcher.java
  
  Index: RegexpParameterMatcher.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.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.environment.ObjectModelHelper;
  
  import java.util.Map;
  
  /**
   * Matches a sitemap parameter against a regular expression.
   *
   * <p><b>Global and local configuration</b></p>
   * <table border="1">
   * <tr><td><code>parameter-name</code></td><td>Name of the sitemap parameter to
   * match against</td></tr>
   * </table>
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @version CVS $Id: RegexpParameterMatcher.java,v 1.1 2002/03/05 01:09:20 vgritsenko Exp $
   */
  public class RegexpParameterMatcher extends AbstractRegexpMatcher
      implements Configurable
  {
      private String defaultParam;
  
      public void configure(Configuration config) throws ConfigurationException {
          this.defaultParam = config.getChild("parameter-name").getValue(null);
      }
  
      protected String getMatchString(Map objectModel, Parameters parameters) {
  
          String paramName = parameters.getParameter("parameter-name", this.defaultParam);
          if (paramName == null) {
              getLogger().warn("No parameter name given. FAILING");
              return null;
          }
  
          String result = parameters.getParameter(paramName, null);
          if (result == null) {
              getLogger().debug("Parameter '" + paramName + "' not set.");
          }
  
          return result;
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/matching/WildcardParameterMatcher.java
  
  Index: WildcardParameterMatcher.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.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.environment.ObjectModelHelper;
  
  import java.util.Map;
  
  /**
   * Matches a sitemap parameter against a wildcard expression.
   *
   * <p><b>Global and local configuration</b></p>
   * <table border="1">
   * <tr><td><code>parameter-name</code></td><td>Name of the sitemap parameter to
   * match against</td></tr>
   * </table>
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @version CVS $Id: WildcardParameterMatcher.java,v 1.1 2002/03/05 01:09:20 vgritsenko Exp $
   */
  public class WildcardParameterMatcher extends AbstractWildcardMatcher
      implements Configurable
  {
      private String defaultParam;
  
      public void configure(Configuration config) throws ConfigurationException {
          this.defaultParam = config.getChild("parameter-name").getValue(null);
      }
  
      protected String getMatchString(Map objectModel, Parameters parameters) {
  
          String paramName = parameters.getParameter("parameter-name", this.defaultParam);
          if (paramName == null) {
              getLogger().warn("No parameter name given. FAILING");
              return null;
          }
  
          String value = parameters.getParameter(paramName, null);
          if (value == null) {
              getLogger().debug("Parameter '" + paramName + "' not set.");
          }
  
          return value;
      }
  }
  
  
  

----------------------------------------------------------------------
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