Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    /**
     * Gets a boolean value of the given attribute
     * @param node
     * @param attrName
     * @param defaultValue
     * @return
     */
    public static boolean getBooleanValue(Node node, String attrName, boolean defaultValue) {
        String value = getValue(node, attrName, null);

        if (value == null)
            return defaultValue;

        return Boolean.valueOf(value);
    }

    /**
     * Gets a string value of the given attribute
     * @param node
     * @param attrName
     * @param defaultValue
     * @return
     */
    public static String getValue(Node node, String attrName, String defaultValue) {
        Node tmp;
        if (node == null)
            return defaultValue;

        NamedNodeMap attrs = node.getAttributes();
        if (attrs == null)
            return defaultValue;

        String value = (tmp = attrs.getNamedItem(attrName)) != null ? tmp.getNodeValue() : null;

        if (value == null)
            return defaultValue;

        return value;
    }
}