use of javax.xml.stream.events.ProcessingInstruction in project wso2-synapse by wso2.
the class SimpleXMLEventFactoryTest method testCreateProcessingInstruction.
@Test
public void testCreateProcessingInstruction() throws XMLStreamException {
ProcessingInstruction event = factory.createProcessingInstruction("foo", "bar");
verify(event, XMLStreamConstants.PROCESSING_INSTRUCTION, "<?foo bar?>");
}
use of javax.xml.stream.events.ProcessingInstruction 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.ProcessingInstruction in project wso2-synapse by wso2.
the class DOMEventConsumer method add.
@Override
public void add(XMLEvent event) throws XMLStreamException {
switch(event.getEventType()) {
case XMLStreamConstants.CDATA:
node.appendChild(document.createCDATASection(event.asCharacters().getData()));
break;
case XMLStreamConstants.CHARACTERS:
node.appendChild(document.createTextNode(event.asCharacters().getData()));
break;
case XMLStreamConstants.COMMENT:
node.appendChild(document.createComment(((Comment) event).getText()));
break;
case XMLStreamConstants.END_ELEMENT:
node = node.getParentNode();
break;
case XMLStreamConstants.ENTITY_REFERENCE:
node.appendChild(document.createEntityReference(((EntityReference) event).getName()));
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
ProcessingInstruction pi = (ProcessingInstruction) event;
node.appendChild(document.createProcessingInstruction(pi.getTarget(), pi.getData()));
break;
case XMLStreamConstants.START_ELEMENT:
StartElement startElement = event.asStartElement();
QName elementName = startElement.getName();
Element element;
if (namespaceAware) {
element = document.createElementNS(elementName.getNamespaceURI(), qName(elementName));
} else {
element = document.createElement(elementName.getLocalPart());
}
Iterator<?> namespaces = startElement.getNamespaces();
while (namespaces.hasNext()) {
Namespace ns = (Namespace) namespaces.next();
element.setAttributeNS(ns.getName().getNamespaceURI(), qName(ns.getName()), ns.getNamespaceURI());
}
Iterator<?> attributes = startElement.getAttributes();
while (attributes.hasNext()) {
Attribute at = (Attribute) attributes.next();
if (namespaceAware) {
element.setAttributeNS(at.getName().getNamespaceURI(), qName(at.getName()), at.getValue());
} else {
element.setAttribute(at.getName().getLocalPart(), at.getValue());
}
}
node = node.appendChild(element);
break;
case XMLStreamConstants.SPACE:
case XMLStreamConstants.ENTITY_DECLARATION:
case XMLStreamConstants.NOTATION_DECLARATION:
case XMLStreamConstants.START_DOCUMENT:
case XMLStreamConstants.END_DOCUMENT:
case XMLStreamConstants.DTD:
break;
default:
throw new XMLStreamException("Unexpected event type " + event.getEventType() + "; " + event);
}
}
use of javax.xml.stream.events.ProcessingInstruction in project wso2-synapse by wso2.
the class SimpleXMLEventAllocatorTest method testProcessingInstruction.
@Test
public void testProcessingInstruction() throws XMLStreamException {
XMLStreamReader reader = createXmlStreamReader("<? joe ?>");
ProcessingInstruction processingInstruction = (ProcessingInstruction) eventAllocator.allocate(reader);
verify(processingInstruction, XMLStreamConstants.PROCESSING_INSTRUCTION, "<?joe?>");
Assert.assertEquals("joe", processingInstruction.getTarget());
Assert.assertNull(processingInstruction.getData());
reader = createXmlStreamReader("<?joe jim?>");
processingInstruction = (ProcessingInstruction) eventAllocator.allocate(reader);
Assert.assertEquals("joe", processingInstruction.getTarget());
Assert.assertEquals("jim", processingInstruction.getData());
}
use of javax.xml.stream.events.ProcessingInstruction in project wso2-synapse by wso2.
the class SimpleXMLEventWriter method add.
@Override
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);
}
}
Aggregations