add methods to convert to text and back
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 28 May 2008 13:11:10 +0000 (15:11 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 28 May 2008 13:11:10 +0000 (15:11 +0200)
src/net/pterodactylus/jsite/project/Override.java

index cdd3a51..1f7bc78 100644 (file)
@@ -101,4 +101,39 @@ public class Override {
                this.redirectTarget = redirectTarget;
        }
 
+       /**
+        * @see java.lang.Object#toString()
+        */
+       @java.lang.Override
+       public String toString() {
+               return ((insert != null) ? String.valueOf(insert) : "") + "|" + ((contentType != null) ? contentType : "") + "|" + ((redirectTarget != null) ? redirectTarget : "");
+       }
+
+       /**
+        * Converts an override string created by {@link #toString()} back to an
+        * {@link Override} object.
+        *
+        * @param overrideString
+        *            The textual representation of the override
+        * @return The parsed override, or <code>null</code> if the string could
+        *         not be parsed
+        */
+       public static Override valueOf(String overrideString) {
+               Override override = new Override();
+               String[] parts = overrideString.split("\\|");
+               if (parts.length < 3) {
+                       return null;
+               }
+               if (parts[0].length() > 0) {
+                       override.insert = Boolean.valueOf(parts[0]);
+               }
+               if (parts[1].length() > 0) {
+                       override.contentType = parts[1];
+               }
+               if (parts[2].length() > 0) {
+                       override.redirectTarget = parts[2];
+               }
+               return override;
+       }
+
 }