X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2FContact.java;h=4c6d5d443b9075d42823af98660df19c904c88d9;hp=948fd8447965a87d06663db2b4513d6bea022d92;hb=e253bd50bb05519f4a16fed4fb95d5b3340128ea;hpb=7f82bf682ab5747b2d4ccdccae9ea3fcdb013cee diff --git a/src/be/nikiroo/jvcard/Contact.java b/src/be/nikiroo/jvcard/Contact.java index 948fd84..4c6d5d4 100644 --- a/src/be/nikiroo/jvcard/Contact.java +++ b/src/be/nikiroo/jvcard/Contact.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.UUID; import be.nikiroo.jvcard.parsers.Format; import be.nikiroo.jvcard.parsers.Parser; @@ -403,6 +404,16 @@ public class Contact extends BaseClass { this.nextBKey = vc.nextBKey; } + @Override + public String getId() { + return "" + getPreferredDataValue("UID"); + } + + @Override + public String getState() { + return "" + getPreferredDataValue("UID"); + } + /** * Return a {@link String} representation of this contact, in vCard 2.1, * without BKeys. @@ -455,12 +466,15 @@ public class Contact extends BaseClass { boolean fn = false; boolean n = false; + boolean uid = false; if (content != null) { for (Data data : content) { if (data.getName().equals("N")) { n = true; } else if (data.getName().equals("FN")) { fn = true; + } else if (data.getName().equals("UID")) { + uid = true; } if (!data.getName().equals("VERSION")) { @@ -470,12 +484,12 @@ public class Contact extends BaseClass { } // required fields: - if (!n) { + if (!n) // required since vCard 3.0, supported in 2.1 datas.add(new Data(null, "N", "", null)); - } - if (!fn) { + if (!fn) // not required anymore but still supported in 4.0 datas.add(new Data(null, "FN", "", null)); - } + if (!uid) // supported by vCard, required by this program + datas.add(new Data(null, "UID", UUID.randomUUID().toString(), null)); return datas; }