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.core;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
25 import net.pterodactylus.util.logging.Logging;
28 * An override is used to enter other information about a file than the defaults
29 * would have yielded. It is also used to add redirects to a project.
31 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
33 public class FileOverride {
36 private static final Logger logger = Logging.getLogger(FileOverride.class.getName());
38 /** The insert override. */
39 private Boolean insert;
41 /** The override content type. */
42 private String contentType;
44 /** The redirect target. */
45 private String redirectTarget;
48 * Checks whether this override has any content.
50 * @return <code>true</code> if this override does not have any effects,
51 * <code>false</code> otherwise
53 public boolean isEmpty() {
54 return (insert == null) && (contentType == null) && (redirectTarget == null);
58 * Returns the insert override.
60 * @return <code>true</code> if the entry should be inserted,
61 * <code>false</code> if it should not be inserted,
62 * <code>null</code> if the default should not be overridden
64 public Boolean isInsert() {
69 * Sets the insert override.
72 * <code>true</code> if the entry should be inserted,
73 * <code>false</code> if it should not be inserted,
74 * <code>null</code> if the default should not be overridden
76 public void setInsert(Boolean insert) {
81 * Returns the override content type.
83 * @return The override content type, or <code>null</code> to not override
86 public String getContentType() {
91 * Sets the override content type.
94 * The override content type, or <code>null</code> to not
95 * override the default
97 public void setContentType(String contentType) {
98 this.contentType = contentType;
102 * Returns the target of a redirect.
104 * @return The target URI of the redirect, or <code>null</code> if no
105 * redirect should be created
107 public String getRedirectTarget() {
108 return redirectTarget;
112 * Sets the target of a redirect.
114 * @param redirectTarget
115 * The target URI of the redirect, or <code>null</code> if no
116 * redirect should be created
118 public void setRedirectTarget(String redirectTarget) {
119 this.redirectTarget = redirectTarget;
123 * @see java.lang.Object#toString()
126 public String toString() {
127 return ((insert != null) ? String.valueOf(insert) : "") + "|" + ((contentType != null) ? contentType : "") + "|" + ((redirectTarget != null) ? redirectTarget : "");
131 * Converts an override string created by {@link #toString()} back to an
132 * {@link FileOverride} object.
134 * @param overrideString
135 * The textual representation of the override
136 * @return The parsed override, or <code>null</code> if the string could
139 public static FileOverride valueOf(String overrideString) {
140 FileOverride override = new FileOverride();
141 String[] parts = overrideString.split("\\|");
142 logger.log(Level.FINEST, "parts.length: " + parts.length);
143 if ((parts.length > 0) && (parts[0].length() > 0)) {
144 override.insert = Boolean.valueOf(parts[0]);
146 if ((parts.length > 1) && (parts[1].length() > 0)) {
147 override.contentType = parts[1];
149 if ((parts.length > 2) && (parts[2].length() > 0)) {
150 override.redirectTarget = parts[2];