whitespace fixups
[jSite2.git] / src / net / pterodactylus / jsite / core / FileOverride.java
1 /*
2  * jSite2 - Override.java -
3  * Copyright © 2008 David Roden
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 package net.pterodactylus.jsite.core;
21
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24
25 import net.pterodactylus.util.logging.Logging;
26
27 /**
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.
30  *
31  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
32  */
33 public class FileOverride {
34
35         /** The logger. */
36         private static final Logger logger = Logging.getLogger(FileOverride.class.getName());
37
38         /** The insert override. */
39         private Boolean insert;
40
41         /** The override content type. */
42         private String contentType;
43
44         /** The redirect target. */
45         private String redirectTarget;
46
47         /**
48          * Checks whether this override has any content.
49          *
50          * @return <code>true</code> if this override does not have any effects,
51          *         <code>false</code> otherwise
52          */
53         public boolean isEmpty() {
54                 return (insert == null) && (contentType == null) && (redirectTarget == null);
55         }
56
57         /**
58          * Returns the insert override.
59          *
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
63          */
64         public Boolean isInsert() {
65                 return insert;
66         }
67
68         /**
69          * Sets the insert override.
70          *
71          * @param insert
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
75          */
76         public void setInsert(Boolean insert) {
77                 this.insert = insert;
78         }
79
80         /**
81          * Returns the override content type.
82          *
83          * @return The override content type, or <code>null</code> to not override
84          *         the default
85          */
86         public String getContentType() {
87                 return contentType;
88         }
89
90         /**
91          * Sets the override content type.
92          *
93          * @param contentType
94          *            The override content type, or <code>null</code> to not
95          *            override the default
96          */
97         public void setContentType(String contentType) {
98                 this.contentType = contentType;
99         }
100
101         /**
102          * Returns the target of a redirect.
103          *
104          * @return The target URI of the redirect, or <code>null</code> if no
105          *         redirect should be created
106          */
107         public String getRedirectTarget() {
108                 return redirectTarget;
109         }
110
111         /**
112          * Sets the target of a redirect.
113          *
114          * @param redirectTarget
115          *            The target URI of the redirect, or <code>null</code> if no
116          *            redirect should be created
117          */
118         public void setRedirectTarget(String redirectTarget) {
119                 this.redirectTarget = redirectTarget;
120         }
121
122         /**
123          * @see java.lang.Object#toString()
124          */
125         @Override
126         public String toString() {
127                 return ((insert != null) ? String.valueOf(insert) : "") + "|" + ((contentType != null) ? contentType : "") + "|" + ((redirectTarget != null) ? redirectTarget : "");
128         }
129
130         /**
131          * Converts an override string created by {@link #toString()} back to an
132          * {@link FileOverride} object.
133          *
134          * @param overrideString
135          *            The textual representation of the override
136          * @return The parsed override, or <code>null</code> if the string could
137          *         not be parsed
138          */
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]);
145                 }
146                 if ((parts.length > 1) && (parts[1].length() > 0)) {
147                         override.contentType = parts[1];
148                 }
149                 if ((parts.length > 2) && (parts[2].length() > 0)) {
150                         override.redirectTarget = parts[2];
151                 }
152                 return override;
153         }
154
155 }