From ed3c99a566139d0022f78e85d61a63a3876e1725 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 24 May 2008 13:01:44 +0200 Subject: [PATCH] add base path scanning --- .../pterodactylus/jsite/project/AbstractEntry.java | 22 +++++++++ src/net/pterodactylus/jsite/project/Entry.java | 17 +++++++ src/net/pterodactylus/jsite/project/Project.java | 53 ++++++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/src/net/pterodactylus/jsite/project/AbstractEntry.java b/src/net/pterodactylus/jsite/project/AbstractEntry.java index 74e9076..6a726c6 100644 --- a/src/net/pterodactylus/jsite/project/AbstractEntry.java +++ b/src/net/pterodactylus/jsite/project/AbstractEntry.java @@ -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; } diff --git a/src/net/pterodactylus/jsite/project/Entry.java b/src/net/pterodactylus/jsite/project/Entry.java index 65f2110..d16e6be 100644 --- a/src/net/pterodactylus/jsite/project/Entry.java +++ b/src/net/pterodactylus/jsite/project/Entry.java @@ -46,6 +46,23 @@ public interface Entry { public void setName(String name); /** + * Returns whether this file should be inserted. + * + * @return true to insert the file, false to + * skip it + */ + public boolean isInsert(); + + /** + * Sets whether this file should be inserted. + * + * @param insert + * true to insert the file, false + * to skip it + */ + public void setInsert(boolean insert); + + /** * Returns the content type of the file. If the content type is * null, the node will auto-detect the content type based on * the filename. The content type is given as a MIME type. diff --git a/src/net/pterodactylus/jsite/project/Project.java b/src/net/pterodactylus/jsite/project/Project.java index 71a3736..6510805 100644 --- a/src/net/pterodactylus/jsite/project/Project.java +++ b/src/net/pterodactylus/jsite/project/Project.java @@ -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 basePathEntries = new ArrayList(); + /** * 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 entries = new ArrayList(); + scanPath("", entries); + } + + /** + * Returns the list of files from the base path. + * + * @return The list of files from the base path + */ + public List 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 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); + } + } + } -- 2.7.4