javax.xml.stream.events.EntityReference Java Examples

The following examples show how to use javax.xml.stream.events.EntityReference. 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 5 votes vote down vote up
private void handleEntityReference(EntityReference reference) throws SAXException {
	if (getLexicalHandler() != null) {
		getLexicalHandler().startEntity(reference.getName());
	}
	if (getLexicalHandler() != null) {
		getLexicalHandler().endEntity(reference.getName());
	}

}
 
Example #2
Source File: StaxEventXMLReader.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void handleEntityReference(EntityReference reference) throws SAXException {
	if (getLexicalHandler() != null) {
		getLexicalHandler().startEntity(reference.getName());
	}
	if (getLexicalHandler() != null) {
		getLexicalHandler().endEntity(reference.getName());
	}

}
 
Example #3
Source File: StaxEventXMLReader.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void handleEntityReference(EntityReference reference) throws SAXException {
	if (getLexicalHandler() != null) {
		getLexicalHandler().startEntity(reference.getName());
	}
	if (getLexicalHandler() != null) {
		getLexicalHandler().endEntity(reference.getName());
	}

}
 
Example #4
Source File: StaxEventXMLReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void handleEntityReference(EntityReference reference) throws SAXException {
	if (getLexicalHandler() != null) {
		getLexicalHandler().startEntity(reference.getName());
	}
	if (getLexicalHandler() != null) {
		getLexicalHandler().endEntity(reference.getName());
	}

}
 
Example #5
Source File: Bug6555001.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNotReplacing() throws Exception {
    JAXPTestUtilities.tryRunWithTmpPermission(() -> {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty("javax.xml.stream.isReplacingEntityReferences", false);

        StringReader sr = new StringReader(XML);
        XMLEventReader reader = factory.createXMLEventReader(sr);

        boolean sawUndef = false;
        boolean sawDef = false;

        while (reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            // System.out.println("Event: " + event);
            if (event.isEntityReference()) {
                EntityReference ref = (EntityReference) event;
                if ("def".equals(ref.getName())) {
                    sawDef = true;
                } else if ("undef".equals(ref.getName())) {
                    sawUndef = true;
                } else {
                    throw new IllegalArgumentException("Unexpected entity name");
                }
            }
        }

        Assert.assertEquals(true, sawDef);
        Assert.assertEquals(true, sawUndef);
        reader.close();
    }, new FilePermission("/tmp/this/does/not/exist/but/that/is/ok", "read"));
}
 
Example #6
Source File: Bug6555001.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testReplacing() throws Exception {
    JAXPTestUtilities.tryRunWithTmpPermission(() -> {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty("javax.xml.stream.isReplacingEntityReferences", true);

        StringReader sr = new StringReader(XML);
        XMLEventReader reader = factory.createXMLEventReader(sr);

        boolean sawUndef = false;
        boolean sawDef = false;

        while (reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            // System.out.println("Event: " + event);
            if (event.isEntityReference()) {
                EntityReference ref = (EntityReference) event;
                if ("def".equals(ref.getName())) {
                    sawDef = true;
                } else if ("undef".equals(ref.getName())) {
                    sawUndef = true;
                } else {
                    throw new IllegalArgumentException("Unexpected entity name");
                }
            }
        }

        Assert.assertEquals(false, sawDef);
        Assert.assertEquals(true, sawUndef);
        reader.close();
    }, new FilePermission("/tmp/this/does/not/exist/but/that/is/ok", "read"));
}
 
Example #7
Source File: XMLEventReaderImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/** Reads the content of a text-only element. Precondition:
 * the current event is START_ELEMENT. Postcondition:
 * The current event is the corresponding END_ELEMENT.
 * @throws XMLStreamException if the current event is not a START_ELEMENT
 * or if a non text element is encountered
 */
public String getElementText() throws XMLStreamException {
    //we have to keep reference to the 'last event' of the stream to be able
    //to make this check - is there another way ? - nb.
    if(fLastEvent.getEventType() != XMLEvent.START_ELEMENT){
        throw new XMLStreamException(
        "parser must be on START_ELEMENT to read next text", fLastEvent.getLocation());
    }

    // STag content ETag
    //[43]   content   ::=   CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*

    //<foo>....some long text say in KB and underlying parser reports multiple character
    // but getElementText() events....</foo>

    String data = null;
    //having a peeked event makes things really worse -- we have to test the first event
    if(fPeekedEvent != null){
        XMLEvent event = fPeekedEvent ;
        fPeekedEvent = null;
        int type = event.getEventType();

        if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
        type == XMLEvent.CDATA){
            data = event.asCharacters().getData();
        }
        else if(type == XMLEvent.ENTITY_REFERENCE){
            data = ((EntityReference)event).getDeclaration().getReplacementText();
        }
        else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
            //ignore
        } else if(type == XMLEvent.START_ELEMENT) {
            throw new XMLStreamException(
            "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
        }else if(type == XMLEvent.END_ELEMENT){
            return "";
        }

        //create the string buffer and add initial data
        StringBuffer buffer = new StringBuffer();
        if(data != null && data.length() > 0 ) {
            buffer.append(data);
        }
        //get the next event -- we should stop at END_ELEMENT but it can be any thing
        //things are worse when implementing this function in XMLEventReader because
        //there isn't any function called getText() which can get values for
        //space, cdata, characters and entity reference
        //nextEvent() would also set the last event.
        event = nextEvent();
        while ((type = event.getEventType()) != XMLEvent.END_ELEMENT) {
            if (type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
                type == XMLEvent.CDATA){
                data = event.asCharacters().getData();
            }
            else if(type == XMLEvent.ENTITY_REFERENCE){
                data = ((EntityReference)event).getDeclaration().getReplacementText();
            }
            else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
                //ignore
                data = null;
            } else if(type == XMLEvent.END_DOCUMENT) {
                throw new XMLStreamException("unexpected end of document when reading element text content");
            } else if(type == XMLEvent.START_ELEMENT) {
                throw new XMLStreamException(
                "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
            } else {
                throw new XMLStreamException(
                "Unexpected event type "+ type, event.getLocation());
            }
            //add the data to the buffer
            if(data != null && data.length() > 0 ) {
                buffer.append(data);
            }
            event = nextEvent();
        }
        return buffer.toString();
    }//if (fPeekedEvent != null)

    //if there was no peeked, delegate everything to fXMLReader
    //update the last event before returning the text
    data = fXMLReader.getElementText();
    fLastEvent = fXMLEventAllocator.allocate(fXMLReader);
    return data;
}
 
