Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 Copyright (c) 2013 eBay, Inc.
 This program is licensed under the terms of the eBay Common Development and
 Distribution License (CDDL) Version 1.0 (the "License") and any subsequent  version 
 thereof released by eBay.  The then-current version of the License can be found 
 at http://www.opensource.org/licenses/cddl1.php and in the eBaySDKLicense file that 
 is under the eBay SDK ../docs directory.
 */

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

public class Main {
    /**
     * Gets the double value of a named attribute of a node.
     * @param node Node The context node.
     * @param name String
     * @param errValue double
     * @return double
     */
    public static double getAttributeDouble(Node node, String name, double errValue) {
        String s = getAttributeString(node, name);
        if (s != null && s.length() > 0)
            return Double.parseDouble(s);
        else
            return errValue;
    }

    /**
     * Gets the value of a named attribute of a node.
     * @param node Node The context node.
     * @param name String
     * @return String null means node is not found.
     */
    public static String getAttributeString(Node node, String name) {
        Node nd = findAttribute(node, name);
        if (nd != null)
            return nd.getNodeValue();
        return null;
    }

    /**
     * Finds attribute of node by name.
     * @param node Node The context node.
     * @param name String
     * @return Node
     */
    public static Node findAttribute(Node node, String name) {
        Node found = null;
        NamedNodeMap nm = node.getAttributes();
        if (nm != null) {
            for (int i = 0; i < nm.getLength(); i++) {
                Node attr = nm.item(i);
                if (attr.getNodeName().compareToIgnoreCase(name) == 0) {
                    found = attr;
                    break;
                }
            }
        }
        return found;
    }
}