1 package be
.nikiroo
.jvcard
;
3 import java
.io
.BufferedReader
;
4 import java
.io
.BufferedWriter
;
6 import java
.io
.FileReader
;
7 import java
.io
.FileWriter
;
8 import java
.io
.IOException
;
9 import java
.util
.Arrays
;
10 import java
.util
.LinkedList
;
11 import java
.util
.List
;
13 import be
.nikiroo
.jvcard
.parsers
.Format
;
14 import be
.nikiroo
.jvcard
.parsers
.Parser
;
17 * A card is a contact information card. It contains data about one or more
24 private List
<Contact
> contacts
;
26 private boolean dirty
;
29 public Card(File file
, Format format
) throws IOException
{
33 name
= file
.getName();
36 BufferedReader buffer
= new BufferedReader(new FileReader(file
));
37 List
<String
> lines
= new LinkedList
<String
>();
38 for (String line
= buffer
.readLine(); line
!= null; line
= buffer
44 dirty
= false; // initial load, so no change yet
47 public List
<Contact
> getContacts() {
51 public boolean saveAs(File file
, Format format
) throws IOException
{
55 BufferedWriter writer
= new BufferedWriter(new FileWriter(file
));
56 writer
.append(toString(format
));
59 if (file
.equals(this.file
)) {
66 public boolean save(Format format
, boolean bKeys
) throws IOException
{
67 return saveAs(file
, format
);
70 public String
toString(Format format
) {
71 return Parser
.toString(this, format
);
74 public String
toString() {
75 return toString(Format
.VCard21
);
78 protected void load(String serializedContent
, Format format
) {
79 // note: fixed size array
80 List
<String
> lines
= Arrays
.asList(serializedContent
.split("\n"));
84 protected void load(List
<String
> lines
, Format format
) {
85 this.contacts
= Parser
.parse(lines
, format
);
88 for (Contact contact
: contacts
) {
89 contact
.setParent(this);
93 public boolean isDirty() {
98 * Return the name of this card.
102 public String
getName() {
107 * Notify that this element has unsaved changes.