X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2FContact.java;h=779b60a3c596ee6ee9bcbc20b09bcf66e3d4edfd;hb=26d254a3ac6cddbd3583cbbcbf8d43aa15c6a32e;hp=08c2a515e563cdfb39aadc7ab84795b1ec1153c6;hpb=e4444b0bc462544629d9e7e7ab62b96a4d9cab10;p=jvcard.git
diff --git a/src/be/nikiroo/jvcard/Contact.java b/src/be/nikiroo/jvcard/Contact.java
index 08c2a51..779b60a 100644
--- a/src/be/nikiroo/jvcard/Contact.java
+++ b/src/be/nikiroo/jvcard/Contact.java
@@ -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;
@@ -117,6 +113,7 @@ public class Contact extends BaseClass {
* 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:
*
@@ -124,31 +121,48 @@ public class Contact extends BaseClass {
*
+ *
+ * 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 + * @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: "'Contact: |N@10|FN@20|NICK@+|PHOTO@x" + *
* * @param format * the format to use @@ -180,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: "N@10|FN@20|NICK@+|PHOTO@x" + *+ * Example: "'Contact: |N@10|FN@20|NICK@+|PHOTO@x" + *
* * @param format * the format to use @@ -240,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 @@ -284,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]; @@ -304,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 {