/** * Method called after a structured collection output has completed */ public void finishWrappedValue(QName wrapperName, QName wrappedName) throws IOException { // First: wrapper to close? if (wrapperName != null) { try { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeEndElement(_xmlWriter, _outputContext.getEntryCount()); } else { _xmlWriter.writeEndElement(); } } catch (XMLStreamException e) { StaxUtil.throwAsGenerationException(e, this); } } }
@Override public void writeNull() throws IOException { _verifyValueWrite("write null value"); if (_nextName == null) { handleMissingName(); } // !!! TODO: proper use of 'xsd:isNil' ? try { if (_nextIsAttribute) { /* With attributes, best just leave it out, right? (since there's no way * to use 'xsi:nil') */ } else if (checkNextIsUnwrapped()) { // as with above, best left unwritten? } else { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeLeafNullElement(_xmlWriter, _nextName.getNamespaceURI(), _nextName.getLocalPart()); } else { _xmlWriter.writeEmptyElement(_nextName.getNamespaceURI(), _nextName.getLocalPart()); } } } catch (XMLStreamException e) { StaxUtil.throwAsGenerationException(e, this); } }
public final void _handleEndObject() throws IOException { // We may want to repeat same element, so: if (_elementNameStack.isEmpty()) { throw new JsonGenerationException("Can not write END_ELEMENT without open START_ELEMENT", this); } _nextName = _elementNameStack.removeLast(); try { // note: since attributes don't nest, can only have one attribute active, so: _nextIsAttribute = false; _xmlWriter.writeEndElement(); // [databind-xml#172]: possibly also need indentation if (_elementNameStack.isEmpty() && (_xmlPrettyPrinter != null)) { // ... but only if it is likely to succeed: if (!_stax2Emulation) { _xmlPrettyPrinter.writePrologLinefeed(_xmlWriter); } } } catch (XMLStreamException e) { StaxUtil.throwAsGenerationException(e, this); } }
@Override public void writeNumber(int i) throws IOException { _verifyValueWrite("write number"); if (_nextName == null) { handleMissingName(); } try { if (_nextIsAttribute) { _xmlWriter.writeIntAttribute(null, _nextName.getNamespaceURI(), _nextName.getLocalPart(), i); } else if (checkNextIsUnwrapped()) { // should we consider pretty-printing or not? _xmlWriter.writeInt(i); } else { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeLeafElement(_xmlWriter, _nextName.getNamespaceURI(), _nextName.getLocalPart(), i); } else { _xmlWriter.writeStartElement(_nextName.getNamespaceURI(), _nextName.getLocalPart()); _xmlWriter.writeInt(i); _xmlWriter.writeEndElement(); } } } catch (XMLStreamException e) { StaxUtil.throwAsGenerationException(e, this); } }
/** * Methdod called when a structured (collection, array, map) is being * output. * * @param wrapperName Element used as wrapper around elements, if any (null if none) * @param wrappedName Element used around individual content items (can not * be null) */ public void startWrappedValue(QName wrapperName, QName wrappedName) throws IOException { if (wrapperName != null) { try { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeStartElement(_xmlWriter, wrapperName.getNamespaceURI(), wrapperName.getLocalPart()); } else { _xmlWriter.writeStartElement(wrapperName.getNamespaceURI(), wrapperName.getLocalPart()); } } catch (XMLStreamException e) { StaxUtil.throwAsGenerationException(e, this); } } this.setNextName(wrappedName); }
@Override public final void writeStartArray() throws IOException { _verifyValueWrite("start an array"); _outputContext = _outputContext.createChildArrayContext(); if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeStartArray(this); } else { // nothing to do here; no-operation } }
@Override public final void writeStartObject() throws IOException { _verifyValueWrite("start an object"); _outputContext = _outputContext.createChildObjectContext(); if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeStartObject(this); } else { _handleStartObject(); } }
@Override public final void writeEndArray() throws IOException { if (!_outputContext.inArray()) { _reportError("Current context not Array but "+_outputContext.typeDesc()); } if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeEndArray(this, _outputContext.getEntryCount()); } else { // nothing to do here; no-operation } _outputContext = _outputContext.getParent(); }
@Override public final void writeEndObject() throws IOException { if (!_outputContext.inObject()) { _reportError("Current context not Object but "+_outputContext.typeDesc()); } _outputContext = _outputContext.getParent(); if (_xmlPrettyPrinter != null) { // as per [Issue#45], need to suppress indentation if only attributes written: int count = _nextIsAttribute ? 0 : _outputContext.getEntryCount(); _xmlPrettyPrinter.writeEndObject(this, count); } else { _handleEndObject(); } }
@Override public void writeNumber(float f) throws IOException { _verifyValueWrite("write number"); if (_nextName == null) { handleMissingName(); } try { if (_nextIsAttribute) { _xmlWriter.writeFloatAttribute(null, _nextName.getNamespaceURI(), _nextName.getLocalPart(), f); } else if (checkNextIsUnwrapped()) { _xmlWriter.writeFloat(f); } else { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeLeafElement(_xmlWriter, _nextName.getNamespaceURI(), _nextName.getLocalPart(), f); } else { _xmlWriter.writeStartElement(_nextName.getNamespaceURI(), _nextName.getLocalPart()); _xmlWriter.writeFloat(f); _xmlWriter.writeEndElement(); } } } catch (XMLStreamException e) { StaxUtil.throwAsGenerationException(e, this); } }
/** * Methdod called when a structured (collection, array, map) is being * output. * * @param wrapperName Element used as wrapper around elements, if any (null if none) * @param wrappedName Element used around individual content items (can not * be null) */ public void startWrappedValue(QName wrapperName, QName wrappedName) throws IOException { if (wrapperName != null) { try { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeStartElement(_xmlWriter, wrapperName.getNamespaceURI(), wrapperName.getLocalPart()); } else { _xmlWriter.writeStartElement(wrapperName.getNamespaceURI(), wrapperName.getLocalPart()); } } catch (XMLStreamException e) { StaxUtil.throwXmlAsIOException(e); } } this.setNextName(wrappedName); }
@Override public void writeNumber(long l) throws IOException { _verifyValueWrite("write number"); if (_nextName == null) { handleMissingName(); } try { if (_nextIsAttribute) { _xmlWriter.writeLongAttribute(null, _nextName.getNamespaceURI(), _nextName.getLocalPart(), l); } else if (checkNextIsUnwrapped()) { _xmlWriter.writeLong(l); } else { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeLeafElement(_xmlWriter, _nextName.getNamespaceURI(), _nextName.getLocalPart(), l); } else { _xmlWriter.writeStartElement(_nextName.getNamespaceURI(), _nextName.getLocalPart()); _xmlWriter.writeLong(l); _xmlWriter.writeEndElement(); } } } catch (XMLStreamException e) { StaxUtil.throwXmlAsIOException(e); } }
public final void _handleEndObject() throws IOException { // We may want to repeat same element, so: if (_elementNameStack.isEmpty()) { throw new JsonGenerationException("Can not write END_ELEMENT without open START_ELEMENT", this); } _nextName = _elementNameStack.removeLast(); try { // note: since attributes don't nest, can only have one attribute active, so: _nextIsAttribute = false; _xmlWriter.writeEndElement(); // [databind-xml#172]: possibly also need indentation if (_elementNameStack.isEmpty() && (_xmlPrettyPrinter != null)) { // ... but only if it is likely to succeed: if (!_stax2Emulation) { _xmlPrettyPrinter.writePrologLinefeed(_xmlWriter); } } } catch (XMLStreamException e) { StaxUtil.throwXmlAsIOException(e); } }
/** * Method called after a structured collection output has completed */ public void finishWrappedValue(QName wrapperName, QName wrappedName) throws IOException { // First: wrapper to close? if (wrapperName != null) { try { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeEndElement(_xmlWriter, _writeContext.getEntryCount()); } else { _xmlWriter.writeEndElement(); } } catch (XMLStreamException e) { StaxUtil.throwXmlAsIOException(e); } } }
@Override public void writeNull() throws IOException { _verifyValueWrite("write null value"); if (_nextName == null) { handleMissingName(); } // !!! TODO: proper use of 'xsd:isNil' ? try { if (_nextIsAttribute) { /* With attributes, best just leave it out, right? (since there's no way * to use 'xsi:nil') */ } else if (checkNextIsUnwrapped()) { // as with above, best left unwritten? } else { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeLeafNullElement(_xmlWriter, _nextName.getNamespaceURI(), _nextName.getLocalPart()); } else { _xmlWriter.writeEmptyElement(_nextName.getNamespaceURI(), _nextName.getLocalPart()); } } } catch (XMLStreamException e) { StaxUtil.throwXmlAsIOException(e); } }
@Override public void writeNumber(float f) throws IOException { _verifyValueWrite("write number"); if (_nextName == null) { handleMissingName(); } try { if (_nextIsAttribute) { _xmlWriter.writeFloatAttribute(null, _nextName.getNamespaceURI(), _nextName.getLocalPart(), f); } else if (checkNextIsUnwrapped()) { _xmlWriter.writeFloat(f); } else { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeLeafElement(_xmlWriter, _nextName.getNamespaceURI(), _nextName.getLocalPart(), f); } else { _xmlWriter.writeStartElement(_nextName.getNamespaceURI(), _nextName.getLocalPart()); _xmlWriter.writeFloat(f); _xmlWriter.writeEndElement(); } } } catch (XMLStreamException e) { StaxUtil.throwXmlAsIOException(e); } }
/** * Method called before writing any other output, to optionally * output XML declaration. */ public void initGenerator() throws IOException { if (_initialized) { return; } _initialized = true; try { if (Feature.WRITE_XML_1_1.enabledIn(_formatFeatures)) { _xmlWriter.writeStartDocument("UTF-8", "1.1"); } else if (Feature.WRITE_XML_DECLARATION.enabledIn(_formatFeatures)) { _xmlWriter.writeStartDocument("UTF-8", "1.0"); } else { return; } // as per [dataformat-xml#172], try adding indentation if (_xmlPrettyPrinter != null) { // ... but only if it is likely to succeed: if (!_stax2Emulation) { _xmlPrettyPrinter.writePrologLinefeed(_xmlWriter); } } } catch (XMLStreamException e) { StaxUtil.throwAsGenerationException(e, this); } }
@Override public void writeBoolean(boolean value) throws IOException { _verifyValueWrite("write boolean value"); if (_nextName == null) { handleMissingName(); } try { if (_nextIsAttribute) { _xmlWriter.writeBooleanAttribute(null, _nextName.getNamespaceURI(), _nextName.getLocalPart(), value); } else if (checkNextIsUnwrapped()) { // should we consider pretty-printing or not? _xmlWriter.writeBoolean(value); } else { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeLeafElement(_xmlWriter, _nextName.getNamespaceURI(), _nextName.getLocalPart(), value); } else { _xmlWriter.writeStartElement(_nextName.getNamespaceURI(), _nextName.getLocalPart()); _xmlWriter.writeBoolean(value); _xmlWriter.writeEndElement(); } } } catch (XMLStreamException e) { StaxUtil.throwAsGenerationException(e, this); } }
/** * Method called before writing any other output, to optionally * output XML declaration. */ public void initGenerator() throws IOException { if (_initialized) { return; } _initialized = true; try { if (Feature.WRITE_XML_1_1.enabledIn(_formatFeatures)) { _xmlWriter.writeStartDocument("UTF-8", "1.1"); } else if (Feature.WRITE_XML_DECLARATION.enabledIn(_formatFeatures)) { _xmlWriter.writeStartDocument("UTF-8", "1.0"); } else { return; } // as per [dataformat-xml#172], try adding indentation if (_xmlPrettyPrinter != null) { // ... but only if it is likely to succeed: if (!_stax2Emulation) { _xmlPrettyPrinter.writePrologLinefeed(_xmlWriter); } } } catch (XMLStreamException e) { StaxUtil.throwXmlAsIOException(e); } }
@Override public void writeNumber(long l) throws IOException { _verifyValueWrite("write number"); if (_nextName == null) { handleMissingName(); } try { if (_nextIsAttribute) { _xmlWriter.writeLongAttribute(null, _nextName.getNamespaceURI(), _nextName.getLocalPart(), l); } else if (checkNextIsUnwrapped()) { _xmlWriter.writeLong(l); } else { if (_xmlPrettyPrinter != null) { _xmlPrettyPrinter.writeLeafElement(_xmlWriter, _nextName.getNamespaceURI(), _nextName.getLocalPart(), l); } else { _xmlWriter.writeStartElement(_nextName.getNamespaceURI(), _nextName.getLocalPart()); _xmlWriter.writeLong(l); _xmlWriter.writeEndElement(); } } } catch (XMLStreamException e) { StaxUtil.throwAsGenerationException(e, this); } }