X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2FCard.java;h=6d833d81f069028b21442aaa6519272a63f41f38;hb=f04a32e97c847d7e2551037a4d5f6a070879215c;hp=547535804b8f37fa80fb5dc3ca22f89afc22857e;hpb=5ad0e17e7fea1c602cb2638a006424af9c7e33e8;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/Card.java b/src/be/nikiroo/jvcard/Card.java index 5475358..6d833d8 100644 --- a/src/be/nikiroo/jvcard/Card.java +++ b/src/be/nikiroo/jvcard/Card.java @@ -15,7 +15,6 @@ import be.nikiroo.jvcard.parsers.Parser; * contacts. * * @author niki - * */ public class Card extends BaseClass { private File file; @@ -97,8 +96,11 @@ 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())) { @@ -140,24 +142,6 @@ public class Card extends BaseClass { 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) { - StringBuilder builder = new StringBuilder(); - for (String line : Parser.toStrings(this, format)) { - builder.append(line); - builder.append("\r\n"); - } - return builder.toString(); - } - /** * Return the name of this card (the name of the {@link File} which it was * opened from). @@ -186,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). @@ -198,7 +191,7 @@ public class Card extends BaseClass { @Override public String toString() { - return toString(Format.VCard21); + return "[Card: " + name + "]"; } @Override