2 * jSite - a tool for uploading websites into Freenet Copyright (C) 2006 David
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place - Suite 330, Boston, MA 02111-1307, USA.
20 package de.todesbaum.jsite.application;
23 * Container for various file options.
25 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
27 public class FileOption {
29 /** The default for the insert state. */
30 private static final boolean DEFAULT_INSERT = true;
32 /** The default for the custom key. */
33 private static final String DEFAULT_CUSTOM_KEY = "CHK@";
35 /** The default container. */
36 private static final String DEFAULT_CONTAINER = "";
38 /** The default edition range. */
39 private static final int DEFAULT_EDITION_RANGE = 3;
41 /** The default for the replace edition state. */
42 private static final boolean DEFAULT_REPLACE_EDITION = false;
44 /** The insert state. */
45 private boolean insert;
47 /** Whether to insert a redirect. */
48 private boolean insertRedirect;
50 /** The custom key. */
51 private String customKey;
53 /** The default MIME type. */
54 private final String defaultMimeType;
56 /** The current MIME type. */
57 private String mimeType;
60 private String container;
62 /** The edition range. */
63 private int editionRange;
65 /** The replace edition state. */
66 private boolean replaceEdition;
69 * Creates new file options.
71 * @param defaultMimeType
72 * The default MIME type of the file
74 public FileOption(String defaultMimeType) {
75 insert = DEFAULT_INSERT;
76 customKey = DEFAULT_CUSTOM_KEY;
77 this.defaultMimeType = defaultMimeType;
78 mimeType = defaultMimeType;
79 container = DEFAULT_CONTAINER;
80 editionRange = DEFAULT_EDITION_RANGE;
81 replaceEdition = DEFAULT_REPLACE_EDITION;
85 * Returns the custom key. The custom key is only used when
86 * {@link #isInsert()} and {@link #isInsertRedirect()} both return {@code
89 * @return The custom key
91 public String getCustomKey() {
96 * Sets the custom key. The custom key is only used when {@link #isInsert()}
97 * and {@link #isInsertRedirect()} both return {@code true}.
102 public void setCustomKey(String customKey) {
103 if (customKey == null) {
106 this.customKey = customKey;
111 * Returns whether the file should be inserted. If a file is not inserted
112 * and {@link #isInsertRedirect()} is also {@code false}, the file will not
113 * be inserted at all.
115 * @see #setCustomKey(String)
116 * @return <code>true</code> if the file should be inserted,
117 * <code>false</code> otherwise
119 public boolean isInsert() {
124 * Sets whether the file should be inserted. If a file is not inserted and
125 * {@link #isInsertRedirect()} is also {@code false}, the file will not be
129 * <code>true</code> if the file should be inserted,
130 * <code>false</code> otherwise
132 public void setInsert(boolean insert) {
133 this.insert = insert;
137 * Returns whether a redirect to a different key should be inserted. This
138 * will only matter if {@link #isInsert()} returns {@code false}. The key
139 * that should be redirected to still needs to be specified via
140 * {@link #setCustomKey(String)}.
142 * @return {@code true} if a redirect should be inserted, {@code false}
145 public boolean isInsertRedirect() {
146 return insertRedirect;
150 * Sets whether a redirect should be inserted. This will only matter if
151 * {@link #isInsert()} returns {@code false}, i.e. it has been
152 * {@link #setInsert(boolean)} to {@code false}. The key that should be
153 * redirected to still needs to be specified via
154 * {@link #setCustomKey(String)}.
156 * @param insertRedirect
157 * {@code true} if a redirect should be inserted, {@code false}
160 public void setInsertRedirect(boolean insertRedirect) {
161 this.insertRedirect = insertRedirect;
165 * Sets the MIME type of the file. Setting the MIME type to
166 * <code>null</code> will set the MIME type to the default MIME type.
169 * The MIME type of the file
171 public void setMimeType(String mimeType) {
172 if (mimeType == null) {
173 this.mimeType = defaultMimeType;
175 this.mimeType = mimeType;
180 * Returns the MIME type of the file. If no custom MIME type has been set,
181 * the default MIME type is returned.
183 * @return The MIME type of the file
185 public String getMimeType() {
190 * Returns the name of the container this file should be put in.
192 * @return The name of the container
194 public String getContainer() {
199 * Sets the name of the container this file should be put in.
202 * The name of the container
204 public void setContainer(String container) {
205 if (container == null) {
206 this.container = DEFAULT_CONTAINER;
208 this.container = container;
213 * Sets whether the file should have “$[EDITION+<i>n</i>]” tags replaced.
215 * @param replaceEdition
216 * <code>true</code> to replace tags, <code>false</code> not to
219 public void setReplaceEdition(boolean replaceEdition) {
220 this.replaceEdition = replaceEdition;
224 * Returns whether the file should have “$[EDITION+<i>n</i>]” tags replaced.
226 * @return <code>true</code> if tags should be replaced, <code>false</code>
229 public boolean getReplaceEdition() {
230 return replaceEdition;
234 * Sets the range of editions that should be replaced.
236 * @param editionRange
237 * The range editions to replace
239 public void setEditionRange(int editionRange) {
240 this.editionRange = editionRange;
244 * Returns the range of editions that should be replaced.
246 * @return The range of editions to replace
248 public int getEditionRange() {
253 * Returns whether the options for this file have been modified, i.e. are
254 * not at their default values.
256 * @return <code>true</code> if the options have been modified,
257 * <code>false</code> if they are at default values
259 public boolean isCustom() {
260 if (insert != DEFAULT_INSERT) {
263 if (!customKey.equals(DEFAULT_CUSTOM_KEY)) {
266 if (!defaultMimeType.equals(mimeType)) {
269 if (!DEFAULT_CONTAINER.equals(container)) {
272 if (replaceEdition != DEFAULT_REPLACE_EDITION) {
275 if (editionRange != DEFAULT_EDITION_RANGE) {