jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject cvs commit: jakarta-taglibs-sandbox/unstandard/src/org/apache/taglibs/unstandard InstanceOfTag.java EqualsTag.java
Date Sat, 01 Mar 2003 03:22:12 GMT
bayard      2003/02/28 19:22:12

  Modified:    unstandard/src/org/apache/taglibs/unstandard
                        InstanceOfTag.java EqualsTag.java
  Log:
  Removed tabs with eight spaces.
  
  Revision  Changes    Path
  1.2       +186 -186  jakarta-taglibs-sandbox/unstandard/src/org/apache/taglibs/unstandard/InstanceOfTag.java
  
  Index: InstanceOfTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs-sandbox/unstandard/src/org/apache/taglibs/unstandard/InstanceOfTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InstanceOfTag.java	10 Feb 2003 16:39:44 -0000	1.1
  +++ InstanceOfTag.java	1 Mar 2003 03:22:12 -0000	1.2
  @@ -1,186 +1,186 @@
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2001-2002 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 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" and "Apache Software Foundation" and
  - *    "Apache Taglibs" 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",
  - *    "Apache Taglibs", 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 (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.unstandard;
  -
  -import java.io.IOException;
  -
  -import javax.servlet.jsp.JspException;
  -import javax.servlet.jsp.JspTagException;
  -import javax.servlet.jsp.tagext.BodyTagSupport;
  -
  -import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
  -import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
  -
  -
  -/**
  - *
  - * @author <a href="bayard@apache.org">Henri Yandell</a>
  - * @author <a href="mailto:tobrien@apache.org">Tim O'Brien</a>
  - */
  -public class InstanceOfTag extends BodyTagSupport {
  -
  -    public static String TAG_NAME = "instanceOf";
  -
  -    // The EL variables, these contain the value from
  -    // the page, may contain unparsed EL content.
  -    private String elVar;
  -    private String elValue;
  -    private String elType;
  -
  -    // These are the true properies.  Note that we've
  -    // got a collection, a boolean, and a String. 
  -    // evaluateExpressions transforms the el strings
  -    // into these values.
  -    private String var = "instanceOf";
  -    private Object value;
  -    private String type;
  -	
  -    public InstanceOfTag() {}
  -
  -    public int doStartTag() throws JspException {
  -		
  -	// Evaluate the EL attributes.  See the 
  -	// JSTL spec.
  -	evaluateExpressions();
  -
  -	boolean instanceOf = false;
  -
  -	if( value == null || type == null ) {
  -	    // If either value or type is null
  -	    instanceOf = false;
  -	} else {
  -
  -	    try {
  -		Class c = Class.forName( type, 
  -					 true, 
  -			     Thread.currentThread().getContextClassLoader() );
  -		instanceOf = c.isInstance( value );
  -	    } catch( Exception e ) {
  -		throw new JspException( e );
  -	    }
  -
  -	}
  -
  -	// Set the result
  -	pageContext.setAttribute( var, new Boolean( instanceOf ) );
  -
  -	return this.EVAL_BODY_BUFFERED;
  -    }
  -
  -    /**
  -     * This function merely writes out the body content.
  -     */
  -    public int doEndTag() throws JspTagException {
  -	try {
  -	    if (getBodyContent() != null) {
  -		getBodyContent().writeOut(getPreviousOut());
  -		getBodyContent().clear();
  -	    }
  -	} catch (IOException e) {
  -	    throw new JspTagException("IOException occured: " + 
  -				      e.getMessage());
  -	}
  -	return EVAL_PAGE;
  -    }
  -	
  -    public String getVar() { return elVar; }
  -    public void setVar(String pVar) { elVar = pVar; }
  -
  -    public String getValue() { return elValue; }
  -    public void setValue(String pValue) { elValue = pValue; }
  -
  -    public String getType() { return elType; }
  -    public void setType(String pType) { elType = pType; }
  -
  -    private void evaluateExpressions() throws JspException {
  -
  -	// Get the Variable name to set.			
  -	if( elVar != null ) {
  -	    Object r = 
  -		ExpressionEvaluatorManager.evaluate( "var", elVar,
  -						     String.class, this,
  -						     this.pageContext );
  -	    if( r == null ) {
  -		throw new NullAttributeException( TAG_NAME, "var" );
  -	    }
  -	    var = ((String) r);
  -	}	
  -
  -	// Get the Value to test.			
  -	if( elValue != null ) {
  -	    Object r = 
  -		ExpressionEvaluatorManager.evaluate( "value", elValue,
  -						     Object.class, this,
  -						     this.pageContext );
  -	    if( r == null ) {
  -		throw new NullAttributeException( TAG_NAME, "value" );
  -	    }
  -	    value = ((Object) r);
  -	}	
  -
  -	// Get the Variable name to set.			
  -	if( elType != null ) {
  -	    Object r = 
  -		ExpressionEvaluatorManager.evaluate( "type", elType,
  -						     String.class, this,
  -						     this.pageContext );
  -	    if( r == null ) {
  -		throw new NullAttributeException( TAG_NAME, "type" );
  -	    }
  -	    type = ((String) r);
  -	}	
  -
  -    }
  -}
  -
  +/* ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001-2002 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 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" and "Apache Software Foundation" and
  + *    "Apache Taglibs" 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",
  + *    "Apache Taglibs", 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 (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.unstandard;
  +
  +import java.io.IOException;
  +
  +import javax.servlet.jsp.JspException;
  +import javax.servlet.jsp.JspTagException;
  +import javax.servlet.jsp.tagext.BodyTagSupport;
  +
  +import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
  +import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
  +
  +
  +/**
  + *
  + * @author <a href="bayard@apache.org">Henri Yandell</a>
  + * @author <a href="mailto:tobrien@apache.org">Tim O'Brien</a>
  + */
  +public class InstanceOfTag extends BodyTagSupport {
  +
  +    public static String TAG_NAME = "instanceOf";
  +
  +    // The EL variables, these contain the value from
  +    // the page, may contain unparsed EL content.
  +    private String elVar;
  +    private String elValue;
  +    private String elType;
  +
  +    // These are the true properies.  Note that we've
  +    // got a collection, a boolean, and a String. 
  +    // evaluateExpressions transforms the el strings
  +    // into these values.
  +    private String var = "instanceOf";
  +    private Object value;
  +    private String type;
  +        
  +    public InstanceOfTag() {}
  +
  +    public int doStartTag() throws JspException {
  +        	
  +        // Evaluate the EL attributes.  See the 
  +        // JSTL spec.
  +        evaluateExpressions();
  +
  +        boolean instanceOf = false;
  +
  +        if( value == null || type == null ) {
  +            // If either value or type is null
  +            instanceOf = false;
  +        } else {
  +
  +            try {
  +        	Class c = Class.forName( type, 
  +        				 true, 
  +        		     Thread.currentThread().getContextClassLoader() );
  +        	instanceOf = c.isInstance( value );
  +            } catch( Exception e ) {
  +        	throw new JspException( e );
  +            }
  +
  +        }
  +
  +        // Set the result
  +        pageContext.setAttribute( var, new Boolean( instanceOf ) );
  +
  +        return this.EVAL_BODY_BUFFERED;
  +    }
  +
  +    /**
  +     * This function merely writes out the body content.
  +     */
  +    public int doEndTag() throws JspTagException {
  +        try {
  +            if (getBodyContent() != null) {
  +        	getBodyContent().writeOut(getPreviousOut());
  +        	getBodyContent().clear();
  +            }
  +        } catch (IOException e) {
  +            throw new JspTagException("IOException occured: " + 
  +        			      e.getMessage());
  +        }
  +        return EVAL_PAGE;
  +    }
  +        
  +    public String getVar() { return elVar; }
  +    public void setVar(String pVar) { elVar = pVar; }
  +
  +    public String getValue() { return elValue; }
  +    public void setValue(String pValue) { elValue = pValue; }
  +
  +    public String getType() { return elType; }
  +    public void setType(String pType) { elType = pType; }
  +
  +    private void evaluateExpressions() throws JspException {
  +
  +        // Get the Variable name to set.			
  +        if( elVar != null ) {
  +            Object r = 
  +        	ExpressionEvaluatorManager.evaluate( "var", elVar,
  +        					     String.class, this,
  +        					     this.pageContext );
  +            if( r == null ) {
  +        	throw new NullAttributeException( TAG_NAME, "var" );
  +            }
  +            var = ((String) r);
  +        }	
  +
  +        // Get the Value to test.			
  +        if( elValue != null ) {
  +            Object r = 
  +        	ExpressionEvaluatorManager.evaluate( "value", elValue,
  +        					     Object.class, this,
  +        					     this.pageContext );
  +            if( r == null ) {
  +        	throw new NullAttributeException( TAG_NAME, "value" );
  +            }
  +            value = ((Object) r);
  +        }	
  +
  +        // Get the Variable name to set.			
  +        if( elType != null ) {
  +            Object r = 
  +        	ExpressionEvaluatorManager.evaluate( "type", elType,
  +        					     String.class, this,
  +        					     this.pageContext );
  +            if( r == null ) {
  +        	throw new NullAttributeException( TAG_NAME, "type" );
  +            }
  +            type = ((String) r);
  +        }	
  +
  +    }
  +}
  +
  
  
  
  1.3       +244 -244  jakarta-taglibs-sandbox/unstandard/src/org/apache/taglibs/unstandard/EqualsTag.java
  
  Index: EqualsTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs-sandbox/unstandard/src/org/apache/taglibs/unstandard/EqualsTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EqualsTag.java	10 Feb 2003 16:39:44 -0000	1.2
  +++ EqualsTag.java	1 Mar 2003 03:22:12 -0000	1.3
  @@ -1,244 +1,244 @@
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2001-2002 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 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" and "Apache Software Foundation" and
  - *    "Apache Taglibs" 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",
  - *    "Apache Taglibs", 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 (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.unstandard;
  -
  -import java.io.IOException;
  -
  -import javax.servlet.jsp.JspException;
  -import javax.servlet.jsp.JspTagException;
  -import javax.servlet.jsp.tagext.BodyTagSupport;
  -import javax.servlet.jsp.PageContext;
  -
  -import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
  -import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
  -
  -
  -/**
  - *
  - *
  - * @author <a href="bayard@apache.org">Henri Yandell</a>
  - * @author <a href="mailto:tobrien@apache.org">Tim O'Brien</a>
  - */
  -public class EqualsTag extends BodyTagSupport {
  -
  -    public static String TAG_NAME = "equals";
  -
  -    // The EL variables, these contain the value from
  -    // the page, may contain unparsed EL content.
  -    private String elVar;
  -    private String elIgnoreCase;
  -    private String elLHS;
  -    private String elRHS;
  -
  -    // These are the true properies.  Note that we've
  -    // got a collection, a boolean, and a String. 
  -    // evaluateExpressions transforms the el strings
  -    // into these values.
  -    private String var = "equals";
  -    private boolean ignoreCase = true;
  -    private Object lhs;
  -    private Object rhs;
  -	
  -    public EqualsTag() {}
  -
  -    public int doStartTag() throws JspException {
  -		
  -	// Evaluate the EL attributes.  See the 
  -	// JSTL spec.
  -	evaluateExpressions();
  -
  -	boolean equals = false;
  -
  -	if( rhs == null || lhs == null ) {
  -	    // If one of the operands is null, return false
  -	    equals = false;
  -	} else if( rhs instanceof String &&
  -		   lhs instanceof String ) {
  -	    String strRHS = (String) rhs;
  -	    String strLHS = (String) lhs;
  -	    
  -	    if( ignoreCase ) {
  -		equals = strLHS.equalsIgnoreCase( strRHS );
  -	    } else {
  -		equals = strLHS.equals( strRHS );
  -	    }
  -	} else {
  -
  -	    // Set temporary attributes on page context
  -	    pageContext.setAttribute("_t_rhs", rhs);
  -	    pageContext.setAttribute("_t_lhs", lhs);
  -
  -	    // throwing this to the EqualityOperator via
  -	    // the ExpressionEvaluatorManager
  -	    Object objEquals =
  -		ExpressionEvaluatorManager.evaluate( "result", 
  -						     "${_t_lhs == _t_rhs}",
  -						     Boolean.class, 
  -						     this,
  -						     this.pageContext );
  -	    equals = ((Boolean) objEquals).booleanValue();
  -
  -	    // Remove temporary attributes on page context
  -	    pageContext.removeAttribute("_t_rhs", PageContext.PAGE_SCOPE );
  -	    pageContext.removeAttribute("_t_lhs", PageContext.PAGE_SCOPE );
  -	}
  -
  -	// Set the result
  -	pageContext.setAttribute( var, new Boolean( equals ) );
  -
  -	return this.EVAL_BODY_BUFFERED;
  -    }
  -
  -    /**
  -     * This function merely writes out the body content.
  -     */
  -    public int doEndTag() throws JspTagException {
  -	try {
  -	    if (getBodyContent() != null) {
  -		getBodyContent().writeOut(getPreviousOut());
  -		getBodyContent().clear();
  -	    }
  -	} catch (IOException e) {
  -	    throw new JspTagException("IOException occured: " + 
  -				      e.getMessage());
  -	}
  -	return EVAL_PAGE;
  -    }
  -	
  -    public String getVar() { return elVar; }
  -    public void setVar(String pVar) { elVar = pVar; }
  -
  -    public String getIgnoreCase() { return elIgnoreCase; }
  -    public void setIgnoreCase(String pIgnoreCase) { 
  -	elIgnoreCase = pIgnoreCase; 
  -    }
  -
  -    public String getLhs() {	return elLHS; }
  -    public void setLhs(String pLHS) { elLHS = pLHS; }
  -
  -    public String getRhs() {	return elRHS; }
  -    public void setRhs(String pRHS) { elRHS = pRHS; }
  -
  -    /**
  -     * This function merely checks to see whether a
  -     * string starts with "${" and ends with "}".  We use
  -     * this to test whether or not a String is an
  -     * EL expression.
  -     */
  -    private boolean isELExpression(String pExpression) {
  -	boolean expression = false;
  -	if( pExpression != null &&
  -	    pExpression.startsWith("${") &&
  -	    pExpression.endsWith("}") ) {
  -	    expression = true;
  -	}
  -	return expression;
  -    }
  -
  -
  -    private void evaluateExpressions() throws JspException {
  -
  -	// Get the Variable name to set.			
  -	if( elVar != null ) {
  -	    Object r = 
  -		ExpressionEvaluatorManager.evaluate( "var", elVar,
  -						     String.class, this,
  -						     this.pageContext );
  -	    if( r == null ) {
  -		throw new NullAttributeException( TAG_NAME, "var" );
  -	    }
  -	    var = ((String) r);
  -	}	
  -
  -	// Get the option to ignore case
  -	if( elIgnoreCase != null ) {
  -	    Object r = 
  -		ExpressionEvaluatorManager.evaluate( "ignoreCase",
  -						     elIgnoreCase,
  -						     Boolean.class,
  -						     this, this.pageContext );
  -	    if( r == null ) {
  -		throw new NullAttributeException( TAG_NAME, "ignoreCase" );
  -	    }
  -			
  -	    Boolean bIgnoreCase = (Boolean) r;
  -	    ignoreCase = bIgnoreCase.booleanValue();
  -	}	
  -
  -	// Get the Variable name to set.			
  -	if( elLHS != null ) {
  -       	    Object r = 
  -		ExpressionEvaluatorManager.evaluate( "lhs", elLHS, 
  -						     Object.class, this,
  -						     this.pageContext );
  -	    if( r == null ) {
  -		throw new NullAttributeException( TAG_NAME, "lhs" );
  -	    }
  -	    lhs = ((Object) r);
  -	}	
  -
  -	// Get the Variable name to set.			
  -	if( elRHS != null ) {
  -	    Object r = 
  -		ExpressionEvaluatorManager.evaluate( "rhs", elRHS,
  -						     Object.class, this,
  -						     this.pageContext );
  -	    if( r == null ) {
  -		throw new NullAttributeException( TAG_NAME, "rhs" );
  -	    }
  -	    rhs = ((Object) r);
  -	}	
  -    }
  -}
  -
  +/* ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001-2002 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 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" and "Apache Software Foundation" and
  + *    "Apache Taglibs" 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",
  + *    "Apache Taglibs", 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 (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.unstandard;
  +
  +import java.io.IOException;
  +
  +import javax.servlet.jsp.JspException;
  +import javax.servlet.jsp.JspTagException;
  +import javax.servlet.jsp.tagext.BodyTagSupport;
  +import javax.servlet.jsp.PageContext;
  +
  +import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
  +import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
  +
  +
  +/**
  + *
  + *
  + * @author <a href="bayard@apache.org">Henri Yandell</a>
  + * @author <a href="mailto:tobrien@apache.org">Tim O'Brien</a>
  + */
  +public class EqualsTag extends BodyTagSupport {
  +
  +    public static String TAG_NAME = "equals";
  +
  +    // The EL variables, these contain the value from
  +    // the page, may contain unparsed EL content.
  +    private String elVar;
  +    private String elIgnoreCase;
  +    private String elLHS;
  +    private String elRHS;
  +
  +    // These are the true properies.  Note that we've
  +    // got a collection, a boolean, and a String. 
  +    // evaluateExpressions transforms the el strings
  +    // into these values.
  +    private String var = "equals";
  +    private boolean ignoreCase = true;
  +    private Object lhs;
  +    private Object rhs;
  +        
  +    public EqualsTag() {}
  +
  +    public int doStartTag() throws JspException {
  +        	
  +        // Evaluate the EL attributes.  See the 
  +        // JSTL spec.
  +        evaluateExpressions();
  +
  +        boolean equals = false;
  +
  +        if( rhs == null || lhs == null ) {
  +            // If one of the operands is null, return false
  +            equals = false;
  +        } else if( rhs instanceof String &&
  +        	   lhs instanceof String ) {
  +            String strRHS = (String) rhs;
  +            String strLHS = (String) lhs;
  +            
  +            if( ignoreCase ) {
  +        	equals = strLHS.equalsIgnoreCase( strRHS );
  +            } else {
  +        	equals = strLHS.equals( strRHS );
  +            }
  +        } else {
  +
  +            // Set temporary attributes on page context
  +            pageContext.setAttribute("_t_rhs", rhs);
  +            pageContext.setAttribute("_t_lhs", lhs);
  +
  +            // throwing this to the EqualityOperator via
  +            // the ExpressionEvaluatorManager
  +            Object objEquals =
  +        	ExpressionEvaluatorManager.evaluate( "result", 
  +        					     "${_t_lhs == _t_rhs}",
  +        					     Boolean.class, 
  +        					     this,
  +        					     this.pageContext );
  +            equals = ((Boolean) objEquals).booleanValue();
  +
  +            // Remove temporary attributes on page context
  +            pageContext.removeAttribute("_t_rhs", PageContext.PAGE_SCOPE );
  +            pageContext.removeAttribute("_t_lhs", PageContext.PAGE_SCOPE );
  +        }
  +
  +        // Set the result
  +        pageContext.setAttribute( var, new Boolean( equals ) );
  +
  +        return this.EVAL_BODY_BUFFERED;
  +    }
  +
  +    /**
  +     * This function merely writes out the body content.
  +     */
  +    public int doEndTag() throws JspTagException {
  +        try {
  +            if (getBodyContent() != null) {
  +        	getBodyContent().writeOut(getPreviousOut());
  +        	getBodyContent().clear();
  +            }
  +        } catch (IOException e) {
  +            throw new JspTagException("IOException occured: " + 
  +        			      e.getMessage());
  +        }
  +        return EVAL_PAGE;
  +    }
  +        
  +    public String getVar() { return elVar; }
  +    public void setVar(String pVar) { elVar = pVar; }
  +
  +    public String getIgnoreCase() { return elIgnoreCase; }
  +    public void setIgnoreCase(String pIgnoreCase) { 
  +        elIgnoreCase = pIgnoreCase; 
  +    }
  +
  +    public String getLhs() {        return elLHS; }
  +    public void setLhs(String pLHS) { elLHS = pLHS; }
  +
  +    public String getRhs() {        return elRHS; }
  +    public void setRhs(String pRHS) { elRHS = pRHS; }
  +
  +    /**
  +     * This function merely checks to see whether a
  +     * string starts with "${" and ends with "}".  We use
  +     * this to test whether or not a String is an
  +     * EL expression.
  +     */
  +    private boolean isELExpression(String pExpression) {
  +        boolean expression = false;
  +        if( pExpression != null &&
  +            pExpression.startsWith("${") &&
  +            pExpression.endsWith("}") ) {
  +            expression = true;
  +        }
  +        return expression;
  +    }
  +
  +
  +    private void evaluateExpressions() throws JspException {
  +
  +        // Get the Variable name to set.			
  +        if( elVar != null ) {
  +            Object r = 
  +        	ExpressionEvaluatorManager.evaluate( "var", elVar,
  +        					     String.class, this,
  +        					     this.pageContext );
  +            if( r == null ) {
  +        	throw new NullAttributeException( TAG_NAME, "var" );
  +            }
  +            var = ((String) r);
  +        }	
  +
  +        // Get the option to ignore case
  +        if( elIgnoreCase != null ) {
  +            Object r = 
  +        	ExpressionEvaluatorManager.evaluate( "ignoreCase",
  +        					     elIgnoreCase,
  +        					     Boolean.class,
  +        					     this, this.pageContext );
  +            if( r == null ) {
  +        	throw new NullAttributeException( TAG_NAME, "ignoreCase" );
  +            }
  +        		
  +            Boolean bIgnoreCase = (Boolean) r;
  +            ignoreCase = bIgnoreCase.booleanValue();
  +        }	
  +
  +        // Get the Variable name to set.			
  +        if( elLHS != null ) {
  +                   Object r = 
  +        	ExpressionEvaluatorManager.evaluate( "lhs", elLHS, 
  +        					     Object.class, this,
  +        					     this.pageContext );
  +            if( r == null ) {
  +        	throw new NullAttributeException( TAG_NAME, "lhs" );
  +            }
  +            lhs = ((Object) r);
  +        }	
  +
  +        // Get the Variable name to set.			
  +        if( elRHS != null ) {
  +            Object r = 
  +        	ExpressionEvaluatorManager.evaluate( "rhs", elRHS,
  +        					     Object.class, this,
  +        					     this.pageContext );
  +            if( r == null ) {
  +        	throw new NullAttributeException( TAG_NAME, "rhs" );
  +            }
  +            rhs = ((Object) r);
  +        }	
  +    }
  +}
  +
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Mime
View raw message