javax.xml.stream.events.Namespace Java Examples

The following examples show how to use javax.xml.stream.events.Namespace. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StaxEventXMLReader.java    From spring-analysis-note with MIT License 6 votes vote down vote up
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));
		}

	}
}
 
Example #2
Source File: StaxEventXMLReader.java    From java-technology-stack with MIT License 6 votes vote down vote up
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));
		}

	}
}
 
Example #3
Source File: TransformerUtil.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private String containsBaseNamespace(StartElement startElement) {
    String localPart, prefix, qual = null;

    Iterator<Namespace> namespaces = startElement.getNamespaces();
    while (namespaces != null && namespaces.hasNext()) {
        Namespace namespace = namespaces.next();
        QName name = namespace.getName();
        localPart = name.getLocalPart();
        prefix = name.getPrefix();
        if (prefix != null && ! prefix.isEmpty())
            qual = (localPart != null && ! localPart.isEmpty()) ? prefix + ":" + localPart : prefix;

        if (qual != null && qual.equals("xmlns"))
            return namespace.getNamespaceURI();
    }
    return null;
}
 
Example #4
Source File: JpaOrmXmlEventReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private List<Namespace> mapNamespaces(Iterator<Namespace> originalNamespaceIterator ) {
		final List<Namespace> mappedNamespaces = new ArrayList<Namespace>();

//		final String elementNamespacePrefix = startElement.getName().getPrefix();
//		if ( EMPTY_NAMESPACE_PREFIX.equals( elementNamespacePrefix ) ) {
//			// add the default namespace mapping
//			mappedNamespaces.add( xmlEventFactory.createNamespace( LocalSchema.ORM.getNamespaceUri() ) );
//		}

		while ( originalNamespaceIterator.hasNext() ) {
			final Namespace originalNamespace  = originalNamespaceIterator.next();
			final Namespace mappedNamespace = mapNamespace( originalNamespace );
			mappedNamespaces.add( mappedNamespace );
		}

		if ( mappedNamespaces.isEmpty() ) {
			mappedNamespaces.add( xmlEventFactory.createNamespace( MappingXsdSupport.INSTANCE.latestJpaDescriptor().getNamespaceUri() ) );
		}

		return mappedNamespaces;
	}
 
Example #5
Source File: StAXEventConnector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void handleStartElement(StartElement event) throws SAXException {
    // start namespace bindings
    for (Iterator i = event.getNamespaces(); i.hasNext();) {
        Namespace ns = (Namespace)i.next();
        visitor.startPrefixMapping(
            fixNull(ns.getPrefix()),
            fixNull(ns.getNamespaceURI()));
    }

    // fire startElement
    QName qName = event.getName();
    tagName.uri = fixNull(qName.getNamespaceURI());
    String localName = qName.getLocalPart();
    tagName.uri = fixNull(qName.getNamespaceURI());
    tagName.local = localName;
    tagName.atts = getAttributes(event);
    visitor.startElement(tagName);

    seenText = false;
}
 
Example #6
Source File: StAXEventConnector.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void handleEndElement(EndElement event) throws SAXException {
    if(!seenText && predictor.expectText()) {
        visitor.text("");
    }

    // fire endElement
    QName qName = event.getName();
    tagName.uri = fixNull(qName.getNamespaceURI());
    tagName.local = qName.getLocalPart();
    visitor.endElement(tagName);

    // end namespace bindings
    for( Iterator<Namespace> i = event.getNamespaces(); i.hasNext();) {
        String prefix = fixNull(i.next().getPrefix());  // be defensive
        visitor.endPrefixMapping(prefix);
    }

    seenText = false;
}
 
Example #7
Source File: MergedNsContext.java    From woodstox with Apache License 2.0 6 votes vote down vote up
@Override
public void outputNamespaceDeclarations(Writer w) throws IOException
{
    for (int i = 0, len = mNamespaces.size(); i < len; ++i) {
        Namespace ns = mNamespaces.get(i);
        w.write(' ');
        w.write(XMLConstants.XMLNS_ATTRIBUTE);
        if (!ns.isDefaultNamespaceDeclaration()) {
            w.write(':');
            w.write(ns.getPrefix());
        }
        w.write("=\"");
        w.write(ns.getNamespaceURI());
        w.write('"');
    }
}
 
Example #8
Source File: XmlResourceValues.java    From bazel with Apache License 2.0 6 votes vote down vote up
public static Map<String, String> parseTagAttributes(StartElement start) {
  // Using a map to deduplicate xmlns declarations on the attributes.
  Map<String, String> attributeMap = new LinkedHashMap<>();
  Iterator<Attribute> attributes = iterateAttributesFrom(start);
  while (attributes.hasNext()) {
    Attribute attribute = attributes.next();
    QName name = attribute.getName();
    // Name used as the resource key, so skip it here.
    if (ATTR_NAME.equals(name)) {
      continue;
    }
    String value = escapeXmlValues(attribute.getValue()).replace("\"", "&quot;");
    if (!name.getNamespaceURI().isEmpty()) {
      attributeMap.put(name.getPrefix() + ":" + attribute.getName().getLocalPart(), value);
    } else {
      attributeMap.put(attribute.getName().getLocalPart(), value);
    }
    Iterator<Namespace> namespaces = iterateNamespacesFrom(start);
    while (namespaces.hasNext()) {
      Namespace namespace = namespaces.next();
      attributeMap.put("xmlns:" + namespace.getPrefix(), namespace.getNamespaceURI());
    }
  }
  return attributeMap;
}
 
