use of javax.xml.stream.events.StartDocument in project wso2-synapse by wso2.
the class SimpleXMLEventFactoryTest method testCreateStartDocument_Encoding_Version.
@Test
public void testCreateStartDocument_Encoding_Version() throws XMLStreamException {
StartDocument event = factory.createStartDocument("UTF-8", "1.1");
verify(event, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.1\" encoding=\"UTF-8\"?>");
}
use of javax.xml.stream.events.StartDocument in project wso2-synapse by wso2.
the class SimpleXMLEventFactoryTest method testCreateStartDocument_Encoding_Version_Standalone.
@Test
public void testCreateStartDocument_Encoding_Version_Standalone() throws XMLStreamException {
StartDocument event = factory.createStartDocument("UTF-8", "1.1", true);
verify(event, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.1\" encoding=\"UTF-8\" standalone=\"yes\"?>");
}
use of javax.xml.stream.events.StartDocument in project wso2-synapse by wso2.
the class XMLEventWriterDelegate method add.
public void add(XMLEvent event) throws XMLStreamException {
switch(event.getEventType()) {
case XMLStreamConstants.ATTRIBUTE:
Attribute attribute = (Attribute) event;
QName attrName = attribute.getName();
delegate.writeAttribute(attrName.getPrefix(), attrName.getNamespaceURI(), attrName.getLocalPart(), attribute.getValue());
break;
case XMLStreamConstants.END_DOCUMENT:
delegate.writeEndDocument();
break;
case XMLStreamConstants.END_ELEMENT:
delegate.writeEndElement();
break;
case XMLStreamConstants.NAMESPACE:
Namespace namespace = (Namespace) event;
delegate.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
break;
case XMLStreamConstants.START_DOCUMENT:
StartDocument startDocument = (StartDocument) event;
if (startDocument.encodingSet()) {
// encoding defined?
delegate.writeStartDocument(startDocument.getCharacterEncodingScheme(), startDocument.getVersion());
} else {
delegate.writeStartDocument(startDocument.getVersion());
}
break;
case XMLStreamConstants.START_ELEMENT:
StartElement startElement = event.asStartElement();
QName elemName = startElement.getName();
delegate.writeStartElement(elemName.getPrefix(), elemName.getLocalPart(), elemName.getNamespaceURI());
Iterator<?> namespaces = startElement.getNamespaces();
while (namespaces.hasNext()) {
add((Namespace) namespaces.next());
}
Iterator<?> attributes = startElement.getAttributes();
while (attributes.hasNext()) {
add((Attribute) attributes.next());
}
break;
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.CDATA:
Characters characters = event.asCharacters();
if (characters.isCData()) {
delegate.writeCData(characters.getData());
} else {
delegate.writeCharacters(characters.getData());
}
break;
case XMLStreamConstants.COMMENT:
delegate.writeComment(((Comment) event).getText());
break;
case XMLStreamConstants.DTD:
delegate.writeDTD(((DTD) event).getDocumentTypeDeclaration());
break;
case XMLStreamConstants.ENTITY_REFERENCE:
delegate.writeEntityRef(((EntityReference) event).getName());
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
ProcessingInstruction processingInstruction = (ProcessingInstruction) event;
delegate.writeProcessingInstruction(processingInstruction.getTarget(), processingInstruction.getData());
break;
case XMLStreamConstants.SPACE:
break;
default:
throw new XMLStreamException("Cannot write event " + event);
}
}
use of javax.xml.stream.events.StartDocument in project wso2-synapse by wso2.
the class SimpleXMLEventAllocatorTest method testStartEndDocument.
@Test
public void testStartEndDocument() throws XMLStreamException {
XMLStreamReader reader = createXmlStreamReader("<? xml ?>");
StartDocument startDocument = (StartDocument) eventAllocator.allocate(reader);
verify(startDocument, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.0\"?>");
Assert.assertEquals("UTF-8", startDocument.getCharacterEncodingScheme());
Assert.assertFalse(startDocument.encodingSet());
Assert.assertEquals("1.0", startDocument.getVersion());
Assert.assertFalse(startDocument.isStandalone());
Assert.assertFalse(startDocument.standaloneSet());
reader.next();
verify((EndDocument) eventAllocator.allocate(reader), XMLStreamConstants.END_DOCUMENT, "");
reader = createXmlStreamReader("<? xml version=\"1.1\" ?>");
startDocument = (StartDocument) eventAllocator.allocate(reader);
Assert.assertEquals("1.1", startDocument.getVersion());
reader = createXmlStreamReader("<? xml encoding=\"UTF-16\"?>");
startDocument = (StartDocument) eventAllocator.allocate(reader);
Assert.assertEquals("UTF-16", startDocument.getCharacterEncodingScheme());
Assert.assertTrue(startDocument.encodingSet());
}
use of javax.xml.stream.events.StartDocument in project wso2-synapse by wso2.
the class SimpleXMLEventFactoryTest method testCreateStartDocument_Encoding.
@Test
public void testCreateStartDocument_Encoding() throws XMLStreamException {
StartDocument event = factory.createStartDocument("UTF-8");
verify(event, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
}
Aggregations