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.Color;
import java.awt.Font;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

public class Main {
    public static final String NAME_ATTR = "name";
    public static final String STRING_ATTR = "stringvalue";
    public static final String INTEGER_ATTR = "intvalue";
    public static final String DOUBLE_ATTR = "doublevalue";
    public static final String FLOAT_ATTR = "doublevalue";
    public static final String BOOLEAN_ATTR = "booleanvalue";
    public static final String COLOR_ATTR = "colorvalue";
    public static final String FONT_ATTR = "fontvalue";

    public static Object getPropertyValue(Element element) {
        NamedNodeMap map = element.getAttributes();
        map.removeNamedItem(NAME_ATTR);

        if (map.item(0).getNodeName().equals(STRING_ATTR)) {
            return map.item(0).getNodeValue();
        } else if (map.item(0).getNodeName().equals(INTEGER_ATTR)) {
            return new Integer(map.item(0).getNodeValue());
        } else if (map.item(0).getNodeName().equals(DOUBLE_ATTR)) {
            return new Double(map.item(0).getNodeValue());
        } else if (map.item(0).getNodeName().equals(FLOAT_ATTR)) {
            return new Float(map.item(0).getNodeValue());
        } else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR)) {
            return Boolean.valueOf(map.item(0).getNodeValue());
        } else if (map.item(0).getNodeName().equals(COLOR_ATTR)) {
            String[] rgb = map.item(0).getNodeValue().split(",");
            return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2]));
        } else if (map.item(0).getNodeName().equals(FONT_ATTR)) {
            String[] font = map.item(0).getNodeValue().split(",");
            return new Font(font[0], new Integer(font[1]), new Integer(font[2]));
        } else {
            return null;
        }
    }
}