add default file
[jSite2.git] / src / net / pterodactylus / jsite / project / Project.java
1 /*
2  * jSite2 - Project.java -
3  * Copyright © 2008 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 net.pterodactylus.jsite.project;
21
22 import java.beans.PropertyChangeListener;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import net.pterodactylus.util.beans.AbstractBean;
27
28 /**
29  * Container for project information. A Project is capable of notifying
30  * {@link PropertyChangeListener}s if any of the contained properties change.
31  *
32  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
33  */
34 public class Project extends AbstractBean {
35
36         /** Name of the “name” property. */
37         public static final String PROPERTY_NAME = "name";
38
39         /** Name of the “description” property. */
40         public static final String PROPERTY_DESCRIPTION = "description";
41
42         /** Name of the “public key” property. */
43         public static final String PROPERTY_PUBLIC_KEY = "publicKey";
44
45         /** Name of the “private key” property. */
46         public static final String PROPERTY_PRIVATE_KEY = "privateKey";
47
48         /** Name of the “base path” property. */
49         public static final String PROPERTY_BASE_PATH = "basePath";
50
51         /** Name of the “default file” property. */
52         public static final String PROPERTY_DEFAULT_FILE = "defaultFile";
53
54         /** Internal ID. */
55         private String id;
56
57         /** The name of the project. */
58         private String name;
59
60         /** The description of the project. */
61         private String description;
62
63         /** The public key. */
64         private String publicKey;
65
66         /** The private key. */
67         private String privateKey;
68
69         /** The base path of the project. */
70         private String basePath;
71
72         /** The default file. */
73         private String defaultFile;
74
75         /** The overrides. */
76         private final Map<String, Override> overrides = new HashMap<String, Override>();
77
78         /**
79          * Creates a new project.
80          */
81         public Project() {
82                 /* do nothing. */
83         }
84
85         /**
86          * Clones the given project.
87          *
88          * @param project
89          */
90         Project(Project project) {
91                 this.name = project.name;
92                 this.description = project.description;
93                 this.publicKey = project.publicKey;
94                 this.privateKey = project.privateKey;
95                 this.basePath = project.basePath;
96         }
97
98         /**
99          * Returns the internal ID.
100          *
101          * @return The internal ID
102          */
103         String getId() {
104                 return id;
105         }
106
107         /**
108          * Sets the internal ID.
109          *
110          * @param id
111          *            The internal ID
112          */
113         void setId(String id) {
114                 this.id = id;
115         }
116
117         /**
118          * Returns the name of the project.
119          *
120          * @return The name of the project
121          */
122         public String getName() {
123                 return name;
124         }
125
126         /**
127          * Sets the name of the project.
128          *
129          * @param name
130          *            The name of the project
131          */
132         public void setName(String name) {
133                 String oldName = this.name;
134                 this.name = name;
135                 fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
136         }
137
138         /**
139          * Returns the description of the project.
140          *
141          * @return The description of the project
142          */
143         public String getDescription() {
144                 return description;
145         }
146
147         /**
148          * Sets the description of the project
149          *
150          * @param description
151          *            The description of the project
152          */
153         public void setDescription(String description) {
154                 String oldDescription = this.description;
155                 this.description = description;
156                 fireIfPropertyChanged(PROPERTY_DESCRIPTION, oldDescription, description);
157         }
158
159         /**
160          * Returns the public key of the project.
161          *
162          * @return The public key of the project
163          */
164         public String getPublicKey() {
165                 return publicKey;
166         }
167
168         /**
169          * Sets the public key of the project.
170          *
171          * @param publicKey
172          *            The public key of the project
173          */
174         void setPublicKey(String publicKey) {
175                 String oldPublicKey = this.publicKey;
176                 this.publicKey = publicKey;
177                 fireIfPropertyChanged(PROPERTY_PUBLIC_KEY, oldPublicKey, publicKey);
178         }
179
180         /**
181          * Returns the private key of the project.
182          *
183          * @return The private key of the project
184          */
185         public String getPrivateKey() {
186                 return privateKey;
187         }
188
189         /**
190          * Sets the private key of the project.
191          *
192          * @param privateKey
193          *            The private key of the project
194          */
195         void setPrivateKey(String privateKey) {
196                 String oldPrivateKey = this.privateKey;
197                 this.privateKey = privateKey;
198                 fireIfPropertyChanged(PROPERTY_PRIVATE_KEY, oldPrivateKey, privateKey);
199         }
200
201         /**
202          * Returns the base path of the project.
203          *
204          * @return The base path of the project
205          */
206         public String getBasePath() {
207                 return basePath;
208         }
209
210         /**
211          * Sets the base path of the project.
212          *
213          * @param basePath
214          *            The base path of the project
215          */
216         public void setBasePath(String basePath) {
217                 String oldBasePath = this.basePath;
218                 this.basePath = basePath;
219                 fireIfPropertyChanged(PROPERTY_BASE_PATH, oldBasePath, basePath);
220         }
221
222         /**
223          * Returns the default file.
224          *
225          * @return The default file
226          */
227         public String getDefaultFile() {
228                 return defaultFile;
229         }
230
231         /**
232          * Sets the default file.
233          *
234          * @param defaultFile
235          *            The default file
236          */
237         public void setDefaultFile(String defaultFile) {
238                 String oldDefaultFile = this.defaultFile;
239                 this.defaultFile = defaultFile;
240                 fireIfPropertyChanged(PROPERTY_DEFAULT_FILE, oldDefaultFile, defaultFile);
241         }
242
243         /**
244          * Adds an override for the given file.
245          *
246          * @param filePath
247          *            The file path
248          * @param override
249          *            The override for the file
250          */
251         public void addOverride(String filePath, Override override) {
252                 overrides.put(filePath, override);
253         }
254
255         /**
256          * Removes the override for the given file.
257          *
258          * @param filePath
259          *            The file path for which to remove the override
260          */
261         public void removeOverride(String filePath) {
262                 overrides.remove(filePath);
263         }
264
265         /**
266          * Returns the list of {@link Override}s.
267          *
268          * @return All overrides
269          */
270         public Map<String, Override> getOverrides() {
271                 return overrides;
272         }
273
274 }