1   package com.atlassian.user.impl.ldap.search.page;
2   
3   import com.atlassian.user.EntityException;
4   import com.atlassian.user.impl.ldap.repository.LdapContextFactory;
5   import com.atlassian.user.impl.ldap.search.LDAPPagerInfo;
6   import com.atlassian.user.impl.ldap.properties.LdapSearchProperties;
7   import org.apache.log4j.Category;
8   
9   import javax.naming.directory.Attribute;
10  import javax.naming.directory.Attributes;
11  import javax.naming.directory.SearchResult;
12  import java.util.List;
13  
14  public class LDAPSingleStringPager extends AbstractLDAPPager<String>
15  {
16      public static final Category log = Category.getInstance(LDAPSingleStringPager.class);
17  
18      public LDAPSingleStringPager(LdapSearchProperties searchProperties, LdapContextFactory repository, LDAPPagerInfo info)
19      {
20          super(searchProperties, repository, info);
21          preload();
22      }
23  
24      protected List<String> preloadSearchResult(SearchResult result, List<String> prefetched) throws EntityException
25      {
26          try
27          {
28              Attributes entityAttributes = result.getAttributes();
29              String attributeToFind = returningAttributes[0];
30              Attribute attr = entityAttributes.get(attributeToFind);
31              prefetched.add((String) attr.get());
32          }
33          catch (Throwable t)
34          {
35              log.error("Error converting search result: " + result + " into a string value.", t);
36          }
37  
38          return prefetched;
39      }
40  }