2 * jSite - ProjectInsertListeners.java - Copyright © 2013–2019 David Roden
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package de.todesbaum.jsite.application;
21 import java.util.ArrayList;
22 import java.util.List;
25 * Manages {@link InsertListener}s for the {@link ProjectInserter}.
27 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
29 class ProjectInsertListeners {
31 /** The list of insert listeners. */
32 private final List<InsertListener> insertListeners = new ArrayList<InsertListener>();
35 * Adds a listener to the list of registered listeners.
37 * @param insertListener
40 void addInsertListener(InsertListener insertListener) {
41 insertListeners.add(insertListener);
45 * Removes a listener from the list of registered listeners.
47 * @param insertListener
48 * The listener to remove
50 void removeInsertListener(InsertListener insertListener) {
51 insertListeners.remove(insertListener);
55 * Notifies all listeners that the project insert has started.
58 * @see InsertListener#projectInsertStarted(Project)
60 void fireProjectInsertStarted(Project project) {
61 for (InsertListener insertListener : insertListeners) {
62 insertListener.projectInsertStarted(project);
67 * Notifies all listeners that the insert has generated a URI.
72 * @see InsertListener#projectURIGenerated(Project, String)
74 void fireProjectURIGenerated(Project project, String uri) {
75 for (InsertListener insertListener : insertListeners) {
76 insertListener.projectURIGenerated(project, uri);
81 * Notifies all listeners that the insert has made some progress.
84 * @see InsertListener#projectUploadFinished(Project)
86 void fireProjectUploadFinished(Project project) {
87 for (InsertListener insertListener : insertListeners) {
88 insertListener.projectUploadFinished(project);
93 * Notifies all listeners that the insert has made some progress.
97 * The number of succeeded blocks
99 * The number of failed blocks
101 * The number of fatally failed blocks
103 * The total number of blocks
105 * <code>true</code> if the total number of blocks has already been
106 * finalized, <code>false</code> otherwise
107 * @see InsertListener#projectInsertProgress(Project, int, int, int, int,
110 void fireProjectInsertProgress(Project project, int succeeded, int failed, int fatal, int total, boolean finalized) {
111 for (InsertListener insertListener : insertListeners) {
112 insertListener.projectInsertProgress(project, succeeded, failed, fatal, total, finalized);
117 * Notifies all listeners the project insert has finished.
121 * <code>true</code> if the project was inserted successfully,
122 * <code>false</code> if it failed
124 * The cause of the failure, if any
125 * @see InsertListener#projectInsertFinished(Project, boolean, Throwable)
127 void fireProjectInsertFinished(Project project, boolean success, Throwable cause) {
128 for (InsertListener insertListener : insertListeners) {
129 insertListener.projectInsertFinished(project, success, cause);