Search in sources :

Example 1 with Impp

use of ezvcard.property.Impp in project qksms by moezbhatti.

the class ContactOperations method convertIms.

private void convertIms(List<NonEmptyContentValues> contentValues, VCard vcard) {
    // handle extended properties
    for (Map.Entry<String, Integer> entry : DataMappings.getImPropertyNameMappings().entrySet()) {
        String propertyName = entry.getKey();
        Integer protocolType = entry.getValue();
        List<RawProperty> rawProperties = vcard.getExtendedProperties(propertyName);
        for (RawProperty rawProperty : rawProperties) {
            NonEmptyContentValues cv = new NonEmptyContentValues(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
            String value = rawProperty.getValue();
            cv.put(ContactsContract.CommonDataKinds.Im.DATA, value);
            cv.put(ContactsContract.CommonDataKinds.Im.PROTOCOL, protocolType);
            contentValues.add(cv);
        }
    }
    // handle IMPP properties
    for (Impp impp : vcard.getImpps()) {
        NonEmptyContentValues cv = new NonEmptyContentValues(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
        String immpAddress = impp.getHandle();
        cv.put(ContactsContract.CommonDataKinds.Im.DATA, immpAddress);
        int immpProtocolType = DataMappings.getIMTypeFromProtocol(impp.getProtocol());
        cv.put(ContactsContract.CommonDataKinds.Im.PROTOCOL, immpProtocolType);
        contentValues.add(cv);
    }
}
Also used : RawProperty(ezvcard.property.RawProperty) Impp(ezvcard.property.Impp) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Impp

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

the class ImppScribeTest method escape_special_chars.

@Test
public void escape_special_chars() {
    Impp impp = new Impp("special", "öffentlich");
    String expected = "special:%C3%B6ffentlich";
    sensei.assertWriteText(impp).run(expected);
    sensei.assertWriteXml(impp).run("<uri>" + expected + "</uri>");
    sensei.assertWriteJson(impp).run(expected);
}
Also used : Impp(ezvcard.property.Impp) Test(org.junit.Test)

Example 3 with Impp

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

the class ImppScribeTest method writeHtmlLink.

@Test
public void writeHtmlLink() {
    assertWriteHtmlLink(new Impp((String) null), null);
    assertWriteHtmlLink(Impp.aim("theuser"), "aim:goim?screenname=theuser");
    assertWriteHtmlLink(Impp.skype("theuser"), "skype:theuser");
    assertWriteHtmlLink(Impp.icq("123456789"), "icq:message?uin=123456789");
    assertWriteHtmlLink(Impp.msn("theuser"), "msnim:chat?contact=theuser");
    assertWriteHtmlLink(Impp.yahoo("theuser"), "ymsgr:sendim?theuser");
    assertWriteHtmlLink(Impp.irc("theuser"), "irc:theuser");
    assertWriteHtmlLink(Impp.sip("theuser"), "sip:theuser");
    assertWriteHtmlLink(Impp.xmpp("theuser"), "xmpp:theuser?message");
    assertWriteHtmlLink(new Impp("foo", "bar"), "foo:bar");
}
Also used : Impp(ezvcard.property.Impp) Test(org.junit.Test)

Example 4 with Impp

use of ezvcard.property.Impp in project android by nextcloud.

the class ContactOperations method convertIms.

private void convertIms(List<NonEmptyContentValues> contentValues, VCard vcard) {
    // handle extended properties
    for (Map.Entry<String, Integer> entry : DataMappings.getImPropertyNameMappings().entrySet()) {
        String propertyName = entry.getKey();
        Integer protocolType = entry.getValue();
        List<RawProperty> rawProperties = vcard.getExtendedProperties(propertyName);
        for (RawProperty rawProperty : rawProperties) {
            NonEmptyContentValues cv = new NonEmptyContentValues(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
            String value = rawProperty.getValue();
            cv.put(ContactsContract.CommonDataKinds.Im.DATA, value);
            cv.put(ContactsContract.CommonDataKinds.Im.PROTOCOL, protocolType);
            contentValues.add(cv);
        }
    }
    // handle IMPP properties
    for (Impp impp : vcard.getImpps()) {
        NonEmptyContentValues cv = new NonEmptyContentValues(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
        String immpAddress = impp.getHandle();
        cv.put(ContactsContract.CommonDataKinds.Im.DATA, immpAddress);
        int immpProtocolType = DataMappings.getIMTypeFromProtocol(impp.getProtocol());
        cv.put(ContactsContract.CommonDataKinds.Im.PROTOCOL, immpProtocolType);
        contentValues.add(cv);
    }
}
Also used : RawProperty(ezvcard.property.RawProperty) Impp(ezvcard.property.Impp) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with Impp

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

the class HCardParser method visit.

private void visit(Element element) {
    boolean visitChildren = true;
    Set<String> classNames = element.classNames();
    for (String className : classNames) {
        className = className.toLowerCase();
        // give special treatment to certain URLs
        if (urlPropertyName.equals(className)) {
            String href = element.attr("href");
            if (href.length() > 0) {
                if (!classNames.contains(emailName) && href.matches("(?i)mailto:.*")) {
                    className = emailName;
                } else if (!classNames.contains(telName) && href.matches("(?i)tel:.*")) {
                    className = telName;
                } else {
                    // try parsing as IMPP
                    VCardPropertyScribe<? extends VCardProperty> scribe = index.getPropertyScribe(Impp.class);
                    context.getWarnings().clear();
                    context.setPropertyName(scribe.getPropertyName());
                    try {
                        VCardProperty property = scribe.parseHtml(new HCardElement(element), context);
                        vcard.addProperty(property);
                        warnings.addAll(context.getWarnings());
                        continue;
                    } catch (SkipMeException e) {
                    // URL is not an instant messenger URL
                    } catch (CannotParseException e) {
                    // URL is not an instant messenger URL
                    }
                }
            }
        }
        // hCard uses a different name for the CATEGORIES property
        if ("category".equals(className)) {
            className = categoriesName;
        }
        VCardPropertyScribe<? extends VCardProperty> scribe = index.getPropertyScribe(className);
        if (scribe == null) {
            // if no scribe is found, and the class name doesn't start with "x-", then it must be an arbitrary CSS class that has nothing to do with vCard
            if (!className.startsWith("x-")) {
                continue;
            }
            scribe = new RawPropertyScribe(className);
        }
        context.getWarnings().clear();
        context.setPropertyName(scribe.getPropertyName());
        VCardProperty property;
        try {
            property = scribe.parseHtml(new HCardElement(element), context);
            warnings.addAll(context.getWarnings());
            // LABELs must be treated specially so they can be matched up with their ADRs
            if (property instanceof Label) {
                labels.add((Label) property);
                continue;
            }
            // add all NICKNAMEs to the same type object
            if (property instanceof Nickname) {
                Nickname nn = (Nickname) property;
                if (nickname == null) {
                    nickname = nn;
                    vcard.addProperty(nickname);
                } else {
                    nickname.getValues().addAll(nn.getValues());
                }
                continue;
            }
            // add all CATEGORIES to the same type object
            if (property instanceof Categories) {
                Categories c = (Categories) property;
                if (categories == null) {
                    categories = c;
                    vcard.addProperty(categories);
                } else {
                    categories.getValues().addAll(c.getValues());
                }
                continue;
            }
        } catch (SkipMeException e) {
            // @formatter:off
            warnings.add(new ParseWarning.Builder(context).message(22, e.getMessage()).build());
            // @formatter:on
            continue;
        } catch (CannotParseException e) {
            // @formatter:off
            warnings.add(new ParseWarning.Builder(context).message(e).build());
            // @formatter:on
            property = new RawProperty(className, element.outerHtml());
        } catch (EmbeddedVCardException e) {
            if (isChildOf(element, embeddedVCards)) {
                // prevents multiple-nested embedded elements from overwriting each other
                continue;
            }
            property = e.getProperty();
            embeddedVCards.add(element);
            HCardParser embeddedReader = new HCardParser(element, pageUrl);
            try {
                VCard embeddedVCard = embeddedReader.readNext();
                e.injectVCard(embeddedVCard);
            } finally {
                warnings.addAll(embeddedReader.getWarnings());
                IOUtils.closeQuietly(embeddedReader);
            }
            visitChildren = false;
        }
        vcard.addProperty(property);
    }
    if (visitChildren) {
        for (Element child : element.children()) {
            visit(child);
        }
    }
}
Also used : VCardPropertyScribe(ezvcard.io.scribe.VCardPropertyScribe) EmbeddedVCardException(ezvcard.io.EmbeddedVCardException) Categories(ezvcard.property.Categories) Impp(ezvcard.property.Impp) RawPropertyScribe(ezvcard.io.scribe.RawPropertyScribe) Element(org.jsoup.nodes.Element) Label(ezvcard.property.Label) SkipMeException(ezvcard.io.SkipMeException) RawProperty(ezvcard.property.RawProperty) CannotParseException(ezvcard.io.CannotParseException) VCardProperty(ezvcard.property.VCardProperty) VCard(ezvcard.VCard) Nickname(ezvcard.property.Nickname)

Aggregations

Impp (ezvcard.property.Impp)7 Test (org.junit.Test)4 VCard (ezvcard.VCard)3 RawProperty (ezvcard.property.RawProperty)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CannotParseException (ezvcard.io.CannotParseException)1 EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)1 SkipMeException (ezvcard.io.SkipMeException)1 RawPropertyScribe (ezvcard.io.scribe.RawPropertyScribe)1 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)1 Address (ezvcard.property.Address)1 Categories (ezvcard.property.Categories)1 Email (ezvcard.property.Email)1 Label (ezvcard.property.Label)1 Nickname (ezvcard.property.Nickname)1 Note (ezvcard.property.Note)1 Photo (ezvcard.property.Photo)1 Role (ezvcard.property.Role)1 SortString (ezvcard.property.SortString)1