work on new project file backend
[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.List;
25 import java.util.Map;
26
27 import net.pterodactylus.util.beans.AbstractBean;
28
29 /**
30  * Container for project information. A Project is capable of notifying
31  * {@link PropertyChangeListener}s if any of the contained properties change.
32  *
33  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
34  */
35 public class Project extends AbstractBean {
36
37         /** Name of the “name” property. */
38         public static final String PROPERTY_NAME = "name";
39
40         /** Name of the “description” property. */
41         public static final String PROPERTY_DESCRIPTION = "description";
42
43         /** Name of the “public key” property. */
44         public static final String PROPERTY_PUBLIC_KEY = "publicKey";
45
46         /** Name of the “private key” property. */
47         public static final String PROPERTY_PRIVATE_KEY = "privateKey";
48
49         /** Name of the “base path” property. */
50         public static final String PROPERTY_BASE_PATH = "basePath";
51
52         /** Name of the “default file” property. */
53         public static final String PROPERTY_DEFAULT_FILE = "defaultFile";
54
55         /** Internal ID. */
56         private String id;
57
58         /** The name of the project. */
59         private String name;
60
61         /** The description of the project. */
62         private String description;
63
64         /** The public key. */
65         private String publicKey;
66
67         /** The private key. */
68         private String privateKey;
69
70         /** The base path of the project. */
71         private String basePath;
72
73         /** The default file. */
74         private String defaultFile;
75
76         /** The overrides. */
77         private final Map<String, Override> overrides = new HashMap<String, Override>();
78
79         /**
80          * Creates a new project.
81          */
82         public Project() {
83                 /* do nothing. */
84         }
85
86         /**
87          * Clones the given project.
88          *
89          * @param project
90          */
91         Project(Project project) {
92                 this.name = project.name;
93                 this.description = project.description;
94                 this.publicKey = project.publicKey;
95                 this.privateKey = project.privateKey;
96                 this.basePath = project.basePath;
97         }
98
99         /**
100          * Returns the internal ID.
101          *
102          * @return The internal ID
103          */
104         String getId() {
105                 return id;
106         }
107
108         /**
109          * Sets the internal ID.
110          *
111          * @param id
112          *            The internal ID
113          */
114         void setId(String id) {
115                 this.id = id;
116         }
117
118         /**
119          * Returns the name of the project.
120          *
121          * @return The name of the project
122          */
123         public String getName() {
124                 return name;
125         }
126
127         /**
128          * Sets the name of the project.
129          *
130          * @param name
131          *            The name of the project
132          */
133         public void setName(String name) {
134                 String oldName = this.name;
135                 this.name = name;
136                 fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
137         }
138
139         /**
140          * Returns the description of the project.
141          *
142          * @return The description of the project
143          */
144         public String getDescription() {
145                 return description;
146         }
147
148         /**
149          * Sets the description of the project
150          *
151          * @param description
152          *            The description of the project
153          */
154         public void setDescription(String description) {
155                 String oldDescription = this.description;
156                 this.description = description;
157                 fireIfPropertyChanged(PROPERTY_DESCRIPTION, oldDescription, description);
158         }
159
160         /**
161          * Returns the public key of the project.
162          *
163          * @return The public key of the project
164          */
165         public String getPublicKey() {
166                 return publicKey;
167         }
168
169         /**
170          * Sets the public key of the project.
171          *
172          * @param publicKey
173          *            The public key of the project
174          */
175         void setPublicKey(String publicKey) {
176                 String oldPublicKey = this.publicKey;
177                 this.publicKey = publicKey;
178                 fireIfPropertyChanged(PROPERTY_PUBLIC_KEY, oldPublicKey, publicKey);
179         }
180
181         /**
182          * Returns the private key of the project.
183          *
184          * @return The private key of the project
185          */
186         public String getPrivateKey() {
187                 return privateKey;
188         }
189
190         /**
191          * Sets the private key of the project.
192          *
193          * @param privateKey
194          *            The private key of the project
195          */
196         void setPrivateKey(String privateKey) {
197                 String oldPrivateKey = this.privateKey;
198                 this.privateKey = privateKey;
199                 fireIfPropertyChanged(PROPERTY_PRIVATE_KEY, oldPrivateKey, privateKey);
200         }
201
202         /**
203          * Returns the base path of the project.
204          *
205          * @return The base path of the project
206          */
207         public String getBasePath() {
208                 return basePath;
209         }
210
211         /**
212          * Sets the base path of the project.
213          *
214          * @param basePath
215          *            The base path of the project
216          */
217         public void setBasePath(String basePath) {
218                 String oldBasePath = this.basePath;
219                 this.basePath = basePath;
220                 fireIfPropertyChanged(PROPERTY_BASE_PATH, oldBasePath, basePath);
221         }
222
223         /**
224          * Returns the default file.
225          *
226          * @return The default file
227          */
228         public String getDefaultFile() {
229                 return defaultFile;
230         }
231
232         /**
233          * Sets the default file.
234          *
235          * @param defaultFile
236          *            The default file
237          */
238         public void setDefaultFile(String defaultFile) {
239                 String oldDefaultFile = this.defaultFile;
240                 this.defaultFile = defaultFile;
241                 fireIfPropertyChanged(PROPERTY_DEFAULT_FILE, oldDefaultFile, defaultFile);
242         }
243
244         /**
245          * Adds an override for the given file.
246          *
247          * @param filePath
248          *            The file path
249          * @param override
250          *            The override for the file
251          */
252         public void addOverride(String filePath, Override override) {
253                 overrides.put(filePath, override);
254         }
255
256         /**
257          * Removes the override for the given file.
258          *
259          * @param filePath
260          *            The file path for which to remove the override
261          */
262         public void removeOverride(String filePath) {
263                 overrides.remove(filePath);
264         }
265
266         /**
267          * Returns the list of {@link Override}s.
268          *
269          * @return All overrides
270          */
271         public Map<String, Override> getOverrides() {
272                 return overrides;
273         }
274
275         /**
276          * Scans the base path for files and returns the {@link ProjectFile} for the
277          * base path. From this file it is possible to reach all files in the base
278          * path.
279          *
280          * This method is disk-intensive and may take some time on larger
281          * directories!
282          *
283          * @return The file for the base path
284          */
285         public ProjectFile getBaseFile() {
286
287         }
288
289         /**
290          * Implementation of a {@link ProjectFile}.
291          *
292          * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
293          */
294         private static class ProjectFileImpl implements ProjectFile {
295
296                 /**
297                  * @see net.pterodactylus.jsite.project.ProjectFile#getName()
298                  */
299                 public String getName() {
300                         // TODO Auto-generated method stub
301                         return null;
302                 }
303
304                 /**
305                  * @see net.pterodactylus.jsite.project.ProjectFile#getParents()
306                  */
307                 public List<ProjectFile> getParents() {
308                         // TODO Auto-generated method stub
309                         return null;
310                 }
311
312                 /**
313                  * @see net.pterodactylus.jsite.project.ProjectFile#isFile()
314                  */
315                 public boolean isFile() {
316                         // TODO Auto-generated method stub
317                         return false;
318                 }
319
320                 /**
321                  * @see net.pterodactylus.jsite.project.ProjectFile#isDirectory()
322                  */
323                 public boolean isDirectory() {
324                         // TODO Auto-generated method stub
325                         return false;
326                 }
327
328                 /**
329                  * @see net.pterodactylus.jsite.project.ProjectFile#isHidden()
330                  */
331                 public boolean isHidden() {
332                         // TODO Auto-generated method stub
333                         return false;
334                 }
335
336                 /**
337                  * @see net.pterodactylus.jsite.project.ProjectFile#getFiles()
338                  */
339                 public List<ProjectFile> getFiles() {
340                         // TODO Auto-generated method stub
341                         return null;
342                 }
343         }
344
345 }