jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gl...@apache.org
Subject cvs commit: jakarta-taglibs/session/src/org/apache/taglibs/session EqualsAttributeTag.java
Date Mon, 09 Jul 2001 02:05:19 GMT
glenn       01/07/08 19:05:19

  Added:       session/src/org/apache/taglibs/session
                        EqualsAttributeTag.java
  Log:
  New tag
  
  Revision  Changes    Path
  1.1                  jakarta-taglibs/session/src/org/apache/taglibs/session/EqualsAttributeTag.java
  
  Index: EqualsAttributeTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-taglibs/session/src/org/apache/taglibs/session/EqualsAttributeTag.java,v
1.1 2001/07/09 02:05:18 glenn Exp $
   * $Revision: 1.1 $
   * $Date: 2001/07/09 02:05:18 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.taglibs.session;
  
  import java.util.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  
  /**
   * JSP Tag <b>equalsAttribute</b>, used to determine if a Session
   * attribute equals the value of the "match" tag attribute.
   * <p>
   * Includes the body of the tag if the attribute equals the value of the 
   * "match" tag attribute.
   * <p>
   * You can set the optional tag attribute <b>value</b> to <i>true</i>
or
   * <i>false</i>.  The body of the tag is included if equalsAttribute matches
   * the value.
   * <p>
   * You can set the optional tag attribute <b>ignoreCase</b> to <i>true</i>
or
   * <i>false</i>.  If ignoreCase is set to true, then the comparison between
the
   * session attribute and the "match" tag attribute will <i>not</i> be 
   * case-sensitive.
   * <p>
   * JSP Tag Lib Descriptor
   * <p><pre>
   * &lt;name>equalsAttribute&lt;/name>
   * &lt;tagclass>org.apache.taglibs.page.EqualsAttributeTag&lt;/tagclass>
   * &lt;bodycontent>JSP&lt;/bodycontent>
   * &lt;info>Includes the body of the tag if the page attribute equals the
   * value of the "match" tag attribute.&lt;/info>
   *   &lt;attribute>
   *     &lt;name>name&lt;/name>
   *     &lt;required>true&lt;/required>
   *     &lt;rtexprvalue>false&lt;/rtexprvalue>
   *   &lt;/attribute>
   *   &lt;attribute>
   *     &lt;name>value&lt;/name>
   *     &lt;required>false&lt;/required>
   *     &lt;rtexprvalue>false&lt;/rtexprvalue>
   *   &lt;/attribute>
   *   &lt;attribute>
   *     &lt;name>match&lt;/name>
   *     &lt;required>true&lt;/required>
   *     &lt;rtexprvalue>true&lt;/rtexprvalue>
   *   &lt;/attribute>
   *   &lt;attribute>
   *     &lt;name>ignoreCase&lt;/name>
   *     &lt;required>false&lt;/required>
   *     &lt;rtexprvalue>false&lt;/rtexprvalue>
   *   &lt;/attribute>
   * </pre>
   *
   * @author Morgan Delagrange
   */
  
  
  public class EqualsAttributeTag extends TagSupport
  {
      private String name = null;
      private String match = null;
      //default behaviour is don't ignore case and execute body when tag contents
      //equal value set by setMatch
      private boolean ignoreCase = false;
      private boolean value = true;
  
      /**
       * Includes the body of the tag if the page attribute equals the value set in the 
       * 'match' attribute.
       *
       * @return SKIP_BODY if equalsAttribute body content does not equal the value of 
       * the match attribute, EVAL_BODY_include if it does
       */
      public final int doStartTag() throws JspException
      {
          //result is whether or not tag contents equal the match attribute
          boolean result = false;
          Object attribute = pageContext.getAttribute(name,PageContext.SESSION_SCOPE);
          
          if (attribute != null) {
              String attributeValue = attribute.toString();
            
              if (ignoreCase) {
                  result = attributeValue.equalsIgnoreCase(match);
              } else {
                  result = attributeValue.equals(match);
              }
          }
          
          if( value == result )
              return EVAL_BODY_INCLUDE;
  
          return SKIP_BODY;
      }
  
      /**
       * Set the required tag attribute <b>name</b>. 
       *
       * @param String name of page attribute
       */
      public final void setName(String str)
      {   
  	name = str;
      }
  
  
      /**
       * Set the String that will be compared to the page
       * attribute.
       *
       * @param String value to match against the page attribute
       */
      public final void setMatch(String str) {
          match=str;
      }
      
  
      /**
       * If ignoreCase is set to true, then the comparison 
       * between the "match" attribute and the 
       * page attribute will <i>not</i> be case sensitive
       * 
       * @param boolean    true = ignore case<BR>false = case sensitive<BR>
       *               default value = false
       */
      public final void setIgnoreCase(boolean value) {
          ignoreCase = value;
      }
      
      /**
       * Set the optional tag attribute <b>value</b> to true or false. 
       *
       * @param boolean true or false
       */
      public final void setValue(boolean value)
      {
  	this.value = value;
      }
  
  }
  
  
  

Mime
View raw message