/** * Write the contents of the buffer to an XMLStreamWriter. * * <p> * The XMLStreamBuffer will be written out to the XMLStreamWriter using * an instance of {@link StreamWriterBufferProcessor}. * * @param writer * A XMLStreamWriter to write to. * @param writeAsFragment * If true, {@link XMLStreamWriter} will not receive {@link XMLStreamWriter#writeStartDocument()} * nor {@link XMLStreamWriter#writeEndDocument()}. This is desirable behavior when * you are writing the contents of a buffer into a bigger document. */ public final void writeToXMLStreamWriter(XMLStreamWriter writer, boolean writeAsFragment) throws XMLStreamException { StreamWriterBufferProcessor p = new StreamWriterBufferProcessor(this,writeAsFragment); p.process(writer); }
private void writeAttributes(int item, XMLStreamWriter writer) throws XMLStreamException { do { switch(getAIIState(item)) { case STATE_ATTRIBUTE_U_LN_QN: { final String uri = readStructureString(); final String localName = readStructureString(); final String prefix = getPrefixFromQName(readStructureString()); writer.writeAttribute(prefix,uri,localName,readContentString()); break; } case STATE_ATTRIBUTE_P_U_LN: writer.writeAttribute(readStructureString(), readStructureString(), readStructureString(), readContentString()); break; case STATE_ATTRIBUTE_U_LN: writer.writeAttribute(readStructureString(), readStructureString(), readContentString()); break; case STATE_ATTRIBUTE_LN: writer.writeAttribute(readStructureString(), readContentString()); break; } // Ignore the attribute type readStructureString(); readStructure(); item = peekStructure(); } while((item & TYPE_MASK) == T_ATTRIBUTE); } }
private void writeAttributes(XMLStreamWriter writer, boolean inscope) throws XMLStreamException { // prefixSet to collect prefixes that are written before writing inscope namespaces Set<String> prefixSet = inscope ? new HashSet<String>() : Collections.<String>emptySet(); int item = peekStructure(); if ((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE) { // Skip the namespace declarations on the element // they will have been added already item = writeNamespaceAttributes(item, writer, inscope, prefixSet); } if (inscope) { writeInscopeNamespaces(writer, prefixSet); } if ((item & TYPE_MASK) == T_ATTRIBUTE) { writeAttributes(item, writer); } }
int item = getEIIState(peekStructure()); if(item==STATE_DOCUMENT) readStructure(); // skip STATE_DOCUMENT item = readEiiState(); case STATE_ELEMENT_U_LN_QN: { depth ++; final String uri = readStructureString(); final String localName = readStructureString(); final String prefix = getPrefixFromQName(readStructureString()); writer.writeStartElement(prefix,localName,uri); writeAttributes(writer, isInscope(depth)); break; final String prefix = readStructureString(); final String uri = readStructureString(); final String localName = readStructureString(); writer.writeStartElement(prefix,localName,uri); writeAttributes(writer, isInscope(depth)); break; final String uri = readStructureString(); final String localName = readStructureString(); writer.writeStartElement("",localName,uri); writeAttributes(writer, isInscope(depth)); break; final String localName = readStructureString();
int item = getEIIState(peekStructure()); writer.flush(); readStructure(); //skip break; case STATE_ELEMENT_U_LN_QN: case STATE_ELEMENT_U_LN: case STATE_ELEMENT_LN: writeFragment(writer); break; case STATE_COMMENT_AS_CHAR_ARRAY_SMALL: { readStructure(); final int length = readStructure(); final int start = readContentCharactersBuffer(length); final String comment = new String(_contentCharactersBuffer, start, length); writer.writeComment(comment); readStructure(); final int length = readStructure16(); final int start = readContentCharactersBuffer(length); final String comment = new String(_contentCharactersBuffer, start, length); writer.writeComment(comment); readStructure(); final char[] ch = readContentCharactersCopy(); writer.writeComment(new String(ch)); break;
private int writeNamespaceAttributes(int item, XMLStreamWriter writer, boolean collectPrefixes, Set<String> prefixSet) throws XMLStreamException { do { switch(getNIIState(item)){ case STATE_NAMESPACE_ATTRIBUTE: String prefix = readStructureString(); writer.writeNamespace(prefix, ""); if (collectPrefixes) { case STATE_NAMESPACE_ATTRIBUTE_P_U: prefix = readStructureString(); writer.writeNamespace(prefix, readStructureString()); if (collectPrefixes) { prefixSet.add(prefix); case STATE_NAMESPACE_ATTRIBUTE_U: writer.writeDefaultNamespace(readStructureString()); if (collectPrefixes) { prefixSet.add(""); readStructure(); item = peekStructure(); } while((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE);
public final void process(XMLStreamBuffer buffer, XMLStreamWriter writer) throws XMLStreamException { setXMLStreamBuffer(buffer,buffer.isFragment()); process(writer); }
private void writeInscopeNamespaces(XMLStreamWriter writer, Set<String> prefixSet) throws XMLStreamException { for (Map.Entry<String, String> e : _buffer.getInscopeNamespaces().entrySet()) { String key = fixNull(e.getKey()); // If the prefix is already written, do not write the prefix if (!prefixSet.contains(key)) { writer.writeNamespace(key, e.getValue()); } } }
int item = getEIIState(peekStructure()); if(item==STATE_DOCUMENT) readStructure(); // skip STATE_DOCUMENT item = readEiiState(); case STATE_ELEMENT_U_LN_QN: { depth ++; final String uri = readStructureString(); final String localName = readStructureString(); final String prefix = getPrefixFromQName(readStructureString()); writer.writeStartElement(prefix,localName,uri); writeAttributes(writer, isInscope(depth)); break; final String prefix = readStructureString(); final String uri = readStructureString(); final String localName = readStructureString(); writer.writeStartElement(prefix,localName,uri); writeAttributes(writer, isInscope(depth)); break; final String uri = readStructureString(); final String localName = readStructureString(); writer.writeStartElement("",localName,uri); writeAttributes(writer, isInscope(depth)); break; final String localName = readStructureString();