From fcdf613062b393888caef2496acce7ce6b49305d Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Fri, 04 Apr 2014 13:06:54 +0000
Subject: [PATCH] Checkpoint for OPENDJ-1303 "opendj-cli" - Added messages in order to decouple LDAPConnectionConsoleInteraction to dsconfig server package. - Added to Utils the getHostNameForLdapUrl (from ConnectionUtils)

---
 opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
index 47f5413..7d4c60c 100644
--- a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
+++ b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
@@ -588,4 +588,31 @@
         }
         return isOutOfMemory;
     }
+
+    /**
+     * Returns the string that can be used to represent a given host name in a LDAP URL.
+     * This method must be used when we have IPv6 addresses (the address in the LDAP URL
+     *  must be enclosed with brackets).
+     *  E.g:<pre>
+     *  -h "[2a01:e35:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]"
+     *  </pre>
+     *
+     * @param host
+     *            The host name.
+     * @return The String that can be used to represent a given host name in a LDAP URL.
+     */
+    public static String getHostNameForLdapUrl(String host) {
+        if (host != null && host.indexOf(":") != -1) {
+            // Assume an IPv6 address has been specified and adds the brackets
+            // for the URL.
+            host = host.trim();
+            if (!host.startsWith("[")) {
+                host = "[" + host;
+            }
+            if (!host.endsWith("]")) {
+                host = host + "]";
+            }
+        }
+        return host;
+    }
 }

--
Gitblit v1.10.0