Search in sources :

Example 1 with EntityReference

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

the class BaseXMLEventReader method getElementText.

@Override
public final String getElementText() throws XMLStreamException {
    XMLEvent event = this.previousEvent;
    if (event == null) {
        throw new XMLStreamException("Must be on START_ELEMENT to read next text, element was null");
    }
    if (!event.isStartElement()) {
        throw new XMLStreamException("Must be on START_ELEMENT to read next text", event.getLocation());
    }
    final StringBuilder text = new StringBuilder();
    while (!event.isEndDocument()) {
        switch(event.getEventType()) {
            case XMLStreamConstants.CHARACTERS:
            case XMLStreamConstants.SPACE:
            case XMLStreamConstants.CDATA:
                {
                    final Characters characters = event.asCharacters();
                    text.append(characters.getData());
                    break;
                }
            case XMLStreamConstants.ENTITY_REFERENCE:
                {
                    final EntityReference entityReference = (EntityReference) event;
                    final EntityDeclaration declaration = entityReference.getDeclaration();
                    text.append(declaration.getReplacementText());
                    break;
                }
            case XMLStreamConstants.COMMENT:
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                {
                    //Ignore
                    break;
                }
            default:
                {
                    throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
                }
        }
        event = this.nextEvent();
    }
    return text.toString();
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EntityDeclaration(javax.xml.stream.events.EntityDeclaration) Characters(javax.xml.stream.events.Characters) XMLEvent(javax.xml.stream.events.XMLEvent) EntityReference(javax.xml.stream.events.EntityReference)

Example 2 with EntityReference

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

the class BaseXMLEventReader method getElementText.

/* (non-Javadoc)
     * @see javax.xml.stream.XMLEventReader#getElementText()
     */
@Override
public final String getElementText() throws XMLStreamException {
    XMLEvent event = this.previousEvent;
    if (event == null) {
        throw new XMLStreamException("Must be on START_ELEMENT to read next text, element was null");
    }
    if (!event.isStartElement()) {
        throw new XMLStreamException("Must be on START_ELEMENT to read next text", event.getLocation());
    }
    final StringBuilder text = new StringBuilder();
    while (!event.isEndDocument()) {
        switch(event.getEventType()) {
            case XMLStreamConstants.CHARACTERS:
            case XMLStreamConstants.SPACE:
            case XMLStreamConstants.CDATA:
                {
                    final Characters characters = event.asCharacters();
                    text.append(characters.getData());
                    break;
                }
            case XMLStreamConstants.ENTITY_REFERENCE:
                {
                    final EntityReference entityReference = (EntityReference) event;
                    final EntityDeclaration declaration = entityReference.getDeclaration();
                    text.append(declaration.getReplacementText());
                    break;
                }
            case XMLStreamConstants.COMMENT:
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                {
                    //Ignore
                    break;
                }
            default:
                {
                    throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
                }
        }
        event = this.nextEvent();
    }
    return text.toString();
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EntityDeclaration(javax.xml.stream.events.EntityDeclaration) Characters(javax.xml.stream.events.Characters) XMLEvent(javax.xml.stream.events.XMLEvent) EntityReference(javax.xml.stream.events.EntityReference)

Example 3 with EntityReference

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

the class BaseXMLEventReader method getElementText.

/* (non-Javadoc)
	 * @see javax.xml.stream.XMLEventReader#getElementText()
	 */
@Override
public final String getElementText() throws XMLStreamException {
    XMLEvent event = this.previousEvent;
    if (event == null) {
        throw new XMLStreamException("Must be on START_ELEMENT to read next text, element was null");
    }
    if (!event.isStartElement()) {
        throw new XMLStreamException("Must be on START_ELEMENT to read next text", event.getLocation());
    }
    final StringBuilder text = new StringBuilder();
    while (!event.isEndDocument()) {
        switch(event.getEventType()) {
            case XMLStreamConstants.CHARACTERS:
            case XMLStreamConstants.SPACE:
            case XMLStreamConstants.CDATA:
                {
                    final Characters characters = event.asCharacters();
                    text.append(characters.getData());
                    break;
                }
            case XMLStreamConstants.ENTITY_REFERENCE:
                {
                    final EntityReference entityReference = (EntityReference) event;
                    final EntityDeclaration declaration = entityReference.getDeclaration();
                    text.append(declaration.getReplacementText());
                    break;
                }
            case XMLStreamConstants.COMMENT:
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                {
                    //Ignore
                    break;
                }
            default:
                {
                    throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
                }
        }
        event = this.nextEvent();
    }
    return text.toString();
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EntityDeclaration(javax.xml.stream.events.EntityDeclaration) Characters(javax.xml.stream.events.Characters) XMLEvent(javax.xml.stream.events.XMLEvent) EntityReference(javax.xml.stream.events.EntityReference)

Example 4 with EntityReference

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

the class XMLEventBufferReader method getElementText.

@Override
public String getElementText() throws XMLStreamException {
    XMLEvent event = this.previousEvent;
    if (event == null) {
        throw new XMLStreamException("Must be on START_ELEMENT to read next text, element was null");
    }
    if (!event.isStartElement()) {
        throw new XMLStreamException("Must be on START_ELEMENT to read next text", event.getLocation());
    }
    final StringBuilder text = new StringBuilder();
    while (!event.isEndDocument()) {
        switch(event.getEventType()) {
            case XMLStreamConstants.CHARACTERS:
            case XMLStreamConstants.SPACE:
            case XMLStreamConstants.CDATA:
                {
                    final Characters characters = event.asCharacters();
                    text.append(characters.getData());
                    break;
                }
            case XMLStreamConstants.ENTITY_REFERENCE:
                {
                    final EntityReference entityReference = (EntityReference) event;
                    final EntityDeclaration declaration = entityReference.getDeclaration();
                    text.append(declaration.getReplacementText());
                    break;
                }
            case XMLStreamConstants.COMMENT:
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                {
                    //Ignore
                    break;
                }
            default:
                {
                    throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
                }
        }
        event = this.nextEvent();
    }
    return text.toString();
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EntityDeclaration(javax.xml.stream.events.EntityDeclaration) Characters(javax.xml.stream.events.Characters) XMLEvent(javax.xml.stream.events.XMLEvent) EntityReference(javax.xml.stream.events.EntityReference)

Aggregations

XMLStreamException (javax.xml.stream.XMLStreamException)4 Characters (javax.xml.stream.events.Characters)4 EntityDeclaration (javax.xml.stream.events.EntityDeclaration)4 EntityReference (javax.xml.stream.events.EntityReference)4 XMLEvent (javax.xml.stream.events.XMLEvent)4