Search in sources :

Example 11 with Namespace

use of javax.xml.stream.events.Namespace in project hibernate-orm by hibernate.

the class JpaNamespaceTransformingEventReader method transform.

private StartElement transform(StartElement startElement) {
    String elementName = startElement.getName().getLocalPart();
    // use the start element to determine whether we have a persistence.xml or orm.xml
    if (START_ELEMENT_TO_NAMESPACE_URI.containsKey(elementName)) {
        currentDocumentNamespaceUri = START_ELEMENT_TO_NAMESPACE_URI.get(elementName);
    }
    List<Attribute> newElementAttributeList = updateElementAttributes(startElement);
    List<Namespace> newNamespaceList = updateElementNamespaces(startElement);
    // create the new element
    return xmlEventFactory.createStartElement(new QName(currentDocumentNamespaceUri, startElement.getName().getLocalPart()), newElementAttributeList.iterator(), newNamespaceList.iterator());
}
Also used : Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) Namespace(javax.xml.stream.events.Namespace)

Example 12 with Namespace

use of javax.xml.stream.events.Namespace in project hibernate-orm by hibernate.

the class JpaOrmXmlEventReader method mapNamespaces.

private List<Namespace> mapNamespaces(Iterator<Namespace> originalNamespaceIterator) {
    final List<Namespace> mappedNamespaces = new ArrayList<Namespace>();
    while (originalNamespaceIterator.hasNext()) {
        final Namespace originalNamespace = originalNamespaceIterator.next();
        final Namespace mappedNamespace = mapNamespace(originalNamespace);
        mappedNamespaces.add(mappedNamespace);
    }
    if (mappedNamespaces.isEmpty()) {
        mappedNamespaces.add(xmlEventFactory.createNamespace(LocalSchema.ORM.getNamespaceUri()));
    }
    return mappedNamespaces;
}
Also used : ArrayList(java.util.ArrayList) Namespace(javax.xml.stream.events.Namespace)

Example 13 with Namespace

use of javax.xml.stream.events.Namespace in project hibernate-orm by hibernate.

the class JpaOrmXmlEventReader method wrap.

private XMLEvent wrap(EndElement endElement) {
    final List<Namespace> targetNamespaces = mapNamespaces(existingXmlNamespacesIterator(endElement));
    // Transfer the location info from the incoming event to the event factory
    // so that the event we ask it to generate for us has the same location info
    xmlEventFactory.setLocation(endElement.getLocation());
    return xmlEventFactory.createEndElement(new QName(LocalSchema.ORM.getNamespaceUri(), endElement.getName().getLocalPart()), targetNamespaces.iterator());
}
Also used : QName(javax.xml.namespace.QName) Namespace(javax.xml.stream.events.Namespace)

Example 14 with Namespace

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

the class StaxEventXMLReader method handleEndElement.

private void handleEndElement(EndElement endElement) throws SAXException {
    if (getContentHandler() != null) {
        QName qName = endElement.getName();
        if (hasNamespacesFeature()) {
            getContentHandler().endElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName));
            for (Iterator i = endElement.getNamespaces(); i.hasNext(); ) {
                Namespace namespace = (Namespace) i.next();
                endPrefixMapping(namespace.getPrefix());
            }
        } else {
            getContentHandler().endElement("", "", toQualifiedName(qName));
        }
    }
}
Also used : QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) Namespace(javax.xml.stream.events.Namespace)

Example 15 with Namespace

use of javax.xml.stream.events.Namespace in project uPortal by Jasig.

the class PortletWindowRegistryImpl method addPortletWindowId.

protected StartElement addPortletWindowId(StartElement element, IPortletWindowId portletWindowId) {
    final Attribute windowIdAttribute = xmlEventFactory.createAttribute(PORTLET_WINDOW_ID_ATTR_NAME, portletWindowId.getStringId());
    // Clone the start element to add the new attribute
    final QName name = element.getName();
    final String prefix = name.getPrefix();
    final String namespaceURI = name.getNamespaceURI();
    final String localPart = name.getLocalPart();
    @SuppressWarnings("unchecked") final Iterator<Attribute> attributes = element.getAttributes();
    @SuppressWarnings("unchecked") final Iterator<Namespace> namespaces = element.getNamespaces();
    final NamespaceContext namespaceContext = element.getNamespaceContext();
    // Create a new iterator of the existing attributes + the new window id attribute
    final Iterator<Attribute> newAttributes = Iterators.concat(attributes, Iterators.forArray(windowIdAttribute));
    return xmlEventFactory.createStartElement(prefix, namespaceURI, localPart, newAttributes, namespaces, namespaceContext);
}
Also used : Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) NamespaceContext(javax.xml.namespace.NamespaceContext) 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