From 21a512927f6d21d04666921a9d7c33fa8224fc69 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 07 Jul 2009 00:00:20 +0000
Subject: [PATCH] Fix for issue 4091 (]  extend behaviour of dsconfig's --commandFilePath, to keep history accross sessions)

---
 opends/src/server/org/opends/server/util/cli/ConsoleApplication.java |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java b/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
index d3204f5..b2866fd 100644
--- a/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
+++ b/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
@@ -43,6 +43,9 @@
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.Reader;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -63,6 +66,7 @@
 import org.opends.server.tools.ClientException;
 import org.opends.server.types.NullOutputStream;
 import org.opends.server.util.PasswordReader;
+import org.opends.server.util.SetupUtils;
 
 
 /**
@@ -109,6 +113,16 @@
    */
   protected final static int CONFIRMATION_MAX_TRIES = 5;
 
+  private static final String COMMENT_SHELL_UNIX = "# ";
+  private static final String COMMENT_BATCH_WINDOWS = "rem ";
+
+  /**
+   * The String used to write comments in a shell (or batch) script.
+   */
+  protected static final String SHELL_COMMENT_SEPARATOR =
+    SetupUtils.isWindows() ?
+      COMMENT_BATCH_WINDOWS : COMMENT_SHELL_UNIX;
+
   /**
    * Creates a new console application instance.
    *
@@ -1011,4 +1025,36 @@
     }
     return ctx;
   }
+
+  /**
+   * Returns the message to be displayed in the file with the equivalent
+   * command-line with information about the current time.
+   * @return  the message to be displayed in the file with the equivalent
+   * command-line with information about the current time.
+   */
+  protected String getCurrentOperationDateMessage()
+  {
+    String date = formatDateTimeStringForEquivalentCommand(new Date());
+    return INFO_OPERATION_START_TIME_MESSAGE.get(date).
+    toString();
+  }
+
+  /**
+   * Formats a Date to String representation in "dd/MMM/yyyy:HH:mm:ss Z".
+   *
+   * @param date to format; null if <code>date</code> is null
+   * @return string representation of the date
+   */
+  protected String formatDateTimeStringForEquivalentCommand(Date date)
+  {
+    String timeStr = null;
+    if (date != null)
+    {
+      SimpleDateFormat dateFormat =
+        new SimpleDateFormat(DATE_FORMAT_LOCAL_TIME);
+      dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+      timeStr = dateFormat.format(date);
+    }
+    return timeStr;
+  }
 }

--
Gitblit v1.10.0