javax.xml.stream.events.EndElement Java Examples

The following examples show how to use javax.xml.stream.events.EndElement. 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: 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 #3
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 #4
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 #5
Source File: StAXEventConnector.java    From openjdk-jdk8u 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 #6
Source File: StaxEventXMLReader.java    From lams with GNU General Public License v2.0 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 #7
Source File: StAXEventConnector.java    From openjdk-jdk8u-backup 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 #8
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 #9
Source File: XMLEventStreamWriter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void writeEndElement() throws XMLStreamException {
	closeEmptyElementIfNecessary();
	int last = this.endElements.size() - 1;
	EndElement lastEndElement = this.endElements.get(last);
	this.eventWriter.add(lastEndElement);
	this.endElements.remove(last);
}
 
Example #10
Source File: StAXEvent2SAX.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private void handleEndElement(EndElement event) throws XMLStreamException {
    QName qName = event.getName();

    //construct prefix:localName from qName
    String qname = "";
    if (qName.getPrefix() != null && qName.getPrefix().trim().length() != 0){
        qname = qName.getPrefix() + ":";
    }
    qname += qName.getLocalPart();

    try {
        // fire endElement
        _sax.endElement(
            qName.getNamespaceURI(),
            qName.getLocalPart(),
            qname);

        // end namespace bindings
        for( Iterator i = event.getNamespaces(); i.hasNext();) {
            String prefix = (String)i.next();
            if( prefix == null ) { // true for default namespace
                prefix = "";
            }
            _sax.endPrefixMapping(prefix);
        }
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
 
Example #11
Source File: EventBase.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Returns this event as an end  element event, may result in
 * a class cast exception if this event is not a end element.
 */
public EndElement asEndElement() {
    if (isEndElement()) {
        return (EndElement)this;
    } else
        throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.endElementCase", new Object[]{getEventTypeString()}));
}
 
Example #12
Source File: ExternalAttachmentsUnmarshaller.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void checkEndTagName(final QName expectedName, final EndElement element) throws PolicyException {
    final QName actualName = element.getName();
    if (!expectedName.equals(actualName)) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0091_END_ELEMENT_NO_MATCH(expectedName, element, element.getLocation())));
    }

}
 
Example #13
Source File: StAXEvent2SAX.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void handleEndElement(EndElement event) throws XMLStreamException {
    QName qName = event.getName();

    //construct prefix:localName from qName
    String qname = "";
    if (qName.getPrefix() != null && qName.getPrefix().trim().length() != 0){
        qname = qName.getPrefix() + ":";
    }
    qname += qName.getLocalPart();

    try {
        // fire endElement
        _sax.endElement(
            qName.getNamespaceURI(),
            qName.getLocalPart(),
            qname);

        // end namespace bindings
        for( Iterator i = event.getNamespaces(); i.hasNext();) {
            String prefix = (String)i.next();
            if( prefix == null ) { // true for default namespace
                prefix = "";
            }
            _sax.endPrefixMapping(prefix);
        }
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
 
Example #14
Source File: XMLEventStreamWriter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void writeEndElement() throws XMLStreamException {
	closeEmptyElementIfNecessary();
	int last = this.endElements.size() - 1;
	EndElement lastEndElement = this.endElements.get(last);
	this.eventWriter.add(lastEndElement);
	this.endElements.remove(last);
}
 
Example #15
Source File: XMLEventStreamWriter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #16
Source File: EventBase.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/** Returns this event as an end  element event, may result in
 * a class cast exception if this event is not a end element.
 */
public EndElement asEndElement() {
    if (isEndElement()) {
        return (EndElement)this;
    } else
        throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.endElementCase", new Object[]{getEventTypeString()}));
}
 
Example #17
Source File: ExternalAttachmentsUnmarshaller.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void checkEndTagName(final QName expectedName, final EndElement element) throws PolicyException {
    final QName actualName = element.getName();
    if (!expectedName.equals(actualName)) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0091_END_ELEMENT_NO_MATCH(expectedName, element, element.getLocation())));
    }

}
 
