KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dom4j > util > AttributeHelper


1 /*
2  * Copyright 2001-2005 (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
8 package org.dom4j.util;
9
10 import org.dom4j.Attribute;
11 import org.dom4j.Element;
12 import org.dom4j.QName;
13
14 /**
15  * <p>
16  * <code>AttributeHelper</code> a number of helper methods for working with
17  * attribute values.
18  * </p>
19  *
20  * @author <a HREF="mailto:jstrachan@apache.org">James Strachan </a>
21  * @version $Revision: 1.7 $
22  */

23 public class AttributeHelper {
24     protected AttributeHelper() {
25     }
26
27     public static boolean booleanValue(Element element, String JavaDoc attributeName) {
28         return booleanValue(element.attribute(attributeName));
29     }
30
31     public static boolean booleanValue(Element element, QName attributeQName) {
32         return booleanValue(element.attribute(attributeQName));
33     }
34
35     protected static boolean booleanValue(Attribute attribute) {
36         if (attribute == null) {
37             return false;
38         }
39
40         Object JavaDoc value = attribute.getData();
41
42         if (value == null) {
43             return false;
44         } else if (value instanceof Boolean JavaDoc) {
45             Boolean JavaDoc b = (Boolean JavaDoc) value;
46
47             return b.booleanValue();
48         } else {
49             return "true".equalsIgnoreCase(value.toString());
50         }
51     }
52 }
53
54 /*
55  * Redistribution and use of this software and associated documentation
56  * ("Software"), with or without modification, are permitted provided that the
57  * following conditions are met:
58  *
59  * 1. Redistributions of source code must retain copyright statements and
60  * notices. Redistributions must also contain a copy of this document.
61  *
62  * 2. Redistributions in binary form must reproduce the above copyright notice,
63  * this list of conditions and the following disclaimer in the documentation
64  * and/or other materials provided with the distribution.
65  *
66  * 3. The name "DOM4J" must not be used to endorse or promote products derived
67  * from this Software without prior written permission of MetaStuff, Ltd. For
68  * written permission, please contact dom4j-info@metastuff.com.
69  *
70  * 4. Products derived from this Software may not be called "DOM4J" nor may
71  * "DOM4J" appear in their names without prior written permission of MetaStuff,
72  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
73  *
74  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
75  *
76  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
77  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
78  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
79  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
80  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
81  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
82  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
83  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
84  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
85  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
86  * POSSIBILITY OF SUCH DAMAGE.
87  *
88  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
89  */

90
Popular Tags