/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt * or http://forgerock.org/license/CDDLv1.0.html. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at legal-notices/CDDLv1_0.txt. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Copyright 2010 Sun Microsystems, Inc. * Portions copyright 2012 ForgeRock AS. */ package org.forgerock.opendj.ldap.controls; import static com.forgerock.opendj.util.StaticUtils.getExceptionMessage; import static org.forgerock.opendj.ldap.CoreMessages.ERR_VLVRES_CONTROL_BAD_OID; import static org.forgerock.opendj.ldap.CoreMessages.INFO_VLVRES_CONTROL_CANNOT_DECODE_VALUE; import static org.forgerock.opendj.ldap.CoreMessages.INFO_VLVRES_CONTROL_NO_VALUE; import java.io.IOException; import org.forgerock.i18n.LocalizableMessage; import org.forgerock.opendj.asn1.ASN1; import org.forgerock.opendj.asn1.ASN1Reader; import org.forgerock.opendj.asn1.ASN1Writer; import org.forgerock.opendj.ldap.ByteString; import org.forgerock.opendj.ldap.ByteStringBuilder; import org.forgerock.opendj.ldap.DecodeException; import org.forgerock.opendj.ldap.DecodeOptions; import org.forgerock.opendj.ldap.ResultCode; import com.forgerock.opendj.util.Validator; /** * The virtual list view response control as defined in * draft-ietf-ldapext-ldapv3-vlv. This control is included with a search result * in response to a virtual list view request included with a search request. *
* If the result code included with this control indicates that the virtual list * view request succeeded then the content count and target position give * sufficient information for the client to update a list box slider position to * match the newly retrieved entries and identify the target entry. *
* The content count and context ID should be used in a subsequent virtual list * view requests. *
* The following example demonstrates use of the virtual list view controls. * *
* ByteString contextID = ByteString.empty();
*
* // Add a window of 2 entries on either side of the first sn=Jensen entry.
* SearchRequest request = Requests.newSearchRequest("ou=People,dc=example,dc=com",
* SearchScope.WHOLE_SUBTREE, "(sn=*)", "sn", "givenName")
* .addControl(ServerSideSortRequestControl.newControl(true, new SortKey("sn")))
* .addControl(VirtualListViewRequestControl.newAssertionControl(
* true, ByteString.valueOf("Jensen"), 2, 2, contextID));
*
* SearchResultHandler resultHandler = new MySearchResultHandler();
* Result result = connection.search(request, resultHandler);
*
* ServerSideSortResponseControl sssControl =
* result.getControl(ServerSideSortResponseControl.DECODER, new DecodeOptions());
* if (sssControl != null && sssControl.getResult() == ResultCode.SUCCESS) {
* // Entries are sorted.
* } else {
* // Entries not necessarily sorted
* }
*
* VirtualListViewResponseControl vlvControl =
* result.getControl(VirtualListViewResponseControl.DECODER, new DecodeOptions());
* // Position in list: vlvControl.getTargetPosition()/vlvControl.getContentCount()
*
*
* The search result handler in this case displays pages of results as LDIF on
* standard out.
*
*
* private static class MySearchResultHandler implements SearchResultHandler {
*
* {@literal @}Override
* public void handleErrorResult(ErrorResultException error) {
* // Ignore.
* }
*
* {@literal @}Override
* public void handleResult(Result result) {
* // Ignore.
* }
*
* {@literal @}Override
* public boolean handleEntry(SearchResultEntry entry) {
* final LDIFEntryWriter writer = new LDIFEntryWriter(System.out);
* try {
* writer.writeEntry(entry);
* writer.flush();
* } catch (final IOException e) {
* // The writer could not write to System.out.
* }
* return true;
* }
*
* {@literal @}Override
* public boolean handleReference(SearchResultReference reference) {
* System.out.println("Got a reference: " + reference.toString());
* return false;
* }
* }
*
*
* @see VirtualListViewRequestControl
* @see
* draft-ietf-ldapext-ldapv3-vlv - LDAP Extensions for Scrolling View
* Browsing of Search Results
*/
public final class VirtualListViewResponseControl implements Control {
/**
* The OID for the virtual list view request control.
*/
public static final String OID = "2.16.840.1.113730.3.4.10";
/**
* A decoder which can be used for decoding the virtual list view response
* control.
*/
public static final ControlDecoder