Java Code Examples for javax.xml.stream.events.EndElement#getName()

The following examples show how to use javax.xml.stream.events.EndElement#getName() . 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 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 5
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 6
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 7
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 8
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-jdk8u-backup 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 9
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 10
Source File: StAXEvent2SAX.java    From openjdk-jdk8u 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 11
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);
    }
}
 
Example 12
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 13
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 14
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 15
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 16
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 17
Source File: XmlModifier.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public void set ( final String expression, final int targetElement, final String value ) throws IOException, XMLStreamException
{
    int pos = 0;

    final Stack<String> ele = new Stack<> ();

    final Pattern pattern = Pattern.compile ( expression );

    final XMLEventReader reader;

    Modification mod = null;

    final XMLInputFactory xmlinf = XMLInputFactory.newInstance ();
    try (final FileInputStream is = new FileInputStream ( this.inputFile ))
    {
        reader = xmlinf.createXMLEventReader ( is );
        try
        {
            while ( reader.hasNext () )
            {
                final XMLEvent event = (XMLEvent)reader.next ();
                if ( event instanceof StartElement )
                {
                    final StartElement startEvent = event.asStartElement ();
                    ele.push ( startEvent.getName ().getLocalPart () );
                }
                else if ( event instanceof EndElement )
                {
                    final EndElement endEvent = event.asEndElement ();
                    final String en = ele.pop ();
                    if ( !endEvent.getName ().getLocalPart ().equals ( en ) )
                    {
                        throw new IllegalStateException ( "Element error: " + en + " / " + endEvent.getName () );
                    }
                }

                boolean inMatch = mod != null;
                final boolean match = isMatch ( ele, pattern );
                if ( inMatch && !match )
                {
                    // end
                    if ( pos == targetElement )
                    {
                        this.mods.add ( mod );
                    }
                    pos++;
                    mod = null;
                }
                else if ( !inMatch && match )
                {
                    // starting
                    mod = new Modification ();
                    mod.start = event.getLocation ().getCharacterOffset ();
                    mod.data = value;
                }
                else if ( inMatch && match )
                {
                    mod.end = event.getLocation ().getCharacterOffset () - 2;
                }
                inMatch = match;
            }
        }
        finally
        {
            reader.close ();
        }
    }
}
 
Example 18
Source File: XmlPolicyModelUnmarshaller.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Method checks whether the actual name of the end tag is equal to the expected name - the name of currently unmarshalled
 * XML policy model element. Throws exception, if the two FQNs are not equal as expected.
 *
 * @param expected The expected element name.
 * @param element The actual element.
 * @throws PolicyException If the actual element name did not match the expected element.
 */
private void checkEndTagName(final QName expected, final EndElement element) throws PolicyException {
    final QName actual = element.getName();
    if (!expected.equals(actual)) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0003_UNMARSHALLING_FAILED_END_TAG_DOES_NOT_MATCH(expected, actual)));
    }

}
 
Example 19
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Method checks whether the actual name of the end tag is equal to the expected name - the name of currently unmarshalled
 * XML policy model element. Throws exception, if the two FQNs are not equal as expected.
 *
 * @param expected The expected element name.
 * @param element The actual element.
 * @throws PolicyException If the actual element name did not match the expected element.
 */
private void checkEndTagName(final QName expected, final EndElement element) throws PolicyException {
    final QName actual = element.getName();
    if (!expected.equals(actual)) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0003_UNMARSHALLING_FAILED_END_TAG_DOES_NOT_MATCH(expected, actual)));
    }

}
 
Example 20
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Method checks whether the actual name of the end tag is equal to the expected name - the name of currently unmarshalled
 * XML policy model element. Throws exception, if the two FQNs are not equal as expected.
 *
 * @param expected The expected element name.
 * @param element The actual element.
 * @throws PolicyException If the actual element name did not match the expected element.
 */
private void checkEndTagName(final QName expected, final EndElement element) throws PolicyException {
    final QName actual = element.getName();
    if (!expected.equals(actual)) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0003_UNMARSHALLING_FAILED_END_TAG_DOES_NOT_MATCH(expected, actual)));
    }

}