Example usage for org.jdom2 AttributeType getAttributeType

List of usage examples for org.jdom2 AttributeType getAttributeType

Introduction

In this page you can find the example usage for org.jdom2 AttributeType getAttributeType.

Prototype

public static final AttributeType getAttributeType(String typeName) 

Source Link

Document

Returns the the JDOM AttributeType value from the SAX 2.0 attribute type string provided by the parser.

Usage

From source file:com.kixeye.kixmpp.jdom.StAXElementBuilder.java

License:Apache License

/**
 * Processes the current event on a stream reader.
 * /*from  w ww.  j a va2  s  . co  m*/
 * @param streamReader
 * @throws JDOMException 
 */
public void process(XMLStreamReader2 streamReader) throws JDOMException {
    switch (streamReader.getEventType()) {
    case XMLStreamReader2.START_ELEMENT: {
        // build the element
        Namespace namespace = getNamespace(streamReader.getPrefix(), streamReader.getNamespaceURI());

        Element element = null;
        if (namespace == null) {
            element = builderFactory.element(streamReader.getLocalName());
        } else {
            element = builderFactory.element(streamReader.getLocalName(),
                    getNamespace(streamReader.getPrefix(), streamReader.getNamespaceURI()));
        }

        if (rootElement == null) {
            rootElement = element;
            currentElement = element;
        } else {
            currentElement.addContent(element);
            currentElement = element;
        }

        // set attributes
        for (int i = 0, len = streamReader.getAttributeCount(); i < len; i++) {
            namespace = getNamespace(streamReader.getAttributePrefix(i), streamReader.getAttributeNamespace(i));
            Attribute attribute = null;

            if (namespace == null) {
                attribute = builderFactory.attribute(streamReader.getAttributeLocalName(i),
                        streamReader.getAttributeValue(i),
                        AttributeType.getAttributeType(streamReader.getAttributeType(i)), getNamespace(
                                streamReader.getAttributePrefix(i), streamReader.getAttributeNamespace(i)));
            } else {
                attribute = builderFactory.attribute(streamReader.getAttributeLocalName(i),
                        streamReader.getAttributeValue(i),
                        AttributeType.getAttributeType(streamReader.getAttributeType(i)));
            }

            builderFactory.setAttribute(element, attribute);
        }

        // set namespaces
        for (int i = 0, len = streamReader.getNamespaceCount(); i < len; i++) {
            namespace = getNamespace(streamReader.getNamespacePrefix(i), streamReader.getNamespaceURI(i));

            if (namespace != null) {
                element.addNamespaceDeclaration(namespace);
            }
        }
    }
        break;
    case XMLStreamReader2.END_ELEMENT: {
        if (currentElement != null) {
            currentElement = currentElement.getParentElement();

            if (currentElement == null) {
                currentElement = rootElement;
            }
        }
    }
        break;
    case XMLStreamReader2.SPACE:
    case XMLStreamReader2.CHARACTERS: {
        currentElement.addContent(builderFactory.text(streamReader.getText()));
    }
        break;
    case XMLStreamReader2.CDATA: {
        currentElement.addContent(builderFactory.cdata(streamReader.getText()));
    }
        break;
    case XMLStreamReader2.ENTITY_REFERENCE: {
        currentElement.addContent(builderFactory.entityRef(streamReader.getText()));
    }
        break;
    case XMLStreamReader2.COMMENT: {
        currentElement.addContent(builderFactory.comment(streamReader.getText()));
    }
        break;
    case XMLStreamReader2.PROCESSING_INSTRUCTION: {
        currentElement.addContent(
                builderFactory.processingInstruction(streamReader.getPITarget(), streamReader.getPIData()));
    }
        break;
    case XMLStreamReader2.DTD: {
        currentElement.addContent(DTDParser.parse(streamReader.getText(), builderFactory));
    }
        break;
    }
}