|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AttributeHelper.java | 16,7% | 27,3% | 66,7% | 30% |
|
||||||||||||||
| 1 | /* | |
| 2 | * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. | |
| 3 | * | |
| 4 | * This software is open source. | |
| 5 | * See the bottom of this file for the licence. | |
| 6 | * | |
| 7 | * $Id: AttributeHelper.java,v 1.5 2004/06/25 08:03:41 maartenc Exp $ | |
| 8 | */ | |
| 9 | ||
| 10 | package org.dom4j.util; | |
| 11 | ||
| 12 | import org.dom4j.Attribute; | |
| 13 | import org.dom4j.Element; | |
| 14 | import org.dom4j.QName; | |
| 15 | ||
| 16 | /** <p><code>AttributeHelper</code> a number of helper methods for | |
| 17 | * working with attribute values.</p> | |
| 18 | * | |
| 19 | * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> | |
| 20 | * @version $Revision: 1.5 $ | |
| 21 | */ | |
| 22 | public class AttributeHelper { | |
| 23 | ||
| 24 | 206 | public static boolean booleanValue(Element element, String attributeName) { |
| 25 | 206 | return booleanValue( element.attribute( attributeName ) ); |
| 26 | } | |
| 27 | ||
| 28 | 0 | public static boolean booleanValue(Element element, QName attributeQName) { |
| 29 | 0 | return booleanValue( element.attribute( attributeQName ) ); |
| 30 | } | |
| 31 | ||
| 32 | 206 | protected static boolean booleanValue(Attribute attribute) { |
| 33 | 206 | if ( attribute == null ) { |
| 34 | 206 | return false; |
| 35 | } | |
| 36 | 0 | Object value = attribute.getData(); |
| 37 | 0 | if ( value == null ) { |
| 38 | 0 | return false; |
| 39 | } | |
| 40 | else | |
| 41 | 0 | if ( value instanceof Boolean ) { |
| 42 | 0 | Boolean b = (Boolean) value; |
| 43 | 0 | return b.booleanValue(); |
| 44 | } | |
| 45 | else { | |
| 46 | 0 | return "true".equalsIgnoreCase( value.toString() ); |
| 47 | } | |
| 48 | } | |
| 49 | } | |
| 50 | ||
| 51 | ||
| 52 | ||
| 53 | ||
| 54 | /* | |
| 55 | * Redistribution and use of this software and associated documentation | |
| 56 | * ("Software"), with or without modification, are permitted provided | |
| 57 | * that the following conditions are met: | |
| 58 | * | |
| 59 | * 1. Redistributions of source code must retain copyright | |
| 60 | * statements and notices. Redistributions must also contain a | |
| 61 | * copy of this document. | |
| 62 | * | |
| 63 | * 2. Redistributions in binary form must reproduce the | |
| 64 | * above copyright notice, this list of conditions and the | |
| 65 | * following disclaimer in the documentation and/or other | |
| 66 | * materials provided with the distribution. | |
| 67 | * | |
| 68 | * 3. The name "DOM4J" must not be used to endorse or promote | |
| 69 | * products derived from this Software without prior written | |
| 70 | * permission of MetaStuff, Ltd. For written permission, | |
| 71 | * please contact dom4j-info@metastuff.com. | |
| 72 | * | |
| 73 | * 4. Products derived from this Software may not be called "DOM4J" | |
| 74 | * nor may "DOM4J" appear in their names without prior written | |
| 75 | * permission of MetaStuff, Ltd. DOM4J is a registered | |
| 76 | * trademark of MetaStuff, Ltd. | |
| 77 | * | |
| 78 | * 5. Due credit should be given to the DOM4J Project - | |
| 79 | * http://www.dom4j.org | |
| 80 | * | |
| 81 | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS | |
| 82 | * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT | |
| 83 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 84 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
| 85 | * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 86 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 87 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 88 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 89 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
| 90 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 91 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
| 92 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 93 | * | |
| 94 | * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. | |
| 95 | * | |
| 96 | * $Id: AttributeHelper.java,v 1.5 2004/06/25 08:03:41 maartenc Exp $ | |
| 97 | */ |
|
||||||||||