/** 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;
/**
* {@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;
}
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.
/** 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.
*
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);
+ }
+ }
+
}