2 * jSite2 - Project.java -
3 * Copyright © 2008 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 net.pterodactylus.jsite.project;
22 import java.beans.PropertyChangeListener;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
28 import net.pterodactylus.util.beans.AbstractBean;
31 * Container for project information. A Project is capable of notifying
32 * {@link PropertyChangeListener}s if any of the contained properties change.
34 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
36 public class Project extends AbstractBean {
38 /** Name of the “name” property. */
39 public static final String PROPERTY_NAME = "name";
41 /** Name of the “description” property. */
42 public static final String PROPERTY_DESCRIPTION = "description";
44 /** Name of the “public key” property. */
45 public static final String PROPERTY_PUBLIC_KEY = "publicKey";
47 /** Name of the “private key” property. */
48 public static final String PROPERTY_PRIVATE_KEY = "privateKey";
50 /** Name of the “base path” property. */
51 public static final String PROPERTY_BASE_PATH = "basePath";
53 /** Name of the “default file” property. */
54 public static final String PROPERTY_DEFAULT_FILE = "defaultFile";
59 /** The name of the project. */
62 /** The description of the project. */
63 private String description;
65 /** The public key. */
66 private String publicKey;
68 /** The private key. */
69 private String privateKey;
71 /** The base path of the project. */
72 private String basePath;
74 /** The default file. */
75 private String defaultFile;
78 private final Map<String, Override> overrides = new HashMap<String, Override>();
81 * Creates a new project.
88 * Clones the given project.
92 Project(Project project) {
93 this.name = project.name;
94 this.description = project.description;
95 this.publicKey = project.publicKey;
96 this.privateKey = project.privateKey;
97 this.basePath = project.basePath;
101 * Returns the internal ID.
103 * @return The internal ID
110 * Sets the internal ID.
115 void setId(String id) {
120 * Returns the name of the project.
122 * @return The name of the project
124 public String getName() {
129 * Sets the name of the project.
132 * The name of the project
134 public void setName(String name) {
135 String oldName = this.name;
137 fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
141 * Returns the description of the project.
143 * @return The description of the project
145 public String getDescription() {
150 * Sets the description of the project
153 * The description of the project
155 public void setDescription(String description) {
156 String oldDescription = this.description;
157 this.description = description;
158 fireIfPropertyChanged(PROPERTY_DESCRIPTION, oldDescription, description);
162 * Returns the public key of the project.
164 * @return The public key of the project
166 public String getPublicKey() {
171 * Sets the public key of the project.
174 * The public key of the project
176 void setPublicKey(String publicKey) {
177 String oldPublicKey = this.publicKey;
178 this.publicKey = publicKey;
179 fireIfPropertyChanged(PROPERTY_PUBLIC_KEY, oldPublicKey, publicKey);
183 * Returns the private key of the project.
185 * @return The private key of the project
187 public String getPrivateKey() {
192 * Sets the private key of the project.
195 * The private key of the project
197 void setPrivateKey(String privateKey) {
198 String oldPrivateKey = this.privateKey;
199 this.privateKey = privateKey;
200 fireIfPropertyChanged(PROPERTY_PRIVATE_KEY, oldPrivateKey, privateKey);
204 * Returns the base path of the project.
206 * @return The base path of the project
208 public String getBasePath() {
213 * Sets the base path of the project.
216 * The base path of the project
218 public void setBasePath(String basePath) {
219 String oldBasePath = this.basePath;
220 this.basePath = basePath;
221 fireIfPropertyChanged(PROPERTY_BASE_PATH, oldBasePath, basePath);
225 * Returns the default file.
227 * @return The default file
229 public String getDefaultFile() {
234 * Sets the default file.
239 public void setDefaultFile(String defaultFile) {
240 String oldDefaultFile = this.defaultFile;
241 this.defaultFile = defaultFile;
242 fireIfPropertyChanged(PROPERTY_DEFAULT_FILE, oldDefaultFile, defaultFile);
246 * Adds an override for the given file.
251 * The override for the file
253 public void addOverride(String filePath, Override override) {
254 overrides.put(filePath, override);
258 * Removes the override for the given file.
261 * The file path for which to remove the override
263 public void removeOverride(String filePath) {
264 overrides.remove(filePath);
268 * Returns the list of {@link Override}s.
270 * @return All overrides
272 public Map<String, Override> getOverrides() {
277 * Scans the base path for files and returns the {@link ProjectFile} for the
278 * base path. From this file it is possible to reach all files in the base
281 * This method is disk-intensive and may take some time on larger
284 * @return The file for the base path
286 public ProjectFile getBaseFile() {
291 * Implementation of a {@link ProjectFile}.
293 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
295 private static class ProjectFileImpl implements ProjectFile {
297 private final ProjectFileImpl parentProjectFile;
298 private final String name;
299 private final boolean directory;
300 private final boolean hidden;
301 private List<ProjectFileImpl> childProjectFiles = new ArrayList<ProjectFileImpl>();
305 public ProjectFileImpl(ProjectFileImpl parentProjectFile, String name, boolean isDirectory, boolean isHidden) {
306 this.parentProjectFile = parentProjectFile;
308 this.directory = isDirectory;
309 this.hidden = isHidden;
313 // INTERFACE ProjectFile
317 * @see net.pterodactylus.jsite.project.ProjectFile#getName()
319 public String getName() {
324 * @see net.pterodactylus.jsite.project.ProjectFile#getParents()
326 public List<ProjectFile> getParents() {
327 List<ProjectFile> parentProjectFiles = new ArrayList<ProjectFile>();
328 ProjectFileImpl currentProjectFile = this;
330 parentProjectFiles.add(0, currentProjectFile);
331 } while ((currentProjectFile = currentProjectFile.parentProjectFile) != null);
332 return parentProjectFiles;
336 * @see net.pterodactylus.jsite.project.ProjectFile#isFile()
338 public boolean isFile() {
339 // TODO Auto-generated method stub
344 * @see net.pterodactylus.jsite.project.ProjectFile#isDirectory()
346 public boolean isDirectory() {
347 // TODO Auto-generated method stub
352 * @see net.pterodactylus.jsite.project.ProjectFile#isHidden()
354 public boolean isHidden() {
355 // TODO Auto-generated method stub
360 * @see net.pterodactylus.jsite.project.ProjectFile#getFiles()
362 public List<ProjectFile> getFiles() {
363 // TODO Auto-generated method stub
371 private ProjectFileImpl getParent() {
372 return parentProjectFile;