use of org.apache.axiom.om.impl.OMXMLStreamReaderEx in project webservices-axiom by apache.
the class StreamingOMSerializer method serializeNode.
protected void serializeNode(XMLStreamReader reader, XMLStreamWriter writer, boolean startAtNext) throws XMLStreamException {
// TODO We get the StAXWriter at this point and uses it hereafter
// assuming that this is the only entry point to this class.
// If there can be other classes calling methodes of this we might
// need to change methode signatures to OMOutputer
// If not startAtNext, then seed the processing with the current element.
boolean useCurrentEvent = !startAtNext;
while (reader.hasNext() || useCurrentEvent) {
int event = 0;
OMDataSource ds = null;
if (useCurrentEvent) {
event = reader.getEventType();
useCurrentEvent = false;
} else {
event = reader.next();
}
// DataSource
if (reader instanceof OMXMLStreamReaderEx) {
ds = ((OMXMLStreamReaderEx) reader).getDataSource();
}
if (ds != null) {
ds.serialize(writer);
} else {
switch(event) {
case START_ELEMENT:
serializeElement(reader, writer);
depth++;
break;
case ATTRIBUTE:
serializeAttributes(reader, writer);
break;
case CHARACTERS:
if (dataHandlerReader != null && dataHandlerReader.isBinary()) {
serializeDataHandler();
break;
}
// Fall through
case SPACE:
serializeText(reader, writer);
break;
case COMMENT:
serializeComment(reader, writer);
break;
case CDATA:
serializeCData(reader, writer);
break;
case PROCESSING_INSTRUCTION:
serializeProcessingInstruction(reader, writer);
break;
case END_ELEMENT:
serializeEndElement(writer);
depth--;
break;
case START_DOCUMENT:
//if a start document is found then increment the depth
depth++;
break;
case END_DOCUMENT:
//for the end document - reduce the depth
if (depth != 0)
depth--;
try {
serializeEndElement(writer);
} catch (Exception e) {
//TODO: log exceptions
}
break;
case DTD:
serializeDTD(reader, writer);
break;
case ENTITY_REFERENCE:
writer.writeEntityRef(reader.getLocalName());
}
}
if (depth == 0) {
break;
}
}
}
Aggregations