2 * jSite2 - InsertManager.java - Copyright © 2008 David Roden
4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation; either version 2 of the License, or (at your option) any later
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307, USA.
19 package net.pterodactylus.jsite.core;
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
28 import net.pterodactylus.util.logging.Logging;
31 * Manages all currently running and past inserts.
33 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
35 public class InsertManager {
38 private static final Logger logger = Logging.getLogger(InsertManager.class.getName());
40 /** The insert listeners. */
41 private final List<InsertListener> insertListeners = new ArrayList<InsertListener>();
43 /** Mapping from insert IDs to inserts. */
44 private final Map<String, Insert> inserts = new HashMap<String, Insert>();
51 * Adds an insert listener to the list of insert listeners.
53 * @param insertListener
54 * The insert listener to add
56 public void addInsertListener(InsertListener insertListener) {
57 logger.log(Level.FINEST, "addInsertListener(insertListener=" + insertListener + ")");
58 synchronized (insertListeners) {
59 insertListeners.add(insertListener);
64 * Removes an insert listener from the list of insert listeners.
66 * @param insertListener
67 * The insert listener to remove
69 public void removeInsertListener(InsertListener insertListener) {
70 logger.log(Level.FINEST, "removeInsertListener(insertListener=" + insertListener + ")");
71 synchronized (insertListeners) {
72 insertListeners.remove(insertListener);
77 * Notifies all listeners that an insert was added.
80 * The insert that was added
82 private void fireInsertAdded(Insert insert) {
83 synchronized (insertListeners) {
84 for (InsertListener insertListener : insertListeners) {
85 insertListener.insertAdded(insert);
91 * Notifies all listeners that an insert was removed.
94 * The insert that was removes
96 @SuppressWarnings("unused")
97 private void fireInsertRemoved(Insert insert) {
98 synchronized (insertListeners) {
99 for (InsertListener insertListener : insertListeners) {
100 insertListener.insertRemoved(insert);
106 * Notifies all listeners that an insert was started.
109 * The insert that was started
111 @SuppressWarnings("unused")
112 private void fireInsertStarted(Insert insert) {
113 synchronized (insertListeners) {
114 for (InsertListener insertListener : insertListeners) {
115 insertListener.insertStarted(insert);
121 * Notifies all listeners that an insert made some progress
124 * The insert that made some progress
126 @SuppressWarnings("unused")
127 private void fireInsertProgressed(Insert insert) {
128 synchronized (insertListeners) {
129 for (InsertListener insertListener : insertListeners) {
130 insertListener.insertProgressed(insert);
136 * Notifies all listeners that an insert generated a URI.
139 * The insert that generated a URI
143 @SuppressWarnings("unused")
144 private void fireInsertGeneratedURI(Insert insert, String uri) {
145 synchronized (insertListeners) {
146 for (InsertListener insertListener : insertListeners) {
147 insertListener.insertGeneratedURI(insert, uri);
153 * Notifies all listeners that an insert has finished.
156 * The insert that has finished
158 @SuppressWarnings("unused")
159 private void fireInsertFinished(Insert insert) {
160 synchronized (insertListeners) {
161 for (InsertListener insertListener : insertListeners) {
162 insertListener.insertFinished(insert);
172 * Starts to insert the given project. The insert will be made to the node
173 * stored in the project, and if no node is specified in the project, the
174 * given node will be used.
177 * The project to insert
179 * The node to insert the project to if the project does not
182 public void insertProject(Project project, Node node) {
183 logger.log(Level.FINEST, "insertProject(project=" + project + ",node=" + node + ")");
184 Node insertNode = project.getNode();
185 if (insertNode == null) {
187 if (insertNode == null) {
188 throw new NullPointerException("node must not be null");
191 String insertId = "insert-" + project.getId();
192 Insert newInsert = new Insert(project, insertNode, insertId);
193 inserts.put(insertId, newInsert);
195 fireInsertAdded(newInsert);
196 /* TODO - start insert */
200 * Starts the insert manager.
202 public void start() {
203 logger.log(Level.FINEST, "start()");
212 * Loads the configuration.
214 private void loadConfiguration() {
215 logger.log(Level.FINEST, "loadConfiguration()");
219 * Saves the configuration.
221 private void saveConfiguration() {
222 logger.log(Level.FINEST, "saveConfiguration()");