directory-api mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lécharny <elecha...@gmail.com>
Subject Re: Search problems
Date Sat, 21 Mar 2015 22:08:01 GMT
Le 21/03/15 16:19, Kiran Ayyagari a écrit :
> On Sat, Mar 21, 2015 at 10:29 PM, Claudio <clamun@gmail.com> wrote:
>
>> Hello friends,
>>
>> I want to list all the mails that have an entry in my ldap server.
>>
> you mean you want to list all the mail addresses present in each entry?
>
>> My code is:
>>
>>
>>
>> LdapConnection connection =new LdapNetworkConnection(hostname));
>>   connection().bind(adminLDAP, password);
>>
>>                 ArrayList<String> mailList = new ArrayList<String>();
>>
>> EntryCursor cursor = connection().search( dnUser, "(mail=*)",
>> SearchScope.SUBTREE );
>> Entry resultSearch= null;
>>  while ( cursor.next() )
>> {
>>
>>  resultSearch = cursor.get();
>>    Attribute attr = resultSearch.get("mail");
>>    mailList.add(attr.getString());
>>
>>
>>  }
>>
>>
>>
>> This code lists only one mail for each of the entry not everyone who has.
>>
> mail is a multivalued attribute, so you  need to iterate on the 'attr'
> reference and
> get all the values instead of calling attr.getString(), which returns only
> one of those present.

Which is done with such a code :

while ( cursor.next() )
{
    resultSearch = cursor.get();
    
    for ( Value<?> mail : resultSearch.getA("mail") )
    { 
        mailList.add(mail.getSTring());
    }
}

>
>> I need help with this
>>
>>
>> thank you very much
>>
>
>


Mime
View raw message