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;
24 import java.util.ArrayList;
25 import java.util.List;
27 import net.pterodactylus.util.beans.AbstractBean;
30 * Container for project information. A Project is capable of notifying
31 * {@link PropertyChangeListener}s if any of the contained properties change.
33 * @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 “base path entries” property. */
54 public static final String PROPERTY_BASE_PATH_ENTRIES = "basePathEntries";
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 list of files from the base path. */
75 private List<Entry> basePathEntries = new ArrayList<Entry>();
78 * Returns the internal ID.
80 * @return The internal ID
87 * Sets the internal ID.
92 void setId(String id) {
97 * Returns the name of the project.
99 * @return The name of the project
101 public String getName() {
106 * Sets the name of the project.
109 * The name of the project
111 public void setName(String name) {
112 String oldName = this.name;
114 fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
118 * Returns the description of the project.
120 * @return The description of the project
122 public String getDescription() {
127 * Sets the description of the project
130 * The description of the project
132 public void setDescription(String description) {
133 String oldDescription = this.description;
134 this.description = description;
135 fireIfPropertyChanged(PROPERTY_DESCRIPTION, oldDescription, description);
139 * Returns the public key of the project.
141 * @return The public key of the project
143 public String getPublicKey() {
148 * Sets the public key of the project.
151 * The public key of the project
153 void setPublicKey(String publicKey) {
154 String oldPublicKey = this.publicKey;
155 this.publicKey = publicKey;
156 fireIfPropertyChanged(PROPERTY_PUBLIC_KEY, oldPublicKey, publicKey);
160 * Returns the private key of the project.
162 * @return The private key of the project
164 public String getPrivateKey() {
169 * Sets the private key of the project.
172 * The private key of the project
174 void setPrivateKey(String privateKey) {
175 String oldPrivateKey = this.privateKey;
176 this.privateKey = privateKey;
177 fireIfPropertyChanged(PROPERTY_PRIVATE_KEY, oldPrivateKey, privateKey);
181 * Returns the base path of the project.
183 * @return The base path of the project
185 public String getBasePath() {
190 * Sets the base path of the project.
193 * The base path of the project
195 public void setBasePath(String basePath) {
196 String oldBasePath = this.basePath;
197 this.basePath = basePath;
198 fireIfPropertyChanged(PROPERTY_BASE_PATH, oldBasePath, basePath);
202 * Rescans the base path for new or changed files.
204 public void rescanBasePath() {
205 List<Entry> entries = new ArrayList<Entry>();
206 scanPath("", entries);
207 basePathEntries.clear();
208 basePathEntries.addAll(entries);
209 firePropertyChange(PROPERTY_BASE_PATH_ENTRIES, null, null);
213 * Returns the list of files from the base path.
215 * @return The list of files from the base path
217 public List<Entry> getBasePathEntries() {
218 return basePathEntries;
226 * Scans the given path relative to {@link #basePath} for files and adds
227 * them to the given list of entries.
230 * The current path, relative to the base path
232 * The list of entries
234 private void scanPath(String currentPath, List<Entry> entries) {
235 File currentDirectory = new File(basePath + File.separatorChar + currentPath);
236 if (!currentDirectory.isDirectory()) {
239 for (File file: currentDirectory.listFiles()) {
240 String fileName = currentPath + file.getName();
241 if (file.isDirectory()) {
242 scanPath(fileName + File.separatorChar, entries);
245 PhysicalEntry entry = new PhysicalEntry();
246 entry.setName(fileName);
247 entry.setPath(file.getPath());
248 entry.setInsert(!file.isHidden());