Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.*;

public class Main {
    /** Helper method - gets a named attribute's value as a <I>long</I>.
       @param pNodeMap The <I>NamedNodeMap</I>.
       @param strName Name of the attribute.
       @return Value of the attribute.
     */
    public static long getAttributeLong(NamedNodeMap pNodeMap, String strName)
            throws ClassCastException, NumberFormatException {
        String strValue = getAttributeString(pNodeMap, strName);

        if (null == strValue)
            return Long.MIN_VALUE;

        return Long.parseLong(strValue);
    }

    /** Helper method - gets a named attribute's value as a <I>String</I>.
       @param pNodeMap The <I>NamedNodeMap</I>.
       @param strName Name of the attribute.
       @return Value of the attribute.
     */
    public static String getAttributeString(NamedNodeMap pNodeMap, String strName) throws ClassCastException {
        Attr pAttr = getAttribute(pNodeMap, strName);

        if (null == pAttr)
            return null;

        return pAttr.getValue();
    }

    /** Helper methods - gets the <I>Attr</I> <I>Node</I> object from a
    <I>NamedNodeMap</I> of attributes.
       @param pNodeMap The <I>NamedNodeMap</I>.
       @param strName Name of the attribute.
       @return An <I>Attr</I> object.
     */
    public static Attr getAttribute(NamedNodeMap pNodeMap, String strName) throws ClassCastException {
        Node pReturn = pNodeMap.getNamedItem(strName);

        if ((null == pReturn) || (pReturn instanceof Attr))
            return (Attr) pReturn;

        throw new ClassCastException("The node retrieved from the NamedNodeMap is not an Attr object.");
    }
}