/**
* 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 {
/** The overrides. */
private final Map<String, FileOverride> fileOverrides = new HashMap<String, FileOverride>();
+ /** The current root project file. */
+ private ProjectFileImpl rootProjectFile;
+
/**
* Creates a new project.
*/
/**
* Clones the given project.
- *
+ *
* @param project
*/
Project(Project project) {
/**
* Returns the internal ID.
- *
+ *
* @return The internal ID
*/
String getId() {
/**
* Sets the internal ID.
- *
+ *
* @param id
* The internal ID
*/
/**
* Returns the name of the project.
- *
+ *
* @return The name of the project
*/
public String getName() {
/**
* Sets the name of the project.
- *
+ *
* @param name
* The name of the project
*/
/**
* Returns the description of the project.
- *
+ *
* @return The description of the project
*/
public String getDescription() {
/**
* Sets the description of the project
- *
+ *
* @param description
* The description of the project
*/
/**
* Returns the public key of the project.
- *
+ *
* @return The public key of the project
*/
public String getPublicKey() {
/**
* Sets the public key of the project.
- *
+ *
* @param publicKey
* The public key of the project
*/
/**
* Returns the private key of the project.
- *
+ *
* @return The private key of the project
*/
public String getPrivateKey() {
/**
* Sets the private key of the project.
- *
+ *
* @param privateKey
* The private key of the project
*/
/**
* Returns the base path of the project.
- *
+ *
* @return The base path of the project
*/
public String getBasePath() {
/**
* Sets the base path of the project.
- *
+ *
* @param basePath
* The base path of the project
*/
/**
* Returns the default file.
- *
+ *
* @return The default file
*/
public String getDefaultFile() {
/**
* Sets the default file.
- *
+ *
* @param defaultFile
* The default file
*/
/**
* Adds a file override for the given file.
- *
+ *
* @param filePath
* The file path
* @param override
/**
* Removes the file override for the given file.
- *
+ *
* @param filePath
* The file path for which to remove the override
*/
/**
* Returns the list of {@link FileOverride}s.
- *
+ *
* @return All file overrides
*/
public Map<String, FileOverride> getFileOverrides() {
* 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
*/
if (!basePathFile.exists() || !basePathFile.isDirectory()) {
return null;
}
- ProjectFileImpl rootProjectFile = new ProjectFileImpl(null, "", 0, true, false);
+ rootProjectFile = new ProjectFileImpl(null, "", 0, true, false);
scanDirectory(basePathFile, rootProjectFile);
return rootProjectFile;
}
+ /**
+ * Returns the file that is specified by its complete path.
+ *
+ * @param completePath
+ * The complete path of the file
+ * @return The project file at the given path, or <code>null</code> if
+ * there is no such file
+ */
+ public ProjectFile getFile(String completePath) {
+ if (rootProjectFile == null) {
+ getBaseFile();
+ }
+ if ((rootProjectFile == null) || (completePath.length() == 0)) {
+ return rootProjectFile;
+ }
+ String[] pathParts = completePath.split("\\" + File.separator);
+ ProjectFileImpl currentProjectFile = rootProjectFile;
+ for (String pathPart: pathParts) {
+ currentProjectFile = currentProjectFile.getFile(pathPart);
+ if (currentProjectFile == null) {
+ return null;
+ }
+ }
+ return currentProjectFile;
+ }
+
//
// PRIVATE METHODS
//
/**
* Scans the given directory and recreates the file and directory structure
* in the given project file.
- *
+ *
* @param directory
* The directory to scan
* @param projectFile
if (!directory.isDirectory()) {
return;
}
- for (File file : directory.listFiles()) {
+ for (File file: directory.listFiles()) {
ProjectFileImpl projectFileChild = projectFile.addFile(file.getName(), file.length(), file.isDirectory(), file.isHidden());
if (file.isDirectory()) {
scanDirectory(file, projectFileChild);
/**
* Implementation of a {@link ProjectFile}.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
private static class ProjectFileImpl implements ProjectFile, Comparable<ProjectFileImpl> {
/**
* 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
}
/**
+ * Returns the project file with the given name. The project file has to
+ * be a direct child of this project file.
+ *
+ * @param name
+ * The name of the file to get
+ * @return The project file, or <code>null</code> if there is no
+ * project file by that name
+ */
+ public ProjectFileImpl getFile(String name) {
+ if (!isDirectory()) {
+ return null;
+ }
+ for (ProjectFileImpl projectFile: childProjectFiles) {
+ if (projectFile.getName().equals(name)) {
+ return projectFile;
+ }
+ }
+ return null;
+ }
+
+ /**
* @see net.pterodactylus.jsite.project.ProjectFile#getFiles()
*/
public List<ProjectFile> getFiles() {
/**
* Adds a new project file as child to this project file.
- *
+ *
* @param name
* The name of the file
* @param size