Remote support ~complete (need more tests at least)
[jvcard.git] / src / be / nikiroo / jvcard / Card.java
index de5ab67a604207f0d294f3d9a7652a460c4754a3..547535804b8f37fa80fb5dc3ca22f89afc22857e 100644 (file)
@@ -22,7 +22,6 @@ public class Card extends BaseClass<Contact> {
        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 +39,10 @@ public class Card extends BaseClass<Contact> {
         *             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 +72,7 @@ public class Card extends BaseClass<Contact> {
         * @throws InvalidParameterException
         *             if format is NULL
         */
-       public Card(List<Contact> contacts) throws IOException {
+       public Card(List<Contact> contacts) {
                super(contacts);
 
                lastModified = -1;
@@ -105,6 +102,7 @@ public class Card extends BaseClass<Contact> {
 
                if (this.file != null
                                && file.getCanonicalPath().equals(this.file.getCanonicalPath())) {
+                       lastModified = file.lastModified();
                        setPristine();
                }
 
@@ -135,8 +133,10 @@ public class Card extends BaseClass<Contact> {
                if (file == null)
                        return false;
 
-               this.replaceListContent(Parser.parse(file, format));
+               this.replaceListContent(Parser.parseContact(file, format));
+               lastModified = file.lastModified();
                setPristine();
+
                return true;
        }
 
@@ -150,7 +150,12 @@ public class Card extends BaseClass<Contact> {
         * @return the {@link String}
         */
        public String toString(Format format) {
-               return Parser.toString(this, format);
+               StringBuilder builder = new StringBuilder();
+               for (String line : Parser.toStrings(this, format)) {
+                       builder.append(line);
+                       builder.append("\r\n");
+               }
+               return builder.toString();
        }
 
        /**
@@ -191,25 +196,6 @@ public class Card extends BaseClass<Contact> {
                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);
@@ -222,6 +208,6 @@ public class Card extends BaseClass<Contact> {
 
        @Override
        public String getState() {
-               return "" + name + format;
+               return ("" + name + format).replace(' ', '_');
        }
 }