Example #8
Source File: XMLEventReaderImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/** Reads the content of a text-only element. Precondition:
 * the current event is START_ELEMENT. Postcondition:
 * The current event is the corresponding END_ELEMENT.
 * @throws XMLStreamException if the current event is not a START_ELEMENT
 * or if a non text element is encountered
 */
public String getElementText() throws XMLStreamException {
    //we have to keep reference to the 'last event' of the stream to be able
    //to make this check - is there another way ? - nb.
    if(fLastEvent.getEventType() != XMLEvent.START_ELEMENT){
        throw new XMLStreamException(
        "parser must be on START_ELEMENT to read next text", fLastEvent.getLocation());
    }

    // STag content ETag
    //[43]   content   ::=   CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*

    //<foo>....some long text say in KB and underlying parser reports multiple character
    // but getElementText() events....</foo>

    String data = null;
    //having a peeked event makes things really worse -- we have to test the first event
    if(fPeekedEvent != null){
        XMLEvent event = fPeekedEvent ;
        fPeekedEvent = null;
        int type = event.getEventType();

        if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
        type == XMLEvent.CDATA){
            data = event.asCharacters().getData();
        }
        else if(type == XMLEvent.ENTITY_REFERENCE){
            data = ((EntityReference)event).getDeclaration().getReplacementText();
        }
        else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
            //ignore
        } else if(type == XMLEvent.START_ELEMENT) {
            throw new XMLStreamException(
            "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
        }else if(type == XMLEvent.END_ELEMENT){
            return "";
        }

        //create the string buffer and add initial data
        StringBuffer buffer = new StringBuffer();
        if(data != null && data.length() > 0 ) {
            buffer.append(data);
        }
        //get the next event -- we should stop at END_ELEMENT but it can be any thing
        //things are worse when implementing this function in XMLEventReader because
        //there isn't any function called getText() which can get values for
        //space, cdata, characters and entity reference
        //nextEvent() would also set the last event.
        event = nextEvent();
        while(event.getEventType() != XMLEvent.END_ELEMENT){
            if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
            type == XMLEvent.CDATA){
                data = event.asCharacters().getData();
            }
            else if(type == XMLEvent.ENTITY_REFERENCE){
                data = ((EntityReference)event).getDeclaration().getReplacementText();
            }
            else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
                //ignore
            } else if(type == XMLEvent.END_DOCUMENT) {
                throw new XMLStreamException("unexpected end of document when reading element text content");
            } else if(type == XMLEvent.START_ELEMENT) {
                throw new XMLStreamException(
                "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
            } else {
                throw new XMLStreamException(
                "Unexpected event type "+ type, event.getLocation());
            }
            //add the data to the buffer
            if(data != null && data.length() > 0 ) {
                buffer.append(data);
            }
            event = nextEvent();
        }
        return buffer.toString();
    }//if (fPeekedEvent != null)

    //if there was no peeked, delegate everything to fXMLReader
    //update the last event before returning the text
    data = fXMLReader.getElementText();
    fLastEvent = fXMLEventAllocator.allocate(fXMLReader);
    return data;
}
 
Example #9
Source File: StaxEventXMLReader.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected void parseInternal() throws SAXException, XMLStreamException {
	boolean documentStarted = false;
	boolean documentEnded = false;
	int elementDepth = 0;
	while (this.reader.hasNext() && elementDepth >= 0) {
		XMLEvent event = this.reader.nextEvent();
		if (!event.isStartDocument() && !event.isEndDocument() && !documentStarted) {
			handleStartDocument(event);
			documentStarted = true;
		}
		switch (event.getEventType()) {
			case XMLStreamConstants.START_DOCUMENT:
				handleStartDocument(event);
				documentStarted = true;
				break;
			case XMLStreamConstants.START_ELEMENT:
				elementDepth++;
				handleStartElement(event.asStartElement());
				break;
			case XMLStreamConstants.END_ELEMENT:
				elementDepth--;
				if (elementDepth >= 0) {
					handleEndElement(event.asEndElement());
				}
				break;
			case XMLStreamConstants.PROCESSING_INSTRUCTION:
				handleProcessingInstruction((ProcessingInstruction) event);
				break;
			case XMLStreamConstants.CHARACTERS:
			case XMLStreamConstants.SPACE:
			case XMLStreamConstants.CDATA:
				handleCharacters(event.asCharacters());
				break;
			case XMLStreamConstants.END_DOCUMENT:
				handleEndDocument();
				documentEnded = true;
				break;
			case XMLStreamConstants.NOTATION_DECLARATION:
				handleNotationDeclaration((NotationDeclaration) event);
				break;
			case XMLStreamConstants.ENTITY_DECLARATION:
				handleEntityDeclaration((EntityDeclaration) event);
				break;
			case XMLStreamConstants.COMMENT:
				handleComment((Comment) event);
				break;
			case XMLStreamConstants.DTD:
				handleDtd((DTD) event);
				break;
			case XMLStreamConstants.ENTITY_REFERENCE:
				handleEntityReference((EntityReference) event);
				break;
		}
	}
	if (documentStarted && !documentEnded) {
		handleEndDocument();
	}

}
 