Example #18
Source File: StAXEvent2SAX.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void handleEndElement(EndElement event) throws XMLStreamException {
    QName qName = event.getName();

    //construct prefix:localName from qName
    String qname = "";
    if (qName.getPrefix() != null && qName.getPrefix().trim().length() != 0){
        qname = qName.getPrefix() + ":";
    }
    qname += qName.getLocalPart();

    try {
        // fire endElement
        _sax.endElement(
            qName.getNamespaceURI(),
            qName.getLocalPart(),
            qname);

        // end namespace bindings
        for( Iterator i = event.getNamespaces(); i.hasNext();) {
            String prefix = (String)i.next();
            if( prefix == null ) { // true for default namespace
                prefix = "";
            }
            _sax.endPrefixMapping(prefix);
        }
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
 
Example #19
Source File: StAXEvent2SAX.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private void handleEndElement(EndElement event) throws XMLStreamException {
    QName qName = event.getName();

    //construct prefix:localName from qName
    String qname = "";
    if (qName.getPrefix() != null && qName.getPrefix().trim().length() != 0){
        qname = qName.getPrefix() + ":";
    }
    qname += qName.getLocalPart();

    try {
        // fire endElement
        _sax.endElement(
            qName.getNamespaceURI(),
            qName.getLocalPart(),
            qname);

        // end namespace bindings
        for( Iterator i = event.getNamespaces(); i.hasNext();) {
            String prefix = (String)i.next();
            if( prefix == null ) { // true for default namespace
                prefix = "";
            }
            _sax.endPrefixMapping(prefix);
        }
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
 
Example #20
Source File: ArtifactsXmlAbsoluteUrlRemover.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isEndTagWithName(@Nullable final XMLEvent tag, final String name) {
  if (tag != null && tag.getEventType() == END_ELEMENT) {
    EndElement endElement = tag.asEndElement();
    if (endElement.getName().getLocalPart().equals(name)) {
      return true;
    }
  }
  return false;
}
 
Example #21
Source File: EventBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** Returns this event as an end  element event, may result in
 * a class cast exception if this event is not a end element.
 */
public EndElement asEndElement() {
    if (isEndElement()) {
        return (EndElement)this;
    } else
        throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.endElementCase", new Object[]{getEventTypeString()}));
}
 
Example #22
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void checkEndTagName(final QName expectedName, final EndElement element) throws PolicyException {
    final QName actualName = element.getName();
    if (!expectedName.equals(actualName)) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0091_END_ELEMENT_NO_MATCH(expectedName, element, element.getLocation())));
    }

}
 
Example #23
Source File: XMLEventStreamWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void writeEndElement() throws XMLStreamException {
	closeEmptyElementIfNecessary();
	int last = this.endElements.size() - 1;
	EndElement lastEndElement = this.endElements.get(last);
	this.eventWriter.add(lastEndElement);
	this.endElements.remove(last);
}
 
Example #24
Source File: XMLEventStreamWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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<Namespace>();
	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);
}
 
Example #25
Source File: JpaOrmXmlEventReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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( MappingXsdSupport.INSTANCE.latestJpaDescriptor().getNamespaceUri(), endElement.getName().getLocalPart() ),
			targetNamespaces.iterator()
	);
}
 
Example #26
Source File: EventBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/** Returns this event as an end  element event, may result in
 * a class cast exception if this event is not a end element.
 */
public EndElement asEndElement() {
    if (isEndElement()) {
        return (EndElement)this;
    } else
        throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.endElementCase", new Object[]{getEventTypeString()}));
}
 
Example #27
Source File: StAXEvent2SAX.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void handleEndElement(EndElement event) throws XMLStreamException {
    QName qName = event.getName();

    //construct prefix:localName from qName
    String qname = "";
    if (qName.getPrefix() != null && qName.getPrefix().trim().length() != 0){
        qname = qName.getPrefix() + ":";
    }
    qname += qName.getLocalPart();

    try {
        // fire endElement
        _sax.endElement(
            qName.getNamespaceURI(),
            qName.getLocalPart(),
            qname);

        // end namespace bindings
        for( Iterator i = event.getNamespaces(); i.hasNext();) {
            String prefix = (String)i.next();
            if( prefix == null ) { // true for default namespace
                prefix = "";
            }
            _sax.endPrefixMapping(prefix);
        }
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
 
Example #28
Source File: StAXEvent2SAX.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private void handleEndElement(EndElement event) throws XMLStreamException {
    QName qName = event.getName();

    //construct prefix:localName from qName
    String qname = "";
    if (qName.getPrefix() != null && qName.getPrefix().trim().length() != 0){
        qname = qName.getPrefix() + ":";
    }
    qname += qName.getLocalPart();

    try {
        // fire endElement
        _sax.endElement(
            qName.getNamespaceURI(),
            qName.getLocalPart(),
            qname);

        // end namespace bindings
        for( Iterator<Namespace> i = event.getNamespaces(); i.hasNext();) {
            String prefix = (i.next()).getPrefix();
            if( prefix == null ) { // true for default namespace
                prefix = "";
            }
            _sax.endPrefixMapping(prefix);
        }
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
 
Example #29
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void checkEndTagName(final QName expectedName, final EndElement element) throws PolicyException {
    final QName actualName = element.getName();
    if (!expectedName.equals(actualName)) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0091_END_ELEMENT_NO_MATCH(expectedName, element, element.getLocation())));
    }

}
 
Example #30
Source File: StAXEvent2SAX.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void handleEndElement(EndElement event) throws XMLStreamException {
    QName qName = event.getName();

    //construct prefix:localName from qName
    String qname = "";
    if (qName.getPrefix() != null && qName.getPrefix().trim().length() != 0){
        qname = qName.getPrefix() + ":";
    }
    qname += qName.getLocalPart();

    try {
        // fire endElement
        _sax.endElement(
            qName.getNamespaceURI(),
            qName.getLocalPart(),
            qname);

        // end namespace bindings
        for( Iterator i = event.getNamespaces(); i.hasNext();) {
            String prefix = (String)i.next();
            if( prefix == null ) { // true for default namespace
                prefix = "";
            }
            _sax.endPrefixMapping(prefix);
        }
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}