Add progress listener that displays the progress of the upload.
[jSite.git] / src / de / todesbaum / jsite / main / CLI.java
index 627517c..3643599 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * jSite - 
+ * jSite -
  * Copyright (C) 2006 David Roden
  *
  * This program is free software; you can redistribute it and/or modify
@@ -26,10 +26,11 @@ import de.todesbaum.jsite.application.InsertListener;
 import de.todesbaum.jsite.application.Node;
 import de.todesbaum.jsite.application.Project;
 import de.todesbaum.jsite.application.ProjectInserter;
+import de.todesbaum.util.io.StreamCopier.ProgressListener;
 
 /**
  * Command-line interface for jSite.
- * 
+ *
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  */
 public class CLI implements InsertListener {
@@ -60,7 +61,7 @@ public class CLI implements InsertListener {
 
        /**
         * Creates a new command-line interface.
-        * 
+        *
         * @param args
         *            The command-line arguments
         */
@@ -157,7 +158,7 @@ public class CLI implements InsertListener {
 
        /**
         * Returns the project with the given name.
-        * 
+        *
         * @param name
         *            The name of the project
         * @return The project, or <code>null</code> if no project could be found
@@ -173,7 +174,7 @@ public class CLI implements InsertListener {
 
        /**
         * Returns the node with the given name.
-        * 
+        *
         * @param name
         *            The name of the node
         * @return The node, or <code>null</code> if no node could be found
@@ -189,7 +190,7 @@ public class CLI implements InsertListener {
 
        /**
         * Inserts the given project.
-        * 
+        *
         * @param currentProject
         *            The project to insert
         * @return <code>true</code> if the insert finished successfully,
@@ -201,7 +202,12 @@ public class CLI implements InsertListener {
                        return false;
                }
                projectInserter.setProject(currentProject);
-               projectInserter.start();
+               projectInserter.start(new ProgressListener() {
+
+                       public void onProgress(long copied, long length) {
+                               System.out.print("Uploaded: " + copied + " / " + length + " bytes...\r");
+                       }
+               });
                synchronized (lockObject) {
                        while (!finished) {
                                try {
@@ -228,6 +234,13 @@ public class CLI implements InsertListener {
        /**
         * {@inheritDoc}
         */
+       public void projectUploadFinished(Project project) {
+               outputWriter.println("Project \"" + project.getName() + "\" has ben uploaded, starting insert...");
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public void projectURIGenerated(Project project, String uri) {
                outputWriter.println("URI: " + uri);
        }
@@ -257,7 +270,7 @@ public class CLI implements InsertListener {
 
        /**
         * Creates a new command-line interface with the given arguments.
-        * 
+        *
         * @param args
         *            The command-line arguments
         */