Example #10
Source File: XMLEventReaderImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/** Reads the content of a text-only element. Precondition:
 * the current event is START_ELEMENT. Postcondition:
 * The current event is the corresponding END_ELEMENT.
 * @throws XMLStreamException if the current event is not a START_ELEMENT
 * or if a non text element is encountered
 */
public String getElementText() throws XMLStreamException {
    //we have to keep reference to the 'last event' of the stream to be able
    //to make this check - is there another way ? - nb.
    if(fLastEvent.getEventType() != XMLEvent.START_ELEMENT){
        throw new XMLStreamException(
        "parser must be on START_ELEMENT to read next text", fLastEvent.getLocation());
    }

    // STag content ETag
    //[43]   content   ::=   CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*

    //<foo>....some long text say in KB and underlying parser reports multiple character
    // but getElementText() events....</foo>

    String data = null;
    //having a peeked event makes things really worse -- we have to test the first event
    if(fPeekedEvent != null){
        XMLEvent event = fPeekedEvent ;
        fPeekedEvent = null;
        int type = event.getEventType();

        if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
        type == XMLEvent.CDATA){
            data = event.asCharacters().getData();
        }
        else if(type == XMLEvent.ENTITY_REFERENCE){
            data = ((EntityReference)event).getDeclaration().getReplacementText();
        }
        else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
            //ignore
        } else if(type == XMLEvent.START_ELEMENT) {
            throw new XMLStreamException(
            "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
        }else if(type == XMLEvent.END_ELEMENT){
            return "";
        }

        //create the string buffer and add initial data
        StringBuffer buffer = new StringBuffer();
        if(data != null && data.length() > 0 ) {
            buffer.append(data);
        }
        //get the next event -- we should stop at END_ELEMENT but it can be any thing
        //things are worse when implementing this function in XMLEventReader because
        //there isn't any function called getText() which can get values for
        //space, cdata, characters and entity reference
        //nextEvent() would also set the last event.
        event = nextEvent();
        while(event.getEventType() != XMLEvent.END_ELEMENT){
            if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
            type == XMLEvent.CDATA){
                data = event.asCharacters().getData();
            }
            else if(type == XMLEvent.ENTITY_REFERENCE){
                data = ((EntityReference)event).getDeclaration().getReplacementText();
            }
            else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
                //ignore
            } else if(type == XMLEvent.END_DOCUMENT) {
                throw new XMLStreamException("unexpected end of document when reading element text content");
            } else if(type == XMLEvent.START_ELEMENT) {
                throw new XMLStreamException(
                "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
            } else {
                throw new XMLStreamException(
                "Unexpected event type "+ type, event.getLocation());
            }
            //add the data to the buffer
            if(data != null && data.length() > 0 ) {
                buffer.append(data);
            }
            event = nextEvent();
        }
        return buffer.toString();
    }//if (fPeekedEvent != null)

    //if there was no peeked, delegate everything to fXMLReader
    //update the last event before returning the text
    data = fXMLReader.getElementText();
    fLastEvent = fXMLEventAllocator.allocate(fXMLReader);
    return data;
}
 
Example #11
Source File: XMLEventReaderImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/** Reads the content of a text-only element. Precondition:
 * the current event is START_ELEMENT. Postcondition:
 * The current event is the corresponding END_ELEMENT.
 * @throws XMLStreamException if the current event is not a START_ELEMENT
 * or if a non text element is encountered
 */