Example #9
Source File: StAXEventConnector.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void handleEndElement(EndElement event) throws SAXException {
    if(!seenText && predictor.expectText()) {
        visitor.text("");
    }

    // fire endElement
    QName qName = event.getName();
    tagName.uri = fixNull(qName.getNamespaceURI());
    tagName.local = qName.getLocalPart();
    visitor.endElement(tagName);

    // end namespace bindings
    for( Iterator<Namespace> i = event.getNamespaces(); i.hasNext();) {
        String prefix = fixNull(i.next().getPrefix());  // be defensive
        visitor.endPrefixMapping(prefix);
    }

    seenText = false;
}
 
Example #10
Source File: StAXEventConnector.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void handleStartElement(StartElement event) throws SAXException {
    // start namespace bindings
    for (Iterator i = event.getNamespaces(); i.hasNext();) {
        Namespace ns = (Namespace)i.next();
        visitor.startPrefixMapping(
            fixNull(ns.getPrefix()),
            fixNull(ns.getNamespaceURI()));
    }

    // fire startElement
    QName qName = event.getName();
    tagName.uri = fixNull(qName.getNamespaceURI());
    String localName = qName.getLocalPart();
    tagName.uri = fixNull(qName.getNamespaceURI());
    tagName.local = localName;
    tagName.atts = getAttributes(event);
    visitor.startElement(tagName);

    seenText = false;
}
 
Example #11
Source File: StaxEventXMLReader.java    From spring-analysis-note with MIT License 6 votes vote down vote up
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));
		}
	}
}
 
Example #12
Source File: StAXEventConnector.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void handleEndElement(EndElement event) throws SAXException {
    if(!seenText && predictor.expectText()) {
        visitor.text("");
    }

    // fire endElement
    QName qName = event.getName();
    tagName.uri = fixNull(qName.getNamespaceURI());
    tagName.local = qName.getLocalPart();
    visitor.endElement(tagName);

    // end namespace bindings
    for( Iterator<Namespace> i = event.getNamespaces(); i.hasNext();) {
        String prefix = fixNull(i.next().getPrefix());  // be defensive
        visitor.endPrefixMapping(prefix);
    }

    seenText = false;
}
 
Example #13
Source File: XMLEventStreamReader.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #14
Source File: StAXEventConnector.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void handleStartElement(StartElement event) throws SAXException {
    // start namespace bindings
    for (Iterator i = event.getNamespaces(); i.hasNext();) {
        Namespace ns = (Namespace)i.next();
        visitor.startPrefixMapping(
            fixNull(ns.getPrefix()),
            fixNull(ns.getNamespaceURI()));
    }

    // fire startElement
    QName qName = event.getName();
    tagName.uri = fixNull(qName.getNamespaceURI());
    String localName = qName.getLocalPart();
    tagName.uri = fixNull(qName.getNamespaceURI());
    tagName.local = localName;
    tagName.atts = getAttributes(event);
    visitor.startElement(tagName);

    seenText = false;
}
 
Example #15
Source File: XmlFilterReader.java    From knox with Apache License 2.0 5 votes vote down vote up
private void streamNamespaces( StartElement event ) {
  Iterator i = event.getNamespaces();
  while( i.hasNext() ) {
    Namespace ns = (Namespace)i.next();
    writer.write( " xmlns" );
    if( !ns.isDefaultNamespaceDeclaration() ) {
      writer.write( ":" );
      writer.write( ns.getPrefix() );
    }
    writer.write( "=\"" );
    writer.write( ns.getNamespaceURI() );
    writer.write( "\"" );
  }
}
 
Example #16
Source File: StAXEventAllocatorBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected void addNamespaces(EndElementEvent event,XMLStreamReader streamReader){
    Namespace namespace = null;
    for(int i=0; i<streamReader.getNamespaceCount(); i++){
        namespace = factory.createNamespace(streamReader.getNamespacePrefix(i),
                            streamReader.getNamespaceURI(i));
        event.addNamespace(namespace);
    }
}
 
Example #17
Source File: StAXSchemaParser.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/** Fills in the list of declared prefixes. */
private void fillDeclaredPrefixes(Iterator namespaces) {
    fDeclaredPrefixes.clear();
    while (namespaces.hasNext()) {
        Namespace ns = (Namespace) namespaces.next();
        String prefix = ns.getPrefix();
        fDeclaredPrefixes.add(prefix != null ? prefix : "");
    }
}
 
Example #18
Source File: StartElementEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void addNamespaces(Iterator namespaces){
    if(namespaces != null) {
        while(namespaces.hasNext()){
            Namespace namespace = (Namespace)namespaces.next();
            _namespaces.add(namespace);
        }
    }
}
 
