public class XCardWriter extends StreamWriter
Writes xCards (XML-encoded vCards) in a streaming fashion.
Example:
VCard vcard1 = ... VCard vcard2 = ... Path file = Paths.get("vcards.xml"); try (XCardWriter writer = new XCardWriter(file)) { writer.write(vcard1); writer.write(vcard2); }
Modifier and Type | Field and Description |
---|---|
protected Map<String,VCardDataType> |
parameterDataTypes
Defines the names (data types) of the XML elements that are used to hold
each parameter's value.
|
protected VCardVersion |
targetVersion |
addProdId, index, versionStrict
Constructor and Description |
---|
XCardWriter(Node parent) |
XCardWriter(OutputStream out) |
XCardWriter(OutputStream out,
Integer indent) |
XCardWriter(OutputStream out,
Integer indent,
String xmlVersion) |
XCardWriter(OutputStream out,
Map<String,String> outputProperties) |
XCardWriter(Path file) |
XCardWriter(Path file,
Integer indent) |
XCardWriter(Path file,
Integer indent,
String xmlVersion) |
XCardWriter(Path file,
Map<String,String> outputProperties) |
XCardWriter(Writer writer) |
XCardWriter(Writer writer,
Integer indent) |
XCardWriter(Writer writer,
Integer indent,
String xmlVersion) |
XCardWriter(Writer writer,
Map<String,String> outputProperties) |
Modifier and Type | Method and Description |
---|---|
protected void |
_write(VCard vcard,
List<VCardProperty> properties)
Writes a vCard to the stream.
|
void |
close()
Terminates the XML document and closes the output stream.
|
protected VCardVersion |
getTargetVersion()
Gets the version that the next vCard will be written as.
|
void |
registerParameterDataType(String parameterName,
VCardDataType dataType)
Registers the data type of an experimental parameter.
|
protected void |
removeUnsupportedParameters(VCardParameters parameters)
Removes parameters that are not supported by xCard.
|
getScribeIndex, isAddProdId, isVersionStrict, registerScribe, setAddProdId, setScribeIndex, setVersionStrict, write
protected final VCardVersion targetVersion
protected final Map<String,VCardDataType> parameterDataTypes
public XCardWriter(OutputStream out)
out
- the output stream to write to (UTF-8 encoding will be used)public XCardWriter(OutputStream out, Integer indent)
out
- the output stream to write to (UTF-8 encoding will be used)indent
- the number of indent spaces to use for pretty-printing or
null to disable pretty-printing (disabled by default)public XCardWriter(OutputStream out, Integer indent, String xmlVersion)
out
- the output stream to write to (UTF-8 encoding will be used)indent
- the number of indent spaces to use for pretty-printing or
null to disable pretty-printing (disabled by default)xmlVersion
- the XML version to use (defaults to "1.0") (Note: Many
JDKs only support 1.0 natively. For XML 1.1 support, add a JAXP library
like xalan to your project)public XCardWriter(OutputStream out, Map<String,String> outputProperties)
out
- the output stream to write to (UTF-8 encoding will be used)outputProperties
- properties to assign to the JAXP transformer (see
Transformer.setOutputProperty(java.lang.String, java.lang.String)
)public XCardWriter(Path file) throws IOException
file
- the file to write to (UTF-8 encoding will be used)IOException
- if there is a problem opening the filepublic XCardWriter(Path file, Integer indent) throws IOException
file
- the file to write to (UTF-8 encoding will be used)indent
- the number of indent spaces to use for pretty-printing or
null to disable pretty-printing (disabled by default)IOException
- if there is a problem opening the filepublic XCardWriter(Path file, Integer indent, String xmlVersion) throws IOException
file
- the file to write to (UTF-8 encoding will be used)indent
- the number of indent spaces to use for pretty-printing or
null to disable pretty-printing (disabled by default)xmlVersion
- the XML version to use (defaults to "1.0") (Note: Many
JDKs only support 1.0 natively. For XML 1.1 support, add a JAXP library
like xalan to your project)IOException
- if there is a problem opening the filepublic XCardWriter(Path file, Map<String,String> outputProperties) throws IOException
file
- the file to write to (UTF-8 encoding will be used)outputProperties
- properties to assign to the JAXP transformer (see
Transformer.setOutputProperty(java.lang.String, java.lang.String)
)IOException
- if there is a problem opening the filepublic XCardWriter(Writer writer)
writer
- the writer to write topublic XCardWriter(Writer writer, Integer indent)
writer
- the writer to write toindent
- the number of indent spaces to use for pretty-printing or
null to disable pretty-printing (disabled by default)public XCardWriter(Writer writer, Integer indent, String xmlVersion)
writer
- the writer to write toindent
- the number of indent spaces to use for pretty-printing or
null to disable pretty-printing (disabled by default)xmlVersion
- the XML version to use (defaults to "1.0") (Note: Many
JDKs only support 1.0 natively. For XML 1.1 support, add a JAXP library
like xalan to your project)public XCardWriter(Writer writer, Map<String,String> outputProperties)
writer
- the writer to write tooutputProperties
- properties to assign to the JAXP transformer (see
Transformer.setOutputProperty(java.lang.String, java.lang.String)
)public XCardWriter(Node parent)
parent
- the DOM node to add child elements toprotected void _write(VCard vcard, List<VCardProperty> properties) throws IOException
StreamWriter
_write
in class StreamWriter
vcard
- the vCard that is being writtenproperties
- the properties to writeIOException
- if there's a problem writing to the output streampublic void close() throws IOException
IOException
protected VCardVersion getTargetVersion()
StreamWriter
getTargetVersion
in class StreamWriter
protected void removeUnsupportedParameters(VCardParameters parameters)
parameters
- the property parameterspublic void registerParameterDataType(String parameterName, VCardDataType dataType)
parameterName
- the parameter name (e.g. "x-foo")dataType
- the data type or null to removeCopyright © 2012–2023 Michael Angstadt. All rights reserved.