public String getElementText() throws XMLStreamException {
    //we have to keep reference to the 'last event' of the stream to be able
    //to make this check - is there another way ? - nb.
    if(fLastEvent.getEventType() != XMLEvent.START_ELEMENT){
        throw new XMLStreamException(
        "parser must be on START_ELEMENT to read next text", fLastEvent.getLocation());
    }

    // STag content ETag
    //[43]   content   ::=   CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*

    //<foo>....some long text say in KB and underlying parser reports multiple character
    // but getElementText() events....</foo>

    String data = null;
    //having a peeked event makes things really worse -- we have to test the first event
    if(fPeekedEvent != null){
        XMLEvent event = fPeekedEvent ;
        fPeekedEvent = null;
        int type = event.getEventType();

        if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
        type == XMLEvent.CDATA){
            data = event.asCharacters().getData();
        }
        else if(type == XMLEvent.ENTITY_REFERENCE){
            data = ((EntityReference)event).getDeclaration().getReplacementText();
        }
        else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
            //ignore
        } else if(type == XMLEvent.START_ELEMENT) {
            throw new XMLStreamException(
            "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
        }else if(type == XMLEvent.END_ELEMENT){
            return "";
        }

        //create the string buffer and add initial data
        StringBuffer buffer = new StringBuffer();
        if(data != null && data.length() > 0 ) {
            buffer.append(data);
        }
        //get the next event -- we should stop at END_ELEMENT but it can be any thing
        //things are worse when implementing this function in XMLEventReader because
        //there isn't any function called getText() which can get values for
        //space, cdata, characters and entity reference
        //nextEvent() would also set the last event.
        event = nextEvent();
        while(event.getEventType() != XMLEvent.END_ELEMENT){
            if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
            type == XMLEvent.CDATA){
                data = event.asCharacters().getData();
            }
            else if(type == XMLEvent.ENTITY_REFERENCE){
                data = ((EntityReference)event).getDeclaration().getReplacementText();
            }
            else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
                //ignore
            } else if(type == XMLEvent.END_DOCUMENT) {
                throw new XMLStreamException("unexpected end of document when reading element text content");
            } else if(type == XMLEvent.START_ELEMENT) {
                throw new XMLStreamException(
                "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
            } else {
                throw new XMLStreamException(
                "Unexpected event type "+ type, event.getLocation());
            }
            //add the data to the buffer
            if(data != null && data.length() > 0 ) {
                buffer.append(data);
            }
            event = nextEvent();
        }
        return buffer.toString();
    }//if (fPeekedEvent != null)

    //if there was no peeked, delegate everything to fXMLReader
    //update the last event before returning the text
    data = fXMLReader.getElementText();
    fLastEvent = fXMLEventAllocator.allocate(fXMLReader);
    return data;
}
 
Example #12
Source File: XMLEventFactoryImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public EntityReference createEntityReference(String name, EntityDeclaration declaration) {
    return null;
}
 
Example #13
Source File: XMLEventFactoryWrapper.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public EntityReference createEntityReference(String name, EntityDeclaration declaration) {
    return defaultImpl.createEntityReference(name, declaration);
}
 
Example #14
Source File: XMLEventFactoryImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) {
    EntityReferenceEvent event =  new EntityReferenceEvent(name, entityDeclaration);
    if(location != null)event.setLocation(location);
    return event;
}
 
Example #15
Source File: XMLEventReaderImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/** Reads the content of a text-only element. Precondition:
 * the current event is START_ELEMENT. Postcondition:
 * The current event is the corresponding END_ELEMENT.
 * @throws XMLStreamException if the current event is not a START_ELEMENT
 * or if a non text element is encountered
 */
public String getElementText() throws XMLStreamException {
    //we have to keep reference to the 'last event' of the stream to be able
    //to make this check - is there another way ? - nb.
    if(fLastEvent.getEventType() != XMLEvent.START_ELEMENT){
        throw new XMLStreamException(
        "parser must be on START_ELEMENT to read next text", fLastEvent.getLocation());
    }

    // STag content ETag
    //[43]   content   ::=   CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*

    //<foo>....some long text say in KB and underlying parser reports multiple character
    // but getElementText() events....</foo>

    String data = null;
    //having a peeked event makes things really worse -- we have to test the first event
    if(fPeekedEvent != null){
        XMLEvent event = fPeekedEvent ;
        fPeekedEvent = null;
        int type = event.getEventType();

        if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
        type == XMLEvent.CDATA){
            data = event.asCharacters().getData();
        }
        else if(type == XMLEvent.ENTITY_REFERENCE){
            data = ((EntityReference)event).getDeclaration().getReplacementText();
        }
        else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
            //ignore
        } else if(type == XMLEvent.START_ELEMENT) {
            throw new XMLStreamException(
            "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
        }else if(type == XMLEvent.END_ELEMENT){
            return "";
        }

        //create the string buffer and add initial data
        StringBuffer buffer = new StringBuffer();
        if(data != null && data.length() > 0 ) {
            buffer.append(data);
        }
        //get the next event -- we should stop at END_ELEMENT but it can be any thing
        //things are worse when implementing this function in XMLEventReader because
        //there isn't any function called getText() which can get values for
        //space, cdata, characters and entity reference
        //nextEvent() would also set the last event.
        event = nextEvent();
        while(event.getEventType() != XMLEvent.END_ELEMENT){
            if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
            type == XMLEvent.CDATA){
                data = event.asCharacters().getData();
            }
            else if(type == XMLEvent.ENTITY_REFERENCE){
                data = ((EntityReference)event).getDeclaration().getReplacementText();
            }
            else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
                //ignore
            } else if(type == XMLEvent.END_DOCUMENT) {
                throw new XMLStreamException("unexpected end of document when reading element text content");
            } else if(type == XMLEvent.START_ELEMENT) {
                throw new XMLStreamException(
                "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
            } else {
                throw new XMLStreamException(
                "Unexpected event type "+ type, event.getLocation());
            }
            //add the data to the buffer
            if(data != null && data.length() > 0 ) {
                buffer.append(data);
            }
            event = nextEvent();
        }
        return buffer.toString();
    }//if (fPeekedEvent != null)

    //if there was no peeked, delegate everything to fXMLReader
    //update the last event before returning the text
    data = fXMLReader.getElementText();
    fLastEvent = fXMLEventAllocator.allocate(fXMLReader);
    return data;
}
 
Example #16
Source File: XMLEventFactoryImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
@Override
public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) {
    EntityReferenceEvent event =  new EntityReferenceEvent(name, entityDeclaration);
    if(location != null)event.setLocation(location);
    return event;
}
 
