remove subversion $Id$ tags
[jSite.git] / src / de / todesbaum / jsite / application / Project.java
index 0f28ef3..85df0ef 100644 (file)
@@ -27,10 +27,9 @@ import java.util.Map;
 import de.todesbaum.util.mime.DefaultMIMETypes;
 
 /**
- * @author David Roden <dr@todesbaum.dyndns.org>
- * @version $Id: Project.java 357 2006-03-24 15:46:03Z bombe $
+ * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public abstract class Project implements Comparable {
+public class Project implements Comparable<Project> {
 
        protected String name;
        protected String description;
@@ -42,6 +41,8 @@ public abstract class Project implements Comparable {
        protected String localPath;
        protected String path;
        protected long lastInsertionTime;
+       /** The edition to insert to. */
+       protected int edition;
 
        protected Map<String, FileOption> fileOptions = new HashMap<String, FileOption>();
 
@@ -59,6 +60,7 @@ public abstract class Project implements Comparable {
                insertURI = project.insertURI;
                requestURI = project.requestURI;
                path = project.path;
+               edition = project.edition;
                localPath = project.localPath;
                indexFile = project.indexFile;
                lastInsertionTime = project.lastInsertionTime;
@@ -77,7 +79,7 @@ public abstract class Project implements Comparable {
         *            The title to set.
         */
        public void setName(String title) {
-               this.name = title;
+               name = title;
        }
 
        /**
@@ -137,7 +139,7 @@ public abstract class Project implements Comparable {
         *            The lastInserted to set.
         */
        public void setLastInsertionTime(long lastInserted) {
-               this.lastInsertionTime = lastInserted;
+               lastInsertionTime = lastInserted;
        }
 
        /**
@@ -152,7 +154,7 @@ public abstract class Project implements Comparable {
         *            The name to set.
         */
        public void setPath(String name) {
-               this.path = name;
+               path = name;
        }
 
        /**
@@ -167,7 +169,7 @@ public abstract class Project implements Comparable {
         *            The insertURI to set.
         */
        public void setInsertURI(String insertURI) {
-               this.insertURI = insertURI;
+               this.insertURI = shortenURI(insertURI);
        }
 
        /**
@@ -182,13 +184,30 @@ public abstract class Project implements Comparable {
         *            The requestURI to set.
         */
        public void setRequestURI(String requestURI) {
-               this.requestURI = requestURI;
+               this.requestURI = shortenURI(requestURI);
        }
 
+       @Override
        public String toString() {
                return name;
        }
 
+       private String shortenURI(String uri) {
+               if (uri.startsWith("freenet:")) {
+                       uri = uri.substring("freenet:".length());
+               }
+               if (uri.startsWith("SSK@")) {
+                       uri = uri.substring("SSK@".length());
+               }
+               if (uri.startsWith("USK@")) {
+                       uri = uri.substring("USK@".length());
+               }
+               if (uri.endsWith("/")) {
+                       uri = uri.substring(0, uri.length() - 1);
+               }
+               return uri;
+       }
+
        public String shortenFilename(File file) {
                String filename = file.getPath();
                if (filename.startsWith(localPath)) {
@@ -210,7 +229,11 @@ public abstract class Project implements Comparable {
        }
 
        public void setFileOption(String filename, FileOption fileOption) {
-               fileOptions.put(filename, fileOption);
+               if (fileOption != null) {
+                       fileOptions.put(filename, fileOption);
+               } else {
+                       fileOptions.remove(filename);
+               }
        }
 
        /**
@@ -229,15 +252,39 @@ public abstract class Project implements Comparable {
                this.fileOptions.putAll(fileOptions);
        }
 
-       public String getFinalURI(int editionOffset) {
-               return requestURI + path + "/";
+       /**
+        * {@inheritDoc}
+        */
+       public int compareTo(Project project) {
+               return name.compareToIgnoreCase(project.name);
        }
 
        /**
-        * {@inheritDoc}
+        * Returns the edition of the project.
+        * 
+        * @return The edition of the project
+        */
+       public int getEdition() {
+               return edition;
+       }
+
+       /**
+        * Sets the edition of the project.
+        * 
+        * @param edition
+        *            The edition to set
+        */
+       public void setEdition(int edition) {
+               this.edition = edition;
+       }
+
+       /**
+        * Constructs the final request URI including the edition number.
+        * 
+        * @return The final request URI
         */
-       public int compareTo(Object o) {
-               return name.compareToIgnoreCase(((Project) o).name);
+       public String getFinalRequestURI(int offset) {
+               return "USK@" + requestURI + "/" + path + "/" + (edition + offset) + "/";
        }
 
 }