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.
19 package net.pterodactylus.jsite.project;
22 * An override is used to enter other information about a file than the defaults
23 * would have yielded. It is also used to add redirects to a project.
25 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
28 public class Override {
30 /** The insert override. */
31 private Boolean insert;
33 /** The override content type. */
34 private String contentType;
36 /** The redirect target. */
37 private String redirectTarget;
40 * Returns the insert override.
42 * @return <code>true</code> if the entry should be inserted,
43 * <code>false</code> if it should not be inserted,
44 * <code>null</code> if the default should not be overridden
46 public Boolean isInsert() {
51 * Sets the insert override.
54 * <code>true</code> if the entry should be inserted,
55 * <code>false</code> if it should not be inserted,
56 * <code>null</code> if the default should not be overridden
58 public void setInsert(Boolean insert) {
63 * Returns the override content type.
65 * @return The override content type, or <code>null</code> to not override
68 public String getContentType() {
73 * Sets the override content type.
76 * The override content type, or <code>null</code> to not
77 * override the default
79 public void setContentType(String contentType) {
80 this.contentType = contentType;
84 * Returns the target of a redirect.
86 * @return The target URI of the redirect, or <code>null</code> if no
87 * redirect should be created
89 public String getRedirectTarget() {
90 return redirectTarget;
94 * Sets the target of a redirect.
96 * @param redirectTarget
97 * The target URI of the redirect, or <code>null</code> if no
98 * redirect should be created
100 public void setRedirectTarget(String redirectTarget) {
101 this.redirectTarget = redirectTarget;
105 * @see java.lang.Object#toString()
108 public String toString() {
109 return ((insert != null) ? String.valueOf(insert) : "") + "|" + ((contentType != null) ? contentType : "") + "|" + ((redirectTarget != null) ? redirectTarget : "");
113 * Converts an override string created by {@link #toString()} back to an
114 * {@link Override} object.
116 * @param overrideString
117 * The textual representation of the override
118 * @return The parsed override, or <code>null</code> if the string could
121 public static Override valueOf(String overrideString) {
122 Override override = new Override();
123 String[] parts = overrideString.split("\\|");
124 if (parts.length < 3) {
127 if (parts[0].length() > 0) {
128 override.insert = Boolean.valueOf(parts[0]);
130 if (parts[1].length() > 0) {
131 override.contentType = parts[1];
133 if (parts[2].length() > 0) {
134 override.redirectTarget = parts[2];