344ae705401652905fe49563fa5fac4110be9f41
1 package be
.nikiroo
.jvcard
.parsers
;
3 import java
.util
.Arrays
;
4 import java
.util
.LinkedList
;
7 import be
.nikiroo
.jvcard
.Card
;
8 import be
.nikiroo
.jvcard
.Contact
;
9 import be
.nikiroo
.jvcard
.Data
;
11 public class AbookParser
{
12 public static List
<Contact
> parse(List
<String
> lines
) {
13 List
<Contact
> contacts
= new LinkedList
<Contact
>();
15 for (String line
: lines
) {
16 List
<Data
> content
= new LinkedList
<Data
>();
18 String tab
[] = line
.split("\t");
21 content
.add(new Data(null, "NICKNAME", tab
[0].trim(), null));
23 content
.add(new Data(null, "FN", tab
[1].trim(), null));
25 content
.add(new Data(null, "EMAIL", tab
[2].trim(), null));
27 content
.add(new Data(null, "X-FCC", tab
[3].trim(), null));
29 content
.add(new Data(null, "NOTE", tab
[4].trim(), null));
31 contacts
.add(new Contact(content
));
38 * Return a {@link String} representation of the given {@link Card}, line by
42 * Note that the BKey is actually not used in Pine mode.
49 * the starting BKey number (all the other will follow) or -1 for
52 * @return the {@link String} representation
54 public static List
<String
> toStrings(Contact contact
, int startingBKey
) {
55 // BKey is not used in pine mode
57 StringBuilder builder
= new StringBuilder();
59 String nick
= contact
.getPreferredDataValue("NICKNAME");
61 nick
= nick
.replaceAll(" ", "_");
62 nick
= nick
.replaceAll(",", "-");
63 nick
= nick
.replaceAll("@", "(a)");
64 nick
= nick
.replaceAll("\"", "'");
65 nick
= nick
.replaceAll(";", ".");
66 nick
= nick
.replaceAll(":", "=");
67 nick
= nick
.replaceAll("[()\\[\\]<>\\\\]", "/");
74 String fn
= contact
.getPreferredDataValue("FN");
80 String email
= contact
.getPreferredDataValue("EMAIL");
82 builder
.append(email
);
84 // optional fields follow:
86 String xfcc
= contact
.getPreferredDataValue("X-FCC");
92 String notes
= contact
.getPreferredDataValue("NOTE");
98 builder
.append(notes
);
101 // note: save as pine means normal LN, nor CRLN
102 builder
.append('\n');
104 return Arrays
.asList(new String
[] { builder
.toString() });
108 * Return a {@link String} representation of the given {@link Card}, line by
112 * the card to convert
114 * @return the {@link String} representation
116 public static List
<String
> toStrings(Card card
) {
117 List
<String
> lines
= new LinkedList
<String
>();
119 for (int index
= 0; index
< card
.size(); index
++) {
120 lines
.addAll(toStrings(card
.get(index
), -1));