Package netscape.ldap.controls
Class LDAPPagedResultsControl
java.lang.Object
netscape.ldap.LDAPControl
netscape.ldap.controls.LDAPPagedResultsControl
- All Implemented Interfaces:
Serializable
,Cloneable
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 Summary
FieldsFields inherited from class netscape.ldap.LDAPControl
m_critical, m_value, MANAGEDSAIT, PWEXPIRED, PWEXPIRING
-
Constructor Summary
ConstructorsConstructorDescriptionLDAPPagedResultsControl
(boolean critical, int pageSize) Constructs anLDAPPagedResultsControl
object without a cookie.LDAPPagedResultsControl
(boolean critical, int pageSize, byte[] cookie) Constructs anLDAPPagedResultsControl
.LDAPPagedResultsControl
(String oid, boolean critical, byte[] vals) Constructs anLDAPPagedResultsControl
object that specifies a paged search. -
Method Summary
Modifier and TypeMethodDescriptionprivate byte[]
Encode the parameters as requested for the controlbyte[]
Gets the cookie for the following search request.int
Gets the page size for the search request.Methods inherited from class netscape.ldap.LDAPControl
clone, createControl, flattenBER, getID, getValue, isCritical, lookupControlClass, newInstance, register, toString
-
Field Details
-
PAGEDSEARCH
- See Also:
-
pageSize
private int pageSize -
cookie
private byte[] cookie
-
-
Constructor Details
-
LDAPPagedResultsControl
public LDAPPagedResultsControl(String oid, boolean critical, byte[] vals) throws LDAPException, IOException Constructs anLDAPPagedResultsControl
object that specifies a paged search.- Parameters:
oid
- the oid of this controlcritical
-true
if this control is critical to the searchvalue
- 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 anLDAPPagedResultsControl
object without a cookie. This is equivalent toLDAPPagedResultsControl(critical, pageSize, null)
- Parameters:
critical
-true
if this control is critical to the searchpageSize
- the number of entries to be returned with the following search request- See Also:
-
LDAPPagedResultsControl
public LDAPPagedResultsControl(boolean critical, int pageSize, byte[] cookie) Constructs anLDAPPagedResultsControl
.- Parameters:
critical
-true
if this control is critical to the searchpageSize
- the number of entries to be returned with the following search requestcookie
- The cookie to access the next entries. This is an opaque value returned by the server ornull
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.
-