/** * Executes the ldap search operation. * * @param config Ldap configuration. * @param filter Ldap filter to search on. * @param attrs Ldap attributes to return. * @throws Exception On errors. */ protected void search(final LdapConfig config, final String filter, final String[] attrs) throws Exception { final Ldap ldap = new Ldap(); ldap.setLdapConfig(config); try { Iterator<SearchResult> results = null; if (attrs == null || attrs.length == 0) { results = ldap.search(new SearchFilter(filter)); } else { results = ldap.search(new SearchFilter(filter), attrs); } if (this.outputDsmlv1) { (new Dsmlv1()).outputDsml(results, new BufferedWriter(new OutputStreamWriter(System.out))); } else if (this.outputDsmlv2) { (new Dsmlv2()).outputDsml(results, new BufferedWriter(new OutputStreamWriter(System.out))); } else { (new Ldif()).outputLdif(results, new BufferedWriter(new OutputStreamWriter(System.out))); } } finally { if (ldap != null) { ldap.close(); } } }