Search in sources :

Example 6 with Namespace

use of javax.xml.stream.events.Namespace in project spring-framework by spring-projects.

the class StaxEventXMLReader method getAttributes.

private Attributes getAttributes(StartElement event) {
    AttributesImpl attributes = new AttributesImpl();
    for (Iterator i = event.getAttributes(); i.hasNext(); ) {
        Attribute attribute = (Attribute) i.next();
        QName qName = attribute.getName();
        String namespace = qName.getNamespaceURI();
        if (namespace == null || !hasNamespacesFeature()) {
            namespace = "";
        }
        String type = attribute.getDTDType();
        if (type == null) {
            type = "CDATA";
        }
        attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue());
    }
    if (hasNamespacePrefixesFeature()) {
        for (Iterator i = event.getNamespaces(); i.hasNext(); ) {
            Namespace namespace = (Namespace) i.next();
            String prefix = namespace.getPrefix();
            String namespaceUri = namespace.getNamespaceURI();
            String qName;
            if (StringUtils.hasLength(prefix)) {
                qName = "xmlns:" + prefix;
            } else {
                qName = "xmlns";
            }
            attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
        }
    }
    return attributes;
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) Namespace(javax.xml.stream.events.Namespace)

Example 7 with Namespace

use of javax.xml.stream.events.Namespace in project spring-framework by spring-projects.

the class StaxEventXMLReader method handleStartElement.

private void handleStartElement(StartElement startElement) throws SAXException {
    if (getContentHandler() != null) {
        QName qName = startElement.getName();
        if (hasNamespacesFeature()) {
            for (Iterator i = startElement.getNamespaces(); i.hasNext(); ) {
                Namespace namespace = (Namespace) i.next();
                startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI());
            }
            for (Iterator i = startElement.getAttributes(); i.hasNext(); ) {
                Attribute attribute = (Attribute) i.next();
                QName attributeName = attribute.getName();
                startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI());
            }
            getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName), getAttributes(startElement));
        } else {
            getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement));
        }
    }
}
Also used : Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) Namespace(javax.xml.stream.events.Namespace)

Example 8 with Namespace

use of javax.xml.stream.events.Namespace in project spring-framework by spring-projects.

the class XMLEventStreamReader method getNamespace.

@SuppressWarnings("rawtypes")
private Namespace getNamespace(int index) {
    Iterator namespaces;
    if (this.event.isStartElement()) {
        namespaces = this.event.asStartElement().getNamespaces();
    } else if (this.event.isEndElement()) {
        namespaces = this.event.asEndElement().getNamespaces();
    } else {
        throw new IllegalStateException();
    }
    int count = 0;
    while (namespaces.hasNext()) {
        Namespace namespace = (Namespace) namespaces.next();
        if (count == index) {
            return namespace;
        } else {
            count++;
        }
    }
    throw new IllegalArgumentException();
}
Also used : Iterator(java.util.Iterator) Namespace(javax.xml.stream.events.Namespace)

Example 9 with Namespace

use of javax.xml.stream.events.Namespace in project spring-framework by spring-projects.

the class XMLEventStreamWriter method doWriteNamespace.

@SuppressWarnings("rawtypes")
private void doWriteNamespace(Namespace namespace) throws XMLStreamException {
    int last = this.endElements.size() - 1;
    EndElement oldEndElement = this.endElements.get(last);
    Iterator oldNamespaces = oldEndElement.getNamespaces();
    List<Namespace> newNamespaces = new ArrayList<>();
    while (oldNamespaces.hasNext()) {
        Namespace oldNamespace = (Namespace) oldNamespaces.next();
        newNamespaces.add(oldNamespace);
    }
    newNamespaces.add(namespace);
    EndElement newEndElement = this.eventFactory.createEndElement(oldEndElement.getName(), newNamespaces.iterator());
    this.eventWriter.add(namespace);
    this.endElements.set(last, newEndElement);
}
Also used : EndElement(javax.xml.stream.events.EndElement) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Namespace(javax.xml.stream.events.Namespace)

Example 10 with Namespace

use of javax.xml.stream.events.Namespace in project cxf by apache.

the class CorbaStreamReader method getNamespacePrefix.

public String getNamespacePrefix(int arg0) {
    List<Namespace> namespaces = eventProducer.getNamespaces();
    if (namespaces == null) {
        return null;
    }
    Namespace ns = namespaces.get(arg0);
    if (ns != null) {
        return ns.getPrefix();
    }
    return null;
}
Also used : Namespace(javax.xml.stream.events.Namespace)

Aggregations

Namespace (javax.xml.stream.events.Namespace)17 QName (javax.xml.namespace.QName)10 Attribute (javax.xml.stream.events.Attribute)7 Iterator (java.util.Iterator)6 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)1 NamespaceContext (javax.xml.namespace.NamespaceContext)1 Characters (javax.xml.stream.events.Characters)1 EndElement (javax.xml.stream.events.EndElement)1 StartDocument (javax.xml.stream.events.StartDocument)1 StartElement (javax.xml.stream.events.StartElement)1 Attr (org.w3c.dom.Attr)1 Comment (org.w3c.dom.Comment)1 Document (org.w3c.dom.Document)1 DocumentFragment (org.w3c.dom.DocumentFragment)1 Element (org.w3c.dom.Element)1 EntityReference (org.w3c.dom.EntityReference)1 ProcessingInstruction (org.w3c.dom.ProcessingInstruction)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1