| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | |
| | | /** |
| | | * This class provides utility functions for all the client side tools. |
| | | */ |
| | | /** This class provides utility functions for all the client side tools. */ |
| | | public final class Utils { |
| | | |
| | | /** Platform appropriate line separator. */ |
| | |
| | | */ |
| | | public static final String OBFUSCATED_VALUE = "******"; |
| | | |
| | | /** |
| | | * The maximum number of times we try to confirm. |
| | | */ |
| | | /** The maximum number of times we try to confirm. */ |
| | | public static final 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. |
| | | */ |
| | | /** The String used to write comments in a shell (or batch) script. */ |
| | | public static final String SHELL_COMMENT_SEPARATOR = OperatingSystem.isWindows() ? COMMENT_BATCH_WINDOWS |
| | | : COMMENT_SHELL_UNIX; |
| | | |
| | | /** |
| | | * The column at which to wrap long lines of output in the command-line |
| | | * tools. |
| | | */ |
| | | /** The column at which to wrap long lines of output in the command-line tools. */ |
| | | public static final int MAX_LINE_WIDTH; |
| | | static { |
| | | int columns = 80; |
| | |
| | | * @return The wrapped text. |
| | | */ |
| | | public static String wrapText(final String text, int width, final int indent) { |
| | | if (text == null) { |
| | | return ""; |
| | | } |
| | | |
| | | // Calculate the real width and indentation padding. |
| | | width -= indent; |
| | | final StringBuilder pb = new StringBuilder(); |
| | |
| | | final String padding = pb.toString(); |
| | | |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | if (text != null) { |
| | | final StringTokenizer lineTokenizer = new StringTokenizer(text, "\r\n", true); |
| | | while (lineTokenizer.hasMoreTokens()) { |
| | | final String line = lineTokenizer.nextToken(); |
| | |
| | | delimBuffer.append(word); |
| | | } |
| | | } else if (word.length() > width) { |
| | | // This is a long word that can't be wrapped, so |
| | | // we'll just have to make do. |
| | | // This is a long word that can't be wrapped, |
| | | // so we'll just have to make do. |
| | | if (lineBuffer.length() > 0) { |
| | | buffer.append(padding); |
| | | buffer.append(lineBuffer); |
| | | buffer.append(EOL); |
| | | buffer.append(padding).append(lineBuffer).append(EOL); |
| | | lineBuffer = new StringBuilder(); |
| | | } |
| | | buffer.append(padding); |
| | |
| | | delimBuffer = new StringBuilder(); |
| | | } |
| | | } else { |
| | | // It's not a space, so see if we can fit it on the |
| | | // current line. |
| | | // It's not a space, so see if we can fit it on the current line. |
| | | final int newLineLength = |
| | | lineBuffer.length() + delimBuffer.length() + word.length(); |
| | | if (newLineLength < width) { |
| | |
| | | } else { |
| | | // It doesn't fit on the line, so end the |
| | | // current line and start a new one. |
| | | buffer.append(padding); |
| | | buffer.append(lineBuffer); |
| | | buffer.append(EOL); |
| | | buffer.append(padding).append(lineBuffer).append(EOL); |
| | | |
| | | lineBuffer = new StringBuilder(); |
| | | lineBuffer.append(word); |
| | |
| | | buffer.append(lineBuffer); |
| | | } |
| | | } |
| | | } |
| | | return buffer.toString(); |
| | | } |
| | | |
| | |
| | | return parentFile != null && parentFile.canWrite(); |
| | | } |
| | | |
| | | |
| | | /** Prevent instantiation. */ |
| | | private Utils() { |
| | | // Do nothing. |
| | |
| | | * @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) { |
| | | if (host != null && host.contains(":")) { |
| | | // Assume an IPv6 address has been specified and adds the brackets |
| | | // for the URL. |
| | | host = host.trim(); |