Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * The contents of this file are subject to the Regenstrief Public License
 * Version 1.0 (the "License"); you may not use this file except in compliance with the License.
 * Please contact Regenstrief Institute if you would like to obtain a copy of the license.
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) Regenstrief Institute.  All Rights Reserved.
 */

import org.w3c.dom.*;

public class Main {
    /**
     * returns XML representation of a non negative integer, with specified XML node name
     * 
     * @param doc XML Document in which to build the XML element
     * @param nodename top level XML node name in XML representation
     * @param i the integer
     * @return XML representation of the object, with specified XML node name
     **/
    public final static Element intNonNegToXML(final Document doc, final String nodename, final int i) {
        return i >= 0 ? intToXML(doc, nodename, i) : null;
    }

    /**
     * returns XML representation of an integer, with specified XML node name
     * 
     * @param doc XML Document in which to build the XML element
     * @param nodename top level XML node name in XML representation
     * @param i the integer
     * @return XML representation of the integer, with specified XML node name
     **/
    public final static Element intToXML(final Document doc, final String nodename, final int i) {
        return strToXML(doc, nodename, String.valueOf(i));
    }

    /**
     * returns XML representation of a string, with specified XML node name
     * 
     * @param doc XML Document in which to build the XML element
     * @param nodename top level XML node name in XML representation
     * @param str the string
     * @return XML representation of the string, with specified XML node name
     **/
    public final static Element strToXML(final Document doc, final String nodename, final String str) {
        return strToXML(doc, null, nodename, str);
    }

    /**
     * returns XML representation of a string, with specified XML node name
     * 
     * @param doc XML Document in which to build the XML element
     * @param namespaceURI the namespace URI
     * @param qname top level qualified XML node name in XML representation
     * @param str the string
     * @return XML representation of the string, with specified XML node name
     **/
    public final static Element strToXML(final Document doc, final String namespaceURI, final String qname,
            final String str) {
        if (str == null /*|| str.length() == 0*/) {
            return null;
        }
        final Element xml = doc.createElementNS(namespaceURI, qname);
        xml.appendChild(doc.createTextNode(str));

        return xml;
    }

    /**
     * Appends a child to the given xml Node
     * 
     * @param xml the parent Node
     * @param child the child Node to append to parent
     **/
    public final static void appendChild(final Node xml, final Node child) {
        if ((xml == null) || (child == null)) {
            return;
        }
        xml.appendChild(child);
    }
}