Example #17
Source File: StaxEventXMLReader.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void parseInternal() throws SAXException, XMLStreamException {
	boolean documentStarted = false;
	boolean documentEnded = false;
	int elementDepth = 0;
	while (this.reader.hasNext() && elementDepth >= 0) {
		XMLEvent event = this.reader.nextEvent();
		if (!event.isStartDocument() && !event.isEndDocument() && !documentStarted) {
			handleStartDocument(event);
			documentStarted = true;
		}
		switch (event.getEventType()) {
			case XMLStreamConstants.START_DOCUMENT:
				handleStartDocument(event);
				documentStarted = true;
				break;
			case XMLStreamConstants.START_ELEMENT:
				elementDepth++;
				handleStartElement(event.asStartElement());
				break;
			case XMLStreamConstants.END_ELEMENT:
				elementDepth--;
				if (elementDepth >= 0) {
					handleEndElement(event.asEndElement());
				}
				break;
			case XMLStreamConstants.PROCESSING_INSTRUCTION:
				handleProcessingInstruction((ProcessingInstruction) event);
				break;
			case XMLStreamConstants.CHARACTERS:
			case XMLStreamConstants.SPACE:
			case XMLStreamConstants.CDATA:
				handleCharacters(event.asCharacters());
				break;
			case XMLStreamConstants.END_DOCUMENT:
				handleEndDocument();
				documentEnded = true;
				break;
			case XMLStreamConstants.NOTATION_DECLARATION:
				handleNotationDeclaration((NotationDeclaration) event);
				break;
			case XMLStreamConstants.ENTITY_DECLARATION:
				handleEntityDeclaration((EntityDeclaration) event);
				break;
			case XMLStreamConstants.COMMENT:
				handleComment((Comment) event);
				break;
			case XMLStreamConstants.DTD:
				handleDtd((DTD) event);
				break;
			case XMLStreamConstants.ENTITY_REFERENCE:
				handleEntityReference((EntityReference) event);
				break;
		}
	}
	if (documentStarted && !documentEnded) {
		handleEndDocument();
	}

}
 
Example #18
Source File: XMLEventReaderImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/** Reads the content of a text-only element. Precondition:
 * the current event is START_ELEMENT. Postcondition:
 * The current event is the corresponding END_ELEMENT.
 * @throws XMLStreamException if the current event is not a START_ELEMENT
 * or if a non text element is encountered
 */
public String getElementText() throws XMLStreamException {
    //we have to keep reference to the 'last event' of the stream to be able
    //to make this check - is there another way ? - nb.
    if(fLastEvent.getEventType() != XMLEvent.START_ELEMENT){
        throw new XMLStreamException(
        "parser must be on START_ELEMENT to read next text", fLastEvent.getLocation());
    }

    // STag content ETag
    //[43]   content   ::=   CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*

    //<foo>....some long text say in KB and underlying parser reports multiple character
    // but getElementText() events....</foo>

    String data = null;
    //having a peeked event makes things really worse -- we have to test the first event
    if(fPeekedEvent != null){
        XMLEvent event = fPeekedEvent ;
        fPeekedEvent = null;
        int type = event.getEventType();

        if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
        type == XMLEvent.CDATA){
            data = event.asCharacters().getData();
        }
        else if(type == XMLEvent.ENTITY_REFERENCE){
            data = ((EntityReference)event).getDeclaration().getReplacementText();
        }
        else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
            //ignore
        } else if(type == XMLEvent.START_ELEMENT) {
            throw new XMLStreamException(
            "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
        }else if(type == XMLEvent.END_ELEMENT){
            return "";
        }

        //create the string buffer and add initial data
        StringBuffer buffer = new StringBuffer();
        if(data != null && data.length() > 0 ) {
            buffer.append(data);
        }
        //get the next event -- we should stop at END_ELEMENT but it can be any thing
        //things are worse when implementing this function in XMLEventReader because
        //there isn't any function called getText() which can get values for
        //space, cdata, characters and entity reference
        //nextEvent() would also set the last event.
        event = nextEvent();
        while(event.getEventType() != XMLEvent.END_ELEMENT){
            if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
            type == XMLEvent.CDATA){
                data = event.asCharacters().getData();
            }
            else if(type == XMLEvent.ENTITY_REFERENCE){
                data = ((EntityReference)event).getDeclaration().getReplacementText();
            }
            else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
                //ignore
            } else if(type == XMLEvent.END_DOCUMENT) {
                throw new XMLStreamException("unexpected end of document when reading element text content");
            } else if(type == XMLEvent.START_ELEMENT) {
                throw new XMLStreamException(
                "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
            } else {
                throw new XMLStreamException(
                "Unexpected event type "+ type, event.getLocation());
            }
            //add the data to the buffer
            if(data != null && data.length() > 0 ) {
                buffer.append(data);
            }
            event = nextEvent();
        }
        return buffer.toString();
    }//if (fPeekedEvent != null)

    //if there was no peeked, delegate everything to fXMLReader
    //update the last event before returning the text
    data = fXMLReader.getElementText();
    fLastEvent = fXMLEventAllocator.allocate(fXMLReader);
    return data;
}
 
Example #19
Source File: BaseXMLEventReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@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();
}
 
Example #20
Source File: BaseXMLEventReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@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();
}
 
