2 * jSite - a tool for uploading websites into Freenet
3 * Copyright (C) 2006 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 de.todesbaum.jsite.application;
23 import java.util.Collections;
24 import java.util.HashMap;
27 import de.todesbaum.util.mime.DefaultMIMETypes;
30 * @author David Roden <dr@todesbaum.dyndns.org>
33 public class Project implements Comparable {
35 protected String name;
36 protected String description;
38 protected String insertURI;
39 protected String requestURI;
41 protected String indexFile;
42 protected String localPath;
43 protected String path;
44 protected long lastInsertionTime;
45 /** The edition to insert to. */
46 protected int edition;
48 protected Map<String, FileOption> fileOptions = new HashMap<String, FileOption>();
58 public Project(Project project) {
60 description = project.description;
61 insertURI = project.insertURI;
62 requestURI = project.requestURI;
64 edition = project.edition;
65 localPath = project.localPath;
66 indexFile = project.indexFile;
67 lastInsertionTime = project.lastInsertionTime;
68 fileOptions = new HashMap<String, FileOption>(project.fileOptions);
72 * @return Returns the title.
74 public String getName() {
82 public void setName(String title) {
87 * @return Returns the description.
89 public String getDescription() {
95 * The description to set.
97 public void setDescription(String description) {
98 this.description = description;
102 * @return Returns the localPath.
104 public String getLocalPath() {
110 * The localPath to set.
112 public void setLocalPath(String localPath) {
113 this.localPath = localPath;
117 * @return Returns the indexFile.
119 public String getIndexFile() {
125 * The indexFile to set.
127 public void setIndexFile(String indexFile) {
128 this.indexFile = indexFile;
132 * @return Returns the lastInserted.
134 public long getLastInsertionTime() {
135 return lastInsertionTime;
139 * @param lastInserted
140 * The lastInserted to set.
142 public void setLastInsertionTime(long lastInserted) {
143 lastInsertionTime = lastInserted;
147 * @return Returns the name.
149 public String getPath() {
157 public void setPath(String name) {
162 * @return Returns the insertURI.
164 public String getInsertURI() {
170 * The insertURI to set.
172 public void setInsertURI(String insertURI) {
173 this.insertURI = shortenURI(insertURI);
177 * @return Returns the requestURI.
179 public String getRequestURI() {
185 * The requestURI to set.
187 public void setRequestURI(String requestURI) {
188 this.requestURI = shortenURI(requestURI);
192 public String toString() {
196 private String shortenURI(String uri) {
197 if (uri.startsWith("freenet:")) {
198 uri = uri.substring("freenet:".length());
200 if (uri.startsWith("SSK@")) {
201 uri = uri.substring("SSK@".length());
203 if (uri.startsWith("USK@")) {
204 uri = uri.substring("USK@".length());
206 if (uri.endsWith("/")) {
207 uri = uri.substring(0, uri.length() - 1);
212 public String shortenFilename(File file) {
213 String filename = file.getPath();
214 if (filename.startsWith(localPath)) {
215 filename = filename.substring(localPath.length());
216 if (filename.startsWith(File.separator)) {
217 filename = filename.substring(1);
223 public FileOption getFileOption(String filename) {
224 FileOption fileOption = fileOptions.get(filename);
225 if (fileOption == null) {
226 fileOption = new FileOption(DefaultMIMETypes.guessMIMEType(filename));
227 fileOptions.put(filename, fileOption);
232 public void setFileOption(String filename, FileOption fileOption) {
233 if (fileOption != null) {
234 fileOptions.put(filename, fileOption);
236 fileOptions.remove(filename);
241 * @return Returns the fileOptions.
243 public Map<String, FileOption> getFileOptions() {
244 return Collections.unmodifiableMap(new HashMap<String, FileOption>(fileOptions));
249 * The fileOptions to set.
251 public void setFileOptions(Map<String, FileOption> fileOptions) {
252 this.fileOptions.clear();
253 this.fileOptions.putAll(fileOptions);
259 public int compareTo(Object o) {
260 return name.compareToIgnoreCase(((Project) o).name);
264 * Returns the edition of the project.
266 * @return The edition of the project
268 public int getEdition() {
273 * Sets the edition of the project.
278 public void setEdition(int edition) {
279 this.edition = edition;
283 * Constructs the final request URI including the edition number.
285 * @return The final request URI
287 public String getFinalRequestURI(int offset) {
288 return "freenet:USK@" + requestURI + "/" + path + "/" + (edition + offset) + "/";