From a8a82a12f692c3d2d67313bcb228dc0403ce81ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 28 May 2008 15:11:10 +0200 Subject: [PATCH] add methods to convert to text and back --- src/net/pterodactylus/jsite/project/Override.java | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/net/pterodactylus/jsite/project/Override.java b/src/net/pterodactylus/jsite/project/Override.java index cdd3a51..1f7bc78 100644 --- a/src/net/pterodactylus/jsite/project/Override.java +++ b/src/net/pterodactylus/jsite/project/Override.java @@ -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 null 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; + } + } -- 2.7.4