New launcher class to start all 3 modes:
[jvcard.git] / src / be / nikiroo / jvcard / Contact.java
index 948fd8447965a87d06663db2b4513d6bea022d92..ce701a26a60ad88031881a13b71291b72c1ef627 100644 (file)
@@ -7,10 +7,11 @@ 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;
-import be.nikiroo.jvcard.tui.StringUtils;
+import be.nikiroo.jvcard.resources.StringUtils;
 
 /**
  * A contact is the information that represent a contact person or organisation.
@@ -102,7 +103,14 @@ public class Contact extends BaseClass<Data> {
         */
        public String toString(Format format, int startingBKey) {
                updateBKeys(false);
-               return Parser.toString(this, format, startingBKey);
+
+               StringBuilder builder = new StringBuilder();
+               for (String line : Parser.toStrings(this, format, startingBKey)) {
+                       builder.append(line);
+                       builder.append("\r\n");
+               }
+
+               return builder.toString();
        }
 
        /**
@@ -403,6 +411,16 @@ public class Contact extends BaseClass<Data> {
                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 +473,15 @@ public class Contact extends BaseClass<Data> {
 
                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 +491,12 @@ public class Contact extends BaseClass<Data> {
                }
 
                // 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;
        }