From 4ffd9fe47a44245d8a9f579e6e22bea655f97bbd Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Wed, 29 Aug 2007 14:40:34 +0000
Subject: [PATCH] Fix issue 1831: dsconfig interactive mode.

---
 opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/PropertyValuePrinter.java |   88 +++++++++++++++++++++++++++-----------------
 1 files changed, 54 insertions(+), 34 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/PropertyValuePrinter.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/PropertyValuePrinter.java
index 9a080e3..35023d8 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/PropertyValuePrinter.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/PropertyValuePrinter.java
@@ -29,7 +29,12 @@
 
 
 import java.text.NumberFormat;
+import org.opends.messages.Message;
+import org.opends.messages.MessageBuilder;
 
+import static org.opends.messages.DSConfigMessages.*;
+
+import org.opends.server.admin.BooleanPropertyDefinition;
 import org.opends.server.admin.DurationPropertyDefinition;
 import org.opends.server.admin.DurationUnit;
 import org.opends.server.admin.PropertyDefinition;
@@ -49,7 +54,7 @@
    * Perform property type specific print formatting.
    */
   private static class MyPropertyValueVisitor extends
-      PropertyValueVisitor<String, Void> {
+      PropertyValueVisitor<Message, Void> {
 
     // The requested size unit (null if the property's unit should be
     // used).
@@ -91,31 +96,13 @@
      * {@inheritDoc}
      */
     @Override
-    public String visitDuration(DurationPropertyDefinition d, Long v, Void p) {
-      if (d.getUpperLimit() == null && (v < 0 || v == Long.MAX_VALUE)) {
-        return "unlimited";
+    public Message visitBoolean(BooleanPropertyDefinition d, Boolean v,
+        Void p) {
+      if (v == false) {
+        return INFO_VALUE_FALSE.get();
+      } else {
+        return INFO_VALUE_TRUE.get();
       }
-
-      long ms = d.getBaseUnit().toMilliSeconds(v);
-
-      // Use human-readable string representation by default.
-      if (timeUnit == null && !isScriptFriendly && ms != 0) {
-        return DurationUnit.toString(ms);
-      }
-
-      // Use either the specified unit or the property definition's
-      // base unit.
-      DurationUnit unit = timeUnit;
-      if (unit == null) {
-        unit = d.getBaseUnit();
-      }
-
-      StringBuilder builder = new StringBuilder();
-      builder.append(numberFormat.format(unit.fromMilliSeconds(ms)));
-      builder.append(' ');
-      builder.append(unit.getShortName());
-
-      return builder.toString();
     }
 
 
@@ -124,9 +111,42 @@
      * {@inheritDoc}
      */
     @Override
-    public String visitSize(SizePropertyDefinition d, Long v, Void p) {
+    public Message visitDuration(DurationPropertyDefinition d, Long v, Void p) {
+      if (d.getUpperLimit() == null && (v < 0 || v == Long.MAX_VALUE)) {
+        return INFO_VALUE_UNLIMITED.get();
+      }
+
+      MessageBuilder builder = new MessageBuilder();
+      long ms = d.getBaseUnit().toMilliSeconds(v);
+
+      if (timeUnit == null && !isScriptFriendly && ms != 0) {
+        // Use human-readable string representation by default.
+        builder.append(DurationUnit.toString(ms));
+      } else {
+        // Use either the specified unit or the property definition's
+        // base unit.
+        DurationUnit unit = timeUnit;
+        if (unit == null) {
+          unit = d.getBaseUnit();
+        }
+
+        builder.append(numberFormat.format(unit.fromMilliSeconds(ms)));
+        builder.append(' ');
+        builder.append(unit.getShortName());
+      }
+
+      return builder.toMessage();
+    }
+
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Message visitSize(SizePropertyDefinition d, Long v, Void p) {
       if (d.isAllowUnlimited() && v < 0) {
-        return "unlimited";
+        return INFO_VALUE_UNLIMITED.get();
       }
 
       SizeUnit unit = sizeUnit;
@@ -139,12 +159,12 @@
         }
       }
 
-      StringBuilder builder = new StringBuilder();
+      MessageBuilder builder = new MessageBuilder();
       builder.append(numberFormat.format(unit.fromBytes(v)));
       builder.append(' ');
       builder.append(unit.getShortName());
 
-      return builder.toString();
+      return builder.toMessage();
     }
 
 
@@ -153,18 +173,18 @@
      * {@inheritDoc}
      */
     @Override
-    public <T> String visitUnknown(PropertyDefinition<T> d, T v, Void p) {
+    public <T> Message visitUnknown(PropertyDefinition<T> d, T v, Void p) {
       // For all other property definition types the default encoding
       // will do.
       String s = d.encodeValue(v);
       if (isScriptFriendly) {
-        return s;
+        return Message.raw("%s", s);
       } else if (s.trim().length() == 0 || s.contains(",")) {
         // Quote empty strings or strings containing commas
         // non-scripting mode.
-        return "\"" + s + "\"";
+        return Message.raw("\"%s\"", s);
       } else {
-        return s;
+        return Message.raw("%s", s);
       }
     }
 
@@ -210,7 +230,7 @@
    *         encoded according to the rules of this property value
    *         printer.
    */
-  public <T> String print(PropertyDefinition<T> pd, T value) {
+  public <T> Message print(PropertyDefinition<T> pd, T value) {
     return pd.accept(pimpl, value, null);
   }
 }

--
Gitblit v1.10.0