Setting type for extended property

20 views
Skip to first unread message

Sachin Gupta

unread,
Feb 18, 2014, 3:38:15 AM2/18/14
to ez-vcard...@googlegroups.com
Hello,

I am trying to set a extended property X-IMPP which can have the following types:
AIM/MSN/Yahoo etc.

IMPP class is defined in vcard but is valid for 3.0 or 4. I however need it for 2.1. Hence using X-IMPP.

Using vcard.addExtendedProperty("X-IMPP", "a...@a.com"); 
i am able to get X-IMPP in vcard, but how do i add the type in this?

I saw the link https://code.google.com/p/ez-vcard/wiki/ExtendedProperties, but it seems that ill have a create a new class to do so.
Is there another way to achieve this or new class or scribe class needs to be created?

Please advise.

Regards

Michael Angstadt

unread,
Feb 18, 2014, 3:24:05 PM2/18/14
to ez-vcard...@googlegroups.com
You could create a scribe class which extends the IMPP scribe class.  Then, override the "getPropertyName" method to return "X-IMPP".  When writing the vCard, you'll also have to disable the "versionStrict" setting, since IMPP is not supported in vCard version 2.1:

public class XImppScribe extends ImppScribe {
  @Override
  public String getPropertyName() {
    return "X-IMPP";
  }

  public static void main(String args[]) throws Throwable {
    VCard vcard = new VCard();
    Impp impp = new Impp("a...@a.com");
    vcard.addImpp(impp);

    StringWriter sw = new StringWriter();
    VCardWriter writer = new VCardWriter(sw, VCardVersion.V2_1);
    writer.registerScribe(new XImppScribe());
    writer.setVersionStrict(false);
    writer.write(vcard);

    System.out.println(sw);
  }
}

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/msgid/ez-vcard-discuss/3c05141d-9682-4dc8-8f0b-0ef998147366%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Sachin Gupta

unread,
Feb 19, 2014, 6:37:53 AM2/19/14
to ez-vcard...@googlegroups.com
Thanks Mike.

It works fine.
However, i am stuck at one issue:
I am using the following method to write the vCard:
Ezvcard.write(vcard).prodId(false).version(VCardVersion.V2_1).go(file);

How do i set the following?
    writer.registerScribe(new XImppScribe());
    writer.setVersionStrict(false);

Regards
Sachin

Sachin Gupta

unread,
Feb 19, 2014, 6:54:04 AM2/19/14
to ez-vcard...@googlegroups.com
I removed the previous lines and using these:
   VCardWriter writer = new VCardWriter(file);
   writer.setTargetVersion(VCardVersion.V2_1);
   writer.registerScribe(new XImppScribe());
   writer.setVersionStrict(false);
   writer.setAddProdId(false);    
   writer.write(vcard);

But even at the end, on validation, i am getting:
[Impp] | W02: Property is not supported in this vCard version.  Supported versions are: [3.0, 4.0]

Am i missing something here?

Regards
Sachin

Sachin Gupta

unread,
Feb 19, 2014, 7:03:03 AM2/19/14
to ez-vcard...@googlegroups.com
Same thing happening for X-ANNIVERSARY also.

Getting the warnings:
[Impp] | W02: Property is not supported in this vCard version.  Supported versions are: [3.0, 4.0]
[Anniversary] | W02: Property is not supported in this vCard version.  Supported versions are: [4.0]

Regards
Sachin

Michael Angstadt

unread,
Feb 19, 2014, 4:47:07 PM2/19/14
to ez-vcard...@googlegroups.com
There are methods for those settings in the Ezvcard class as well:

Ezvcard.write(vcard).prodId(
false).version(VCardVersion.V2_1).versionStrict(true).register(new XImppScribe()).go(file);

-Mike


Michael Angstadt

unread,
Feb 19, 2014, 4:59:40 PM2/19/14
to ez-vcard...@googlegroups.com

On Wed, Feb 19, 2014 at 6:54 AM, Sachin Gupta <chin...@gmail.com> wrote:
But even at the end, on validation, i am getting:
[Impp] | W02: Property is not supported in this vCard version.  Supported versions are: [3.0, 4.0]

That's because the "XImppScribe" class still uses the original "Impp" class, which supports only 3.0 and 4.0.  To get rid of this validation error, you would have to create a "XImppScribe" class that is an exact copy of "ImppScribe".  You'd also have to create a new property class, "XImpp", which would extend "Impp" and override the method that defines the supported vCard versions:

public class XImpp extends Impp {
  public XImpp(String protocol, String handle) {
  super(protocol, handle);
  }

  @Override
  public Set<VCardVersion> _supportedVersions() {
  return EnumSet.of(VCardVersion.V2_1);
  }
}

public class XImppScribe extends VCardPropertyScribe<XImpp> {
  public XImppScribe() {
  super(XImpp.class, "X-IMPP");
  }

  //the rest of the contents of the "ImppScribe" class
}
Reply all
Reply to author
Forward
0 new messages