| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | | import static com.forgerock.opendj.ldap.tools.ToolConstants.*; |
| | | import static com.forgerock.opendj.cli.CliConstants.*; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.*; |
| | | import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode; |
| | | import static com.forgerock.opendj.cli.Utils.filterExitCode; |
| | | import static com.forgerock.opendj.cli.Utils.readBytesFromFile; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.FileNotFoundException; |
| | |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ArgumentParser; |
| | | import com.forgerock.opendj.cli.BooleanArgument; |
| | | import com.forgerock.opendj.cli.CommonArguments; |
| | | import com.forgerock.opendj.cli.ConsoleApplication; |
| | | import com.forgerock.opendj.cli.IntegerArgument; |
| | | import com.forgerock.opendj.cli.StringArgument; |
| | | |
| | | /** |
| | | * A tool that can be used to issue Compare requests to the Directory Server. |
| | | */ |
| | |
| | | |
| | | try { |
| | | connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this); |
| | | propertiesFileArgument = |
| | | new StringArgument("propertiesFilePath", null, OPTION_LONG_PROP_FILE_PATH, |
| | | false, false, true, INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null, |
| | | INFO_DESCRIPTION_PROP_FILE_PATH.get()); |
| | | |
| | | propertiesFileArgument = CommonArguments.getPropertiesFileArgument(); |
| | | argParser.addArgument(propertiesFileArgument); |
| | | argParser.setFilePropertiesArgument(propertiesFileArgument); |
| | | |
| | | noPropertiesFileArgument = |
| | | new BooleanArgument("noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE, |
| | | INFO_DESCRIPTION_NO_PROP_FILE.get()); |
| | | noPropertiesFileArgument = CommonArguments.getNoPropertiesFileArgument(); |
| | | argParser.addArgument(noPropertiesFileArgument); |
| | | argParser.setNoPropertiesFileArgument(noPropertiesFileArgument); |
| | | |
| | |
| | | controlStr.setPropertyName("control"); |
| | | argParser.addArgument(controlStr); |
| | | |
| | | version = |
| | | new IntegerArgument("version", OPTION_SHORT_PROTOCOL_VERSION, |
| | | OPTION_LONG_PROTOCOL_VERSION, false, false, true, |
| | | INFO_PROTOCOL_VERSION_PLACEHOLDER.get(), 3, null, |
| | | INFO_DESCRIPTION_VERSION.get()); |
| | | version.setPropertyName(OPTION_LONG_PROTOCOL_VERSION); |
| | | version = CommonArguments.getVersionArgument(); |
| | | argParser.addArgument(version); |
| | | |
| | | encodingStr = |
| | |
| | | encodingStr.setPropertyName("encoding"); |
| | | argParser.addArgument(encodingStr); |
| | | |
| | | continueOnError = |
| | | new BooleanArgument("continueOnError", 'c', "continueOnError", |
| | | INFO_DESCRIPTION_CONTINUE_ON_ERROR.get()); |
| | | continueOnError.setPropertyName("continueOnError"); |
| | | continueOnError = CommonArguments.getContinueOnErrorArgument(); |
| | | argParser.addArgument(continueOnError); |
| | | |
| | | noop = |
| | |
| | | noop.setPropertyName(OPTION_LONG_DRYRUN); |
| | | argParser.addArgument(noop); |
| | | |
| | | verbose = |
| | | new BooleanArgument("verbose", 'v', "verbose", INFO_DESCRIPTION_VERBOSE.get()); |
| | | verbose.setPropertyName("verbose"); |
| | | verbose = CommonArguments.getVerbose(); |
| | | argParser.addArgument(verbose); |
| | | |
| | | showUsage = |
| | | new BooleanArgument("showUsage", OPTION_SHORT_HELP, OPTION_LONG_HELP, |
| | | INFO_DESCRIPTION_SHOWUSAGE.get()); |
| | | showUsage = CommonArguments.getShowUsage(); |
| | | argParser.addArgument(showUsage); |
| | | argParser.setUsageArgument(showUsage, getOutputStream()); |
| | | |
| | | } catch (final ArgumentException ae) { |
| | | final LocalizableMessage message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage()); |
| | | println(message); |
| | |
| | | try { |
| | | argParser.parseArguments(args); |
| | | |
| | | // If we should just display usage or version information, |
| | | // then print it and exit. |
| | | /* If we should just display usage or version information, |
| | | then print it and exit.*/ |
| | | if (argParser.usageOrVersionDisplayed()) { |
| | | return 0; |
| | | } |
| | |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | |
| | | // If trailing DNs were provided and the filename argument was also |
| | | // provided, exit with an error. |
| | | /* If trailing DNs were provided and the filename argument was also |
| | | provided, exit with an error.*/ |
| | | if (!dnStrings.isEmpty() && filename.isPresent()) { |
| | | println(ERR_LDAPCOMPARE_FILENAME_AND_DNS.get()); |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | |
| | | } else if (nextChar == '<') { |
| | | try { |
| | | final String filePath = remainder.substring(1, remainder.length()); |
| | | attributeVal = ByteString.wrap(Utils.readBytesFromFile(filePath)); |
| | | attributeVal = ByteString.wrap(readBytesFromFile(filePath)); |
| | | } catch (final Exception e) { |
| | | println(INFO_COMPARE_CANNOT_READ_ASSERTION_VALUE_FROM_FILE.get(String |
| | | .valueOf(e))); |