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>
35 public class Project extends AbstractBean {
37 /** Name of the “name” property. */
38 public static final String PROPERTY_NAME = "name";
40 /** Name of the “description” property. */
41 public static final String PROPERTY_DESCRIPTION = "description";
43 /** Name of the “public key” property. */
44 public static final String PROPERTY_PUBLIC_KEY = "publicKey";
46 /** Name of the “private key” property. */
47 public static final String PROPERTY_PRIVATE_KEY = "privateKey";
49 /** Name of the “base path” property. */
50 public static final String PROPERTY_BASE_PATH = "basePath";
52 /** Name of the “base path entries” property. */
53 public static final String PROPERTY_BASE_PATH_ENTRIES = "basePathEntries";
58 /** The name of the project. */
61 /** The description of the project. */
62 private String description;
64 /** The public key. */
65 private String publicKey;
67 /** The private key. */
68 private String privateKey;
70 /** The base path of the project. */
71 private String basePath;
73 /** The list of files from the base path. */
74 private List<Entry> basePathEntries = new ArrayList<Entry>();
76 /** The list of virtual files. */
77 private List<Entry> virtualEntries = new ArrayList<Entry>();
80 * Returns the internal ID.
82 * @return The internal ID
89 * Sets the internal ID.
94 void setId(String id) {
99 * Returns the name of the project.
101 * @return The name of the project
103 public String getName() {
108 * Sets the name of the project.
111 * The name of the project
113 public void setName(String name) {
114 String oldName = this.name;
116 fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
120 * Returns the description of the project.
122 * @return The description of the project
124 public String getDescription() {
129 * Sets the description of the project
132 * The description of the project
134 public void setDescription(String description) {
135 String oldDescription = this.description;
136 this.description = description;
137 fireIfPropertyChanged(PROPERTY_DESCRIPTION, oldDescription, description);
141 * Returns the public key of the project.
143 * @return The public key of the project
145 public String getPublicKey() {
150 * Sets the public key of the project.
153 * The public key of the project
155 void setPublicKey(String publicKey) {
156 String oldPublicKey = this.publicKey;
157 this.publicKey = publicKey;
158 fireIfPropertyChanged(PROPERTY_PUBLIC_KEY, oldPublicKey, publicKey);
162 * Returns the private key of the project.
164 * @return The private key of the project
166 public String getPrivateKey() {
171 * Sets the private key of the project.
174 * The private key of the project
176 void setPrivateKey(String privateKey) {
177 String oldPrivateKey = this.privateKey;
178 this.privateKey = privateKey;
179 fireIfPropertyChanged(PROPERTY_PRIVATE_KEY, oldPrivateKey, privateKey);
183 * Returns the base path of the project.
185 * @return The base path of the project
187 public String getBasePath() {
192 * Sets the base path of the project.
195 * The base path of the project
197 public void setBasePath(String basePath) {
198 String oldBasePath = this.basePath;
199 this.basePath = basePath;
200 fireIfPropertyChanged(PROPERTY_BASE_PATH, oldBasePath, basePath);
204 * Rescans the base path for new or changed files.
206 public void rescanBasePath() {
207 List<Entry> entries = new ArrayList<Entry>();
208 scanPath("", entries);
209 basePathEntries.clear();
210 basePathEntries.addAll(entries);
211 firePropertyChange(PROPERTY_BASE_PATH_ENTRIES, null, null);
215 * Returns the list of files from the base path.
217 * @return The list of files from the base path
219 public List<Entry> getBasePathEntries() {
220 return basePathEntries;
224 * Returns the list of visual entries.
226 * @return The visual entries
228 public List<Entry> getVirtualEntries() {
229 return virtualEntries;
233 * Adds a virtual entry that redirects to the given target.
236 * The name of the entry
238 * The content type of the entry, or <code>null</code> for
241 * The target URI of the redirect
243 public void addVirtualEntry(String name, String contentType, String target) {
244 RedirectEntry redirectEntry = new RedirectEntry();
245 redirectEntry.setName(name);
246 redirectEntry.setContentType(contentType);
247 redirectEntry.setTarget(target);
248 redirectEntry.setInsert(true);
256 * Scans the given path relative to {@link #basePath} for files and adds
257 * them to the given list of entries.
260 * The current path, relative to the base path
262 * The list of entries
264 private void scanPath(String currentPath, List<Entry> entries) {
265 File currentDirectory = new File(basePath + File.separatorChar + currentPath);
266 if (!currentDirectory.isDirectory()) {
269 for (File file: currentDirectory.listFiles()) {
270 String fileName = currentPath + file.getName();
271 if (file.isDirectory()) {
272 scanPath(fileName + File.separatorChar, entries);
275 PhysicalEntry entry = new PhysicalEntry();
276 entry.setName(fileName);
277 entry.setPath(file.getPath());
278 entry.setInsert(!file.isHidden());