Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Copyright (C) 2014-2017 Philip Helger (www.helger.com)
 * philip[at]helger[dot]com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License 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 javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.w3c.dom.Attr;

import org.w3c.dom.Element;

public class Main {
    /**
     * The latest version of XercesJ 2.9 returns an empty string for non existing
     * attributes. To differentiate between empty attributes and non-existing
     * attributes, this method returns null for non existing attributes.
     *
     * @param aElement
     *        the source element to get the attribute from
     * @param sNamespaceURI
     *        The namespace URI of the attribute to retrieve. May be
     *        <code>null</code>.
     * @param sAttrName
     *        the name of the attribute to query
     * @return <code>null</code> if the attribute does not exists, the string
     *         value otherwise
     */
    @Nullable
    public static String getAttributeValueNS(@Nonnull final Element aElement, @Nullable final String sNamespaceURI,
            @Nonnull final String sAttrName) {
        return getAttributeValueNS(aElement, sNamespaceURI, sAttrName, null);
    }

    /**
     * The latest version of XercesJ 2.9 returns an empty string for non existing
     * attributes. To differentiate between empty attributes and non-existing
     * attributes, this method returns a default value for non existing
     * attributes.
     *
     * @param aElement
     *        the source element to get the attribute from. May not be
     *        <code>null</code>.
     * @param sNamespaceURI
     *        The namespace URI of the attribute to retrieve. May be
     *        <code>null</code>.
     * @param sAttrName
     *        the name of the attribute to query. May not be <code>null</code>.
     * @param sDefault
     *        the value to be returned if the attribute is not present.
     * @return the default value if the attribute does not exists, the string
     *         value otherwise
     */
    @Nullable
    public static String getAttributeValueNS(@Nonnull final Element aElement, @Nullable final String sNamespaceURI,
            @Nonnull final String sAttrName, @Nullable final String sDefault) {
        final Attr aAttr = aElement.getAttributeNodeNS(sNamespaceURI, sAttrName);
        return aAttr == null ? sDefault : aAttr.getValue();
    }
}