Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Misc-Utils - Miscellaneous Utility Classes
 * Copyright (C) 2007 Newisys, Inc. or its licensors, as applicable.
 * Java is a registered trademark of Sun Microsystems, Inc. in the U.S. or
 * other countries.
 *
 * Licensed under the Open Software License version 3.0 (the "License"); you
 * may not use this file except in compliance with the License. You should
 * have received a copy of the License along with this software; if not, you
 * may obtain a copy of the License at
 *
 * http://opensource.org/licenses/osl-3.0.php
 *
 * This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */

import org.w3c.dom.Attr;

import org.w3c.dom.Element;

public class Main {
    /**
     * Returns the Boolean value of the unqualified attribute with the given
     * local name belonging to the given element, or null if the attribute is
     * not present.
     * 
     * @param elem an element
     * @param localName an unqualified attribute name
     * @return the Boolean value of the attribute, or null if the attribute is
     *         not present
     */
    public static Boolean getAttrBoolean(Element elem, String localName) {
        String str = getAttrString(elem, localName);
        if (str != null) {
            // valid XML Schema boolean values are 0, 1, false, true
            return new Boolean(str.equals("true") || str.equals("1"));
        } else {
            return null;
        }
    }

    /**
     * Returns the String value of the unqualified attribute with the given
     * local name belonging to the given element, or null if the attribute is
     * not present.
     * 
     * @param elem an element
     * @param localName an unqualified attribute name
     * @return the String value of the attribute, or null if the attribute is
     *         not present
     */
    public static String getAttrString(Element elem, String localName) {
        Attr attr = elem.getAttributeNodeNS(null, localName);
        String value = (attr != null) ? attr.getValue() : null;
        return value;
    }
}