VCard format: correctly co/decode escaped values
[jvcard.git] / src / be / nikiroo / jvcard / TypeInfo.java
index 760f75ce54caa9bfe711ea56a368954bcb2843d0..c172996bdb64e939a1718787ac48111a3e4aa87c 100644 (file)
@@ -6,24 +6,59 @@ package be.nikiroo.jvcard;
  * @author niki
  *
  */
-@SuppressWarnings("rawtypes") // expected
-public class TypeInfo extends BaseClass {
+public class TypeInfo extends BaseClass<TypeInfo> {
        private String name;
        private String value;
 
-       @SuppressWarnings("unchecked") // expected
+       /**
+        * Create a new {@link TypeInfo}.
+        * 
+        * @param name
+        *            the name of this {@link TypeInfo} (<b>MUST NOT</b> be NULL)
+        * @param value
+        *            its value (<b>MUST NOT</b> be NULL)
+        */
        public TypeInfo(String name, String value) {
                super(null);
 
-               this.name = name;
-               this.value = value;
+               this.name = name.toUpperCase();
+               this.value = escape(value.toString()); // crash NOW if null
        }
 
+       /**
+        * Return the name.
+        * 
+        * @return the name
+        */
        public String getName() {
                return name;
        }
 
+       /**
+        * Return the value.
+        * 
+        * @return the value
+        */
        public String getValue() {
+               return unescape(value);
+       }
+
+       /**
+        * Return the RAW value
+        * 
+        * @return the RAW value
+        */
+       public String getRawValue() {
                return value;
        }
-}
\ No newline at end of file
+
+       @Override
+       public String getId() {
+               return "" + name;
+       }
+
+       @Override
+       public String getState() {
+               return ("" + name + value).replace(' ', '_');
+       }
+}