Example #19
Source File: StaxEventHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void startElementInternal(QName name, Attributes atts,
		Map<String, String> namespaceMapping) throws XMLStreamException {

	List<Attribute> attributes = getAttributes(atts);
	List<Namespace> namespaces = getNamespaces(namespaceMapping);
	this.eventWriter.add(
			this.eventFactory.createStartElement(name, attributes.iterator(), namespaces.iterator()));

}
 
Example #20
Source File: XMLEventFactoryImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public StartElement createStartElement(String prefix, String namespaceUri,
        String localName, Iterator<? extends Attribute> attributes,
        Iterator<? extends Namespace> namespaces, NamespaceContext context) {
    StartElementEvent elem =  new StartElementEvent(prefix, namespaceUri, localName);
    elem.addAttributes(attributes);
    elem.addNamespaceAttributes(namespaces);
    elem.setNamespaceContext(context);
    if(location != null)elem.setLocation(location);
    return elem;
}
 
Example #21
Source File: StAXEventAllocatorBase.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected void addNamespaces(EndElementEvent event,XMLStreamReader streamReader){
    Namespace namespace = null;
    for(int i=0; i<streamReader.getNamespaceCount(); i++){
        namespace = factory.createNamespace(streamReader.getNamespacePrefix(i),
                            streamReader.getNamespaceURI(i));
        event.addNamespace(namespace);
    }
}
 
Example #22
Source File: StAXSchemaParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** Fills in the list of declared prefixes. */
private void fillDeclaredPrefixes(Iterator namespaces) {
    fDeclaredPrefixes.clear();
    while (namespaces.hasNext()) {
        Namespace ns = (Namespace) namespaces.next();
        String prefix = ns.getPrefix();
        fDeclaredPrefixes.add(prefix != null ? prefix : "");
    }
}
 
Example #23
Source File: StartElementEvent.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void addNamespaces(Iterator namespaces){
    if(namespaces != null) {
        while(namespaces.hasNext()){
            Namespace namespace = (Namespace)namespaces.next();
            _namespaces.add(namespace);
        }
    }
}
 
Example #24
Source File: XMLEventFactoryImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public javax.xml.stream.events.EndElement createEndElement(String prefix, String namespaceUri, String localName, java.util.Iterator namespaces) {

        EndElementEvent event =  new EndElementEvent(prefix, namespaceUri, localName);
        if(namespaces!=null){
            while(namespaces.hasNext())
                event.addNamespace((Namespace)namespaces.next());
        }
        if(location != null)event.setLocation(location);
        return event;
    }
 
Example #25
Source File: XMLEventFactoryImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public javax.xml.stream.events.EndElement createEndElement(String prefix, String namespaceUri, String localName, java.util.Iterator namespaces) {

        EndElementEvent event =  new EndElementEvent(prefix, namespaceUri, localName);
        if(namespaces!=null){
            while(namespaces.hasNext())
                event.addNamespace((Namespace)namespaces.next());
        }
        if(location != null)event.setLocation(location);
        return event;
    }
 
Example #26
Source File: StaxEventHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private List<Namespace> getNamespaces(Map<String, String> namespaceMapping) {
	List<Namespace> result = new ArrayList<Namespace>();
	for (Map.Entry<String, String> entry : namespaceMapping.entrySet()) {
		String prefix = entry.getKey();
		String namespaceUri = entry.getValue();
		result.add(this.eventFactory.createNamespace(prefix, namespaceUri));
	}
	return result;
}
 
Example #27
Source File: EndElementEvent.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an Iterator of namespaces that have gone out of scope. Returns an
 * empty iterator if no namespaces have gone out of scope.
 *
 * @return an Iterator over Namespace interfaces, or an empty iterator
 */
@Override
public Iterator<Namespace> getNamespaces() {
    if (fNamespaces != null) {
        fNamespaces.iterator();
    }
    return new ReadOnlyIterator<>();
}
 
Example #28
Source File: StaxEventHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private List<Namespace> getNamespaces(Map<String, String> namespaceMapping) {
	List<Namespace> result = new ArrayList<Namespace>();
	for (Map.Entry<String, String> entry : namespaceMapping.entrySet()) {
		String prefix = entry.getKey();
		String namespaceUri = entry.getValue();
		result.add(this.eventFactory.createNamespace(prefix, namespaceUri));
	}
	return result;
}
 
Example #29
Source File: StartElementEvent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void addNamespaceAttributes(Iterator attrs){
    if(attrs == null)
        return;
    while(attrs.hasNext()){
        Namespace attr = (Namespace)attrs.next();
        fNamespaces.add(attr);
    }
}
 
Example #30
Source File: XMLEventFactoryImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public javax.xml.stream.events.EndElement createEndElement(String prefix, String namespaceUri,
        String localName, Iterator<? extends Namespace> namespaces) {

    EndElementEvent event =  new EndElementEvent(prefix, namespaceUri, localName);
    if(namespaces!=null){
        while(namespaces.hasNext())
            event.addNamespace(namespaces.next());
    }
    if(location != null)event.setLocation(location);
    return event;
}