Search in sources :

Example 16 with Address

use of ezvcard.property.Address in project ez-vcard by mangstadt.

the class AddressScribe method _parseHtml.

@Override
protected Address _parseHtml(HCardElement element, ParseContext context) {
    Address property = new Address();
    property.getPoBoxes().addAll(element.allValues("post-office-box"));
    property.getExtendedAddresses().addAll(element.allValues("extended-address"));
    property.getStreetAddresses().addAll(element.allValues("street-address"));
    property.getLocalities().addAll(element.allValues("locality"));
    property.getRegions().addAll(element.allValues("region"));
    property.getPostalCodes().addAll(element.allValues("postal-code"));
    property.getCountries().addAll(element.allValues("country-name"));
    List<String> types = element.types();
    property.getParameters().putAll(VCardParameters.TYPE, types);
    return property;
}
Also used : Address(ezvcard.property.Address)

Example 17 with Address

use of ezvcard.property.Address in project ez-vcard by mangstadt.

the class AddressScribe method parseSemiStructuredValue.

private static Address parseSemiStructuredValue(SemiStructuredValueIterator it) {
    Address property = new Address();
    String next = it.next();
    if (next != null) {
        property.getPoBoxes().add(next);
    }
    next = it.next();
    if (next != null) {
        property.getExtendedAddresses().add(next);
    }
    next = it.next();
    if (next != null) {
        property.getStreetAddresses().add(next);
    }
    next = it.next();
    if (next != null) {
        property.getLocalities().add(next);
    }
    next = it.next();
    if (next != null) {
        property.getRegions().add(next);
    }
    next = it.next();
    if (next != null) {
        property.getPostalCodes().add(next);
    }
    next = it.next();
    if (next != null) {
        property.getCountries().add(next);
    }
    return property;
}
Also used : Address(ezvcard.property.Address)

Example 18 with Address

use of ezvcard.property.Address in project ez-vcard by mangstadt.

the class VCardReaderTest method nested_vcard_with_labels.

@Test
public void nested_vcard_with_labels() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        /*
			 * Test against all versions, even though nested vCards are only
			 * supported by 2.1.
			 */
        // @formatter:off
        String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "ADR;TYPE=home:;;;;;\r\n" + "ADR;TYPE=work:;;;;;\r\n" + "AGENT:\r\n" + "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "LABEL;TYPE=home:home label\r\n" + "AGENT:\r\n" + "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "ADR;TYPE=dom:;;;;;\r\n" + "LABEL;TYPE=dom:dom label\r\n" + "END:VCARD\r\n" + "ADR;TYPE=dom:;;;;;\r\n" + "END:VCARD\r\n" + "LABEL;TYPE=work:work label\r\n" + "END:VCARD\r\n";
        // @formatter:on
        VCardReader reader = new VCardReader(str);
        VCard vcard = reader.readNext();
        assertVersion(version, vcard);
        assertPropertyCount(3, vcard);
        Iterator<Address> adrs = vcard.getAddresses().iterator();
        Address adr = adrs.next();
        assertEquals(Arrays.asList(AddressType.HOME), adr.getTypes());
        assertNull(adr.getLabel());
        adr = adrs.next();
        assertEquals(Arrays.asList(AddressType.WORK), adr.getTypes());
        assertEquals("work label", adr.getLabel());
        {
            VCard agentVCard = vcard.getAgent().getVCard();
            assertVersion(version, agentVCard);
            assertPropertyCount(3, agentVCard);
            adr = agentVCard.getAddresses().get(0);
            assertEquals(Arrays.asList(AddressType.DOM), adr.getTypes());
            assertNull(adr.getLabel());
            Label label = agentVCard.getOrphanedLabels().get(0);
            assertEquals(Arrays.asList(AddressType.HOME), label.getTypes());
            {
                VCard agentAgentVCard = agentVCard.getAgent().getVCard();
                assertVersion(version, agentAgentVCard);
                assertPropertyCount(1, agentAgentVCard);
                adr = agentAgentVCard.getAddresses().get(0);
                assertEquals(Arrays.asList(AddressType.DOM), adr.getTypes());
                assertEquals("dom label", adr.getLabel());
            }
        }
        assertParseWarnings(reader);
        assertNoMoreVCards(reader);
    }
}
Also used : Address(ezvcard.property.Address) Label(ezvcard.property.Label) VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 19 with Address

use of ezvcard.property.Address in project ez-vcard by mangstadt.

the class VCardWriterTest method rfc2426_example.

