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 /** The custom key. */
48 private String customKey;
50 /** The default MIME type. */
51 private final String defaultMimeType;
53 /** The current MIME type. */
54 private String mimeType;
57 private String container;
59 /** The edition range. */
60 private int editionRange;
62 /** The replace edition state. */
63 private boolean replaceEdition;
66 * Creates new file options.
68 * @param defaultMimeType
69 * The default MIME type of the file
71 public FileOption(String defaultMimeType) {
72 insert = DEFAULT_INSERT;
73 customKey = DEFAULT_CUSTOM_KEY;
74 this.defaultMimeType = defaultMimeType;
75 mimeType = defaultMimeType;
76 container = DEFAULT_CONTAINER;
77 editionRange = DEFAULT_EDITION_RANGE;
78 replaceEdition = DEFAULT_REPLACE_EDITION;
82 * Returns the custom key. The custom key is only used when
83 * {@link #isInsert()} returns <code>true</code>.
85 * @return The custom key
87 public String getCustomKey() {
92 * Sets the custom key. The custom key is only used when {@link #isInsert()}
93 * returns <code>true</code>.
98 public void setCustomKey(String customKey) {
99 if (customKey == null) {
102 this.customKey = customKey;
107 * Returns whether the file should be inserted. If a file is not inserted, a
108 * custom key has to be specified for it.
110 * @see #setCustomKey(String)
111 * @return <code>true</code> if the file should be inserted,
112 * <code>false</code> otherwise
114 public boolean isInsert() {
119 * Sets whether the file should be inserted. If a file is not inserted, a
120 * custom key has to be specified for it.
123 * <code>true</code> if the file should be inserted,
124 * <code>false</code> otherwise
126 public void setInsert(boolean insert) {
127 this.insert = insert;
131 * Sets the MIME type of the file. Setting the MIME type to
132 * <code>null</code> will set the MIME type to the default MIME type.
135 * The MIME type of the file
137 public void setMimeType(String mimeType) {
138 if (mimeType == null) {
139 this.mimeType = defaultMimeType;
141 this.mimeType = mimeType;
146 * Returns the MIME type of the file. If no custom MIME type has been set,
147 * the default MIME type is returned.
149 * @return The MIME type of the file
151 public String getMimeType() {
156 * Returns the name of the container this file should be put in.
158 * @return The name of the container
160 public String getContainer() {
165 * Sets the name of the container this file should be put in.
168 * The name of the container
170 public void setContainer(String container) {
171 if (container == null) {
172 this.container = DEFAULT_CONTAINER;
174 this.container = container;
179 * Sets whether the file should have “$[EDITION+<i>n</i>]” tags replaced.
181 * @param replaceEdition
182 * <code>true</code> to replace tags, <code>false</code> not to
185 public void setReplaceEdition(boolean replaceEdition) {
186 this.replaceEdition = replaceEdition;
190 * Returns whether the file should have “$[EDITION+<i>n</i>]” tags replaced.
192 * @return <code>true</code> if tags should be replaced, <code>false</code>
195 public boolean getReplaceEdition() {
196 return replaceEdition;
200 * Sets the range of editions that should be replaced.
202 * @param editionRange
203 * The range editions to replace
205 public void setEditionRange(int editionRange) {
206 this.editionRange = editionRange;
210 * Returns the range of editions that should be replaced.
212 * @return The range of editions to replace
214 public int getEditionRange() {
219 * Returns whether the options for this file have been modified, i.e. are
220 * not at their default values.
222 * @return <code>true</code> if the options have been modified,
223 * <code>false</code> if they are at default values
225 public boolean isCustom() {
226 if (insert != DEFAULT_INSERT) {
229 if (!customKey.equals(DEFAULT_CUSTOM_KEY)) {
232 if (!defaultMimeType.equals(mimeType)) {
235 if (!DEFAULT_CONTAINER.equals(container)) {
238 if (replaceEdition != DEFAULT_REPLACE_EDITION) {
241 if (editionRange != DEFAULT_EDITION_RANGE) {