Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

public class Main {
    public static final AttributesImpl EMPTY_ATTRIBUTES = new AttributesImpl();
    public static final String NULL_TYPE = "";

    public static void start(final ContentHandler handler, final String... elementAndAttributes)
            throws SAXException {
        if (elementAndAttributes == null || elementAndAttributes.length == 0
                || elementAndAttributes.length % 2 != 1) {
            throw new IllegalArgumentException(
                    "elementAndAttributes must contains element name and 0..n pais of attr name-value");
        }
        final String elementName = elementAndAttributes[0];
        AttributesImpl attributes = EMPTY_ATTRIBUTES;
        if (elementAndAttributes.length > 1) {
            attributes = new AttributesImpl();
            for (int i = 1; i + 1 < elementAndAttributes.length;) {
                String attributeName = elementAndAttributes[i++];
                String attributeValue = elementAndAttributes[i++];
                attributes.addAttribute("", attributeName, attributeName, NULL_TYPE, attributeValue);
            }
        }
        start(handler, elementName, attributes);
    }

    public static void start(final ContentHandler handler, final String elementName,
            final AttributesImpl attributes) throws SAXException {
        handler.startElement("", elementName, elementName, attributes);
    }
}