How to handle CustomLabels?

154 views
Skip to first unread message

dom.j...@googlemail.com

unread,
Apr 25, 2013, 10:15:51 AM4/25/13
to ez-vcard...@googlegroups.com
Hi,

assuming i have a vcard which contains an email address with a custom label.
I parse it with Ezvcard.parse(vCardFile) and access the emails with vcard.getEmails().

e.g.
item1.EMAIL;TYPE=INTERNET:Custo...@adress.com
item1.X-ABLabel:customemail

EmailType.getValue() give me the email adress but how can i access the customlabel?

Thanks in advance,
dom

Michael Angstadt

unread,
Apr 25, 2013, 6:09:05 PM4/25/13
to ez-vcard...@googlegroups.com
Hi dom,

You need to use the "VCard.getExtendedType()" method to retrieve the custom labels.  This method is used to retrieve non-standard and extended properties (e.g. properties that begin with "X-"):

VCard vcard = Ezvcard.parse(vCardFile).first();
List<RawType> customLabels = vcard.getExtendedType("X-ABLabel");
String customLabel = customLabels.get(0).getValue();

If there are multiple emails in the vCard, it looks like you will need more extensive logic in order to match each email address with its corresponding label.  The code below stores each email/label combination inside of a String array.  If the email address doesn't have a custom label, then a null value will be associated with it.

public List<String[]> groupEmailsWithTheirLabels(VCard vcard){
  List<String[]> emailsAndLabels = new ArrayList<String[]>();

  List<EmailType> emails = vcard.getEmails();
  List<RawType> customLabels = vcard.getExtendedType("X-ABLabel");

  for (EmailType email : emails){
    String emailValue = email.getValue();
    String customLabelValue = null;
    String group = email.getGroup();
    if (group != null){
      for (RawType customLabel : customLabels){
        if (group.equals(customLabel.getGroup())){
          customLabelValue = customLabel.getValue();
          break;
        }
      }
    }
    emailsAndLabels.add(new String[]{emailValue, customLabelValue});
  }

  return emailsAndLabels;
}

Regards,
Mike
> --
> You received this message because you are subscribed to the Google Groups "ez-vcard-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ez-vcard-discu...@googlegroups.com.
> To post to this group, send email to ez-vcard...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msg/ez-vcard-discuss/-/3JttpOgEMt0J.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Reply all
Reply to author
Forward
0 new messages