From 179832f1486eec5991ea4edc584b2ca962c95e90 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 27 Aug 2007 08:37:44 +0000
Subject: [PATCH] Fix for issue 2167.

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java                  |    8 +++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java   |    6 +--
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java |    6 +--
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Application.java                          |   69 ++++++++++++++++++++++++++++++----
 4 files changed, 72 insertions(+), 17 deletions(-)

diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Application.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Application.java
index 20e604e..8e517ed 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Application.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Application.java
@@ -83,6 +83,9 @@
   /** Handler for listeners and event firing. */
   protected ProgressUpdateListenerDelegate listenerDelegate;
 
+  private ErrorPrintStream err = new ErrorPrintStream();
+  private OutputPrintStream out = new OutputPrintStream();
+
   /**
    * Creates an application by instantiating the Application class
    * denoted by the System property
@@ -725,6 +728,27 @@
   }
 
   /**
+   * Returns the error stream to be used by the application when launching
+   * command lines.
+   * @return  the error stream to be used by the application when launching
+   * command lines.
+   */
+  protected ErrorPrintStream getApplicationErrorStream()
+  {
+    return err;
+  }
+
+  /**
+   * Returns the output stream to be used by the application when launching
+   * command lines.
+   * @return  the output stream to be used by the application when launching
+   * command lines.
+   */
+  protected OutputPrintStream getApplicationOutputStream()
+  {
+    return out;
+  }
+  /**
    * This class is used to notify the ProgressUpdateListeners of events
    * that are written to the standard error.  It is used in WebStartInstaller
    * and in OfflineInstaller.  These classes just create a ErrorPrintStream and
@@ -791,6 +815,8 @@
 
     private boolean isFirstLine;
 
+    private boolean notifyListeners = true;
+
     /**
      * Format a string before sending a listener notification.
      * @param string to format
@@ -814,16 +840,21 @@
     @Override
     public void println(String msg)
     {
-      MessageBuilder mb = new MessageBuilder();
-      if (isFirstLine)
+      if (notifyListeners)
       {
-        mb.append(formatString(msg));
-      } else
-      {
-        mb.append(formatter.getLineBreak());
-        mb.append(formatString(msg));
+        MessageBuilder mb = new MessageBuilder();
+        if (isFirstLine)
+        {
+          mb.append(formatString(msg));
+        } else
+        {
+          mb.append(formatter.getLineBreak());
+          mb.append(formatString(msg));
+        }
+
+        notifyListeners(mb.toMessage());
       }
-      notifyListeners(mb.toMessage());
+      LOG.log(Level.INFO, "server: " + msg);
       isFirstLine = false;
     }
 
@@ -845,5 +876,27 @@
       }
       println(new String(b, off, len));
     }
+
+    /**
+     * Notifies the progress update listeners of the application of the message
+     * we received.
+     * @return <CODE>true</CODE> if we must notify the application listeners
+     * of the message and <CODE>false</CODE> otherwise.
+     */
+    public boolean isNotifyListeners()
+    {
+      return notifyListeners;
+    }
+
+    /**
+     * Tells whether we must notify the listeners or not of the message
+     * received.
+     * @param notifyListeners the boolean that informs of whether we have
+     * to notify the listeners or not.
+     */
+    public void setNotifyListeners(boolean notifyListeners)
+    {
+      this.notifyListeners = notifyListeners;
+    }
   }
 }
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
index a257e5b..b8475dd 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -1002,6 +1002,8 @@
     String[] args = new String[argList.size()];
     argList.toArray(args);
 
+    getApplicationOutputStream().setNotifyListeners(false);
+    getApplicationErrorStream().setNotifyListeners(false);
     try
     {
       int result = helper.invokeImportLDIF(args);
@@ -1018,7 +1020,11 @@
           ApplicationReturnCode.ReturnCode.CONFIGURATION_ERROR,
           getThrowableMsg(INFO_ERROR_CREATING_BASE_ENTRY.get(), t), t);
     }
-
+    finally
+    {
+      getApplicationOutputStream().setNotifyListeners(true);
+      getApplicationErrorStream().setNotifyListeners(true);
+    }
     notifyListeners(getFormattedDone());
   }
 
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java
index 06a3580..29a7d85 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java
@@ -88,10 +88,8 @@
 
     try
     {
-      PrintStream err = new ErrorPrintStream();
-      PrintStream out = new OutputPrintStream();
-      System.setErr(err);
-      System.setOut(out);
+      System.setErr(getApplicationErrorStream());
+      System.setOut(getApplicationOutputStream());
 
       checkAbort();
 
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java
index 1869bc6..b9b2d38 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java
@@ -107,10 +107,8 @@
     PrintStream origOut = System.out;
     try
     {
-      PrintStream err = new ErrorPrintStream();
-      PrintStream out = new OutputPrintStream();
-      System.setErr(err);
-      System.setOut(out);
+      System.setErr(getApplicationErrorStream());
+      System.setOut(getApplicationOutputStream());
 
       setCurrentProgressStep(InstallProgressStep.DOWNLOADING);
 

--
Gitblit v1.10.0