jSite: First commit : verion 4.0 (written by Bombe)
[jSite.git] / src / de / todesbaum / jsite / application / Project.java
1 /*
2  * jSite - a tool for uploading websites into Freenet
3  * Copyright (C) 2006 David Roden
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 package de.todesbaum.jsite.application;
21
22 import java.io.File;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import de.todesbaum.util.mime.DefaultMIMETypes;
28
29 /**
30  * @author David Roden <dr@todesbaum.dyndns.org>
31  * @version $Id: Project.java 357 2006-03-24 15:46:03Z bombe $
32  */
33 public abstract class Project implements Comparable {
34
35         protected String name;
36         protected String description;
37
38         protected String insertURI;
39         protected String requestURI;
40
41         protected String indexFile;
42         protected String localPath;
43         protected String path;
44         protected long lastInsertionTime;
45
46         protected Map<String, FileOption> fileOptions = new HashMap<String, FileOption>();
47
48         public Project() {
49         }
50
51         /**
52          * Clone-constructor.
53          * 
54          * @param project
55          */
56         public Project(Project project) {
57                 name = project.name;
58                 description = project.description;
59                 insertURI = project.insertURI;
60                 requestURI = project.requestURI;
61                 path = project.path;
62                 localPath = project.localPath;
63                 indexFile = project.indexFile;
64                 lastInsertionTime = project.lastInsertionTime;
65                 fileOptions = new HashMap<String, FileOption>(project.fileOptions);
66         }
67
68         /**
69          * @return Returns the title.
70          */
71         public String getName() {
72                 return name;
73         }
74
75         /**
76          * @param title
77          *            The title to set.
78          */
79         public void setName(String title) {
80                 this.name = title;
81         }
82
83         /**
84          * @return Returns the description.
85          */
86         public String getDescription() {
87                 return description;
88         }
89
90         /**
91          * @param description
92          *            The description to set.
93          */
94         public void setDescription(String description) {
95                 this.description = description;
96         }
97
98         /**
99          * @return Returns the localPath.
100          */
101         public String getLocalPath() {
102                 return localPath;
103         }
104
105         /**
106          * @param localPath
107          *            The localPath to set.
108          */
109         public void setLocalPath(String localPath) {
110                 this.localPath = localPath;
111         }
112
113         /**
114          * @return Returns the indexFile.
115          */
116         public String getIndexFile() {
117                 return indexFile;
118         }
119
120         /**
121          * @param indexFile
122          *            The indexFile to set.
123          */
124         public void setIndexFile(String indexFile) {
125                 this.indexFile = indexFile;
126         }
127
128         /**
129          * @return Returns the lastInserted.
130          */
131         public long getLastInsertionTime() {
132                 return lastInsertionTime;
133         }
134
135         /**
136          * @param lastInserted
137          *            The lastInserted to set.
138          */
139         public void setLastInsertionTime(long lastInserted) {
140                 this.lastInsertionTime = lastInserted;
141         }
142
143         /**
144          * @return Returns the name.
145          */
146         public String getPath() {
147                 return path;
148         }
149
150         /**
151          * @param name
152          *            The name to set.
153          */
154         public void setPath(String name) {
155                 this.path = name;
156         }
157
158         /**
159          * @return Returns the insertURI.
160          */
161         public String getInsertURI() {
162                 return insertURI;
163         }
164
165         /**
166          * @param insertURI
167          *            The insertURI to set.
168          */
169         public void setInsertURI(String insertURI) {
170                 this.insertURI = insertURI;
171         }
172
173         /**
174          * @return Returns the requestURI.
175          */
176         public String getRequestURI() {
177                 return requestURI;
178         }
179
180         /**
181          * @param requestURI
182          *            The requestURI to set.
183          */
184         public void setRequestURI(String requestURI) {
185                 this.requestURI = requestURI;
186         }
187
188         public String toString() {
189                 return name;
190         }
191
192         public String shortenFilename(File file) {
193                 String filename = file.getPath();
194                 if (filename.startsWith(localPath)) {
195                         filename = filename.substring(localPath.length());
196                         if (filename.startsWith(File.separator)) {
197                                 filename = filename.substring(1);
198                         }
199                 }
200                 return filename;
201         }
202
203         public FileOption getFileOption(String filename) {
204                 FileOption fileOption = fileOptions.get(filename);
205                 if (fileOption == null) {
206                         fileOption = new FileOption(DefaultMIMETypes.guessMIMEType(filename));
207                         fileOptions.put(filename, fileOption);
208                 }
209                 return fileOption;
210         }
211
212         public void setFileOption(String filename, FileOption fileOption) {
213                 fileOptions.put(filename, fileOption);
214         }
215
216         /**
217          * @return Returns the fileOptions.
218          */
219         public Map<String, FileOption> getFileOptions() {
220                 return Collections.unmodifiableMap(fileOptions);
221         }
222
223         /**
224          * @param fileOptions
225          *            The fileOptions to set.
226          */
227         public void setFileOptions(Map<String, FileOption> fileOptions) {
228                 this.fileOptions.clear();
229                 this.fileOptions.putAll(fileOptions);
230         }
231
232         public String getFinalURI(int editionOffset) {
233                 return requestURI + path + "/";
234         }
235
236         /**
237          * {@inheritDoc}
238          */
239         public int compareTo(Object o) {
240                 return name.compareToIgnoreCase(((Project) o).name);
241         }
242
243 }