X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2FCard.java;h=6d833d81f069028b21442aaa6519272a63f41f38;hb=f04a32e97c847d7e2551037a4d5f6a070879215c;hp=de5ab67a604207f0d294f3d9a7652a460c4754a3;hpb=1c03abafc3987d93fa682e7b8758e51bed8a4faf;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/Card.java b/src/be/nikiroo/jvcard/Card.java index de5ab67..6d833d8 100644 --- a/src/be/nikiroo/jvcard/Card.java +++ b/src/be/nikiroo/jvcard/Card.java @@ -15,14 +15,12 @@ import be.nikiroo.jvcard.parsers.Parser; * contacts. * * @author niki - * */ public class Card extends BaseClass { private File file; private String name; private Format format; private long lastModified; - private boolean remote; /** * Create a new {@link Card} from the given {@link File} and {@link Format}. @@ -40,12 +38,10 @@ public class Card extends BaseClass { * if format is NULL */ public Card(File file, Format format) throws IOException { - this(Parser.parse(file, format)); + this(Parser.parseContact(file, format)); - if (file != null) { - if (file.exists()) { - lastModified = file.lastModified(); - } + if (file != null && file.exists()) { + lastModified = file.lastModified(); } this.format = format; @@ -75,7 +71,7 @@ public class Card extends BaseClass { * @throws InvalidParameterException * if format is NULL */ - public Card(List contacts) throws IOException { + public Card(List contacts) { super(contacts); lastModified = -1; @@ -100,11 +96,15 @@ public class Card extends BaseClass { return false; BufferedWriter writer = new BufferedWriter(new FileWriter(file)); - writer.append(toString(format)); - writer.close(); + try { + Parser.write(writer, format, this); + } finally { + writer.close(); + } if (this.file != null && file.getCanonicalPath().equals(this.file.getCanonicalPath())) { + lastModified = file.lastModified(); setPristine(); } @@ -135,22 +135,11 @@ public class Card extends BaseClass { if (file == null) return false; - this.replaceListContent(Parser.parse(file, format)); + this.replaceListContent(Parser.parseContact(file, format)); + lastModified = file.lastModified(); setPristine(); - return true; - } - /** - * Return a {@link String} representation of this {@link Card} in the given - * {@link Format}. - * - * @param format - * the {@link Format} to use - * - * @return the {@link String} - */ - public String toString(Format format) { - return Parser.toString(this, format); + return true; } /** @@ -181,6 +170,15 @@ public class Card extends BaseClass { return file; } + /** + * Break the link between this {@link Card} and he {@link File} which was + * used to open it if any. + */ + public void unlink() { + file = null; + lastModified = -1; + } + /** * Return the date of the last modification for this {@link Card} (or -1 if * unknown/new). @@ -191,28 +189,9 @@ public class Card extends BaseClass { return lastModified; } - /** - * Check if this {@link Card} is remote. - * - * @return TRUE if this {@link Card} is remote - */ - public boolean isRemote() { - return remote; - } - - /** - * Set the remote option on this {@link Card}. - * - * @param remote - * TRUE if this {@link Card} is remote - */ - public void setRemote(boolean remote) { - this.remote = remote; - } - @Override public String toString() { - return toString(Format.VCard21); + return "[Card: " + name + "]"; } @Override @@ -222,6 +201,6 @@ public class Card extends BaseClass { @Override public String getState() { - return "" + name + format; + return ("" + name + format).replace(' ', '_'); } }