Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.awt.Point;
import org.w3c.dom.Element;

public class Main {
    public static Point getChildAsPoint(Element parent, String childName) {
        if (doesElementContainChildren(parent, childName)) {
            String pointString = getFirstChildElement(parent, childName).getTextContent();
            String[] coords = pointString.split(",");
            if (coords.length == 2) {
                Point point = new Point(Integer.parseInt(coords[0].replaceAll(" ", "")),
                        Integer.parseInt(coords[1].replaceAll(" ", "")));
                return point;
            }
        }
        return null;
    }

    public static boolean doesElementContainChildren(Element parent, String... childNames) {
        boolean missingChild = false;
        for (String childName : childNames) {
            if (parent.getElementsByTagName(childName).getLength() == 0) {
                missingChild = true;
            }
        }
        if (missingChild)
            return false;
        else
            return true;
    }

    public static Element getFirstChildElement(Element parent, String childName) {
        if (parent.getElementsByTagName(childName).getLength() > 0) {
            return (Element) parent.getElementsByTagName(childName).item(0);
        }
        return null;
    }
}