X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FProject.java;h=c601d76fcf996dbfcd7fd83b3763bc992f1f30b6;hb=c63257e8cc0ba1a5aca9364b22171abe7279d479;hp=1edb93337b87e765fe27d394104726ca3968f900;hpb=dc37f1e959fe36099d157e6d09b5790d4e06897c;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/core/Project.java b/src/net/pterodactylus/jsite/core/Project.java index 1edb933..c601d76 100644 --- a/src/net/pterodactylus/jsite/core/Project.java +++ b/src/net/pterodactylus/jsite/core/Project.java @@ -27,12 +27,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.pterodactylus.jsite.util.IdGenerator; import net.pterodactylus.util.beans.AbstractBean; +import net.pterodactylus.util.number.Hex; /** * Container for project information. A Project is capable of notifying * {@link PropertyChangeListener}s if any of the contained properties change. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ public class Project extends AbstractBean { @@ -55,6 +57,9 @@ public class Project extends AbstractBean { /** Name of the “default file” property. */ public static final String PROPERTY_DEFAULT_FILE = "defaultFile"; + /** Name of the “node” property. */ + public static final String PROPERTY_NODE = "node"; + /** Internal ID. */ private String id; @@ -79,6 +84,9 @@ public class Project extends AbstractBean { /** The overrides. */ private final Map fileOverrides = new HashMap(); + /** The default node to insert to. */ + private Node node; + /** The current root project file. */ private ProjectFileImpl rootProjectFile; @@ -86,15 +94,16 @@ public class Project extends AbstractBean { * Creates a new project. */ public Project() { - /* do nothing. */ + id = Hex.toHex(IdGenerator.generateId()); } /** * Clones the given project. - * + * * @param project */ Project(Project project) { + this(); this.name = project.name; this.description = project.description; this.publicKey = project.publicKey; @@ -104,7 +113,7 @@ public class Project extends AbstractBean { /** * Returns the internal ID. - * + * * @return The internal ID */ String getId() { @@ -113,17 +122,21 @@ public class Project extends AbstractBean { /** * Sets the internal ID. - * + * * @param id * The internal ID */ void setId(String id) { - this.id = id; + if (id == null) { + this.id = Hex.toHex(IdGenerator.generateId()); + } else { + this.id = id; + } } /** * Returns the name of the project. - * + * * @return The name of the project */ public String getName() { @@ -132,7 +145,7 @@ public class Project extends AbstractBean { /** * Sets the name of the project. - * + * * @param name * The name of the project */ @@ -144,7 +157,7 @@ public class Project extends AbstractBean { /** * Returns the description of the project. - * + * * @return The description of the project */ public String getDescription() { @@ -153,7 +166,7 @@ public class Project extends AbstractBean { /** * Sets the description of the project - * + * * @param description * The description of the project */ @@ -165,7 +178,7 @@ public class Project extends AbstractBean { /** * Returns the public key of the project. - * + * * @return The public key of the project */ public String getPublicKey() { @@ -174,7 +187,7 @@ public class Project extends AbstractBean { /** * Sets the public key of the project. - * + * * @param publicKey * The public key of the project */ @@ -186,7 +199,7 @@ public class Project extends AbstractBean { /** * Returns the private key of the project. - * + * * @return The private key of the project */ public String getPrivateKey() { @@ -195,7 +208,7 @@ public class Project extends AbstractBean { /** * Sets the private key of the project. - * + * * @param privateKey * The private key of the project */ @@ -207,7 +220,7 @@ public class Project extends AbstractBean { /** * Returns the base path of the project. - * + * * @return The base path of the project */ public String getBasePath() { @@ -216,7 +229,7 @@ public class Project extends AbstractBean { /** * Sets the base path of the project. - * + * * @param basePath * The base path of the project */ @@ -228,7 +241,7 @@ public class Project extends AbstractBean { /** * Returns the default file. - * + * * @return The default file */ public String getDefaultFile() { @@ -237,7 +250,7 @@ public class Project extends AbstractBean { /** * Sets the default file. - * + * * @param defaultFile * The default file */ @@ -249,7 +262,7 @@ public class Project extends AbstractBean { /** * Adds a file override for the given file. - * + * * @param projectFile * The file * @param override @@ -261,7 +274,7 @@ public class Project extends AbstractBean { /** * Adds a file override for the given file. - * + * * @param filePath * The file path * @param override @@ -273,7 +286,7 @@ public class Project extends AbstractBean { /** * Removes the file override for the given file. - * + * * @param projectFile * The file for which to remove the override */ @@ -283,7 +296,7 @@ public class Project extends AbstractBean { /** * Removes the file override for the given file. - * + * * @param filePath * The file path for which to remove the override */ @@ -293,7 +306,7 @@ public class Project extends AbstractBean { /** * Returns the file override for the given file. - * + * * @param projectFile * The file for which to get the override * @return The file override, or null if the given file does @@ -305,7 +318,7 @@ public class Project extends AbstractBean { /** * Returns the file override for the given file. - * + * * @param filePath * The file path for which to get the override * @return The file override, or null if the given file does @@ -317,7 +330,7 @@ public class Project extends AbstractBean { /** * Returns the list of {@link FileOverride}s. - * + * * @return All file overrides */ public Map getFileOverrides() { @@ -329,7 +342,7 @@ public class Project extends AbstractBean { * base path. From this file it is possible to reach all files in the base * path. This method is disk-intensive and may take some time on larger * directories! - * + * * @return The file for the base path, or null if the base * path does not denote an existing directory */ @@ -345,7 +358,7 @@ public class Project extends AbstractBean { /** * Returns the file that is specified by its complete path. - * + * * @param completePath * The complete path of the file * @return The project file at the given path, or null if @@ -369,6 +382,35 @@ public class Project extends AbstractBean { return currentProjectFile; } + /** + * Returns the default node to insert this project to. + * + * @return The node to insert this project to + */ + public Node getNode() { + return node; + } + + /** + * Sets the default node to insert this project to. + * + * @param node + * The node to insert this project to + */ + public void setNode(Node node) { + Node oldNode = this.node; + this.node = node; + fireIfPropertyChanged(PROPERTY_NODE, oldNode, node); + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return getClass().getName() + "[id=" + id + ",name=" + name + ",description=" + description + ",publicKey=" + publicKey + ",privateKey=" + privateKey + ",basePath=" + basePath + ",defaultFile=" + defaultFile + ",node=" + node + "]"; + } + // // PRIVATE METHODS // @@ -376,7 +418,7 @@ public class Project extends AbstractBean { /** * Scans the given directory and recreates the file and directory structure * in the given project file. - * + * * @param directory * The directory to scan * @param projectFile @@ -398,7 +440,7 @@ public class Project extends AbstractBean { /** * Implementation of a {@link ProjectFile}. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ private static class ProjectFileImpl implements ProjectFile, Comparable { @@ -423,7 +465,7 @@ public class Project extends AbstractBean { /** * Creates a new project fie. - * + * * @param parentProjectFile * The parent of the project file, or null if * the new project file does not have a parent @@ -521,7 +563,7 @@ public class Project extends AbstractBean { /** * Returns the project file with the given name. The project file has to * be a direct child of this project file. - * + * * @param name * The name of the file to get * @return The project file, or null if there is no @@ -553,7 +595,7 @@ public class Project extends AbstractBean { /** * Adds a new project file as child to this project file. - * + * * @param name * The name of the file * @param size