|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectezvcard.io.xml.XCardDocument
public class XCardDocument
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.parseAll(); //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);
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
void |
add(VCard vcard)
Adds a vCard to the XML document. |
Document |
getDocument()
Gets the XML document that was generated. |
List<List<String>> |
getParseWarnings()
Gets the warnings from the last parse operation. |
ScribeIndex |
getScribeIndex()
Gets the scribe index. |
boolean |
isAddProdId()
Gets whether or not a "PRODID" property will be added to each vCard, saying that the vCard was generated by this library. |
boolean |
isVersionStrict()
Gets whether properties that do not support xCard (vCard version 4.0) will be excluded from the written vCard. |
List<VCard> |
parseAll()
Parses all the VCard objects from the xCard document. |
VCard |
parseFirst()
Parses the first the VCard object from the xCard document. |
void |
registerParameterDataType(String parameterName,
VCardDataType dataType)
Registers the data type of an experimental parameter. |
void |
registerScribe(VCardPropertyScribe<? extends VCardProperty> scribe)
Registers a property scribe. |
void |
setAddProdId(boolean addProdId)
Sets whether or not to add a "PRODID" property to each vCard, saying that the vCard was generated by this library. |
void |
setScribeIndex(ScribeIndex index)
Sets the scribe index. |
void |
setVersionStrict(boolean versionStrict)
Sets whether properties that do not support xCard (vCard version 4.0) will be excluded from the written vCard. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XCardDocument()
public XCardDocument(String xml) throws SAXException
xml
- the XML string to read the vCards from
SAXException
- if there's a problem parsing the XMLpublic XCardDocument(InputStream in) throws SAXException, IOException
in
- the input stream to read the vCards from
IOException
- if there's a problem reading from the input stream
SAXException
- if there's a problem parsing the XMLpublic XCardDocument(File file) throws SAXException, IOException
file
- the file to read the vCards from
IOException
- if there's a problem reading from the file
SAXException
- 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 from
IOException
- if there's a problem reading from the reader
SAXException
- if there's a problem parsing the XMLpublic XCardDocument(Document document)
document
- the XML DOM that contains the xCard documentMethod Detail |
---|
public boolean isAddProdId()
public void setAddProdId(boolean addProdId)
addProdId
- true to add this property, false not to (defaults to
true)public boolean isVersionStrict()
public void setVersionStrict(boolean versionStrict)
versionStrict
- true to exclude properties that do not support
xCard, false to include them anyway (defaults to true)public List<List<String>> getParseWarnings()
VCard
object has its own warnings list)parseAll()
,
parseFirst()
public void registerParameterDataType(String parameterName, VCardDataType dataType)
parameterName
- the parameter name (e.g. "x-foo")dataType
- the data type or null to removepublic void registerScribe(VCardPropertyScribe<? extends VCardProperty> scribe)
Registers a property scribe. This is the same as calling:
getScribeIndex().register(scribe)
scribe
- the scribe to registerpublic ScribeIndex getScribeIndex()
public void setScribeIndex(ScribeIndex index)
index
- the scribe indexpublic Document getDocument()
public List<VCard> parseAll()
VCard
objects from the xCard document.
public VCard parseFirst()
VCard
object from the xCard document.
public String write()
public String write(int indent)
indent
- the number of indent spaces to use for pretty-printing
public void write(OutputStream out) throws TransformerException
out
- the output stream
TransformerException
- 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-printing
TransformerException
- if there's a problem writing to the output
streampublic void write(File file) throws TransformerException, IOException
file
- the file
TransformerException
- if there's a problem writing to the file
IOException
- 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-printing
TransformerException
- if there's a problem writing to the file
IOException
- if there's a problem writing to the filepublic void write(Writer writer) throws TransformerException
writer
- the writer
TransformerException
- 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-printing
TransformerException
- if there's a problem writing to the writerpublic void add(VCard vcard)
vcard
- the vCard to add
IllegalArgumentException
- if a scribe hasn't been registered for a
custom property class (see: registerScribe(ezvcard.io.scribe.VCardPropertyScribe extends ezvcard.property.VCardProperty>)
)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |