be11887b0b34974e9c36637b242e66017b2affa8
[jSite2.git] / src / net / pterodactylus / jsite / project / 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 package net.pterodactylus.jsite.project;
20
21 /**
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.
24  *
25  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
26  * @version $Id$
27  */
28 public class FileOverride {
29
30         /** The insert override. */
31         private Boolean insert;
32
33         /** The override content type. */
34         private String contentType;
35
36         /** The redirect target. */
37         private String redirectTarget;
38
39         /**
40          * Returns the insert override.
41          *
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
45          */
46         public Boolean isInsert() {
47                 return insert;
48         }
49
50         /**
51          * Sets the insert override.
52          *
53          * @param insert
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
57          */
58         public void setInsert(Boolean insert) {
59                 this.insert = insert;
60         }
61
62         /**
63          * Returns the override content type.
64          *
65          * @return The override content type, or <code>null</code> to not override
66          *         the default
67          */
68         public String getContentType() {
69                 return contentType;
70         }
71
72         /**
73          * Sets the override content type.
74          *
75          * @param contentType
76          *            The override content type, or <code>null</code> to not
77          *            override the default
78          */
79         public void setContentType(String contentType) {
80                 this.contentType = contentType;
81         }
82
83         /**
84          * Returns the target of a redirect.
85          *
86          * @return The target URI of the redirect, or <code>null</code> if no
87          *         redirect should be created
88          */
89         public String getRedirectTarget() {
90                 return redirectTarget;
91         }
92
93         /**
94          * Sets the target of a redirect.
95          *
96          * @param redirectTarget
97          *            The target URI of the redirect, or <code>null</code> if no
98          *            redirect should be created
99          */
100         public void setRedirectTarget(String redirectTarget) {
101                 this.redirectTarget = redirectTarget;
102         }
103
104         /**
105          * @see java.lang.Object#toString()
106          */
107         @java.lang.Override
108         public String toString() {
109                 return ((insert != null) ? String.valueOf(insert) : "") + "|" + ((contentType != null) ? contentType : "") + "|" + ((redirectTarget != null) ? redirectTarget : "");
110         }
111
112         /**
113          * Converts an override string created by {@link #toString()} back to an
114          * {@link FileOverride} object.
115          *
116          * @param overrideString
117          *            The textual representation of the override
118          * @return The parsed override, or <code>null</code> if the string could
119          *         not be parsed
120          */
121         public static FileOverride valueOf(String overrideString) {
122                 FileOverride override = new FileOverride();
123                 String[] parts = overrideString.split("\\|");
124                 if (parts.length < 3) {
125                         return null;
126                 }
127                 if (parts[0].length() > 0) {
128                         override.insert = Boolean.valueOf(parts[0]);
129                 }
130                 if (parts[1].length() > 0) {
131                         override.contentType = parts[1];
132                 }
133                 if (parts[2].length() > 0) {
134                         override.redirectTarget = parts[2];
135                 }
136                 return override;
137         }
138
139 }