Package org.n52.svalbard.write
Class XmlStreamWriter<S>
- java.lang.Object
-
- org.n52.svalbard.write.XmlStreamWriter<S>
-
- Type Parameters:
S- object to write
- Direct Known Subclasses:
AbstractGetDataAvailabilityStreamWriter,AbstractOmV20XmlStreamWriter,AbstractSwesXmlStreamWriter,AqdGetObservationResponseXmlStreamWriter,EReportingHeaderEncoder,InspireXmlStreamWriter,RdfStreamWriter,RelatedOfferingXmlStreamWriter,Soap12XmlStreamWriter,Wsdlv11XmlStreamWriter
public abstract class XmlStreamWriter<S> extends Object
Abstract XML stream writer.
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringXML_FRAGMENT
-
Constructor Summary
Constructors Constructor Description XmlStreamWriter(EncodingContext context, OutputStream outputStream, S element)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddXlinkHrefAttr(String value)protected voidaddXlinkTitleAttr(String value)protected voidattr(String name, String value)Write attribute to stream.protected voidattr(String namespace, String localName, String value)Write attribute to stream.protected voidattr(QName name, String value)Write attribute to stream.protected voidchars(String chars)Write characters to stream.protected voidchars(String chars, boolean escape)Write characters to stream.protected voidempty(QName name)Write an empty element to stream.protected voidend()Write the document end to stream.protected voidend(QName name)Write the end element to new line.protected voidendInline(QName name)Write end element to the same line.protected voidfinish()Finish the stream writing, flush and close.protected voidflush()Flush written elements.protected EncodingContextgetContext()Get the encoding context.protected SgetElement()protected Optional<String>getEncodeNamespace()protected <T,S>
Optional<Encoder<T,S>>getEncoder()protected <T,S>
Encoder<T,S>getEncoder(String namespace, Object o)protected <T,S>
Encoder<T,S>getEncoder(EncoderKey key)Get encoder forEncoderKey.protected OutputStreamgetOutputStream()Get the underlying output stream.protected StringgetReplacement(QName qname)Create the replacement fromQName.protected org.apache.xmlbeans.XmlOptionsgetXmlOptions()Get the XML options.protected booleanisAddSchemaLocation()protected voidnamespace(String prefix, String namespace)Write namespace to stream.protected voidrawText(String text)Write raw text to stream an adds current indent before writing the text (and before each subsequent line).protected voidschemaLocation(Set<SchemaLocation> schemaLocations)WriteSchemaLocations as xsi:schemaLocations attribute to stream.protected voidstart()Write document start to stream with or without.protected voidstart(QName name)Write start element to stream.protected voidtime(TimeInstant time)WriteTimeInstantto stream.protected voidtime(TimePosition time)WriteTimePositionas ISO 8601 to stream.protected <T,S>
Optional<Encoder<T,S>>tryGetEncoder(EncoderKey key)Try to get encoder forEncoderKey.abstract voidwrite()Encode and write element to theOutputStream.protected voidwriteXmlObject(org.apache.xmlbeans.XmlObject xmlObject)WriteXmlObjectto stream and replace xml-fragment withQName.protected voidwriteXmlObject(org.apache.xmlbeans.XmlObject xmlObject, QName qname)WriteXmlObjectto stream and replace xml-fragment withQName.
-
-
-
Field Detail
-
XML_FRAGMENT
protected static final String XML_FRAGMENT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XmlStreamWriter
public XmlStreamWriter(EncodingContext context, OutputStream outputStream, S element) throws XMLStreamException
- Throws:
XMLStreamException
-
-
Method Detail
-
getElement
protected S getElement()
-
getXmlOptions
protected org.apache.xmlbeans.XmlOptions getXmlOptions()
Get the XML options.- Returns:
- the xml options
-
getOutputStream
protected OutputStream getOutputStream() throws XMLStreamException
Get the underlying output stream. This will flush this writer.- Returns:
- the output stream
- Throws:
XMLStreamException- if the flush fails
-
getContext
protected EncodingContext getContext()
Get the encoding context.- Returns:
- the context
-
attr
protected void attr(QName name, String value) throws XMLStreamException
Write attribute to stream.- Parameters:
name- Attribute namevalue- Attribute value- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
attr
protected void attr(String name, String value) throws XMLStreamException
Write attribute to stream.- Parameters:
name- Attribute namevalue- Attribute value- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
attr
protected void attr(String namespace, String localName, String value) throws XMLStreamException
Write attribute to stream.- Parameters:
namespace- namespace of the attribute namelocalName- LocalName of the attribute namevalue- Attribute value- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
namespace
protected void namespace(String prefix, String namespace) throws XMLStreamException
Write namespace to stream.- Parameters:
prefix- Namespace prefixnamespace- Namespace URI- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
start
protected void start(QName name) throws XMLStreamException
Write start element to stream.- Parameters:
name- Element name- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
start
protected void start() throws XMLStreamExceptionWrite document start to stream with or without.- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
empty
protected void empty(QName name) throws XMLStreamException
Write an empty element to stream.- Parameters:
name- Element name- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
chars
protected void chars(String chars) throws XMLStreamException
Write characters to stream.- Parameters:
chars- Characters to write- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
chars
protected void chars(String chars, boolean escape) throws XMLStreamException
Write characters to stream.- Parameters:
chars- Characters to writeescape- if the chars should be XML escaped- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
end
protected void end(QName name) throws XMLStreamException
Write the end element to new line.- Parameters:
name- Element name- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
end
protected void end() throws XMLStreamExceptionWrite the document end to stream.- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
endInline
protected void endInline(QName name) throws XMLStreamException
Write end element to the same line.- Parameters:
name- Element name- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
finish
protected void finish() throws XMLStreamExceptionFinish the stream writing, flush and close.- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
flush
protected void flush() throws XMLStreamExceptionFlush written elements.- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
write
public abstract void write() throws XMLStreamException, EncodingExceptionEncode and write element to theOutputStream.- Throws:
XMLStreamException- If an error occurs when writing toOutputStreamEncodingException- If an encoding error occurs
-
rawText
protected void rawText(String text) throws XMLStreamException
Write raw text to stream an adds current indent before writing the text (and before each subsequent line).- Parameters:
text- Text to write to stream- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
getReplacement
protected String getReplacement(QName qname)
Create the replacement fromQName.- Parameters:
qname-QNameto create replacement from- Returns:
- Created replacement
-
writeXmlObject
protected void writeXmlObject(org.apache.xmlbeans.XmlObject xmlObject, QName qname) throws XMLStreamExceptionWriteXmlObjectto stream and replace xml-fragment withQName.- Parameters:
xmlObject-XmlObjectto writeqname- Replacement for xml-fragment- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
writeXmlObject
protected void writeXmlObject(org.apache.xmlbeans.XmlObject xmlObject) throws XMLStreamExceptionWriteXmlObjectto stream and replace xml-fragment withQName.- Parameters:
xmlObject-XmlObjectto write- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
schemaLocation
protected void schemaLocation(Set<SchemaLocation> schemaLocations) throws XMLStreamException
WriteSchemaLocations as xsi:schemaLocations attribute to stream.- Parameters:
schemaLocations-SchemaLocations to write- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
time
protected void time(TimeInstant time) throws XMLStreamException
WriteTimeInstantto stream.- Parameters:
time-TimeInstantto write to stream- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
time
protected void time(TimePosition time) throws XMLStreamException
WriteTimePositionas ISO 8601 to stream.- Parameters:
time-TimePositionto write as ISO 8601 to stream- Throws:
XMLStreamException- If an error occurs when writing toOutputStream
-
addXlinkHrefAttr
protected void addXlinkHrefAttr(String value) throws XMLStreamException
- Throws:
XMLStreamException
-
addXlinkTitleAttr
protected void addXlinkTitleAttr(String value) throws XMLStreamException
- Throws:
XMLStreamException
-
tryGetEncoder
protected <T,S> Optional<Encoder<T,S>> tryGetEncoder(EncoderKey key)
Try to get encoder forEncoderKey.- Type Parameters:
T- the resulting type, the "Target"S- the input type, the "Source"- Parameters:
key- Encoder key to get encoder for- Returns:
- Matching encoder
-
getEncoder
protected <T,S> Encoder<T,S> getEncoder(EncoderKey key) throws NoEncoderForKeyException
Get encoder forEncoderKey.- Type Parameters:
T- the resulting type, the "Target"S- the input type, the "Source"- Parameters:
key- Encoder key to get encoder for- Returns:
- Matching encoder
- Throws:
NoEncoderForKeyException- If no matching encoder was found
-
getEncoder
protected <T,S> Encoder<T,S> getEncoder(String namespace, Object o) throws NoEncoderForKeyException
- Throws:
NoEncoderForKeyException
-
isAddSchemaLocation
protected boolean isAddSchemaLocation()
-
-