2 * jSite - a tool for uploading websites into Freenet
3 * Copyright (C) 2006 David Roden
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.
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.
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.
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;
106 * Returns whether the file should be inserted. If a file is not inserted, a
107 * custom key has to be specified for it.
109 * @see #setCustomKey(String)
110 * @return <code>true</code> if the file should be inserted,
111 * <code>false</code> otherwise
113 public boolean isInsert() {
118 * Sets whether the file should be inserted. If a file is not inserted, a
119 * custom key has to be specified for it.
122 * <code>true</code> if the file should be inserted,
123 * <code>false</code> otherwise
125 public void setInsert(boolean insert) {
126 this.insert = insert;
130 * Sets the MIME type of the file. Setting the MIME type to
131 * <code>null</code> will set the MIME type to the default MIME type.
134 * The MIME type of the file
136 public void setMimeType(String mimeType) {
137 if (mimeType == null) {
138 mimeType = defaultMimeType;
140 this.mimeType = mimeType;
144 * Returns the MIME type of the file. If no custom MIME type has been set,
145 * the default MIME type is returned.
147 * @return The MIME type of the file
149 public String getMimeType() {
154 * Returns the name of the container this file should be put in.
156 * @return The name of the container
158 public String getContainer() {
163 * Sets the name of the container this file should be put in.
166 * The name of the container
168 public void setContainer(String container) {
169 if (container == null) {
170 container = DEFAULT_CONTAINER;
172 this.container = container;
176 * Sets whether the file should have “$[EDITION+<i>n</i>]” tags replaced.
178 * @param replaceEdition
179 * <code>true</code> to replace tags, <code>false</code> not
182 public void setReplaceEdition(boolean replaceEdition) {
183 this.replaceEdition = replaceEdition;
187 * Returns whether the file should have “$[EDITION+<i>n</i>]” tags
190 * @return <code>true</code> if tags should be replaced,
191 * <code>false</code> otherwise
193 public boolean getReplaceEdition() {
194 return replaceEdition;
198 * Sets the range of editions that should be replaced.
200 * @param editionRange
201 * The range editions to replace
203 public void setEditionRange(int editionRange) {
204 this.editionRange = editionRange;
208 * Returns the range of editions that should be replaced.
210 * @return The range of editions to replace
212 public int getEditionRange() {
217 * Returns whether the options for this file have been modified, i.e. are
218 * not at their default values.
220 * @return <code>true</code> if the options have been modified,
221 * <code>false</code> if they are at default values
223 public boolean isCustom() {
224 if (insert != DEFAULT_INSERT) {
227 if (!customKey.equals(DEFAULT_CUSTOM_KEY)) {
230 if (!defaultMimeType.equals(mimeType)) {
233 if (!DEFAULT_CONTAINER.equals(container)) {
236 if (replaceEdition != DEFAULT_REPLACE_EDITION) {
239 if (editionRange != DEFAULT_EDITION_RANGE) {