add base path scanning
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 24 May 2008 11:01:44 +0000 (13:01 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 24 May 2008 11:01:44 +0000 (13:01 +0200)
src/net/pterodactylus/jsite/project/AbstractEntry.java
src/net/pterodactylus/jsite/project/Entry.java
src/net/pterodactylus/jsite/project/Project.java

index 74e9076..6a726c6 100644 (file)
@@ -32,12 +32,18 @@ public abstract class AbstractEntry extends AbstractBean implements Entry {
        /** The name of the “name” property. */
        public static final String PROPERTY_NAME = "name";
 
+       /** The name of the “insert” property. */
+       public static final String PROPERTY_INSERT = "insert";
+
        /** The name of the “content type” property. */
        public static final String PROPERTY_CONTENT_TYPE = "contentType";
 
        /** The name of the file. */
        private String name;
 
+       /** Whether to insert the file. */
+       private boolean insert;
+
        /** The content type of the file. */
        private String contentType;
 
@@ -60,6 +66,22 @@ public abstract class AbstractEntry extends AbstractBean implements Entry {
        /**
         * {@inheritDoc}
         */
+       public boolean isInsert() {
+               return insert;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void setInsert(boolean insert) {
+               boolean oldInsert = this.insert;
+               this.insert = insert;
+               fireIfPropertyChanged(PROPERTY_INSERT, oldInsert, insert);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public String getContentType() {
                return contentType;
        }
index 65f2110..d16e6be 100644 (file)
@@ -46,6 +46,23 @@ public interface Entry {
        public void setName(String name);
 
        /**
+        * Returns whether this file should be inserted.
+        * 
+        * @return <code>true</code> to insert the file, <code>false</code> to
+        *         skip it
+        */
+       public boolean isInsert();
+
+       /**
+        * Sets whether this file should be inserted.
+        * 
+        * @param insert
+        *            <code>true</code> to insert the file, <code>false</code>
+        *            to skip it
+        */
+       public void setInsert(boolean insert);
+
+       /**
         * Returns the content type of the file. If the content type is
         * <code>null</code>, the node will auto-detect the content type based on
         * the filename. The content type is given as a MIME type.
index 71a3736..6510805 100644 (file)
@@ -65,6 +65,9 @@ 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>();
+
        /**
         * Returns the internal ID.
         * 
@@ -189,4 +192,54 @@ public class Project extends AbstractBean {
                fireIfPropertyChanged(PROPERTY_BASE_PATH, oldBasePath, basePath);
        }
 
+       /**
+        * 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;
+               }
+               
+               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);
+               }
+       }
+
 }