@Test public void testCharactersCData() throws XMLStreamException { XMLStreamReader reader = createXmlStreamReader("<alice>bob</alice>"); reader.next(); Characters characters = eventAllocator.allocate(reader).asCharacters(); verify(characters, XMLStreamConstants.CHARACTERS, "bob"); Assert.assertEquals("bob", characters.getData()); Assert.assertFalse(characters.isCData()); Assert.assertFalse(characters.isWhiteSpace()); Assert.assertFalse(characters.isIgnorableWhiteSpace()); reader = createXmlStreamReader("<alice><![CDATA[bob]]></alice>"); reader.next(); characters = eventAllocator.allocate(reader).asCharacters(); verify(characters, XMLStreamConstants.CDATA, "<![CDATA[bob]]>"); Assert.assertEquals("bob", characters.getData()); Assert.assertTrue(characters.isCData()); reader = createXmlStreamReader("<alice><![CDATA[ ]]></alice>"); reader.next(); characters = eventAllocator.allocate(reader).asCharacters(); verify(characters, XMLStreamConstants.CDATA, "<![CDATA[ ]]>"); Assert.assertEquals(" ", characters.getData()); Assert.assertTrue(characters.isWhiteSpace()); Assert.assertFalse(characters.isIgnorableWhiteSpace()); }
@Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } } }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }  }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }  @Override XMLEventAllocator newInstance(); @Override XMLEvent allocate(XMLStreamReader reader); @Override void allocate(XMLStreamReader reader, XMLEventConsumer consumer); }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }  @Override XMLEventAllocator newInstance(); @Override XMLEvent allocate(XMLStreamReader reader); @Override void allocate(XMLStreamReader reader, XMLEventConsumer consumer);  }