cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/selection RequestAttributeSelector.java
Date Thu, 10 Jan 2002 16:11:10 GMT
vgritsenko    02/01/10 08:11:10

  Added:       src/java/org/apache/cocoon/selection
                        RequestAttributeSelector.java
  Log:
  Same as SessionAttrbuteSelector, but for request attributes
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/selection/RequestAttributeSelector.java
  
  Index: RequestAttributeSelector.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  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.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  
  import java.util.Map;
  
  /**
   * This class generates source code to implement a selector that
   * matches a string against an arbitrary request attribute.
   *
   * <p><b>Global and local configuration</b></p>
   * <table border="1">
   * <tr><td><code>attribute-name</code></td><td>String
identifying the request attribute.</td></tr>
   * </table>
   *
   * @author <a href="mailto:haul@informatik.tu-darmstadt.de">Christian Haul</a>
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/01/10 16:11:10 $
   */
  public class RequestAttributeSelector extends AbstractLoggable
    implements Configurable, ThreadSafe, Selector {
  
      protected String defaultName;
  
      public void configure(Configuration config) throws ConfigurationException {
          this.defaultName = config.getChild("attribute-name").getValue(null);
      }
  
      public boolean select(String expression, Map objectModel, Parameters parameters) {
          String name = parameters.getParameter("attribute-name", this.defaultName);
  
          if (name == null) {
              getLogger().warn("No attribute name given -- failing.");
              return false;
          }
  
          Object value = ObjectModelHelper.getRequest(objectModel).getAttribute(name);
          if (value == null) {
              getLogger().debug("Request attribute '" + name + "' not set -- failing.");
              return false;
          }
  
          return value.equals(expression);
      }
  }
  
  
  

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


Mime
View raw message