// FIXME -- Need to add a mechanism for verifying the file signature.
// Create the command-line argument parser for use with this program.
LDAPConnectionArgumentParser argParser =
createArgParser("org.nasutekds.server.tools.ImportLDIF",
INFO_LDIFIMPORT_TOOL_DESCRIPTION.get());
// Initialize all the command-line argument types and register them with the
// parser.
try
{
configClass =
new StringArgument("configclass", OPTION_SHORT_CONFIG_CLASS,
OPTION_LONG_CONFIG_CLASS, true, false,
true, INFO_CONFIGCLASS_PLACEHOLDER.get(),
ConfigFileHandler.class.getName(), null,
INFO_DESCRIPTION_CONFIG_CLASS.get());
configClass.setHidden(true);
argParser.addArgument(configClass);
configFile =
new StringArgument("configfile", 'f', "configFile", true, false,
true, INFO_CONFIGFILE_PLACEHOLDER.get(), null,
null,
INFO_DESCRIPTION_CONFIG_FILE.get());
configFile.setHidden(true);
argParser.addArgument(configFile);
ldifFiles =
new StringArgument("ldiffile", OPTION_SHORT_LDIF_FILE,
OPTION_LONG_LDIF_FILE, false, true, true,
INFO_LDIFFILE_PLACEHOLDER.get(), null, null,
INFO_LDIFIMPORT_DESCRIPTION_LDIF_FILE.get());
argParser.addArgument(ldifFiles);
templateFile =
new StringArgument("templatefile", 'A', "templateFile", false, false,
true, INFO_TEMPLATE_FILE_PLACEHOLDER.get(), null,
null,
INFO_LDIFIMPORT_DESCRIPTION_TEMPLATE_FILE.get());
argParser.addArgument(templateFile);
append =
new BooleanArgument("append", 'a', "append",
INFO_LDIFIMPORT_DESCRIPTION_APPEND.get());
argParser.addArgument(append);
replaceExisting =
new BooleanArgument(
"replaceexisting", 'r', "replaceExisting",
INFO_LDIFIMPORT_DESCRIPTION_REPLACE_EXISTING.get());
argParser.addArgument(replaceExisting);
backendID =
new StringArgument("backendid", 'n', "backendID", false, false, true,
INFO_BACKENDNAME_PLACEHOLDER.get(), null, null,
INFO_LDIFIMPORT_DESCRIPTION_BACKEND_ID.get());
argParser.addArgument(backendID);
clearBackend =
new BooleanArgument("clearbackend", 'F', "clearBackend",
INFO_LDIFIMPORT_DESCRIPTION_CLEAR_BACKEND.get());
argParser.addArgument(clearBackend);
includeBranchStrings =
new StringArgument("includebranch", 'b', "includeBranch", false,
true, true, INFO_BRANCH_DN_PLACEHOLDER.get(),
null, null,
INFO_LDIFIMPORT_DESCRIPTION_INCLUDE_BRANCH.get());
argParser.addArgument(includeBranchStrings);
excludeBranchStrings =
new StringArgument("excludebranch", 'B', "excludeBranch", false,
true, true, INFO_BRANCH_DN_PLACEHOLDER.get(),
null, null,
INFO_LDIFIMPORT_DESCRIPTION_EXCLUDE_BRANCH.get());
argParser.addArgument(excludeBranchStrings);
includeAttributeStrings =
new StringArgument(
"includeattribute", 'i', "includeAttribute",
false, true, true, INFO_ATTRIBUTE_PLACEHOLDER.get(), null,
null,
INFO_LDIFIMPORT_DESCRIPTION_INCLUDE_ATTRIBUTE.get());
argParser.addArgument(includeAttributeStrings);
excludeAttributeStrings =
new StringArgument(
"excludeattribute", 'e', "excludeAttribute",
false, true, true, INFO_ATTRIBUTE_PLACEHOLDER.get(), null,
null,
INFO_LDIFIMPORT_DESCRIPTION_EXCLUDE_ATTRIBUTE.get());
argParser.addArgument(excludeAttributeStrings);
includeFilterStrings =
new StringArgument(
"includefilter", 'I', "includeFilter",
false, true, true, INFO_FILTER_PLACEHOLDER.get(), null, null,
INFO_LDIFIMPORT_DESCRIPTION_INCLUDE_FILTER.get());
argParser.addArgument(includeFilterStrings);
excludeFilterStrings =
new StringArgument("excludefilter", 'E', "excludeFilter",
false, true, true, INFO_FILTER_PLACEHOLDER.get(),
null, null,
INFO_LDIFIMPORT_DESCRIPTION_EXCLUDE_FILTER.get());
argParser.addArgument(excludeFilterStrings);
rejectFile =
new StringArgument("rejectfile", 'R', "rejectFile", false, false,
true, INFO_REJECT_FILE_PLACEHOLDER.get(), null,
null,
INFO_LDIFIMPORT_DESCRIPTION_REJECT_FILE.get());
argParser.addArgument(rejectFile);
skipFile =
new StringArgument("skipfile", null, "skipFile", false, false,
true, INFO_SKIP_FILE_PLACEHOLDER.get(), null,
null,
INFO_LDIFIMPORT_DESCRIPTION_SKIP_FILE.get());
argParser.addArgument(skipFile);
overwrite =
new BooleanArgument("overwrite", 'O', "overwrite",
INFO_LDIFIMPORT_DESCRIPTION_OVERWRITE.get());
argParser.addArgument(overwrite);
randomSeed =
new IntegerArgument("randomseed", OPTION_SHORT_RANDOM_SEED,
OPTION_LONG_RANDOM_SEED, false, false,
true, INFO_SEED_PLACEHOLDER.get(),
0, null, false, 0, false, 0,
INFO_LDIFIMPORT_DESCRIPTION_RANDOM_SEED.get());
argParser.addArgument(randomSeed);
skipSchemaValidation =
new BooleanArgument("skipschema", 'S', "skipSchemaValidation",
INFO_LDIFIMPORT_DESCRIPTION_SKIP_SCHEMA_VALIDATION.get());
argParser.addArgument(skipSchemaValidation);
skipDNValidation =
new BooleanArgument("skipDNValidation", null, "skipDNValidation",
INFO_LDIFIMPORT_DESCRIPTION_DN_VALIDATION.get());
argParser.addArgument(skipDNValidation);
threadCount = new IntegerArgument("threadCount", null, "threadCount",
false, false, true,
INFO_LDIFIMPORT_THREAD_COUNT_PLACEHOLDER.get(),
0, null,
true, 1, true, Integer.MAX_VALUE,
INFO_LDIFIMPORT_DESCRIPTION_THREAD_COUNT.get());
argParser.addArgument(threadCount);
tmpDirectory =
new StringArgument("tmpdirectory", null, "tmpdirectory", false,
false, true, INFO_LDIFIMPORT_TEMP_DIR_PLACEHOLDER.get(),
"import-tmp",
null, INFO_LDIFIMPORT_DESCRIPTION_TEMP_DIRECTORY.get());
argParser.addArgument(tmpDirectory);
countRejects =
new BooleanArgument("countrejects", null, "countRejects",
INFO_LDIFIMPORT_DESCRIPTION_COUNT_REJECTS.get());
argParser.addArgument(countRejects);
isCompressed =
new BooleanArgument("iscompressed", 'c', "isCompressed",
INFO_LDIFIMPORT_DESCRIPTION_IS_COMPRESSED.get());
argParser.addArgument(isCompressed);
isEncrypted =
new BooleanArgument("isencrypted", 'y', "isEncrypted",
INFO_LDIFIMPORT_DESCRIPTION_IS_ENCRYPTED.get());
isEncrypted.setHidden(true); //See issue #27
argParser.addArgument(isEncrypted);
quietMode = new BooleanArgument("quietmode", OPTION_SHORT_QUIET,
OPTION_LONG_QUIET,
INFO_LDIFIMPORT_DESCRIPTION_QUIET.get());
argParser.addArgument(quietMode);
displayUsage =
new BooleanArgument("help", OPTION_SHORT_HELP, OPTION_LONG_HELP,
INFO_DESCRIPTION_USAGE.get());
argParser.addArgument(displayUsage);
argParser.setUsageArgument(displayUsage);
}
catch (ArgumentException ae)
{
Message message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
// Init the default values so that they can appear also on the usage.
try
{
argParser.getArguments().initArgumentsWithConfiguration();
}
catch (ConfigException ce)
{
// Ignore.
}
// Parse the command-line arguments provided to this program.
try
{
argParser.parseArguments(args);
validateTaskArgs();
}
catch (ArgumentException ae)
{
Message message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
err.println(wrapText(message, MAX_LINE_WIDTH));
err.println(argParser.getUsage());
return 1;
}
catch (CLIException ce)
{
// No need to display the usage since the problem comes with a provided
// value.
err.println(wrapText(ce.getMessageObject(), MAX_LINE_WIDTH));
return 1;
}
// If we should just display usage or version information,
// then print it and exit.
if (argParser.usageOrVersionDisplayed())
{
return 0;
}
// Make sure that either the "ldifFile" argument or the "templateFile"
// argument was provided, but not both.
if (ldifFiles.isPresent())
{
if (templateFile.isPresent())
{
Message message = ERR_LDIFIMPORT_CONFLICTING_OPTIONS.get(
ldifFiles.getLongIdentifier(),
templateFile.getLongIdentifier());
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
}
else if (! templateFile.isPresent())
{
Message message = ERR_LDIFIMPORT_MISSING_REQUIRED_ARGUMENT.get(
ldifFiles.getLongIdentifier(),
templateFile.getLongIdentifier());
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
// Make sure that either the "includeBranchStrings" argument or the
// "backendID" argument was provided.
if(!includeBranchStrings.isPresent() && !backendID.isPresent())
{
Message message = ERR_LDIFIMPORT_MISSING_BACKEND_ARGUMENT.get(
includeBranchStrings.getLongIdentifier(),
backendID.getLongIdentifier());
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
// Count rejects option requires the ability to return result codes
// which are potentially greater than 1. This is not supported by
// the task framework.
if (countRejects.isPresent()
&& argParser.connectionArgumentsPresent())
{
Message message =
ERR_LDIFIMPORT_COUNT_REJECTS_REQUIRES_OFFLINE
.get(countRejects.getLongIdentifier());
err.println(wrapText(message, MAX_LINE_WIDTH));