X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2FContact.java;h=779b60a3c596ee6ee9bcbc20b09bcf66e3d4edfd;hb=26d254a3ac6cddbd3583cbbcbf8d43aa15c6a32e;hp=4c6d5d443b9075d42823af98660df19c904c88d9;hpb=e253bd50bb05519f4a16fed4fb95d5b3340128ea;p=jvcard.git
diff --git a/src/be/nikiroo/jvcard/Contact.java b/src/be/nikiroo/jvcard/Contact.java
index 4c6d5d4..779b60a 100644
--- a/src/be/nikiroo/jvcard/Contact.java
+++ b/src/be/nikiroo/jvcard/Contact.java
@@ -11,7 +11,7 @@ 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.
@@ -47,13 +47,9 @@ public class Contact extends BaseClass {
for (Data data : getData(name)) {
if (first == null)
first = data;
- for (int index = 0; index < data.size(); index++) {
- TypeInfo type = data.get(index);
- if (type.getName().equals("TYPE")
- && type.getValue().equals("pref")) {
- return data;
- }
- }
+
+ if (data.isPreferred())
+ return data;
}
return first;
@@ -103,13 +99,21 @@ public class Contact extends BaseClass {
*/
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();
}
/**
* Return a {@link String} representation of this contact formated
* accordingly to the given format.
*
+ *
* The format is basically a list of field names separated by a pipe and
* optionally parametrised. The parameters allows you to:
*
@@ -117,31 +121,48 @@ public class Contact extends BaseClass {
*
+ *
+ * You can also add a fixed text if it starts with a simple-quote ('). + *
+ * + *+ * Example: "'Contact: |N@10|FN@20|NICK@+|PHOTO@x" + *
* * @param format * the format to use + * @param separator + * the separator {@link String} to use between fields * * @return the {@link String} representation */ - public String toString(String format) { - return toString(format, "|", null, -1, true, false); + public String toString(String format, String separator) { + return toString(format, separator, null, -1, true, false); } /** * Return a {@link String} representation of this contact formated * accordingly to the given format. * + ** The format is basically a list of field names separated by a pipe and * optionally parametrised. The parameters allows you to: *
+ * You can also add a fixed text if it starts with a simple-quote ('). + *
* - * Example: "N@10|FN@20|NICK@+|PHOTO@x" + *+ * Example: "'Contact: |N@10|FN@20|NICK@+|PHOTO@x" + *
* * @param format * the format to use @@ -173,6 +194,7 @@ public class Contact extends BaseClass { * Return a {@link String} representation of this contact formated * accordingly to the given format, part by part. * + ** The format is basically a list of field names separated by a pipe and * optionally parametrised. The parameters allows you to: *
+ * You can also add a fixed text if it starts with a simple-quote ('). + *
+ * + *+ * Example: "'Contact: |N@10|FN@20|NICK@+|PHOTO@x" + *
* * @param format * the format to use @@ -233,6 +262,7 @@ public class Contact extends BaseClass { * Return a {@link String} representation of this contact formated * accordingly to the given format, part by part. * + ** The format is basically a list of field names separated by a pipe and * optionally parametrised. The parameters allows you to: *
+ * You can also add a fixed text if it starts with a simple-quote ('). + *
* - * Example: "N@10|FN@20|NICK@+|PHOTO@x" + *+ * Example: "'Contact: |N@10|FN@20|NICK@+|PHOTO@x" + *
* * @param format * the format to use @@ -277,7 +314,8 @@ public class Contact extends BaseClass { boolean binary = false; boolean expand = false; - if (field.contains("@")) { + if (field.length() > 0 && field.charAt(0) != '\'' + && field.contains("@")) { String[] opts = field.split("@"); if (opts.length > 0) field = opts[0]; @@ -297,7 +335,13 @@ public class Contact extends BaseClass { } } - String value = getPreferredDataValue(field); + String value = null; + if (field.length() > 0 && field.charAt(0) == '\'') { + value = field.substring(1); + } else { + value = getPreferredDataValue(field); + } + if (value == null) { value = ""; } else { @@ -411,7 +455,7 @@ public class Contact extends BaseClass { @Override public String getState() { - return "" + getPreferredDataValue("UID"); + return getId(); } /**