fix complete bash of base file
[jSite2.git] / src / net / pterodactylus / jsite / project / Project.java
index 4d778ab..0e96b9c 100644 (file)
@@ -32,7 +32,7 @@ import net.pterodactylus.util.beans.AbstractBean;
 /**
  * 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 {
@@ -77,7 +77,7 @@ public class Project extends AbstractBean {
        private String defaultFile;
 
        /** The overrides. */
-       private final Map<String, Override> overrides = new HashMap<String, Override>();
+       private final Map<String, FileOverride> fileOverrides = new HashMap<String, FileOverride>();
 
        /**
         * Creates a new project.
@@ -88,7 +88,7 @@ public class Project extends AbstractBean {
 
        /**
         * Clones the given project.
-        * 
+        *
         * @param project
         */
        Project(Project project) {
@@ -101,7 +101,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the internal ID.
-        * 
+        *
         * @return The internal ID
         */
        String getId() {
@@ -110,7 +110,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the internal ID.
-        * 
+        *
         * @param id
         *            The internal ID
         */
@@ -120,7 +120,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the name of the project.
-        * 
+        *
         * @return The name of the project
         */
        public String getName() {
@@ -129,7 +129,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the name of the project.
-        * 
+        *
         * @param name
         *            The name of the project
         */
@@ -141,7 +141,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the description of the project.
-        * 
+        *
         * @return The description of the project
         */
        public String getDescription() {
@@ -150,7 +150,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the description of the project
-        * 
+        *
         * @param description
         *            The description of the project
         */
@@ -162,7 +162,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the public key of the project.
-        * 
+        *
         * @return The public key of the project
         */
        public String getPublicKey() {
@@ -171,7 +171,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the public key of the project.
-        * 
+        *
         * @param publicKey
         *            The public key of the project
         */
@@ -183,7 +183,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the private key of the project.
-        * 
+        *
         * @return The private key of the project
         */
        public String getPrivateKey() {
@@ -192,7 +192,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the private key of the project.
-        * 
+        *
         * @param privateKey
         *            The private key of the project
         */
@@ -204,7 +204,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the base path of the project.
-        * 
+        *
         * @return The base path of the project
         */
        public String getBasePath() {
@@ -213,7 +213,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the base path of the project.
-        * 
+        *
         * @param basePath
         *            The base path of the project
         */
@@ -225,7 +225,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the default file.
-        * 
+        *
         * @return The default file
         */
        public String getDefaultFile() {
@@ -234,7 +234,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the default file.
-        * 
+        *
         * @param defaultFile
         *            The default file
         */
@@ -245,34 +245,34 @@ public class Project extends AbstractBean {
        }
 
        /**
-        * Adds an override for the given file.
-        * 
+        * Adds a file override for the given file.
+        *
         * @param filePath
         *            The file path
         * @param override
         *            The override for the file
         */
-       public void addOverride(String filePath, Override override) {
-               overrides.put(filePath, override);
+       public void addFileOverride(String filePath, FileOverride override) {
+               fileOverrides.put(filePath, override);
        }
 
        /**
-        * Removes the override for the given file.
-        * 
+        * Removes the file override for the given file.
+        *
         * @param filePath
         *            The file path for which to remove the override
         */
-       public void removeOverride(String filePath) {
-               overrides.remove(filePath);
+       public void removeFileOverride(String filePath) {
+               fileOverrides.remove(filePath);
        }
 
        /**
-        * Returns the list of {@link Override}s.
-        * 
-        * @return All overrides
+        * Returns the list of {@link FileOverride}s.
+        *
+        * @return All file overrides
         */
-       public Map<String, Override> getOverrides() {
-               return overrides;
+       public Map<String, FileOverride> getFileOverrides() {
+               return fileOverrides;
        }
 
        /**
@@ -280,7 +280,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 <code>null</code> if the base
         *         path does not denote an existing directory
         */
@@ -289,7 +289,7 @@ public class Project extends AbstractBean {
                if (!basePathFile.exists() || !basePathFile.isDirectory()) {
                        return null;
                }
-               ProjectFileImpl rootProjectFile = new ProjectFileImpl(null, "", true, false);
+               ProjectFileImpl rootProjectFile = new ProjectFileImpl(null, "", 0, true, false);
                scanDirectory(basePathFile, rootProjectFile);
                return rootProjectFile;
        }
@@ -301,7 +301,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
@@ -312,8 +312,8 @@ public class Project extends AbstractBean {
                if (!directory.isDirectory()) {
                        return;
                }
-               for (File file: directory.listFiles()) {
-                       ProjectFileImpl projectFileChild = projectFile.addFile(file.getName(), file.isDirectory(), file.isHidden());
+               for (File file : directory.listFiles()) {
+                       ProjectFileImpl projectFileChild = projectFile.addFile(file.getName(), file.length(), file.isDirectory(), file.isHidden());
                        if (file.isDirectory()) {
                                scanDirectory(file, projectFileChild);
                        }
@@ -323,7 +323,7 @@ public class Project extends AbstractBean {
 
        /**
         * Implementation of a {@link ProjectFile}.
-        * 
+        *
         * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
         */
        private static class ProjectFileImpl implements ProjectFile, Comparable<ProjectFileImpl> {
@@ -334,6 +334,9 @@ public class Project extends AbstractBean {
                /** The name of this project file. */
                private final String name;
 
+               /** The size of the file. */
+               private final long size;
+
                /** Whether this project file is a directory. */
                private final boolean directory;
 
@@ -345,12 +348,14 @@ public class Project extends AbstractBean {
 
                /**
                 * Creates a new project fie.
-                * 
+                *
                 * @param parentProjectFile
                 *            The parent of the project file, or <code>null</code> if
                 *            the new project file does not have a parent
                 * @param name
                 *            The name of the project file
+                * @param size
+                *            The size of the file
                 * @param isDirectory
                 *            <code>true</code> if this project file is a directory,
                 *            <code>false</code> otherwise
@@ -358,9 +363,10 @@ public class Project extends AbstractBean {
                 *            <code>true</code> if this project file is hidden,
                 *            <code>false</code> otherwise
                 */
-               ProjectFileImpl(ProjectFileImpl parentProjectFile, String name, boolean isDirectory, boolean isHidden) {
+               ProjectFileImpl(ProjectFileImpl parentProjectFile, String name, long size, boolean isDirectory, boolean isHidden) {
                        this.parentProjectFile = parentProjectFile;
                        this.name = name;
+                       this.size = size;
                        this.directory = isDirectory;
                        this.hidden = isHidden;
                }
@@ -377,6 +383,20 @@ public class Project extends AbstractBean {
                }
 
                /**
+                * @see net.pterodactylus.jsite.project.ProjectFile#getParent()
+                */
+               public ProjectFile getParent() {
+                       return parentProjectFile;
+               }
+
+               /**
+                * {@inheritDoc}
+                */
+               public long getSize() {
+                       return size;
+               }
+
+               /**
                 * @see net.pterodactylus.jsite.project.ProjectFile#getParents()
                 */
                public List<ProjectFile> getParents() {
@@ -389,6 +409,20 @@ public class Project extends AbstractBean {
                }
 
                /**
+                * {@inheritDoc}
+                */
+               /* TODO - caching? */
+               public String getCompletePath() {
+                       StringBuilder completePath = new StringBuilder();
+                       ProjectFileImpl currentProjectFile = this;
+                       while ((currentProjectFile != null) && (currentProjectFile.parentProjectFile != null)) {
+                               completePath.insert(0, currentProjectFile.getName()).insert(0, File.separatorChar);
+                               currentProjectFile = currentProjectFile.parentProjectFile;
+                       }
+                       return (completePath.length() > 0) ? completePath.substring(1) : "";
+               }
+
+               /**
                 * @see net.pterodactylus.jsite.project.ProjectFile#isFile()
                 */
                public boolean isFile() {
@@ -423,9 +457,11 @@ 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
+                *            The size of the file
                 * @param isDirectory
                 *            <code>true</code> if the new file is a directory,
                 *            <code>false</code> otherwise
@@ -434,8 +470,8 @@ public class Project extends AbstractBean {
                 *            <code>false</code> otherwise
                 * @return The created project file
                 */
-               public ProjectFileImpl addFile(String name, boolean isDirectory, boolean isHidden) {
-                       ProjectFileImpl newProjectFile = new ProjectFileImpl(this, name, isDirectory, isHidden);
+               public ProjectFileImpl addFile(String name, long size, boolean isDirectory, boolean isHidden) {
+                       ProjectFileImpl newProjectFile = new ProjectFileImpl(this, name, size, isDirectory, isHidden);
                        childProjectFiles.add(newProjectFile);
                        return newProjectFile;
                }