From 2f3cecff551c3f56e6e5f4457cba7d72ba36eb90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 28 May 2008 14:54:07 +0200 Subject: [PATCH] remove entries altogether --- .../pterodactylus/jsite/project/AbstractEntry.java | 170 --------------------- src/net/pterodactylus/jsite/project/Entry.java | 113 -------------- .../pterodactylus/jsite/project/PhysicalEntry.java | 63 -------- src/net/pterodactylus/jsite/project/Project.java | 130 ++-------------- .../jsite/project/ProjectManager.java | 23 ++- .../pterodactylus/jsite/project/RedirectEntry.java | 64 -------- 6 files changed, 25 insertions(+), 538 deletions(-) delete mode 100644 src/net/pterodactylus/jsite/project/AbstractEntry.java delete mode 100644 src/net/pterodactylus/jsite/project/Entry.java delete mode 100644 src/net/pterodactylus/jsite/project/PhysicalEntry.java delete mode 100644 src/net/pterodactylus/jsite/project/RedirectEntry.java diff --git a/src/net/pterodactylus/jsite/project/AbstractEntry.java b/src/net/pterodactylus/jsite/project/AbstractEntry.java deleted file mode 100644 index ff04760..0000000 --- a/src/net/pterodactylus/jsite/project/AbstractEntry.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * jSite2 - AbstractEntry.java - - * Copyright © 2008 David Roden - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package net.pterodactylus.jsite.project; - -import java.io.File; - -import net.pterodactylus.util.beans.AbstractBean; - -/** - * Abstract base implementation of a {@link Entry}. - * - * @author David ‘Bombe’ Roden <bombe@freenetproject.org> - */ -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"; - - /** Whether this entry is virtual. */ - private final boolean virtual; - - /** The name of the file. */ - private String name; - - /** The default insert flag for this entry. */ - private boolean defaultInsert; - - /** Whether to insert the file. */ - private boolean insert; - - /** The default content type of this entry. */ - private String defaultContentType; - - /** The content type of the file. */ - private String contentType; - - /** - * Creates a new entry. - * - * @param virtual - * true if this entry is virtual, - * false otherwise - */ - protected AbstractEntry(boolean virtual) { - this.virtual = virtual; - } - - /** - * {@inheritDoc} - */ - public boolean isVirtual() { - return virtual; - } - - /** - * {@inheritDoc} - */ - public boolean isDefault() { - return (insert == defaultInsert) && isDefaultContentType(); - } - - /** - * {@inheritDoc} - */ - public boolean isDefaultContentType() { - return ((defaultContentType != null) ? defaultContentType.equals(contentType) : (contentType == null)); - } - - /** - * Sets the default insert flag for this entry. The default insert flag is - * derived from {@link File#isHidden()}. - * - * @param defaultInsert - * true if the default for this entry is to insert - * it, false otherwise - */ - void setDefaultInsert(boolean defaultInsert) { - this.defaultInsert = defaultInsert; - } - - /** - * {@inheritDoc} - */ - public String getName() { - return name; - } - - /** - * {@inheritDoc} - */ - public void setName(String name) { - String oldName = this.name; - this.name = name; - fireIfPropertyChanged(PROPERTY_NAME, oldName, name); - } - - /** - * {@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; - } - - /** - * {@inheritDoc} - */ - public void setContentType(String contentType) { - String oldContentType = this.contentType; - this.contentType = contentType; - fireIfPropertyChanged(PROPERTY_CONTENT_TYPE, oldContentType, contentType); - } - - /** - * Sets the default content type of the entry. The default content type is - * derived from its extension. - * - * @param defaultContentType - * The default content type - */ - void setDefaultContentType(String defaultContentType) { - this.defaultContentType = defaultContentType; - } - - /** - * {@inheritDoc} - */ - public void restoreDefaultContentType() { - this.contentType = defaultContentType; - } - -} diff --git a/src/net/pterodactylus/jsite/project/Entry.java b/src/net/pterodactylus/jsite/project/Entry.java deleted file mode 100644 index 52643be..0000000 --- a/src/net/pterodactylus/jsite/project/Entry.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * jSite2 - Entry.java - - * Copyright © 2008 David Roden - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package net.pterodactylus.jsite.project; - -import java.io.File; - -/** - * A file is an entry in a directory. Its name can contain multiple components, - * separated by the platform’s {@link File#separatorChar}. - * - * @author David ‘Bombe’ Roden <bombe@freenetproject.org> - */ -public interface Entry { - - /** - * Returns whether this entry denotes a virtual file. A virtual file entry - * is a file entry that does not have a corresponding file on the disk. - * - * @return true if this entry is a virtual file entry, - * false otherwise - */ - public boolean isVirtual(); - - /** - * Returns whether this entry still has its default settings. - * - * @return true if this entry has not been changed by the - * user, false otherwise - */ - public boolean isDefault(); - - /** - * Returns whether the content type setting is still the default. - * - * @return true if the content type has not been changed by - * the user, false otherwise - */ - public boolean isDefaultContentType(); - - /** - * Returns the name of the file. The name can contain multiple path - * components, separated by the platform’s {@link File#separatorChar}. It - * will never start with a separator, though. - * - * @return The name of the file - */ - public String getName(); - - /** - * Sets the name of the file. - * - * @param name - * The name of the file - */ - 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. - * - * @return The content of the file - */ - public String getContentType(); - - /** - * Sets the content type of the file. - * - * @param contentType - * The content type of the file - */ - public void setContentType(String contentType); - - /** - * Restores the default content type. - */ - public void restoreDefaultContentType(); - -} diff --git a/src/net/pterodactylus/jsite/project/PhysicalEntry.java b/src/net/pterodactylus/jsite/project/PhysicalEntry.java deleted file mode 100644 index 6985580..0000000 --- a/src/net/pterodactylus/jsite/project/PhysicalEntry.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * jSite2 - PhysicalEntry.java - - * Copyright © 2008 David Roden - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package net.pterodactylus.jsite.project; - -/** - * A physical file represents a file on the disk. - * - * @author David ‘Bombe’ Roden <bombe@freenetproject.org> - */ -public class PhysicalEntry extends AbstractEntry { - - /** The name of the “path” property. */ - public static final String PROPERTY_PATH = "path"; - - /** The path of the file. */ - private String path; - - /** - * Creates a new entry that represents a physical file on disk. - */ - public PhysicalEntry() { - super(false); - } - - /** - * Returns the path of the file. - * - * @return The path of the file - */ - public String getPath() { - return path; - } - - /** - * Sets the path of the file. - * - * @param path - * The path of the file - */ - public void setPath(String path) { - String oldPath = this.path; - this.path = path; - fireIfPropertyChanged(PROPERTY_PATH, oldPath, path); - } - -} diff --git a/src/net/pterodactylus/jsite/project/Project.java b/src/net/pterodactylus/jsite/project/Project.java index 36a27f9..04760e2 100644 --- a/src/net/pterodactylus/jsite/project/Project.java +++ b/src/net/pterodactylus/jsite/project/Project.java @@ -20,17 +20,13 @@ package net.pterodactylus.jsite.project; import java.beans.PropertyChangeListener; -import java.io.File; -import java.util.ArrayList; -import java.util.List; import net.pterodactylus.util.beans.AbstractBean; -import net.pterodactylus.util.io.MimeTypes; /** * 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 { @@ -50,9 +46,6 @@ public class Project extends AbstractBean { /** 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; @@ -71,12 +64,6 @@ 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 virtual files. */ - private List virtualEntries = new ArrayList(); - /** * Creates a new project. */ @@ -86,7 +73,7 @@ public class Project extends AbstractBean { /** * Clones the given project. - * + * * @param project */ Project(Project project) { @@ -95,13 +82,11 @@ public class Project extends AbstractBean { this.publicKey = project.publicKey; this.privateKey = project.privateKey; this.basePath = project.basePath; - this.basePathEntries.addAll(project.basePathEntries); - this.virtualEntries.addAll(project.virtualEntries); } /** * Returns the internal ID. - * + * * @return The internal ID */ String getId() { @@ -110,7 +95,7 @@ public class Project extends AbstractBean { /** * Sets the internal ID. - * + * * @param id * The internal ID */ @@ -120,7 +105,7 @@ public class Project extends AbstractBean { /** * Returns the name of the project. - * + * * @return The name of the project */ public String getName() { @@ -129,7 +114,7 @@ public class Project extends AbstractBean { /** * Sets the name of the project. - * + * * @param name * The name of the project */ @@ -141,7 +126,7 @@ public class Project extends AbstractBean { /** * Returns the description of the project. - * + * * @return The description of the project */ public String getDescription() { @@ -150,7 +135,7 @@ public class Project extends AbstractBean { /** * Sets the description of the project - * + * * @param description * The description of the project */ @@ -162,7 +147,7 @@ public class Project extends AbstractBean { /** * Returns the public key of the project. - * + * * @return The public key of the project */ public String getPublicKey() { @@ -171,7 +156,7 @@ public class Project extends AbstractBean { /** * Sets the public key of the project. - * + * * @param publicKey * The public key of the project */ @@ -183,7 +168,7 @@ public class Project extends AbstractBean { /** * Returns the private key of the project. - * + * * @return The private key of the project */ public String getPrivateKey() { @@ -192,7 +177,7 @@ public class Project extends AbstractBean { /** * Sets the private key of the project. - * + * * @param privateKey * The private key of the project */ @@ -204,7 +189,7 @@ public class Project extends AbstractBean { /** * Returns the base path of the project. - * + * * @return The base path of the project */ public String getBasePath() { @@ -213,7 +198,7 @@ public class Project extends AbstractBean { /** * Sets the base path of the project. - * + * * @param basePath * The base path of the project */ @@ -223,91 +208,4 @@ 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); - 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.setDefaultInsert(!file.isHidden()); - entry.setInsert(!file.isHidden()); - String extension = fileName.substring(fileName.lastIndexOf('.') + 1); - List mimeTypes = MimeTypes.getMimeTypes(extension); - if (!mimeTypes.isEmpty()) { - entry.setDefaultContentType(mimeTypes.get(0)); - entry.setContentType(mimeTypes.get(0)); - } - entries.add(entry); - } - } - } diff --git a/src/net/pterodactylus/jsite/project/ProjectManager.java b/src/net/pterodactylus/jsite/project/ProjectManager.java index 2cad1e4..69b0522 100644 --- a/src/net/pterodactylus/jsite/project/ProjectManager.java +++ b/src/net/pterodactylus/jsite/project/ProjectManager.java @@ -43,7 +43,7 @@ import net.pterodactylus.util.number.Hex; /** * Manages projects, taking care of persistence, lifetime statistics, and other * things. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ public class ProjectManager implements PropertyChangeListener { @@ -66,7 +66,7 @@ public class ProjectManager implements PropertyChangeListener { /** * Creates a new project manager that saves and restores its state to/from * the given directory. - * + * * @param directory * The directory to save and restore states to/from */ @@ -80,7 +80,7 @@ public class ProjectManager implements PropertyChangeListener { /** * Returns the directory the projects are loaded from and saved to. - * + * * @return The directory for storing the projects */ public String getDirectory() { @@ -89,7 +89,7 @@ public class ProjectManager implements PropertyChangeListener { /** * Returns a list of all projects. - * + * * @return A list of all projects */ public List getProjects() { @@ -98,7 +98,7 @@ public class ProjectManager implements PropertyChangeListener { /** * Sets the node manager to use. - * + * * @param nodeManager * The node manager to use */ @@ -112,7 +112,7 @@ public class ProjectManager implements PropertyChangeListener { /** * Loads projects and statistics. - * + * * @throws IOException * if an I/O error occurs */ @@ -146,7 +146,6 @@ public class ProjectManager implements PropertyChangeListener { project.setPrivateKey(projectPrivateKey); project.setPublicKey(projectPublicKey); project.setBasePath(projectBasePath); - project.rescanBasePath(); projects.add(project); logger.fine("loaded project “" + project.getName() + "”."); projectIndex++; @@ -155,7 +154,7 @@ public class ProjectManager implements PropertyChangeListener { /** * Saves projects and statistics. - * + * * @throws IOException * if an I/O error occurs */ @@ -191,7 +190,7 @@ public class ProjectManager implements PropertyChangeListener { /** * Creates a new project. The returned {@link Project} will contain a newly * generated key pair. - * + * * @return A newly created project * @throws IOException * if an I/O error occured communicating with the node @@ -221,7 +220,7 @@ public class ProjectManager implements PropertyChangeListener { * Clones the given project and returns the clone. The clone will be * identical in all user-exposed fields, except for the project’s * {@link Project#getId ID}. - * + * * @param project * The project to clone * @return The cloned project @@ -241,7 +240,7 @@ public class ProjectManager implements PropertyChangeListener { /** * Removes the given project. - * + * * @param project * The project to remove */ @@ -261,7 +260,7 @@ public class ProjectManager implements PropertyChangeListener { /** * Generates a new random ID, consisting of 16 random bytes converted to a * hexadecimal number. - * + * * @return The new ID */ private static String generateId() { diff --git a/src/net/pterodactylus/jsite/project/RedirectEntry.java b/src/net/pterodactylus/jsite/project/RedirectEntry.java deleted file mode 100644 index 82b2968..0000000 --- a/src/net/pterodactylus/jsite/project/RedirectEntry.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * jSite2 - RedirectEntry.java - - * Copyright © 2008 David Roden - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package net.pterodactylus.jsite.project; - -/** - * A redirect is a file that is not really inserted, instead it just points to - * another file on freenet. - * - * @author David ‘Bombe’ Roden <bombe@freenetproject.org> - */ -public class RedirectEntry extends AbstractEntry { - - /** The name of the “target” property. */ - public static final String PROPERTY_TARGET = "target"; - - /** The target of the redirect. */ - private String target; - - /** - * Creates a new entry that redirects to another URL. - */ - public RedirectEntry() { - super(true); - } - - /** - * Returns the target of the redirect. - * - * @return The target of the redirect - */ - public String getTarget() { - return target; - } - - /** - * Sets the target of the redirect. - * - * @param target - * The target of the redirect - */ - public void setTarget(String target) { - String oldTarget = target; - this.target = target; - fireIfPropertyChanged(PROPERTY_TARGET, oldTarget, target); - } - -} -- 2.7.4