use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.
the class ChainingXmlWriter method createXCardDocument.
private XCardDocument createXCardDocument() {
XCardDocument document = new XCardDocument();
XCardDocumentStreamWriter writer = document.writer();
writer.setAddProdId(prodId);
writer.setVersionStrict(versionStrict);
for (Map.Entry<String, VCardDataType> entry : parameterDataTypes.entrySet()) {
String parameterName = entry.getKey();
VCardDataType dataType = entry.getValue();
writer.registerParameterDataType(parameterName, dataType);
}
if (index != null) {
writer.setScribeIndex(index);
}
for (VCard vcard : vcards) {
writer.write(vcard);
}
return document;
}
use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.
the class XCardDocumentTest method add_no_existing_vcards_element.
@Test
public void add_no_existing_vcards_element() throws Throwable {
VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
XCardDocument xcard = new XCardDocument("<root><a /></root>");
XCardDocumentStreamWriter writer = xcard.writer();
writer.setAddProdId(false);
writer.write(vcard);
Document actual = xcard.getDocument();
// @formatter:off
String xml = "<root>" + "<a />" + "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "</vcard>" + "</vcards>" + "</root>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
assertXMLEqual(expected, actual);
}
use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.
the class XCardDocumentTest method add_parameters.
@Test
public void add_parameters() throws Throwable {
VCard vcard = new VCard();
Note note = new Note("This is a\nnote.");
note.setParameter(VCardParameters.ALTID, "value");
note.setParameter(VCardParameters.CALSCALE, "value");
note.setParameter(VCardParameters.GEO, "geo:123.456,234.567");
note.setParameter(VCardParameters.LABEL, "value");
note.setParameter(VCardParameters.LANGUAGE, "en");
note.setParameter(VCardParameters.MEDIATYPE, "text/plain");
note.getPids().add(new Pid(1, 1));
note.setParameter(VCardParameters.PREF, "1");
note.setParameter(VCardParameters.SORT_AS, "value");
note.setParameter(VCardParameters.TYPE, "home");
note.setParameter(VCardParameters.TZ, "America/New_York");
note.setParameter("X-CUSTOM", "xxx");
note.setParameter("X-INT", "11");
vcard.addNote(note);
XCardDocument xcard = new XCardDocument();
XCardDocumentStreamWriter writer = xcard.writer();
writer.setAddProdId(false);
writer.registerParameterDataType("X-INT", VCardDataType.INTEGER);
writer.registerParameterDataType("X-CUSTOM", VCardDataType.BOOLEAN);
writer.registerParameterDataType("X-CUSTOM", null);
writer.write(vcard);
Document actual = xcard.getDocument();
// @formatter:off
String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<note>" + "<parameters>" + "<altid><text>value</text></altid>" + "<calscale><text>value</text></calscale>" + "<geo><uri>geo:123.456,234.567</uri></geo>" + "<label><text>value</text></label>" + "<language><language-tag>en</language-tag></language>" + "<mediatype><text>text/plain</text></mediatype>" + "<pid><text>1.1</text></pid>" + "<pref><integer>1</integer></pref>" + "<sort-as><text>value</text></sort-as>" + "<type><text>home</text></type>" + "<tz><uri>America/New_York</uri></tz>" + "<x-custom><unknown>xxx</unknown></x-custom>" + "<x-int><integer>11</integer></x-int>" + "</parameters>" + "<text>This is a\nnote.</text>" + "</note>" + "</vcard>" + "</vcards>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
assertXMLEqual(expected, actual);
}
use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.
the class XCardDocumentTest method add_xml_property.
@Test
public void add_xml_property() throws Throwable {
VCard vcard = new VCard();
Xml xmlProperty = new Xml("<foo xmlns=\"http://example.com\" a=\"b\">bar<car/></foo>");
xmlProperty.addParameter("name", "value");
vcard.addXml(xmlProperty);
XCardDocument xcard = new XCardDocument();
XCardDocumentStreamWriter writer = xcard.writer();
writer.setAddProdId(false);
writer.write(vcard);
Document actual = xcard.getDocument();
// @formatter:off
String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<foo xmlns=\"http://example.com\" a=\"b\">" + "<parameters xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<name><unknown>value</unknown></name>" + "</parameters>" + "bar<car/>" + "</foo>" + "</vcard>" + "</vcards>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
/*
* When using xalan as the JAXP parser, XMLUnit thinks the <name>
* element in the "actual" DOM has the wrong namespace. But when you
* inspect the DOM yourself, the <name> element *does* have the correct
* namespace!
*
* As a workaround, let's compare the string versions of the two DOMs.
*/
assertEquals(XmlUtils.toString(expected), XmlUtils.toString(actual));
// assertXMLEqual(expected, actual);
}
use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.
the class XCardDocumentTest method add_multiple.
@Test
public void add_multiple() throws Throwable {
VCard vcard1 = new VCard();
vcard1.setFormattedName("John Doe");
VCard vcard2 = new VCard();
vcard2.addNote("Hello world!");
XCardDocument xcard = new XCardDocument();
XCardDocumentStreamWriter writer = xcard.writer();
writer.setAddProdId(false);
writer.write(vcard1);
writer.write(vcard2);
Document actual = xcard.getDocument();
// @formatter:off
String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "</vcard>" + "<vcard>" + "<note><text>Hello world!</text></note>" + "</vcard>" + "</vcards>";
Document expected = XmlUtils.toDocument(xml);
// @formatter:on
assertXMLEqual(expected, actual);
}
Aggregations