Class LDAPPagedResultsControl

java.lang.Object
netscape.ldap.LDAPControl
netscape.ldap.controls.LDAPPagedResultsControl
All Implemented Interfaces:
Serializable, Cloneable

public class LDAPPagedResultsControl extends LDAPControl
Represents an LDAP v3 server control that specifies a simple pagd result manipulation, which allows your LDAP client to get entries in multiple chunks (The OID for this control is 1.2.840.113556.1.4.319).

To use paged search you create a "paged search" control that specifies the page size and the cookie from last search. You include the control in a search request. When a search is performed only a page is returned to the client and a new search has to be performed to access the following elements.

When constructing an LDAPPagedResultsControl object, you can specify the following information:

  • the size of the page to be returned
  • the cookie to keep track of the previous page. This is null for the first page and the server returned value for the following.

For example:

...
     LDAPConnection ld = new LDAPConnection();

     try {
         // Connect to server.
         ld.connect(3,3, hostname, portnumber, "", "" );

         LDAPPagedResultsControl pagecon = new LDAPPagedResultsControl(false, 3);
         // Set the search constraints to use that control.
         LDAPSearchConstraints cons = new LDAPSearchConstraints();
         cons.setBatchSize(1);
         cons.setServerControls(pagecon);

         // Start the paged search.
         byte[] cookie = null;
         int pag = 1;
         do{
             LDAPSearchResults res = ld.search(baseDn,
                     LDAPv3.SCOPE_SUB, filter, null, false, cons);

             // Loop through the incoming results.
             while (res.hasMoreElements()) {
                 LDAPEntry entry = res.next();
                 System.out.println("DN: " + entry.getDN());
             }
             for (LDAPControl c: res.getResponseControls()){
                 if(c instanceof LDAPPagedResultsControl resC){
                     System.out.println("The control for pag " + pag + " return a total or " + resC.getPageSize());
                     cookie = resC.getCookie();
                     if(cookie!=null){
                         pagecon = new LDAPPagedResultsControl(false, 3, cookie);
                         cons.setServerControls(pagecon);
                     }
                 }
             }
             pag++;
         } while (cookie != null);
     } catch (Exception e) {
         e.printStackTrace();
     }
See Also:
  • Field Details

    • PAGEDSEARCH

      public static final String PAGEDSEARCH
      See Also:
    • pageSize

      private int pageSize
  • Constructor Details

    • LDAPPagedResultsControl

      public LDAPPagedResultsControl(String oid, boolean critical, byte[] vals) throws LDAPException, IOException
      Constructs an LDAPPagedResultsControl object that specifies a paged search.
      Parameters:
      oid - the oid of this control
      critical - true if this control is critical to the search
      value - the value associated with this control
      Throws:
      LDAPException
      IOException - If value contains an invalid BER sequence.
      See Also:
    • LDAPPagedResultsControl

      public LDAPPagedResultsControl(boolean critical, int pageSize)
      Constructs an LDAPPagedResultsControl object without a cookie. This is equivalent to LDAPPagedResultsControl(critical, pageSize, null)
      Parameters:
      critical - true if this control is critical to the search
      pageSize - the number of entries to be returned with the following search request
      See Also:
    • LDAPPagedResultsControl

      public LDAPPagedResultsControl(boolean critical, int pageSize, byte[] cookie)
      Constructs an LDAPPagedResultsControl.
      Parameters:
      critical - true if this control is critical to the search
      pageSize - the number of entries to be returned with the following search request
      cookie - The cookie to access the next entries. This is an opaque value returned by the server or null for the initial search
      See Also:
  • Method Details

    • generateNextPageValues

      private byte[] generateNextPageValues()
      Encode the parameters as requested for the control
      Returns:
      Binary sequence for next page
    • getPageSize

      public int getPageSize()
      Gets the page size for the search request.
      Returns:
      the number of entries to be returned when a search is requested to the server and the number of entries available when returned from the server.
    • getCookie

      public byte[] getCookie()
      Gets the cookie for the following search request.
      Returns:
      the cookie to use for the following request or null if all entries have been returned.