2 * jSite2 - Override.java -
3 * Copyright © 2008 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.jsite.project;
23 * An override is used to enter other information about a file than the defaults
24 * would have yielded. It is also used to add redirects to a project.
26 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
29 public class FileOverride {
31 /** The insert override. */
32 private Boolean insert;
34 /** The override content type. */
35 private String contentType;
37 /** The redirect target. */
38 private String redirectTarget;
41 * Checks whether this override has any content.
43 * @return <code>true</code> if this override does not have any effects,
44 * <code>false</code> otherwise
46 public boolean isEmpty() {
47 return (insert == null) && (contentType == null) && (redirectTarget == null);
51 * Returns the insert override.
53 * @return <code>true</code> if the entry should be inserted,
54 * <code>false</code> if it should not be inserted,
55 * <code>null</code> if the default should not be overridden
57 public Boolean isInsert() {
62 * Sets the insert override.
65 * <code>true</code> if the entry should be inserted,
66 * <code>false</code> if it should not be inserted,
67 * <code>null</code> if the default should not be overridden
69 public void setInsert(Boolean insert) {
74 * Returns the override content type.
76 * @return The override content type, or <code>null</code> to not override
79 public String getContentType() {
84 * Sets the override content type.
87 * The override content type, or <code>null</code> to not
88 * override the default
90 public void setContentType(String contentType) {
91 this.contentType = contentType;
95 * Returns the target of a redirect.
97 * @return The target URI of the redirect, or <code>null</code> if no
98 * redirect should be created
100 public String getRedirectTarget() {
101 return redirectTarget;
105 * Sets the target of a redirect.
107 * @param redirectTarget
108 * The target URI of the redirect, or <code>null</code> if no
109 * redirect should be created
111 public void setRedirectTarget(String redirectTarget) {
112 this.redirectTarget = redirectTarget;
116 * @see java.lang.Object#toString()
119 public String toString() {
120 return ((insert != null) ? String.valueOf(insert) : "") + "|" + ((contentType != null) ? contentType : "") + "|" + ((redirectTarget != null) ? redirectTarget : "");
124 * Converts an override string created by {@link #toString()} back to an
125 * {@link FileOverride} object.
127 * @param overrideString
128 * The textual representation of the override
129 * @return The parsed override, or <code>null</code> if the string could
132 public static FileOverride valueOf(String overrideString) {
133 FileOverride override = new FileOverride();
134 String[] parts = overrideString.split("\\|");
135 if (parts.length < 3) {
138 if (parts[0].length() > 0) {
139 override.insert = Boolean.valueOf(parts[0]);
141 if (parts[1].length() > 0) {
142 override.contentType = parts[1];
144 if (parts[2].length() > 0) {
145 override.redirectTarget = parts[2];