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;
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>
34 public class FileOverride {
37 private static final Logger logger = Logging.getLogger(FileOverride.class.getName());
39 /** The insert override. */
40 private Boolean insert;
42 /** The override content type. */
43 private String contentType;
45 /** The redirect target. */
46 private String redirectTarget;
49 * Checks whether this override has any content.
51 * @return <code>true</code> if this override does not have any effects,
52 * <code>false</code> otherwise
54 public boolean isEmpty() {
55 return (insert == null) && (contentType == null) && (redirectTarget == null);
59 * Returns the insert override.
61 * @return <code>true</code> if the entry should be inserted,
62 * <code>false</code> if it should not be inserted,
63 * <code>null</code> if the default should not be overridden
65 public Boolean isInsert() {
70 * Sets the insert override.
73 * <code>true</code> if the entry should be inserted,
74 * <code>false</code> if it should not be inserted,
75 * <code>null</code> if the default should not be overridden
77 public void setInsert(Boolean insert) {
82 * Returns the override content type.
84 * @return The override content type, or <code>null</code> to not override
87 public String getContentType() {
92 * Sets the override content type.
95 * The override content type, or <code>null</code> to not
96 * override the default
98 public void setContentType(String contentType) {
99 this.contentType = contentType;
103 * Returns the target of a redirect.
105 * @return The target URI of the redirect, or <code>null</code> if no
106 * redirect should be created
108 public String getRedirectTarget() {
109 return redirectTarget;
113 * Sets the target of a redirect.
115 * @param redirectTarget
116 * The target URI of the redirect, or <code>null</code> if no
117 * redirect should be created
119 public void setRedirectTarget(String redirectTarget) {
120 this.redirectTarget = redirectTarget;
124 * @see java.lang.Object#toString()
127 public String toString() {
128 return ((insert != null) ? String.valueOf(insert) : "") + "|" + ((contentType != null) ? contentType : "") + "|" + ((redirectTarget != null) ? redirectTarget : "");
132 * Converts an override string created by {@link #toString()} back to an
133 * {@link FileOverride} object.
135 * @param overrideString
136 * The textual representation of the override
137 * @return The parsed override, or <code>null</code> if the string could
140 public static FileOverride valueOf(String overrideString) {
141 FileOverride override = new FileOverride();
142 String[] parts = overrideString.split("\\|");
143 logger.log(Level.FINEST, "parts.length: " + parts.length);
144 if ((parts.length > 0) && (parts[0].length() > 0)) {
145 override.insert = Boolean.valueOf(parts[0]);
147 if ((parts.length > 1) && (parts[1].length() > 0)) {
148 override.contentType = parts[1];
150 if ((parts.length > 2) && (parts[2].length() > 0)) {
151 override.redirectTarget = parts[2];