Example #21
Source File: StaxEventXMLReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void parseInternal() throws SAXException, XMLStreamException {
	boolean documentStarted = false;
	boolean documentEnded = false;
	int elementDepth = 0;
	while (this.reader.hasNext() && elementDepth >= 0) {
		XMLEvent event = this.reader.nextEvent();
		if (!event.isStartDocument() && !event.isEndDocument() && !documentStarted) {
			handleStartDocument(event);
			documentStarted = true;
		}
		switch (event.getEventType()) {
			case XMLStreamConstants.START_DOCUMENT:
				handleStartDocument(event);
				documentStarted = true;
				break;
			case XMLStreamConstants.START_ELEMENT:
				elementDepth++;
				handleStartElement(event.asStartElement());
				break;
			case XMLStreamConstants.END_ELEMENT:
				elementDepth--;
				if (elementDepth >= 0) {
					handleEndElement(event.asEndElement());
				}
				break;
			case XMLStreamConstants.PROCESSING_INSTRUCTION:
				handleProcessingInstruction((ProcessingInstruction) event);
				break;
			case XMLStreamConstants.CHARACTERS:
			case XMLStreamConstants.SPACE:
			case XMLStreamConstants.CDATA:
				handleCharacters(event.asCharacters());
				break;
			case XMLStreamConstants.END_DOCUMENT:
				handleEndDocument();
				documentEnded = true;
				break;
			case XMLStreamConstants.NOTATION_DECLARATION:
				handleNotationDeclaration((NotationDeclaration) event);
				break;
			case XMLStreamConstants.ENTITY_DECLARATION:
				handleEntityDeclaration((EntityDeclaration) event);
				break;
			case XMLStreamConstants.COMMENT:
				handleComment((Comment) event);
				break;
			case XMLStreamConstants.DTD:
				handleDtd((DTD) event);
				break;
			case XMLStreamConstants.ENTITY_REFERENCE:
				handleEntityReference((EntityReference) event);
				break;
		}
	}
	if (documentStarted && !documentEnded) {
		handleEndDocument();
	}

}
 
Example #22
Source File: XMLEventReaderImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/** Reads the content of a text-only element. Precondition:
 * the current event is START_ELEMENT. Postcondition:
 * The current event is the corresponding END_ELEMENT.
 * @throws XMLStreamException if the current event is not a START_ELEMENT
 * or if a non text element is encountered
 */
public String getElementText() throws XMLStreamException {
    //we have to keep reference to the 'last event' of the stream to be able
    //to make this check - is there another way ? - nb.
    if(fLastEvent.getEventType() != XMLEvent.START_ELEMENT){
        throw new XMLStreamException(
        "parser must be on START_ELEMENT to read next text", fLastEvent.getLocation());
    }

    // STag content ETag
    //[43]   content   ::=   CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*

    //<foo>....some long text say in KB and underlying parser reports multiple character
    // but getElementText() events....</foo>

    String data = null;
    //having a peeked event makes things really worse -- we have to test the first event
    if(fPeekedEvent != null){
        XMLEvent event = fPeekedEvent ;
        fPeekedEvent = null;
        int type = event.getEventType();

        if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
        type == XMLEvent.CDATA){
            data = event.asCharacters().getData();
        }
        else if(type == XMLEvent.ENTITY_REFERENCE){
            data = ((EntityReference)event).getDeclaration().getReplacementText();
        }
        else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
            //ignore
        } else if(type == XMLEvent.START_ELEMENT) {
            throw new XMLStreamException(
            "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
        }else if(type == XMLEvent.END_ELEMENT){
            return "";
        }

        //create the string buffer and add initial data
        StringBuffer buffer = new StringBuffer();
        if(data != null && data.length() > 0 ) {
            buffer.append(data);
        }
        //get the next event -- we should stop at END_ELEMENT but it can be any thing
        //things are worse when implementing this function in XMLEventReader because
        //there isn't any function called getText() which can get values for
        //space, cdata, characters and entity reference
        //nextEvent() would also set the last event.
        event = nextEvent();
        while(event.getEventType() != XMLEvent.END_ELEMENT){
            if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
            type == XMLEvent.CDATA){
                data = event.asCharacters().getData();
            }
            else if(type == XMLEvent.ENTITY_REFERENCE){
                data = ((EntityReference)event).getDeclaration().getReplacementText();
            }
            else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
                //ignore
            } else if(type == XMLEvent.END_DOCUMENT) {
                throw new XMLStreamException("unexpected end of document when reading element text content");
            } else if(type == XMLEvent.START_ELEMENT) {
                throw new XMLStreamException(
                "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
            } else {
                throw new XMLStreamException(
                "Unexpected event type "+ type, event.getLocation());
            }
            //add the data to the buffer
            if(data != null && data.length() > 0 ) {
                buffer.append(data);
            }
            event = nextEvent();
        }
        return buffer.toString();
    }//if (fPeekedEvent != null)

    //if there was no peeked, delegate everything to fXMLReader
    //update the last event before returning the text
    data = fXMLReader.getElementText();
    fLastEvent = fXMLEventAllocator.allocate(fXMLReader);
    return data;
}
 
Example #23
Source File: XMLEventReaderImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/** Reads the content of a text-only element. Precondition:
 * the current event is START_ELEMENT. Postcondition:
 * The current event is the corresponding END_ELEMENT.
 * @throws XMLStreamException if the current event is not a START_ELEMENT
 * or if a non text element is encountered
 */
