work on new project file backend
[jSite2.git] / src / net / pterodactylus / jsite / project / Project.java
index 6510805..44ffaff 100644 (file)
 package net.pterodactylus.jsite.project;
 
 import java.beans.PropertyChangeListener;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 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>
- * @version $Id$
  */
 public class Project extends AbstractBean {
 
@@ -44,9 +46,12 @@ public class Project extends AbstractBean {
        /** Name of the “private key” property. */
        public static final String PROPERTY_PRIVATE_KEY = "privateKey";
 
-       /** Name of the “local path” property. */
+       /** Name of the “base path” property. */
        public static final String PROPERTY_BASE_PATH = "basePath";
 
+       /** Name of the “default file” property. */
+       public static final String PROPERTY_DEFAULT_FILE = "defaultFile";
+
        /** Internal ID. */
        private String id;
 
@@ -65,12 +70,35 @@ public class Project extends AbstractBean {
        /** The base path of the project. */
        private String basePath;
 
-       /** The list of files from the base path. */
-       private List<Entry> basePathEntries = new ArrayList<Entry>();
+       /** The default file. */
+       private String defaultFile;
+
+       /** The overrides. */
+       private final Map<String, Override> overrides = new HashMap<String, Override>();
+
+       /**
+        * Creates a new project.
+        */
+       public Project() {
+               /* do nothing. */
+       }
+
+       /**
+        * Clones the given project.
+        *
+        * @param project
+        */
+       Project(Project project) {
+               this.name = project.name;
+               this.description = project.description;
+               this.publicKey = project.publicKey;
+               this.privateKey = project.privateKey;
+               this.basePath = project.basePath;
+       }
 
        /**
         * Returns the internal ID.
-        * 
+        *
         * @return The internal ID
         */
        String getId() {
@@ -79,7 +107,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the internal ID.
-        * 
+        *
         * @param id
         *            The internal ID
         */
@@ -89,7 +117,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the name of the project.
-        * 
+        *
         * @return The name of the project
         */
        public String getName() {
@@ -98,7 +126,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the name of the project.
-        * 
+        *
         * @param name
         *            The name of the project
         */
@@ -110,7 +138,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the description of the project.
-        * 
+        *
         * @return The description of the project
         */
        public String getDescription() {
@@ -119,7 +147,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the description of the project
-        * 
+        *
         * @param description
         *            The description of the project
         */
@@ -131,7 +159,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the public key of the project.
-        * 
+        *
         * @return The public key of the project
         */
        public String getPublicKey() {
@@ -140,7 +168,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the public key of the project.
-        * 
+        *
         * @param publicKey
         *            The public key of the project
         */
@@ -152,7 +180,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the private key of the project.
-        * 
+        *
         * @return The private key of the project
         */
        public String getPrivateKey() {
@@ -161,7 +189,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the private key of the project.
-        * 
+        *
         * @param privateKey
         *            The private key of the project
         */
@@ -173,7 +201,7 @@ public class Project extends AbstractBean {
 
        /**
         * Returns the base path of the project.
-        * 
+        *
         * @return The base path of the project
         */
        public String getBasePath() {
@@ -182,7 +210,7 @@ public class Project extends AbstractBean {
 
        /**
         * Sets the base path of the project.
-        * 
+        *
         * @param basePath
         *            The base path of the project
         */
@@ -193,53 +221,125 @@ public class Project extends AbstractBean {
        }
 
        /**
-        * Rescans the base path for new or changed files.
-        */
-       public void rescanBasePath() {
-               List<Entry> entries = new ArrayList<Entry>();
-               scanPath("", entries);
-       }
-       /**
-        * Returns the list of files from the base path.
-        * 
-        * @return The list of files from the base path
-        */
-       public List<Entry> getBasePathEntries() {
-               return basePathEntries;
-       }
-       //
-       // PRIVATE METHODS
-       //
-       /**
-        * Scans the given path relative to {@link #basePath} for files and adds
-        * them to the given list of entries.
-        * 
-        * @param currentPath
-        *            The current path, relative to the base path
-        * @param entries
-        *            The list of entries
-        */
-       private void scanPath(String currentPath, List<Entry> entries) {
-               File currentDirectory = new File(basePath + File.separatorChar + currentPath);
-               if (!currentDirectory.isDirectory()) {
-                       return;
+        * Returns the default file.
+        *
+        * @return The default file
+        */
+       public String getDefaultFile() {
+               return defaultFile;
+       }
+
+       /**
+        * Sets the default file.
+        *
+        * @param defaultFile
+        *            The default file
+        */
+       public void setDefaultFile(String defaultFile) {
+               String oldDefaultFile = this.defaultFile;
+               this.defaultFile = defaultFile;
+               fireIfPropertyChanged(PROPERTY_DEFAULT_FILE, oldDefaultFile, defaultFile);
+       }
+
+       /**
+        * Adds an 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);
+       }
+
+       /**
+        * Removes the override for the given file.
+        *
+        * @param filePath
+        *            The file path for which to remove the override
+        */
+       public void removeOverride(String filePath) {
+               overrides.remove(filePath);
+       }
+
+       /**
+        * Returns the list of {@link Override}s.
+        *
+        * @return All overrides
+        */
+       public Map<String, Override> getOverrides() {
+               return overrides;
+       }
+
+       /**
+        * Scans the base path for files and returns the {@link ProjectFile} for the
+        * 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
+        */
+       public ProjectFile getBaseFile() {
+
+       }
+
+       /**
+        * Implementation of a {@link ProjectFile}.
+        *
+        * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+        */
+       private static class ProjectFileImpl implements ProjectFile {
+
+               /**
+                * @see net.pterodactylus.jsite.project.ProjectFile#getName()
+                */
+               public String getName() {
+                       // TODO Auto-generated method stub
+                       return null;
+               }
+
+               /**
+                * @see net.pterodactylus.jsite.project.ProjectFile#getParents()
+                */
+               public List<ProjectFile> getParents() {
+                       // TODO Auto-generated method stub
+                       return null;
+               }
+
+               /**
+                * @see net.pterodactylus.jsite.project.ProjectFile#isFile()
+                */
+               public boolean isFile() {
+                       // TODO Auto-generated method stub
+                       return false;
+               }
+
+               /**
+                * @see net.pterodactylus.jsite.project.ProjectFile#isDirectory()
+                */
+               public boolean isDirectory() {
+                       // TODO Auto-generated method stub
+                       return false;
+               }
+
+               /**
+                * @see net.pterodactylus.jsite.project.ProjectFile#isHidden()
+                */
+               public boolean isHidden() {
+                       // TODO Auto-generated method stub
+                       return false;
+               }
+
+               /**
+                * @see net.pterodactylus.jsite.project.ProjectFile#getFiles()
+                */
+               public List<ProjectFile> getFiles() {
+                       // TODO Auto-generated method stub
+                       return null;
                }
-               
-               for (File file: currentDirectory.listFiles()) {
-                       String fileName = currentPath + File.separatorChar + file.getName();
-                       if (file.isDirectory()) {
-                               scanPath(fileName, entries);
-                               continue;
-                       }
-                       PhysicalEntry entry = new PhysicalEntry();
-                       entry.setName(fileName);
-                       entry.setPath(file.getPath());
-                       entry.setInsert(!file.isHidden());
-                       entries.add(entry);
-               }
        }
 
 }