X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fapplication%2FProject.java;h=76042594199a180e08c2a6371624da0353de12b5;hb=e44d6888ffaa3151a99b9bb7cb3c887d11feb596;hp=0f28ef3df794247580eacc60c4fe374c3acb79bd;hpb=6f1a8216cfba28add0ef365b46a08d16d4eb87fe;p=jSite.git diff --git a/src/de/todesbaum/jsite/application/Project.java b/src/de/todesbaum/jsite/application/Project.java index 0f28ef3..7604259 100644 --- a/src/de/todesbaum/jsite/application/Project.java +++ b/src/de/todesbaum/jsite/application/Project.java @@ -28,9 +28,9 @@ import de.todesbaum.util.mime.DefaultMIMETypes; /** * @author David Roden - * @version $Id: Project.java 357 2006-03-24 15:46:03Z bombe $ + * @version $Id$ */ -public abstract class Project implements Comparable { +public class Project implements Comparable { protected String name; protected String description; @@ -42,6 +42,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 fileOptions = new HashMap(); @@ -59,6 +61,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 +80,7 @@ public abstract class Project implements Comparable { * The title to set. */ public void setName(String title) { - this.name = title; + name = title; } /** @@ -137,7 +140,7 @@ public abstract class Project implements Comparable { * The lastInserted to set. */ public void setLastInsertionTime(long lastInserted) { - this.lastInsertionTime = lastInserted; + lastInsertionTime = lastInserted; } /** @@ -152,7 +155,7 @@ public abstract class Project implements Comparable { * The name to set. */ public void setPath(String name) { - this.path = name; + path = name; } /** @@ -167,7 +170,7 @@ public abstract class Project implements Comparable { * The insertURI to set. */ public void setInsertURI(String insertURI) { - this.insertURI = insertURI; + this.insertURI = shortenURI(insertURI); } /** @@ -182,12 +185,29 @@ 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(); @@ -210,14 +230,18 @@ 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); + } } /** * @return Returns the fileOptions. */ public Map getFileOptions() { - return Collections.unmodifiableMap(fileOptions); + return Collections.unmodifiableMap(new HashMap(fileOptions)); } /** @@ -228,11 +252,7 @@ public abstract class Project implements Comparable { this.fileOptions.clear(); this.fileOptions.putAll(fileOptions); } - - public String getFinalURI(int editionOffset) { - return requestURI + path + "/"; - } - + /** * {@inheritDoc} */ @@ -240,4 +260,32 @@ public abstract class Project implements Comparable { return name.compareToIgnoreCase(((Project) o).name); } + /** + * 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 String getFinalRequestURI(int offset) { + return "freenet:USK@" + requestURI + "/" + path + "/" + (edition + offset) + "/"; + } + }