public String getElementText() throws XMLStreamException {
    //we have to keep reference to the 'last event' of the stream to be able
    //to make this check - is there another way ? - nb.
    if(fLastEvent.getEventType() != XMLEvent.START_ELEMENT){
        throw new XMLStreamException(
        "parser must be on START_ELEMENT to read next text", fLastEvent.getLocation());
    }

    // STag content ETag
    //[43]   content   ::=   CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*

    //<foo>....some long text say in KB and underlying parser reports multiple character
    // but getElementText() events....</foo>

    String data = null;
    //having a peeked event makes things really worse -- we have to test the first event
    if(fPeekedEvent != null){
        XMLEvent event = fPeekedEvent ;
        fPeekedEvent = null;
        int type = event.getEventType();

        if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
        type == XMLEvent.CDATA){
            data = event.asCharacters().getData();
        }
        else if(type == XMLEvent.ENTITY_REFERENCE){
            data = ((EntityReference)event).getDeclaration().getReplacementText();
        }
        else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
            //ignore
        } else if(type == XMLEvent.START_ELEMENT) {
            throw new XMLStreamException(
            "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
        }else if(type == XMLEvent.END_ELEMENT){
            return "";
        }

        //create the string buffer and add initial data
        StringBuffer buffer = new StringBuffer();
        if(data != null && data.length() > 0 ) {
            buffer.append(data);
        }
        //get the next event -- we should stop at END_ELEMENT but it can be any thing
        //things are worse when implementing this function in XMLEventReader because
        //there isn't any function called getText() which can get values for
        //space, cdata, characters and entity reference
        //nextEvent() would also set the last event.
        event = nextEvent();
        while(event.getEventType() != XMLEvent.END_ELEMENT){
            if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
            type == XMLEvent.CDATA){
                data = event.asCharacters().getData();
            }
            else if(type == XMLEvent.ENTITY_REFERENCE){
                data = ((EntityReference)event).getDeclaration().getReplacementText();
            }
            else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
                //ignore
            } else if(type == XMLEvent.END_DOCUMENT) {
                throw new XMLStreamException("unexpected end of document when reading element text content");
            } else if(type == XMLEvent.START_ELEMENT) {
                throw new XMLStreamException(
                "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
            } else {
                throw new XMLStreamException(
                "Unexpected event type "+ type, event.getLocation());
            }
            //add the data to the buffer
            if(data != null && data.length() > 0 ) {
                buffer.append(data);
            }
            event = nextEvent();
        }
        return buffer.toString();
    }//if (fPeekedEvent != null)

    //if there was no peeked, delegate everything to fXMLReader
    //update the last event before returning the text
    data = fXMLReader.getElementText();
    fLastEvent = fXMLEventAllocator.allocate(fXMLReader);
    return data;
}
 
Example #24
Source File: StaxEventXMLReader.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void parseInternal() throws SAXException, XMLStreamException {
	boolean documentStarted = false;
	boolean documentEnded = false;
	int elementDepth = 0;
	while (this.reader.hasNext() && elementDepth >= 0) {
		XMLEvent event = this.reader.nextEvent();
		if (!event.isStartDocument() && !event.isEndDocument() && !documentStarted) {
			handleStartDocument(event);
			documentStarted = true;
		}
		switch (event.getEventType()) {
			case XMLStreamConstants.START_DOCUMENT:
				handleStartDocument(event);
				documentStarted = true;
				break;
			case XMLStreamConstants.START_ELEMENT:
				elementDepth++;
				handleStartElement(event.asStartElement());
				break;
			case XMLStreamConstants.END_ELEMENT:
				elementDepth--;
				if (elementDepth >= 0) {
					handleEndElement(event.asEndElement());
				}
				break;
			case XMLStreamConstants.PROCESSING_INSTRUCTION:
				handleProcessingInstruction((ProcessingInstruction) event);
				break;
			case XMLStreamConstants.CHARACTERS:
			case XMLStreamConstants.SPACE:
			case XMLStreamConstants.CDATA:
				handleCharacters(event.asCharacters());
				break;
			case XMLStreamConstants.END_DOCUMENT:
				handleEndDocument();
				documentEnded = true;
				break;
			case XMLStreamConstants.NOTATION_DECLARATION:
				handleNotationDeclaration((NotationDeclaration) event);
				break;
			case XMLStreamConstants.ENTITY_DECLARATION:
				handleEntityDeclaration((EntityDeclaration) event);
				break;
			case XMLStreamConstants.COMMENT:
				handleComment((Comment) event);
				break;
			case XMLStreamConstants.DTD:
				handleDtd((DTD) event);
				break;
			case XMLStreamConstants.ENTITY_REFERENCE:
				handleEntityReference((EntityReference) event);
				break;
		}
	}
	if (documentStarted && !documentEnded) {
		handleEndDocument();
	}

}
 
Example #25
Source File: XMLEventReaderImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/** Reads the content of a text-only element. Precondition:
 * the current event is START_ELEMENT. Postcondition:
 * The current event is the corresponding END_ELEMENT.
 * @throws XMLStreamException if the current event is not a START_ELEMENT
 * or if a non text element is encountered
 */
