public class XCardDocument extends Object
Represents an XML document that contains vCard objects ("xCard" standard). This class can be used to read and write xCard documents.
Examples:
String xml = "<vcards xmlns=\"urn:ietf:params:xml:ns:vcard-4.0\">" + "<vcard>" + "<fn>" + "<text>John Doe</text>" + "</fn>" + "<n>" + "<surname>Doe</surname>" + "<given>Johnathan</given>" + "<additional>Jonny</additional>" + "<additional>John</additional>" + "<prefix>Mr.</prefix>" + "<suffix />" + "</n>" + "</vcard>" + "</vcards>"; //parsing an existing xCard document XCardDocument xcard = new XCardDocument(xml); List<VCard> vcards = xcard.getVCards(); //creating an empty xCard document XCardDocument xcard = new XCardDocument(); //VCard objects can be added at any time VCard vcard = ... xcard.add(vcard); //retrieving the raw XML DOM Document document = xcard.getDocument(); //call one of the "write()" methods to output the xCard document File file = new File("johndoe.xml"); xcard.write(file);
Modifier and Type | Class and Description |
---|---|
class |
XCardDocument.XCardDocumentStreamWriter |
Constructor and Description |
---|
XCardDocument()
Creates an xCard document.
|
XCardDocument(Document document)
Wraps an existing XML DOM object.
|
XCardDocument(File file)
Parses an xCard document from a file.
|
XCardDocument(InputStream in)
Parses an xCard document from an input stream.
|
XCardDocument(Reader reader)
Parses an xCard document from a reader.
|
XCardDocument(String xml)
Parses an xCard document from a string.
|
Modifier and Type | Method and Description |
---|---|
void |
add(VCard vcard)
Adds a vCard to the XML document.
|
Document |
getDocument()
Gets the XML document that was generated.
|
List<VCard> |
getVCards()
Parses all of the vCards from this XML document.
|
StreamReader |
reader()
Creates a
StreamReader object that reads vCards from this XML
document. |
String |
write()
Writes the XML document to a string without pretty-printing it.
|
void |
write(File file)
Writes the XML document to a file without pretty-printing it.
|
void |
write(File file,
int indent)
Writes the XML document to a file and pretty-prints it.
|
String |
write(int indent)
Writes the XML document to a string and pretty-prints it.
|
void |
write(OutputStream out)
Writes the XML document to an output stream without pretty-printing it.
|
void |
write(OutputStream out,
int indent)
Writes the XML document to an output stream and pretty-prints it.
|
void |
write(Writer writer)
Writes the XML document to a writer without pretty-printing it.
|
void |
write(Writer writer,
int indent)
Writes the XML document to a writer and pretty-prints it.
|
XCardDocument.XCardDocumentStreamWriter |
writer()
Creates a
StreamWriter object that adds vCards to this XML
document. |
public XCardDocument()
public XCardDocument(String xml) throws SAXException
xml
- the XML string to read the vCards fromSAXException
- if there's a problem parsing the XMLpublic XCardDocument(InputStream in) throws SAXException, IOException
in
- the input stream to read the vCards fromIOException
- if there's a problem reading from the input streamSAXException
- if there's a problem parsing the XMLpublic XCardDocument(File file) throws SAXException, IOException
file
- the file to read the vCards fromIOException
- if there's a problem reading from the fileSAXException
- if there's a problem parsing the XMLpublic XCardDocument(Reader reader) throws SAXException, IOException
Parses an xCard document from a reader.
Note that use of this constructor is discouraged. It ignores the
character encoding that is defined within the XML document itself, and
should only be used if the encoding is undefined or if the encoding needs
to be ignored for whatever reason. The
XCardDocument(InputStream)
constructor should be used instead,
since it takes the XML document's character encoding into account when
parsing.
reader
- the reader to read the vCards fromIOException
- if there's a problem reading from the readerSAXException
- if there's a problem parsing the XMLpublic XCardDocument(Document document)
document
- the XML DOM that contains the xCard documentpublic StreamReader reader()
StreamReader
object that reads vCards from this XML
document.public XCardDocument.XCardDocumentStreamWriter writer()
StreamWriter
object that adds vCards to this XML
document.public Document getDocument()
public List<VCard> getVCards()
VCard
objects will NOT be applied to the XML document.public void add(VCard vcard)
vcard
- the vCard to addIllegalArgumentException
- if a scribe hasn't been registered for a
custom property classpublic String write()
public String write(int indent)
indent
- the number of indent spaces to use for pretty-printingpublic void write(OutputStream out) throws TransformerException
out
- the output streamTransformerException
- if there's a problem writing to the output
streampublic void write(OutputStream out, int indent) throws TransformerException
out
- the output streamindent
- the number of indent spaces to use for pretty-printingTransformerException
- if there's a problem writing to the output
streampublic void write(File file) throws TransformerException, IOException
file
- the fileTransformerException
- if there's a problem writing to the fileIOException
- if there's a problem writing to the filepublic void write(File file, int indent) throws TransformerException, IOException
file
- the file streamindent
- the number of indent spaces to use for pretty-printingTransformerException
- if there's a problem writing to the fileIOException
- if there's a problem writing to the filepublic void write(Writer writer) throws TransformerException
writer
- the writerTransformerException
- if there's a problem writing to the writerpublic void write(Writer writer, int indent) throws TransformerException
writer
- the writerindent
- the number of indent spaces to use for pretty-printingTransformerException
- if there's a problem writing to the writerThis software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.