+++ /dev/null
-/*
- * 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
- * <code>true</code> if this entry is virtual,
- * <code>false</code> 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
- * <code>true</code> if the default for this entry is to insert
- * it, <code>false</code> 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;
- }
-
-}
+++ /dev/null
-/*
- * 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 <code>true</code> if this entry is a virtual file entry,
- * <code>false</code> otherwise
- */
- public boolean isVirtual();
-
- /**
- * Returns whether this entry still has its default settings.
- *
- * @return <code>true</code> if this entry has not been changed by the
- * user, <code>false</code> otherwise
- */
- public boolean isDefault();
-
- /**
- * Returns whether the content type setting is still the default.
- *
- * @return <code>true</code> if the content type has not been changed by
- * the user, <code>false</code> 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 <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.
- *
- * @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();
-
-}
+++ /dev/null
-/*
- * 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);
- }
-
-}
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 {
/** 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;
/** The base path of the project. */
private String basePath;
- /** The list of files from the base path. */
- private List<Entry> basePathEntries = new ArrayList<Entry>();
-
- /** The list of virtual files. */
- private List<Entry> virtualEntries = new ArrayList<Entry>();
-
/**
* Creates a new project.
*/
/**
* Clones the given project.
- *
+ *
* @param project
*/
Project(Project project) {
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() {
/**
* 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
*/
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);
- 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<Entry> getBasePathEntries() {
- return basePathEntries;
- }
-
- /**
- * Returns the list of visual entries.
- *
- * @return The visual entries
- */
- public List<Entry> 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 <code>null</code> 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<Entry> 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<String> mimeTypes = MimeTypes.getMimeTypes(extension);
- if (!mimeTypes.isEmpty()) {
- entry.setDefaultContentType(mimeTypes.get(0));
- entry.setContentType(mimeTypes.get(0));
- }
- entries.add(entry);
- }
- }
-
}
/**
* Manages projects, taking care of persistence, lifetime statistics, and other
* things.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
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
*/
/**
* Returns the directory the projects are loaded from and saved to.
- *
+ *
* @return The directory for storing the projects
*/
public String getDirectory() {
/**
* Returns a list of all projects.
- *
+ *
* @return A list of all projects
*/
public List<Project> getProjects() {
/**
* Sets the node manager to use.
- *
+ *
* @param nodeManager
* The node manager to use
*/
/**
* Loads projects and statistics.
- *
+ *
* @throws IOException
* if an I/O error occurs
*/
project.setPrivateKey(projectPrivateKey);
project.setPublicKey(projectPublicKey);
project.setBasePath(projectBasePath);
- project.rescanBasePath();
projects.add(project);
logger.fine("loaded project “" + project.getName() + "”.");
projectIndex++;
/**
* Saves projects and statistics.
- *
+ *
* @throws IOException
* if an I/O error occurs
*/
/**
* 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
* 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
/**
* Removes the given project.
- *
+ *
* @param project
* The project to remove
*/
/**
* Generates a new random ID, consisting of 16 random bytes converted to a
* hexadecimal number.
- *
+ *
* @return The new ID
*/
private static String generateId() {
+++ /dev/null
-/*
- * 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);
- }
-
-}