@Test
public void rfc2426_example() throws Throwable {
    StringWriter sw = new StringWriter();
    VCardWriter writer = new VCardWriter(sw, VCardVersion.V3_0);
    writer.getVObjectWriter().getFoldedLineWriter().setLineLength(null);
    writer.setAddProdId(false);
    {
        VCard vcard = new VCard();
        vcard.setFormattedName("Frank Dawson");
        vcard.setOrganization("Lotus Development Corporation");
        Address adr = new Address();
        adr.setStreetAddress("6544 Battleford Drive");
        adr.setLocality("Raleigh");
        adr.setRegion("NC");
        adr.setPostalCode("27613-3502");
        adr.setCountry("U.S.A.");
        adr.getTypes().add(AddressType.WORK);
        adr.getTypes().add(AddressType.POSTAL);
        adr.getTypes().add(AddressType.PARCEL);
        vcard.addAddress(adr);
        vcard.addTelephoneNumber("+1-919-676-9515", TelephoneType.VOICE, TelephoneType.MSG, TelephoneType.WORK);
        vcard.addTelephoneNumber("+1-919-676-9564", TelephoneType.FAX, TelephoneType.WORK);
        vcard.addEmail("Frank_Dawson@Lotus.com", EmailType.INTERNET, EmailType.PREF);
        vcard.addEmail("fdawson@earthlink.net", EmailType.INTERNET);
        vcard.addUrl("http://home.earthlink.net/�fdawson");
        assertValidate(vcard).versions(VCardVersion.V3_0).prop(null, 0).run();
        writer.write(vcard);
    }
    {
        VCard vcard = new VCard();
        vcard.setFormattedName("Tim Howes");
        vcard.setOrganization("Netscape Communications Corp.");
        Address adr = new Address();
        adr.setStreetAddress("501 E. Middlefield Rd.");
        adr.setLocality("Mountain View");
        adr.setRegion("CA");
        adr.setPostalCode("94043");
        adr.setCountry("U.S.A.");
        adr.getTypes().add(AddressType.WORK);
        vcard.addAddress(adr);
        vcard.addTelephoneNumber("+1-415-937-3419", TelephoneType.VOICE, TelephoneType.MSG, TelephoneType.WORK);
        vcard.addTelephoneNumber("+1-415-528-4164", TelephoneType.FAX, TelephoneType.WORK);
        vcard.addEmail("howes@netscape.com", EmailType.INTERNET);
        assertValidate(vcard).versions(VCardVersion.V3_0).prop(null, 0).run();
        writer.write(vcard);
    }
    writer.close();
    // @formatter:off
    String expected = "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "FN:Frank Dawson\r\n" + "ORG:Lotus Development Corporation\r\n" + "ADR;TYPE=work,postal,parcel:;;6544 Battleford Drive;Raleigh;NC;27613-3502;U.S.A.\r\n" + "TEL;TYPE=voice,msg,work:+1-919-676-9515\r\n" + "TEL;TYPE=fax,work:+1-919-676-9564\r\n" + "EMAIL;TYPE=internet,pref:Frank_Dawson@Lotus.com\r\n" + "EMAIL;TYPE=internet:fdawson@earthlink.net\r\n" + "URL:http://home.earthlink.net/�fdawson\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "FN:Tim Howes\r\n" + "ORG:Netscape Communications Corp.\r\n" + "ADR;TYPE=work:;;501 E. Middlefield Rd.;Mountain View;CA;94043;U.S.A.\r\n" + "TEL;TYPE=voice,msg,work:+1-415-937-3419\r\n" + "TEL;TYPE=fax,work:+1-415-528-4164\r\n" + "EMAIL;TYPE=internet:howes@netscape.com\r\n" + "END:VCARD\r\n";
    // @formatter:on
    String actual = sw.toString();
    assertEquals(expected, actual);
}
Also used : StringWriter(java.io.StringWriter) Address(ezvcard.property.Address) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 20 with Address

use of ezvcard.property.Address in project ez-vcard by mangstadt.

the class StreamWriterTest method labels.

@Test
public void labels() throws Throwable {
    writer.setAddProdId(false);
    // address with label and type
    Address adr = new Address();
    adr.setLabel("value1");
    adr.getTypes().add(AddressType.HOME);
    vcard.addAddress(adr);
    // address with label
    adr = new Address();
    adr.setLabel("value2");
    vcard.addAddress(adr);
    // address
    adr = new Address();
    vcard.addAddress(adr);
    for (VCardVersion version : each(V2_1, V3_0)) {
        writer.write(vcard, version);
        assertEquals(5, writer.count());
        assertEquals(3, writer.count(Address.class));
        assertEquals(2, writer.count(Label.class));
        Label label = writer.get(Label.class).get(0);
        assertEquals("value1", label.getValue());
        assertEquals(Arrays.asList(AddressType.HOME), label.getTypes());
        label = writer.get(Label.class).get(1);
        assertEquals("value2", label.getValue());
        assertEquals(Arrays.asList(), label.getTypes());
    }
    writer.write(vcard, V4_0);
    assertEquals(3, writer.count());
    assertEquals(3, writer.count(Address.class));
}
Also used : Address(ezvcard.property.Address) Label(ezvcard.property.Label) VCardVersion(ezvcard.VCardVersion) Test(org.junit.Test)

Aggregations

Address (ezvcard.property.Address)28 Test (org.junit.Test)14 VCard (ezvcard.VCard)12 StructuredName (ezvcard.property.StructuredName)9 Telephone (ezvcard.property.Telephone)8 Timezone (ezvcard.property.Timezone)6 TelUri (ezvcard.util.TelUri)6 UtcOffset (ezvcard.util.UtcOffset)6 Birthday (ezvcard.property.Birthday)5 Anniversary (ezvcard.property.Anniversary)4 Geo (ezvcard.property.Geo)4 Key (ezvcard.property.Key)4 Label (ezvcard.property.Label)4 VCardVersion (ezvcard.VCardVersion)3 Email (ezvcard.property.Email)3 Photo (ezvcard.property.Photo)3 Sound (ezvcard.property.Sound)3 File (java.io.File)3 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)2 Person (com.google.api.services.people.v1.model.Person)2