/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in * compliance with the NPL. You may obtain a copy of the NPL at * http://www.mozilla.org/NPL/ * * Software distributed under the NPL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL * for the specific language governing rights and limitations under the * NPL. * * The Initial Developer of this code under the NPL is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ package netscape.ldap.controls; import netscape.ldap.LDAPControl; /** * Represents an LDAP v3 server control that contains a string as its * only value. This is to be used as a base class by real such controls. */ abstract class LDAPStringControl extends LDAPControl { /** * Parses a response control sent by the server and * retrieves a string. *
*
* You can get the controls returned by the server by using the
* getResponseControls method of the
* LDAPConnection class.
*
*
* @param controls An array of LDAPControl objects,
* representing the controls returned by the server
* after a search. To get these controls, use the
* getResponseControls method of the
* LDAPConnection class.
* @param type The OID of the control to look for.
* @return A message string, or null if the server did
* not return a string.
* @see netscape.ldap.LDAPConnection#getResponseControls
*/
public static String parseResponse( LDAPControl[] controls, String type ) {
String msg = null;
LDAPControl cont = null;
/* See if there is a password control in the array */
for( int i = 0; (controls != null) && (i < controls.length); i++ ) {
if ( controls[i].getID().equals( type ) ) {
cont = controls[i];
break;
}
}
if ( cont != null ) {
/* Suck out the data and return it */
try {
msg = new String( cont.getValue(), "UTF8" );
} catch ( Exception e ) {
}
}
return msg;
}
}