From 2095a28e3b117ddc7b565bc7fbe410af70cb48f4 Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Mon, 31 Oct 2016 14:00:38 +0000
Subject: [PATCH] OPENDJ-2772 Align SDK client tool with server's
---
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java | 71 ++++++++++++++++++++---------------
1 files changed, 40 insertions(+), 31 deletions(-)
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java
index a0cdc1d..198b6f0 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java
@@ -17,6 +17,7 @@
package com.forgerock.opendj.ldap.tools;
import static com.forgerock.opendj.cli.ArgumentConstants.USE_SYSTEM_STREAM_TOKEN;
+import static com.forgerock.opendj.cli.CliConstants.NO_WRAPPING_BY_DEFAULT;
import static com.forgerock.opendj.cli.Utils.readBytesFromFile;
import static com.forgerock.opendj.cli.Utils.secondsToTimeString;
import static com.forgerock.opendj.ldap.tools.LDAPToolException.newToolException;
@@ -42,6 +43,7 @@
import com.forgerock.opendj.cli.BooleanArgument;
import com.forgerock.opendj.cli.IntegerArgument;
import com.forgerock.opendj.cli.StringArgument;
+
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageDescriptor;
import org.forgerock.i18n.LocalizedIllegalArgumentException;
@@ -119,18 +121,6 @@
return rc;
}
- static void printSuccessMessage(
- final ConsoleApplication app, final Result r, final String operationType, final String dn) {
- app.println(INFO_OPERATION_SUCCESSFUL.get(operationType, dn));
- printlnTextMsg(app, r.getDiagnosticMessage());
- final List<String> referralURIs = r.getReferralURIs();
- if (referralURIs != null) {
- for (final String uri : referralURIs) {
- app.println(LocalizableMessage.raw(uri));
- }
- }
- }
-
static void printPasswordPolicyResults(final ConsoleApplication app, final BindResult result) {
try {
final AuthorizationIdentityResponseControl control = result.getControl(
@@ -227,25 +217,6 @@
}
}
- static List<Filter> readFiltersFromFile(final String fileName) throws LDAPToolException {
- final List<Filter> filters = new ArrayList<>();
- try (final BufferedReader in = new BufferedReader(new FileReader(fileName))) {
- String line;
- while ((line = in.readLine()) != null) {
- if ("".equals(line.trim())) {
- // ignore empty lines.
- continue;
- }
- filters.add(Filter.valueOf(line));
- }
- return filters;
- } catch (final IOException e) {
- throw newToolException(e, ResultCode.CLIENT_SIDE_FILTER_ERROR, LocalizableMessage.raw(e.toString()));
- } catch (final LocalizedIllegalArgumentException e) {
- throw newToolException(e, ResultCode.CLIENT_SIDE_FILTER_ERROR, e.getMessageObject());
- }
- }
-
static Filter readFilterFromString(final String filterStr) throws LDAPToolException {
try {
return Filter.valueOf(filterStr);
@@ -293,6 +264,30 @@
}
}
+ /**
+ * Return the content of all file which path are provided in the {@link List<String>}.
+ *
+ * @param filePaths
+ * The list of the paths of the files to get content from.
+ * @return The aggregated content of the files in a {@link List<String>}.
+ */
+ static List<String> getLinesFromFiles(final List<String> filePaths) throws LDAPToolException {
+ final List<String> filesLines = new ArrayList<>();
+
+ for (final String filePath : filePaths) {
+ try (final BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ filesLines.add(line);
+ }
+ } catch (final IOException e) {
+ throw newToolParamException(
+ e, ERR_LDIF_FILE_CANNOT_OPEN_FOR_READ.get(filePath, e.getLocalizedMessage()));
+ }
+ }
+ return filesLines;
+ }
+
static void ensureLdapProtocolVersionIsSupported(final IntegerArgument version) throws LDAPToolException {
try {
final int versionNumber = version.getIntValue();
@@ -451,6 +446,20 @@
}
}
+ /**
+ * Return the maximum line length before wrapping or {@code 0} if no wrap should be done.
+ *
+ * @param wrapColumn
+ * {@link IntegerArgument} which could be provided on the command line.
+ * @return The maximum line length before wrapping or {@code 0} if no wrap should be done.
+ */
+ static int computeWrapColumn(final IntegerArgument wrapColumn) throws ArgumentException {
+ if (wrapColumn.isPresent()) {
+ return wrapColumn.getIntValue();
+ }
+ return NO_WRAPPING_BY_DEFAULT;
+ }
+
/** Prevent instantiation. */
private Utils() {
// Do nothing.
--
Gitblit v1.10.0