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.
*/
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();
}
/**
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.
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")) {
}
// 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;
}