jSite: First commit : verion 4.0 (written by Bombe)
[jSite.git] / src / de / todesbaum / jsite / application / FileOption.java
1 /*
2  * jSite - a tool for uploading websites into Freenet
3  * Copyright (C) 2006 David Roden
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 package de.todesbaum.jsite.application;
21
22 public class FileOption {
23
24         private static final boolean DEFAULT_INSERT = true;
25         private static final String DEFAULT_CUSTOM_KEY = "CHK@";
26         private static final String DEFAULT_CONTAINER = "";
27         private static final int DEFAULT_EDITION_RANGE = 3;
28         private static final boolean DEFAULT_REPLACE_EDITION = false;
29
30         private boolean insert;
31         private String customKey;
32         private final String defaultMimeType;
33         private String mimeType;
34         private String container;
35         private int editionRange;
36         private boolean replaceEdition;
37
38         public FileOption(String defaultMimeType) {
39                 insert = DEFAULT_INSERT;
40                 customKey = DEFAULT_CUSTOM_KEY;
41                 this.defaultMimeType = defaultMimeType;
42                 this.mimeType = defaultMimeType;
43                 this.container = DEFAULT_CONTAINER;
44                 this.editionRange = DEFAULT_EDITION_RANGE;
45                 this.replaceEdition = DEFAULT_REPLACE_EDITION;
46         }
47
48         /**
49          * @return Returns the customKey.
50          */
51         public String getCustomKey() {
52                 return customKey;
53         }
54
55         /**
56          * @param customKey
57          *            The customKey to set.
58          */
59         public void setCustomKey(String customKey) {
60                 if (customKey == null) {
61                         customKey = "";
62                 }
63                 this.customKey = customKey;
64         }
65
66         /**
67          * @return Returns the insert.
68          */
69         public boolean isInsert() {
70                 return insert;
71         }
72
73         /**
74          * @param insert
75          *            The insert to set.
76          */
77         public void setInsert(boolean insert) {
78                 this.insert = insert;
79         }
80
81         public void setMimeType(String mimeType) {
82                 if (mimeType == null) {
83                         mimeType = defaultMimeType;
84                 }
85                 this.mimeType = mimeType;
86         }
87
88         public String getMimeType() {
89                 return mimeType;
90         }
91
92         /**
93          * @return Returns the container.
94          */
95         public String getContainer() {
96                 return container;
97         }
98
99         /**
100          * @param container
101          *            The container to set.
102          */
103         public void setContainer(String container) {
104                 if (container == null) {
105                         container = DEFAULT_CONTAINER;
106                 }
107                 this.container = container;
108         }
109
110         public void setReplaceEdition(boolean replaceEdition) {
111                 this.replaceEdition = replaceEdition;
112         }
113
114         public boolean getReplaceEdition() {
115                 return replaceEdition;
116         }
117
118         public void setEditionRange(int editionRange) {
119                 this.editionRange = editionRange;
120         }
121
122         public int getEditionRange() {
123                 return editionRange;
124         }
125
126         public boolean isCustom() {
127                 if (insert != DEFAULT_INSERT)
128                         return true;
129                 if (!customKey.equals(DEFAULT_CUSTOM_KEY))
130                         return true;
131                 if (!defaultMimeType.equals(mimeType))
132                         return true;
133                 if (!DEFAULT_CONTAINER.equals(container))
134                         return true;
135                 if (replaceEdition != DEFAULT_REPLACE_EDITION)
136                         return true;
137                 if (editionRange != DEFAULT_EDITION_RANGE)
138                         return true;
139                 return false;
140         }
141
142 }