public String getElementText() throws XMLStreamException {
    //we have to keep reference to the 'last event' of the stream to be able
    //to make this check - is there another way ? - nb.
    if(fLastEvent.getEventType() != XMLEvent.START_ELEMENT){
        throw new XMLStreamException(
        "parser must be on START_ELEMENT to read next text", fLastEvent.getLocation());
    }

    // STag content ETag
    //[43]   content   ::=   CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*

    //<foo>....some long text say in KB and underlying parser reports multiple character
    // but getElementText() events....</foo>

    String data = null;
    //having a peeked event makes things really worse -- we have to test the first event
    if(fPeekedEvent != null){
        XMLEvent event = fPeekedEvent ;
        fPeekedEvent = null;
        int type = event.getEventType();

        if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
        type == XMLEvent.CDATA){
            data = event.asCharacters().getData();
        }
        else if(type == XMLEvent.ENTITY_REFERENCE){
            data = ((EntityReference)event).getDeclaration().getReplacementText();
        }
        else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
            //ignore
        } else if(type == XMLEvent.START_ELEMENT) {
            throw new XMLStreamException(
            "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
        }else if(type == XMLEvent.END_ELEMENT){
            return "";
        }

        //create the string buffer and add initial data
        StringBuffer buffer = new StringBuffer();
        if(data != null && data.length() > 0 ) {
            buffer.append(data);
        }
        //get the next event -- we should stop at END_ELEMENT but it can be any thing
        //things are worse when implementing this function in XMLEventReader because
        //there isn't any function called getText() which can get values for
        //space, cdata, characters and entity reference
        //nextEvent() would also set the last event.
        event = nextEvent();
        while(event.getEventType() != XMLEvent.END_ELEMENT){
            if(  type == XMLEvent.CHARACTERS || type == XMLEvent.SPACE ||
            type == XMLEvent.CDATA){
                data = event.asCharacters().getData();
            }
            else if(type == XMLEvent.ENTITY_REFERENCE){
                data = ((EntityReference)event).getDeclaration().getReplacementText();
            }
            else if(type == XMLEvent.COMMENT || type == XMLEvent.PROCESSING_INSTRUCTION){
                //ignore
            } else if(type == XMLEvent.END_DOCUMENT) {
                throw new XMLStreamException("unexpected end of document when reading element text content");
            } else if(type == XMLEvent.START_ELEMENT) {
                throw new XMLStreamException(
                "elementGetText() function expects text only elment but START_ELEMENT was encountered.", event.getLocation());
            } else {
                throw new XMLStreamException(
                "Unexpected event type "+ type, event.getLocation());
            }
            //add the data to the buffer
            if(data != null && data.length() > 0 ) {
                buffer.append(data);
            }
            event = nextEvent();
        }
        return buffer.toString();
    }//if (fPeekedEvent != null)

    //if there was no peeked, delegate everything to fXMLReader
    //update the last event before returning the text
    data = fXMLReader.getElementText();
    fLastEvent = fXMLEventAllocator.allocate(fXMLReader);
    return data;
}
 
Example #26
Source File: EntityReplacer.java    From nebula with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Returns the String representation of the given {@link EntityReference}.
 * 
 * @param reference
 *            The {@link EntityReference} for which the String representation is requested.
 * @return The String representation for the given {@link EntityReference}.
 */
String getEntityReferenceValue(EntityReference reference);
 
Example #27
Source File: XmlUtils.java    From entity-fishing with Apache License 2.0 2 votes vote down vote up
/**
 * Compares two {@link XMLEvent} instances. This method delegates actual
 * matching to the appropriate overloaded method.
 * 
 * @param a
 *            The first event.
 * @param b
 *            The second event.
 * @return <code>true</code> if the events match, <code>false</code>
 *         otherwise.
 */
public static boolean eventsMatch(XMLEvent a, XMLEvent b) {

	if (a == b) {

		return true;

	} else if (a == null || b == null) {

		return false;

	} else if (a.getEventType() == b.getEventType()) {

		switch (a.getEventType()) {

		case XMLEvent.START_ELEMENT:
			return eventsMatch(a.asStartElement(), b.asStartElement());

		case XMLEvent.END_ELEMENT:
			return eventsMatch(a.asEndElement(), b.asEndElement());

		case XMLEvent.CDATA:
		case XMLEvent.SPACE:
		case XMLEvent.CHARACTERS:
			return eventsMatch(a.asCharacters(), b.asCharacters());

		case XMLEvent.COMMENT:
			return eventsMatch((Comment) a, (Comment) b);

		case XMLEvent.ENTITY_REFERENCE:
			return eventsMatch((EntityReference) a, (EntityReference) b);

		case XMLEvent.ATTRIBUTE:
			return eventsMatch((Attribute) a, (Attribute) b);

		case XMLEvent.NAMESPACE:
			return eventsMatch((Namespace) a, (Namespace) b);

		case XMLEvent.START_DOCUMENT:
			return eventsMatch((StartDocument) a, (StartDocument) b);

		case XMLEvent.END_DOCUMENT:
			return eventsMatch((EndDocument) a, (EndDocument) b);

		case XMLEvent.PROCESSING_INSTRUCTION:
			return eventsMatch((ProcessingInstruction) a, (ProcessingInstruction) b);

		case XMLEvent.DTD:
			return eventsMatch((DTD) a, (DTD) b);

		case XMLEvent.ENTITY_DECLARATION:
			return eventsMatch((EntityDeclaration) a, (EntityDeclaration) b);

		case XMLEvent.NOTATION_DECLARATION:
			return eventsMatch((NotationDeclaration) a, (NotationDeclaration) b);

		}

	}

	return false;

}