add saveConfiguration stub
[jSite2.git] / src / net / pterodactylus / jsite / core / InsertManager.java
index be8cc5e..c91b513 100644 (file)
  * 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.ArrayList;
-import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -38,6 +40,9 @@ public class InsertManager {
        /** The insert listeners. */
        private final List<InsertListener> insertListeners = new ArrayList<InsertListener>();
 
+       /** Mapping from insert IDs to inserts. */
+       private final Map<String, Insert> inserts = new HashMap<String, Insert>();
+
        //
        // EVENT MANAGEMENT
        //
@@ -88,6 +93,7 @@ public class InsertManager {
         * @param insert
         *            The insert that was removes
         */
+       @SuppressWarnings("unused")
        private void fireInsertRemoved(Insert insert) {
                synchronized (insertListeners) {
                        for (InsertListener insertListener : insertListeners) {
@@ -102,6 +108,7 @@ public class InsertManager {
         * @param insert
         *            The insert that was started
         */
+       @SuppressWarnings("unused")
        private void fireInsertStarted(Insert insert) {
                synchronized (insertListeners) {
                        for (InsertListener insertListener : insertListeners) {
@@ -116,6 +123,7 @@ public class InsertManager {
         * @param insert
         *            The insert that made some progress
         */
+       @SuppressWarnings("unused")
        private void fireInsertProgressed(Insert insert) {
                synchronized (insertListeners) {
                        for (InsertListener insertListener : insertListeners) {
@@ -129,7 +137,10 @@ public class InsertManager {
         * 
         * @param insert
         *            The insert that generated a URI
+        * @param uri
+        *            The generated URI
         */
+       @SuppressWarnings("unused")
        private void fireInsertGeneratedURI(Insert insert, String uri) {
                synchronized (insertListeners) {
                        for (InsertListener insertListener : insertListeners) {
@@ -144,6 +155,7 @@ public class InsertManager {
         * @param insert
         *            The insert that has finished
         */
+       @SuppressWarnings("unused")
        private void fireInsertFinished(Insert insert) {
                synchronized (insertListeners) {
                        for (InsertListener insertListener : insertListeners) {
@@ -157,6 +169,34 @@ public class InsertManager {
        //
 
        /**
+        * Starts to insert the given project. The insert will be made to the node
+        * stored in the project, and if no node is specified in the project, the
+        * given node will be used.
+        * 
+        * @param project
+        *            The project to insert
+        * @param node
+        *            The node to insert the project to if the project does not
+        *            specify a node
+        */
+       public void insertProject(Project project, Node node) {
+               logger.log(Level.FINEST, "insertProject(project=" + project + ",node=" + node + ")");
+               Node insertNode = project.getNode();
+               if (insertNode == null) {
+                       insertNode = node;
+                       if (insertNode == null) {
+                               throw new NullPointerException("node must not be null");
+                       }
+               }
+               String insertId = "insert-" + project.getId();
+               Insert newInsert = new Insert(project, insertNode, insertId);
+               inserts.put(insertId, newInsert);
+               saveConfiguration();
+               fireInsertAdded(newInsert);
+               /* TODO - start insert */
+       }
+
+       /**
         * Starts the insert manager.
         */
        public void start() {
@@ -175,4 +215,11 @@ public class InsertManager {
                logger.log(Level.FINEST, "loadConfiguration()");
        }
 
+       /**
+        * Saves the configuration.
+        */
+       private void saveConfiguration() {
+               logger.log(Level.FINEST, "saveConfiguration()");
+       }
+
 }