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 ‘Bombe’ Roden <bombe@freenetproject.org>
32 public class Project implements Comparable<Project> {
34 protected String name;
35 protected String description;
37 protected String insertURI;
38 protected String requestURI;
40 protected String indexFile;
41 protected String localPath;
42 protected String path;
43 protected long lastInsertionTime;
44 /** The edition to insert to. */
45 protected int edition;
47 protected Map<String, FileOption> fileOptions = new HashMap<String, FileOption>();
57 public Project(Project project) {
59 description = project.description;
60 insertURI = project.insertURI;
61 requestURI = project.requestURI;
63 edition = project.edition;
64 localPath = project.localPath;
65 indexFile = project.indexFile;
66 lastInsertionTime = project.lastInsertionTime;
67 fileOptions = new HashMap<String, FileOption>(project.fileOptions);
71 * @return Returns the title.
73 public String getName() {
81 public void setName(String title) {
86 * @return Returns the description.
88 public String getDescription() {
94 * The description to set.
96 public void setDescription(String description) {
97 this.description = description;
101 * @return Returns the localPath.
103 public String getLocalPath() {
109 * The localPath to set.
111 public void setLocalPath(String localPath) {
112 this.localPath = localPath;
116 * @return Returns the indexFile.
118 public String getIndexFile() {
124 * The indexFile to set.
126 public void setIndexFile(String indexFile) {
127 this.indexFile = indexFile;
131 * @return Returns the lastInserted.
133 public long getLastInsertionTime() {
134 return lastInsertionTime;
138 * @param lastInserted
139 * The lastInserted to set.
141 public void setLastInsertionTime(long lastInserted) {
142 lastInsertionTime = lastInserted;
146 * @return Returns the name.
148 public String getPath() {
156 public void setPath(String name) {
161 * @return Returns the insertURI.
163 public String getInsertURI() {
169 * The insertURI to set.
171 public void setInsertURI(String insertURI) {
172 this.insertURI = shortenURI(insertURI);
176 * @return Returns the requestURI.
178 public String getRequestURI() {
184 * The requestURI to set.
186 public void setRequestURI(String requestURI) {
187 this.requestURI = shortenURI(requestURI);
191 public String toString() {
195 private String shortenURI(String uri) {
196 if (uri.startsWith("freenet:")) {
197 uri = uri.substring("freenet:".length());
199 if (uri.startsWith("SSK@")) {
200 uri = uri.substring("SSK@".length());
202 if (uri.startsWith("USK@")) {
203 uri = uri.substring("USK@".length());
205 if (uri.endsWith("/")) {
206 uri = uri.substring(0, uri.length() - 1);
211 public String shortenFilename(File file) {
212 String filename = file.getPath();
213 if (filename.startsWith(localPath)) {
214 filename = filename.substring(localPath.length());
215 if (filename.startsWith(File.separator)) {
216 filename = filename.substring(1);
222 public FileOption getFileOption(String filename) {
223 FileOption fileOption = fileOptions.get(filename);
224 if (fileOption == null) {
225 fileOption = new FileOption(DefaultMIMETypes.guessMIMEType(filename));
226 fileOptions.put(filename, fileOption);
231 public void setFileOption(String filename, FileOption fileOption) {
232 if (fileOption != null) {
233 fileOptions.put(filename, fileOption);
235 fileOptions.remove(filename);
240 * @return Returns the fileOptions.
242 public Map<String, FileOption> getFileOptions() {
243 return Collections.unmodifiableMap(fileOptions);
248 * The fileOptions to set.
250 public void setFileOptions(Map<String, FileOption> fileOptions) {
251 this.fileOptions.clear();
252 this.fileOptions.putAll(fileOptions);
258 public int compareTo(Project project) {
259 return name.compareToIgnoreCase(project.name);
263 * Returns the edition of the project.
265 * @return The edition of the project
267 public int getEdition() {
272 * Sets the edition of the project.
277 public void setEdition(int edition) {
278 this.edition = edition;
282 * Constructs the final request URI including the edition number.
284 * @return The final request URI
286 public String getFinalRequestURI(int offset) {
287 return "USK@" + requestURI + "/" + path + "/" + (edition + offset) + "/";