| | |
| | | import static com.forgerock.opendj.ldap.tools.LDAPToolException.newToolException; |
| | | import static com.forgerock.opendj.ldap.tools.LDAPToolException.newToolParamException; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.*; |
| | | import static com.forgerock.opendj.cli.Utils.filterExitCode; |
| | | import static com.forgerock.opendj.cli.CommonArguments.*; |
| | | |
| | | import static com.forgerock.opendj.ldap.tools.Utils.computeWrapColumn; |
| | |
| | | import static com.forgerock.opendj.ldap.tools.Utils.getLDIFToolOutputStream; |
| | | import static com.forgerock.opendj.ldap.tools.Utils.parseArguments; |
| | | import static com.forgerock.opendj.ldap.tools.Utils.readFilterFromString; |
| | | import static com.forgerock.opendj.ldap.tools.Utils.runTool; |
| | | import static com.forgerock.opendj.ldap.tools.Utils.runToolAndExit; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.PrintStream; |
| | |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.i18n.LocalizableException; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ArgumentParser; |
| | | import com.forgerock.opendj.cli.BooleanArgument; |
| | | import com.forgerock.opendj.cli.ConsoleApplication; |
| | | import com.forgerock.opendj.cli.IntegerArgument; |
| | | import com.forgerock.opendj.cli.MultiChoiceArgument; |
| | | import com.forgerock.opendj.cli.StringArgument; |
| | | import org.forgerock.util.annotations.VisibleForTesting; |
| | | |
| | | /** This utility can be used to perform search operations against data in an LDIF file. */ |
| | | public final class LDIFSearch extends ConsoleApplication { |
| | | public final class LDIFSearch extends ToolConsoleApplication { |
| | | |
| | | /** |
| | | * The main method for ldifsearch tool. |
| | |
| | | * The command-line arguments provided to this program. |
| | | */ |
| | | public static void main(final String[] args) { |
| | | System.exit(filterExitCode(run(System.out, System.err, args))); |
| | | runToolAndExit(new LDIFSearch(System.out, System.err), args); |
| | | } |
| | | |
| | | /** |
| | | * Run {@link LDIFSearch} tool with the provided arguments. |
| | | * Output and errors will be written on the provided streams. |
| | | * This method can be used to run the tool programmatically. |
| | | * This method should be used to run this tool programmatically. |
| | | * Output and errors will be printed on provided {@link PrintStream}. |
| | | * |
| | | * @param out |
| | | * {@link PrintStream} which will be used by the tool to write results and information messages. |
| | | * The {@link PrintStream} to use to write tool output. |
| | | * @param err |
| | | * {@link PrintStream} which will be used by the tool to write errors. |
| | | * The {@link PrintStream} to use to write tool errors. |
| | | * @param args |
| | | * Arguments set to pass to the tool. |
| | | * @return |
| | | * An integer which represents the result code of the tool. |
| | | * The arguments to use with this tool. |
| | | * @return The code returned by the tool |
| | | */ |
| | | public static int run(final PrintStream out, final PrintStream err, final String... args) { |
| | | final LDIFSearch ldifSearch = new LDIFSearch(out, err); |
| | | try { |
| | | return ldifSearch.run(args); |
| | | } catch (final LDAPToolException e) { |
| | | e.printErrorMessage(ldifSearch); |
| | | return e.getResultCode(); |
| | | } |
| | | return runTool(new LDIFSearch(out, err), args); |
| | | } |
| | | |
| | | private LDIFSearch(final PrintStream out, final PrintStream err) { |
| | | @VisibleForTesting |
| | | LDIFSearch(final PrintStream out, final PrintStream err) { |
| | | super(out, err); |
| | | } |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | private int run(final String[] args) throws LDAPToolException { |
| | | @Override |
| | | int run(final String... args) throws LDAPToolException { |
| | | final ArgumentParser argParser = LDAPToolArgumentParser.builder(LDIFSearch.class.getName()) |
| | | .toolDescription(INFO_LDIFSEARCH_TOOL_DESCRIPTION.get()) |
| | | .trailingArgumentsUnbounded(2, "source filter [attributes ...]") |