Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Main {
    /**
     * Creates an element without text content
     */
    public static Element createElement(Element parent, Document document, String name) {
        Element element = document.createElement(name);
        parent.appendChild(element);
        return element;
    }

    /**
     * Creates an element with a given text content
     */
    public static Element createElement(Element parent, Document document, String name, String value) {
        Element element = createElement(parent, document, name);
        element.setTextContent(value);
        return element;
    }

    /**
     * Creates an element with content in the form of an integer
     */
    public static Element createElement(Element parent, Document document, String name, int value) {
        return createElement(parent, document, name, Integer.toString(value));
    }

    /**
     * Creates an element with content in the form of a Boolean
     */
    public static Element createElement(Element parent, Document document, String name, boolean value) {
        return createElement(parent, document, name, value ? "S" : "N");
    }

    /**
     * Creates an element with content in the form of a double
     */
    public static Element createElement(Element parent, Document document, String name, double value) {
        return createElement(parent, document, name, Double.toString(value));
    }

    /**
     * Creates an element with content in the form of a date
     */
    public static Element createElement(Element parent, Document document, String name, DateTime value) {
        DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd");
        return createElement(parent, document, name, dtf.print(value));
    }
}