rename Override to FileOverride
[jSite2.git] / src / net / pterodactylus / jsite / project / FileOverride.java
diff --git a/src/net/pterodactylus/jsite/project/FileOverride.java b/src/net/pterodactylus/jsite/project/FileOverride.java
new file mode 100644 (file)
index 0000000..be11887
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * jSite2 - Override.java -
+ * Copyright © 2008 David Roden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+package net.pterodactylus.jsite.project;
+
+/**
+ * An override is used to enter other information about a file than the defaults
+ * would have yielded. It is also used to add redirects to a project.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ * @version $Id$
+ */
+public class FileOverride {
+
+       /** The insert override. */
+       private Boolean insert;
+
+       /** The override content type. */
+       private String contentType;
+
+       /** The redirect target. */
+       private String redirectTarget;
+
+       /**
+        * Returns the insert override.
+        *
+        * @return <code>true</code> if the entry should be inserted,
+        *         <code>false</code> if it should not be inserted,
+        *         <code>null</code> if the default should not be overridden
+        */
+       public Boolean isInsert() {
+               return insert;
+       }
+
+       /**
+        * Sets the insert override.
+        *
+        * @param insert
+        *            <code>true</code> if the entry should be inserted,
+        *            <code>false</code> if it should not be inserted,
+        *            <code>null</code> if the default should not be overridden
+        */
+       public void setInsert(Boolean insert) {
+               this.insert = insert;
+       }
+
+       /**
+        * Returns the override content type.
+        *
+        * @return The override content type, or <code>null</code> to not override
+        *         the default
+        */
+       public String getContentType() {
+               return contentType;
+       }
+
+       /**
+        * Sets the override content type.
+        *
+        * @param contentType
+        *            The override content type, or <code>null</code> to not
+        *            override the default
+        */
+       public void setContentType(String contentType) {
+               this.contentType = contentType;
+       }
+
+       /**
+        * Returns the target of a redirect.
+        *
+        * @return The target URI of the redirect, or <code>null</code> if no
+        *         redirect should be created
+        */
+       public String getRedirectTarget() {
+               return redirectTarget;
+       }
+
+       /**
+        * Sets the target of a redirect.
+        *
+        * @param redirectTarget
+        *            The target URI of the redirect, or <code>null</code> if no
+        *            redirect should be created
+        */
+       public void setRedirectTarget(String redirectTarget) {
+               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 FileOverride} 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 FileOverride valueOf(String overrideString) {
+               FileOverride override = new FileOverride();
+               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;
+       }
+
+}