import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.pterodactylus.util.logging.Logging;
/**
* The core of jSite.
*/
public class CoreImpl implements Core, NodeListener, RequestListener {
+ /** The logger. */
+ private static final Logger logger = Logging.getLogger(CoreImpl.class.getName());
+
/** The core listeners. */
private final List<CoreListener> coreListeners = new ArrayList<CoreListener>();
* {@inheritDoc}
*/
public void addCoreListener(CoreListener coreListener) {
+ logger.log(Level.FINEST, "adding core listener: " + coreListener);
coreListeners.add(coreListener);
}
* {@inheritDoc}
*/
public void removeCoreListener(CoreListener coreListener) {
+ logger.log(Level.FINEST, "removing core listener: " + coreListener);
coreListeners.remove(coreListener);
}
* The directory the projects were loaded from
*/
private void fireLoadingProjectsDone(String directory) {
+ logger.log(Level.FINEST, "firing loadingProjectsDone event with [directory=" + directory + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.loadingProjectsDone(directory);
}
* The exception that occured when loading projects
*/
private void fireLoadingProjectsFailed(String directory, Throwable throwable) {
+ logger.log(Level.FINEST, "firing loadingProjectsFailed event with [directory=" + directory + ",throwable=" + throwable + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.loadingProjectsFailed(directory, throwable);
}
* The directory the projects were saved to
*/
private void fireSavingProjectsDone(String directory) {
+ logger.log(Level.FINEST, "firing savingProjectsDone event with [directory=" + directory + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.savingProjectsDone(directory);
}
* The exception that occured when saving the projects
*/
private void fireSavingProjectsFailed(String directory, Throwable throwable) {
+ logger.log(Level.FINEST, "firing savingProjectsFailed event with [directory=" + directory + ",throwable=" + throwable + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.savingProjectsFailed(directory, throwable);
}
* The project that was added
*/
private void fireProjectAdded(Project project) {
+ logger.log(Level.FINEST, "firing projectAdded event with [project=" + project + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.projectAdded(project);
}
* The clone of the project
*/
private void fireProjectCloned(Project clonedProject, Project projectClone) {
+ logger.log(Level.FINEST, "firing projectCloned event with [clonedProject=" + clonedProject + ",projectClone=" + projectClone + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.projectCloned(clonedProject, projectClone);
}
* The project that was removed
*/
private void fireProjectRemoved(Project project) {
+ logger.log(Level.FINEST, "firing projectRemoved event with [project=" + project + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.projectRemoved(project);
}
* The directory the nodes were loaded from
*/
private void fireLoadingNodesDone(String directory) {
+ logger.log(Level.FINEST, "firing loadingNodesDone event with [directory=" + directory + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.loadingNodesDone(directory);
}
* The exception that occured while loading the nodes
*/
private void fireLoadingNodesFailed(String directory, Throwable throwable) {
+ logger.log(Level.FINEST, "firing loadingNodesFailed event with [directory=" + directory + ",throwable=" + throwable + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.loadingNodesFailed(directory, throwable);
}
* The directory the nodes were saved to
*/
private void fireSavingNodesDone(String directory) {
+ logger.log(Level.FINEST, "firing savingNodesDone event with [directory=" + directory + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.savingNodesDone(directory);
}
* The exception that occured while saving the nodes
*/
private void fireSavingNodesFailed(String directory, Throwable throwable) {
+ logger.log(Level.FINEST, "firing savingNodesFailed event with [directory=" + directory + ",throwable=" + throwable + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.savingProjectsFailed(directory, throwable);
}
* Notifies all core listeners that the core has loaded and is ready to run.
*/
private void fireCoreLoaded() {
+ logger.log(Level.FINEST, "firing coreLoaded event");
for (CoreListener coreListener : coreListeners) {
coreListener.coreLoaded();
}
* Notifies all listeners that the core was stopped.
*/
private void fireCoreStopped() {
+ logger.log(Level.FINEST, "firing coreStopped event");
for (CoreListener coreListener : coreListeners) {
coreListener.coreStopped();
}
* The node that was added
*/
private void fireNodeAdded(Node node) {
+ logger.log(Level.FINEST, "firing nodeAdded event with [node=" + node + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeAdded(node);
}
* The node that was removed
*/
private void fireNodeRemoved(Node node) {
+ logger.log(Level.FINEST, "firing nodeRemoved event with [node=" + node + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeRemoved(node);
}
* The node that is being connected to
*/
private void fireNodeConnecting(Node node) {
+ logger.log(Level.FINEST, "firing nodeConnecting event with [node=" + node + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeConnecting(node);
}
* The node that is now connected
*/
private void fireNodeConnected(Node node) {
+ logger.log(Level.FINEST, "firing nodeConnected event with [node=" + node + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeConnected(node);
}
* The cause of the failure
*/
private void fireNodeConnectionFailed(Node node, Throwable cause) {
+ logger.log(Level.FINEST, "firing nodeConnectionFailed event with [node=" + node + ",cause=" + cause + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeConnectionFailed(node, cause);
}
* if there was no exception
*/
private void fireNodeDisconnected(Node node, Throwable throwable) {
+ logger.log(Level.FINEST, "firing nodeDisconnected event with [node=" + node + ",throwable=" + throwable + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeDisconnected(node, throwable);
}
* {@inheritDoc}
*/
public void start() {
+ logger.log(Level.INFO, "starting core…");
try {
nodeManager.load();
fireLoadingNodesDone(nodeManager.getDirectory());
* {@inheritDoc}
*/
public void stop() {
+ logger.log(Level.INFO, "stopping core…");
try {
projectManager.save();
fireSavingProjectsDone(projectManager.getDirectory());
* {@inheritDoc}
*/
public boolean addNode(Node node) throws UnknownHostException {
+ logger.log(Level.FINEST, "addNode(node=" + node + ")");
return nodeManager.addNode(node);
}
* {@inheritDoc}
*/
public void removeNode(Node node) {
+ logger.log(Level.FINEST, "removeNode(node=" + node + ")");
nodeManager.removeNode(node);
}
* {@inheritDoc}
*/
public void connectToNode(Node node) {
+ logger.log(Level.FINEST, "connectToNode(node=" + node + ")");
fireNodeConnecting(node);
nodeManager.connect(node);
}
* {@inheritDoc}
*/
public void disconnectFromNode(Node node) {
+ logger.log(Level.FINEST, "disconnectFromNode(node=" + node + ")");
nodeManager.disconnect(node);
}
* {@inheritDoc}
*/
public void createProject() throws IOException, JSiteException {
+ logger.log(Level.FINEST, "createProject()");
Project newProject = projectManager.createProject();
fireProjectAdded(newProject);
}
* {@inheritDoc}
*/
public void cloneProject(Project project) {
+ logger.log(Level.FINEST, "cloneProject(project=" + project + ")");
Project projectClone = projectManager.cloneProject(project);
fireProjectCloned(project, projectClone);
}
* {@inheritDoc}
*/
public void removeProject(Project project) {
+ logger.log(Level.FINEST, "removeProject(project=" + project + ")");
projectManager.removeProject(project);
fireProjectRemoved(project);
}
*/
@SuppressWarnings("unused")
private void loadConfig() {
+ logger.log(Level.FINEST, "loadConfig()");
/* TODO */
}
*/
@SuppressWarnings("unused")
private void saveConfig() {
+ logger.log(Level.FINEST, "saveConfig()");
/* TODO */
}
/**
* @see java.lang.Object#toString()
*/
- @java.lang.Override
+ @Override
public String toString() {
return ((insert != null) ? String.valueOf(insert) : "") + "|" + ((contentType != null) ? contentType : "") + "|" + ((redirectTarget != null) ? redirectTarget : "");
}
--- /dev/null
+/*
+ * jSite2 - InsertListener.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.core;
+
+import java.util.EventListener;
+
+/**
+ * Interface for objects that want to be notified on events emitted by the
+ * {@link InsertManager}.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ */
+public interface InsertListener extends EventListener {
+
+ /**
+ * Notifies a listener that an insert was added.
+ *
+ * @param insert
+ * The insert that was added
+ */
+ public void insertAdded(Insert insert);
+
+ /**
+ * Notifies a listener that an insert was removed.
+ *
+ * @param insert
+ * The insert that was removed
+ */
+ public void insertRemoved(Insert insert);
+
+ /**
+ * Notifies a listener that an insert was started.
+ *
+ * @param insert
+ * The insert that was started
+ */
+ public void insertStarted(Insert insert);
+
+ /**
+ * Notifies a listener that an insert made some progress.
+ *
+ * @param insert
+ * The insert that made some progress
+ */
+ public void insertProgressed(Insert insert);
+
+ /**
+ * Notifies listeners that an insert generated a URI.
+ *
+ * @param insert
+ * The insert that generated a URI
+ * @param uri
+ * The generated URI
+ */
+ public void insertGeneratedURI(Insert insert, String uri);
+
+ /**
+ * Notifies a listener that an insert has finished.
+ *
+ * @param insert
+ * The insert that has finished
+ */
+ public void insertFinished(Insert insert);
+
+}
*/
@Override
public String toString() {
- return name + " (" + hostname + ((port == 9481) ? ("") : (":" + port)) + ")";
+ return getClass().getName() + "[name=" + name + ",hostname=" + hostname + ",port=" + port + "]";
}
}
* The node that was added.
*/
private void fireNodeAdded(Node node) {
+ logger.log(Level.FINEST, "firing nodeAdded event with [node=" + node + "]");
for (NodeListener nodeListener : nodeListeners) {
nodeListener.nodeAdded(node);
}
* The node that was removed
*/
private void fireNodeRemoved(Node node) {
+ logger.log(Level.FINEST, "firing nodeRemoved event with [node=" + node + "]");
for (NodeListener nodeListener : nodeListeners) {
nodeListener.nodeRemoved(node);
}
* The node that is now connected
*/
private void fireNodeConnected(Node node) {
+ logger.log(Level.FINEST, "firing nodeConnected event with [node=" + node + "]");
for (NodeListener nodeListener : nodeListeners) {
nodeListener.nodeConnected(node);
}
* The cause of the failure
*/
private void fireNodeConnectionFailed(Node node, Throwable cause) {
+ logger.log(Level.FINEST, "firing nodeConnectionFailed event with [node=" + node + ",cause=" + cause + "]");
for (NodeListener nodeListener : nodeListeners) {
nodeListener.nodeConnectionFailed(node, cause);
}
* if there was no exception
*/
private void fireNodeDisconnected(Node node, Throwable throwable) {
+ logger.log(Level.FINEST, "firing nodeDisconnected event with [node=" + node + ",throwable=" + throwable + "]");
for (NodeListener nodeListener : nodeListeners) {
nodeListener.nodeDisconnected(node, throwable);
}
* if an I/O error occurs loading the nodes
*/
public void load() throws IOException {
+ logger.log(Level.FINEST, "load()");
File directoryFile = new File(directory);
File nodeFile = new File(directoryFile, "nodes.properties");
if (!nodeFile.exists() || !nodeFile.isFile() || !nodeFile.canRead()) {
newNode.setPort(nodePort);
loadedNodes.add(newNode);
}
- logger.fine("loaded " + loadedNodes.size() + " nodes from config");
+ logger.log(Level.FINE, "loaded " + loadedNodes.size() + " nodes from config");
synchronized (syncObject) {
nodes.clear();
for (Node node : loadedNodes) {
* if an I/O error occurs saving the nodes
*/
public void save() throws IOException {
+ logger.log(Level.FINEST, "save()");
File directoryFile = new File(directory);
if (!directoryFile.exists()) {
if (!directoryFile.mkdirs()) {
* if the node was not added because it was already known
*/
public boolean addNode(Node node) {
+ logger.log(Level.FINEST, "addNode(node=" + node + ")");
if (nodes.contains(node)) {
- logger.warning("was told to add already known node: " + node);
+ logger.log(Level.WARNING, "was told to add already known node: " + node);
return false;
}
node.addPropertyChangeListener(this);
* The node to remove
*/
public void removeNode(Node node) {
+ logger.log(Level.FINEST, "removeNode(node=" + node + ")");
synchronized (syncObject) {
if (!nodes.contains(node)) {
return;
* The node to connect to
*/
public void connect(Node node) {
+ logger.log(Level.FINEST, "connect(node=" + node + ")");
HighLevelClient highLevelClient;
highLevelClient = nodeClients.get(node);
if (highLevelClient == null) {
- logger.warning("was told to connect to unknown node: " + node);
+ logger.log(Level.WARNING, "was told to connect to unknown node: " + node);
return;
}
try {
* The node to disconnect
*/
public void disconnect(Node node) {
+ logger.log(Level.FINEST, "disconnect(node=" + node + ")");
synchronized (syncObject) {
if (!nodes.contains(node)) {
return;
* if there is a problem with the node
*/
public String[] generateKeyPair() throws IOException, JSiteException {
+ logger.log(Level.FINEST, "generateKeyPair()");
if (nodes.isEmpty()) {
throw new NoNodeException("no node configured");
}
* {@inheritDoc}
*/
public void clientConnected(HighLevelClient highLevelClient) {
- logger.log(Level.FINER, "clientConnected(c=" + highLevelClient + ")");
+ logger.log(Level.FINEST, "clientConnected(highLevelClient=" + highLevelClient + ")");
Node node = clientNodes.get(highLevelClient);
if (node == null) {
logger.log(Level.WARNING, "got event for unknown client");
* {@inheritDoc}
*/
public void clientDisconnected(HighLevelClient highLevelClient, Throwable throwable) {
- logger.log(Level.FINER, "clientDisconnected(c=" + highLevelClient + ",t=" + throwable + ")");
+ logger.log(Level.FINEST, "clientDisconnected(highLevelClient=" + highLevelClient + ",throwable=" + throwable + ")");
synchronized (syncObject) {
Node node = clientNodes.get(highLevelClient);
if (node == null) {
fireIfPropertyChanged(PROPERTY_NODE, oldNode, node);
}
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return getClass().getName() + "[id=" + id + ",name=" + name + ",description=" + description + ",publicKey=" + publicKey + ",privateKey=" + privateKey + ",basePath=" + basePath + ",defaultFile=" + defaultFile + ",node=" + node + "]";
+ }
+
//
// PRIVATE METHODS
//
}
}
};
+ overrideContentTypeDefaultAction.setEnabled(false);
contentTypeOverrideAction = new AbstractAction() {
/**
boolean overrideInsertSelected = false;
boolean insertOverrideEnabled = false;
boolean insertOverrideSelected = false;
- String defaultContentType = MimeTypes.DEFAULT_CONTENT_TYPE;
+ String defaultContentType = "";
boolean overrideContentTypeEnabled = false;
boolean overrideContentTypeSelected = false;
boolean contentTypeOverrideEnabled = false;
package net.pterodactylus.jsite.gui;
import java.awt.BorderLayout;
+import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
+import javax.swing.DefaultListCellRenderer;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
+import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
propertiesPanel.add(editFilesButton, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0));
nodeComboBox = new JComboBox(new DefaultComboBoxModel());
+ nodeComboBox.setRenderer(new NodeComboBoxCellRenderer());
((DefaultComboBoxModel) nodeComboBox.getModel()).addElement(null);
for (Node node : swingInterface.getNodes()) {
((DefaultComboBoxModel) nodeComboBox.getModel()).addElement(node);
textFieldsUpdated(documentEvent.getDocument());
}
+ /**
+ * Cell cenderer for the node combo box.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ */
+ private static class NodeComboBoxCellRenderer extends DefaultListCellRenderer {
+
+ /**
+ * Empty constructor.
+ */
+ public NodeComboBoxCellRenderer() {
+ super();
+ }
+
+ /**
+ * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList,
+ * java.lang.Object, int, boolean, boolean)
+ */
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ if (value == null) {
+ return super.getListCellRendererComponent(list, "\u00a0", index, isSelected, cellHasFocus);
+ }
+ return super.getListCellRendererComponent(list, ((Node) value).getName(), index, isSelected, cellHasFocus);
+ }
+
+ }
+
}