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 changed name. */
54 private String changedName;
56 /** The default MIME type. */
57 private final String defaultMimeType;
59 /** The current MIME type. */
60 private String mimeType;
63 private String container;
65 /** The edition range. */
66 private int editionRange;
68 /** The replace edition state. */
69 private boolean replaceEdition;
72 * Creates new file options.
74 * @param defaultMimeType
75 * The default MIME type of the file
77 public FileOption(String defaultMimeType) {
78 insert = DEFAULT_INSERT;
79 customKey = DEFAULT_CUSTOM_KEY;
80 this.defaultMimeType = defaultMimeType;
81 mimeType = defaultMimeType;
82 container = DEFAULT_CONTAINER;
83 editionRange = DEFAULT_EDITION_RANGE;
84 replaceEdition = DEFAULT_REPLACE_EDITION;
88 * Returns the custom key. The custom key is only used when
89 * {@link #isInsert()} and {@link #isInsertRedirect()} both return {@code
92 * @return The custom key
94 public String getCustomKey() {
99 * Sets the custom key. The custom key is only used when {@link #isInsert()}
100 * and {@link #isInsertRedirect()} both return {@code true}.
105 public void setCustomKey(String customKey) {
106 if (customKey == null) {
109 this.customKey = customKey;
114 * Returns whether the file should be inserted. If a file is not inserted
115 * and {@link #isInsertRedirect()} is also {@code false}, the file will not
116 * be inserted at all.
118 * @see #setCustomKey(String)
119 * @return <code>true</code> if the file should be inserted,
120 * <code>false</code> otherwise
122 public boolean isInsert() {
127 * Sets whether the file should be inserted. If a file is not inserted and
128 * {@link #isInsertRedirect()} is also {@code false}, the file will not be
132 * <code>true</code> if the file should be inserted,
133 * <code>false</code> otherwise
135 public void setInsert(boolean insert) {
136 this.insert = insert;
140 * Returns whether a redirect to a different key should be inserted. This
141 * will only matter if {@link #isInsert()} returns {@code false}. The key
142 * that should be redirected to still needs to be specified via
143 * {@link #setCustomKey(String)}.
145 * @return {@code true} if a redirect should be inserted, {@code false}
148 public boolean isInsertRedirect() {
149 return insertRedirect;
153 * Sets whether a redirect should be inserted. This will only matter if
154 * {@link #isInsert()} returns {@code false}, i.e. it has been
155 * {@link #setInsert(boolean)} to {@code false}. The key that should be
156 * redirected to still needs to be specified via
157 * {@link #setCustomKey(String)}.
159 * @param insertRedirect
160 * {@code true} if a redirect should be inserted, {@code false}
163 public void setInsertRedirect(boolean insertRedirect) {
164 this.insertRedirect = insertRedirect;
168 * Returns whether this file has a changed name. Use
169 * {@link #getChangedName()} is this method returns {@code true}.
171 * @return {@code true} if this file has a changed name, {@code false}
174 public boolean hasChangedName() {
175 return (changedName != null) && (changedName.length() > 0);
179 * Returns the changed name for this file. This method will return {@code
180 * null} or an empty {@link String} if this file should not be renamed.
182 * @return The changed name, or {@code null} if this file should not be
185 public String getChangedName() {
190 * Sets the changed name for this file. Setting the changed file to {@code
191 * null} or an empty {@link String} will disable renaming.
194 * The new changed name for this file
196 public void setChangedName(String changedName) {
197 this.changedName = changedName;
201 * Sets the MIME type of the file. Setting the MIME type to
202 * <code>null</code> will set the MIME type to the default MIME type.
205 * The MIME type of the file
207 public void setMimeType(String mimeType) {
208 if (mimeType == null) {
209 this.mimeType = defaultMimeType;
211 this.mimeType = mimeType;
216 * Returns the MIME type of the file. If no custom MIME type has been set,
217 * the default MIME type is returned.
219 * @return The MIME type of the file
221 public String getMimeType() {
226 * Returns the name of the container this file should be put in.
228 * @return The name of the container
230 public String getContainer() {
235 * Sets the name of the container this file should be put in.
238 * The name of the container
240 public void setContainer(String container) {
241 if (container == null) {
242 this.container = DEFAULT_CONTAINER;
244 this.container = container;
249 * Sets whether the file should have “$[EDITION+<i>n</i>]” tags replaced.
251 * @param replaceEdition
252 * <code>true</code> to replace tags, <code>false</code> not to
255 public void setReplaceEdition(boolean replaceEdition) {
256 this.replaceEdition = replaceEdition;
260 * Returns whether the file should have “$[EDITION+<i>n</i>]” tags replaced.
262 * @return <code>true</code> if tags should be replaced, <code>false</code>
265 public boolean getReplaceEdition() {
266 return replaceEdition;
270 * Sets the range of editions that should be replaced.
272 * @param editionRange
273 * The range editions to replace
275 public void setEditionRange(int editionRange) {
276 this.editionRange = editionRange;
280 * Returns the range of editions that should be replaced.
282 * @return The range of editions to replace
284 public int getEditionRange() {
289 * Returns whether the options for this file have been modified, i.e. are
290 * not at their default values.
292 * @return <code>true</code> if the options have been modified,
293 * <code>false</code> if they are at default values
295 public boolean isCustom() {
296 if (insert != DEFAULT_INSERT) {
299 if (!customKey.equals(DEFAULT_CUSTOM_KEY)) {
302 if (!defaultMimeType.equals(mimeType)) {
305 if (!DEFAULT_CONTAINER.equals(container)) {
308 if (replaceEdition != DEFAULT_REPLACE_EDITION) {
311 if (editionRange != DEFAULT_EDITION_RANGE) {