001/* 002 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 003 * 004 * This software is open source. 005 * See the bottom of this file for the licence. 006 * 007 * $Id: AttributeHelper.java,v 1.1 2001/05/30 22:24:27 jstrachan Exp $ 008 */ 009 010package org.dom4j.util; 011 012import org.dom4j.Attribute; 013import org.dom4j.Element; 014import org.dom4j.Node; 015import org.dom4j.QName; 016 017/** <p><code>AttributeHelper</code> a number of helper methods for 018 * working with attribute values.</p> 019 * 020 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> 021 * @version $Revision: 1.1 $ 022 */ 023public class AttributeHelper { 024 025 public static boolean booleanValue(Element element, String attributeName) { 026 return booleanValue( element.attribute( attributeName ) ); 027 } 028 029 public static boolean booleanValue(Element element, QName attributeQName) { 030 return booleanValue( element.attribute( attributeQName ) ); 031 } 032 033 protected static boolean booleanValue(Attribute attribute) { 034 if ( attribute == null ) { 035 return false; 036 } 037 Object value = attribute.getData(); 038 if ( value == null ) { 039 return false; 040 } 041 else 042 if ( value instanceof Boolean ) { 043 Boolean b = (Boolean) value; 044 return b.booleanValue(); 045 } 046 else { 047 return "true".equalsIgnoreCase( value.toString() ); 048 } 049 } 050} 051 052 053 054 055/* 056 * Redistribution and use of this software and associated documentation 057 * ("Software"), with or without modification, are permitted provided 058 * that the following conditions are met: 059 * 060 * 1. Redistributions of source code must retain copyright 061 * statements and notices. Redistributions must also contain a 062 * copy of this document. 063 * 064 * 2. Redistributions in binary form must reproduce the 065 * above copyright notice, this list of conditions and the 066 * following disclaimer in the documentation and/or other 067 * materials provided with the distribution. 068 * 069 * 3. The name "DOM4J" must not be used to endorse or promote 070 * products derived from this Software without prior written 071 * permission of MetaStuff, Ltd. For written permission, 072 * please contact dom4j-info@metastuff.com. 073 * 074 * 4. Products derived from this Software may not be called "DOM4J" 075 * nor may "DOM4J" appear in their names without prior written 076 * permission of MetaStuff, Ltd. DOM4J is a registered 077 * trademark of MetaStuff, Ltd. 078 * 079 * 5. Due credit should be given to the DOM4J Project 080 * (http://dom4j.org/). 081 * 082 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 083 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 084 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 085 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 086 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 087 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 088 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 089 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 090 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 091 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 092 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 093 * OF THE POSSIBILITY OF SUCH DAMAGE. 094 * 095 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 096 * 097 * $Id: AttributeHelper.java,v 1.1 2001/05/30 22:24:27 jstrachan Exp $ 098 */