X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fproject%2FProject.java;h=b6c514b8e5964aa6fb6235921d110505c18f50df;hb=2357d27038c4dc266052fd9a07dad5eb24d8760d;hp=51ec2d323669c7508972e8f900806f16712a5ba3;hpb=5cbf06525c3a71ff25c5c1f0ebe794396b8d35a4;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/project/Project.java b/src/net/pterodactylus/jsite/project/Project.java index 51ec2d3..b6c514b 100644 --- a/src/net/pterodactylus/jsite/project/Project.java +++ b/src/net/pterodactylus/jsite/project/Project.java @@ -31,7 +31,6 @@ import net.pterodactylus.util.beans.AbstractBean; * {@link PropertyChangeListener}s if any of the contained properties change. * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> - * @version $Id$ */ public class Project extends AbstractBean { @@ -47,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 “base path entries” property. */ + public static final String PROPERTY_BASE_PATH_ENTRIES = "basePathEntries"; + /** Internal ID. */ private String id; @@ -68,8 +70,11 @@ 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(); + /** The list of files from the base path. */ + private List basePathEntries = new ArrayList(); + + /** The list of virtual files. */ + private List virtualEntries = new ArrayList(); /** * Returns the internal ID. @@ -196,52 +201,83 @@ public class Project extends AbstractBean { } /** - * 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; + * Rescans the base path for new or changed files. + */ + public void rescanBasePath() { + List entries = new ArrayList(); + scanPath("", entries); + basePathEntries.clear(); + basePathEntries.addAll(entries); + firePropertyChange(PROPERTY_BASE_PATH_ENTRIES, null, null); + } + + /** + * Returns the list of files from the base path. + * + * @return The list of files from the base path + */ + public List getBasePathEntries() { + return basePathEntries; + } + + /** + * Returns the list of visual entries. + * + * @return The visual entries + */ + public List getVirtualEntries() { + return virtualEntries; + } + + /** + * Adds a virtual entry that redirects to the given target. + * + * @param name + * The name of the entry + * @param contentType + * The content type of the entry, or null for + * auto-detection + * @param target + * The target URI of the redirect + */ + public void addVirtualEntry(String name, String contentType, String target) { + RedirectEntry redirectEntry = new RedirectEntry(); + redirectEntry.setName(name); + redirectEntry.setContentType(contentType); + redirectEntry.setTarget(target); + redirectEntry.setInsert(true); + } + + // + // 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.getName(); + if (file.isDirectory()) { + scanPath(fileName + File.separatorChar, entries); + continue; + } + PhysicalEntry entry = new PhysicalEntry(); + entry.setName(fileName); + entry.setPath(file.getPath()); + entry.setInsert(!file.isHidden()); + entries.add(entry); } - for (File file: currentDirectory.listFiles()) { - String fileName = currentPath + file.getName(); - if (file.isDirectory()) { - scanPath(fileName + File.separatorChar, entries); - continue; - } - PhysicalEntry entry = new PhysicalEntry(); - entry.setName(fileName); - entry.setPath(file.getPath()); - entry.setInsert(!file.isHidden()); - entries.add(entry); - } } }