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 insert redirect state. */
33 private static final boolean DEFAULT_INSERT_REDIRECT = true;
35 /** The default for the custom key. */
36 private static final String DEFAULT_CUSTOM_KEY = "CHK@";
38 /** The default container. */
39 private static final String DEFAULT_CONTAINER = "";
41 /** The default edition range. */
42 private static final int DEFAULT_EDITION_RANGE = 3;
44 /** The default for the replace edition state. */
45 private static final boolean DEFAULT_REPLACE_EDITION = false;
47 /** The insert state. */
48 private boolean insert;
50 /** Whether to insert a redirect. */
51 private boolean insertRedirect;
53 /** The custom key. */
54 private String customKey;
56 /** The changed name. */
57 private String changedName;
59 /** The default MIME type. */
60 private final String defaultMimeType;
62 /** The current MIME type. */
63 private String mimeType;
66 private String container;
68 /** The edition range. */
69 private int editionRange;
71 /** The replace edition state. */
72 private boolean replaceEdition;
75 * Creates new file options.
77 * @param defaultMimeType
78 * The default MIME type of the file
80 public FileOption(String defaultMimeType) {
81 insert = DEFAULT_INSERT;
82 insertRedirect = DEFAULT_INSERT_REDIRECT;
83 customKey = DEFAULT_CUSTOM_KEY;
84 this.defaultMimeType = defaultMimeType;
85 mimeType = defaultMimeType;
86 container = DEFAULT_CONTAINER;
87 editionRange = DEFAULT_EDITION_RANGE;
88 replaceEdition = DEFAULT_REPLACE_EDITION;
92 * Returns the custom key. The custom key is only used when
93 * {@link #isInsert()} and {@link #isInsertRedirect()} both return {@code
96 * @return The custom key
98 public String getCustomKey() {
103 * Sets the custom key. The custom key is only used when {@link #isInsert()}
104 * and {@link #isInsertRedirect()} both return {@code true}.
109 public void setCustomKey(String customKey) {
110 if (customKey == null) {
113 this.customKey = customKey;
118 * Returns whether the file should be inserted. If a file is not inserted
119 * and {@link #isInsertRedirect()} is also {@code false}, the file will not
120 * be inserted at all.
122 * @see #setCustomKey(String)
123 * @return <code>true</code> if the file should be inserted,
124 * <code>false</code> otherwise
126 public boolean isInsert() {
131 * Sets whether the file should be inserted. If a file is not inserted and
132 * {@link #isInsertRedirect()} is also {@code false}, the file will not be
136 * <code>true</code> if the file should be inserted,
137 * <code>false</code> otherwise
139 public void setInsert(boolean insert) {
140 this.insert = insert;
144 * Returns whether a redirect to a different key should be inserted. This
145 * will only matter if {@link #isInsert()} returns {@code false}. The key
146 * that should be redirected to still needs to be specified via
147 * {@link #setCustomKey(String)}.
149 * @return {@code true} if a redirect should be inserted, {@code false}
152 public boolean isInsertRedirect() {
153 return insertRedirect;
157 * Sets whether a redirect should be inserted. This will only matter if
158 * {@link #isInsert()} returns {@code false}, i.e. it has been
159 * {@link #setInsert(boolean)} to {@code false}. The key that should be
160 * redirected to still needs to be specified via
161 * {@link #setCustomKey(String)}.
163 * @param insertRedirect
164 * {@code true} if a redirect should be inserted, {@code false}
167 public void setInsertRedirect(boolean insertRedirect) {
168 this.insertRedirect = insertRedirect;
172 * Returns whether this file has a changed name. Use
173 * {@link #getChangedName()} is this method returns {@code true}.
175 * @return {@code true} if this file has a changed name, {@code false}
178 public boolean hasChangedName() {
179 return (changedName != null) && (changedName.length() > 0);
183 * Returns the changed name for this file. This method will return {@code
184 * null} or an empty {@link String} if this file should not be renamed.
186 * @return The changed name, or {@code null} if this file should not be
189 public String getChangedName() {
194 * Sets the changed name for this file. Setting the changed file to {@code
195 * null} or an empty {@link String} will disable renaming.
198 * The new changed name for this file
200 public void setChangedName(String changedName) {
201 this.changedName = changedName;
205 * Sets the MIME type of the file. Setting the MIME type to
206 * <code>null</code> will set the MIME type to the default MIME type.
209 * The MIME type of the file
211 public void setMimeType(String mimeType) {
212 if (mimeType == null) {
213 this.mimeType = defaultMimeType;
215 this.mimeType = mimeType;
220 * Returns the MIME type of the file. If no custom MIME type has been set,
221 * the default MIME type is returned.
223 * @return The MIME type of the file
225 public String getMimeType() {
230 * Returns the name of the container this file should be put in.
232 * @return The name of the container
234 public String getContainer() {
239 * Sets the name of the container this file should be put in.
242 * The name of the container
244 public void setContainer(String container) {
245 if (container == null) {
246 this.container = DEFAULT_CONTAINER;
248 this.container = container;
253 * Sets whether the file should have “$[EDITION+<i>n</i>]” tags replaced.
255 * @param replaceEdition
256 * <code>true</code> to replace tags, <code>false</code> not to
259 public void setReplaceEdition(boolean replaceEdition) {
260 this.replaceEdition = replaceEdition;
264 * Returns whether the file should have “$[EDITION+<i>n</i>]” tags replaced.
266 * @return <code>true</code> if tags should be replaced, <code>false</code>
269 public boolean getReplaceEdition() {
270 return replaceEdition;
274 * Sets the range of editions that should be replaced.
276 * @param editionRange
277 * The range editions to replace
279 public void setEditionRange(int editionRange) {
280 this.editionRange = editionRange;
284 * Returns the range of editions that should be replaced.
286 * @return The range of editions to replace
288 public int getEditionRange() {
293 * Returns whether the options for this file have been modified, i.e. are
294 * not at their default values.
296 * @return <code>true</code> if the options have been modified,
297 * <code>false</code> if they are at default values
299 public boolean isCustom() {
300 if (insert != DEFAULT_INSERT) {
303 if (!customKey.equals(DEFAULT_CUSTOM_KEY)) {
306 if (!defaultMimeType.equals(mimeType)) {
309 if (!DEFAULT_CONTAINER.equals(container)) {
312 if (replaceEdition != DEFAULT_REPLACE_EDITION) {
315 if (editionRange != DEFAULT_EDITION_RANGE) {
318 if (insertRedirect != DEFAULT_INSERT_REDIRECT) {