}
private static SearchParameter getSearchParameter( ISearch search )
{
SearchParameter searchParameter = ( SearchParameter ) search.getSearchParameter().clone();
// add children detetion attributes
if ( search.isInitHasChildrenFlag() )
{
if ( search.getBrowserConnection().getSchema().hasAttributeTypeDescription(
IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES )
&& !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES ) )
{
String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
.getReturningAttributes().length );
returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES;
searchParameter.setReturningAttributes( returningAttributes );
}
else if ( search.getBrowserConnection().getSchema().hasAttributeTypeDescription(
IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES )
&& !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES ) )
{
String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
.getReturningAttributes().length );
returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES;
searchParameter.setReturningAttributes( returningAttributes );
}
else if ( search.getBrowserConnection().getSchema().hasAttributeTypeDescription(
IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT )
&& !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT ) )
{
String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
.getReturningAttributes().length );
returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT;
searchParameter.setReturningAttributes( returningAttributes );
}
}
// always add the objectClass attribute, we need it
// - to detect alias and referral entries
// - to determine the entry's icon
// - to determine must and may attributes
if ( !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
IAttribute.OBJECTCLASS_ATTRIBUTE )
&& !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
ISearch.ALL_USER_ATTRIBUTES ) )
{
String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
.getReturningAttributes().length );
returningAttributes[returningAttributes.length - 1] = IAttribute.OBJECTCLASS_ATTRIBUTE;
searchParameter.setReturningAttributes( returningAttributes );
}
// filter controls if not supported by server
if ( searchParameter.getControls() != null )
{
IBrowserConnection connection = search.getBrowserConnection();
Set<String> suppportedConrolSet = new HashSet<String>();
if ( connection.getRootDSE() != null
&& connection.getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL ) != null )
{
IAttribute scAttribute = connection.getRootDSE().getAttribute(
IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL );
String[] supportedControls = scAttribute.getStringValues();
for ( int i = 0; i < supportedControls.length; i++ )
{
suppportedConrolSet.add( supportedControls[i].toLowerCase() );
}
}
org.apache.directory.studio.ldapbrowser.core.model.Control[] controls = searchParameter.getControls();
List<org.apache.directory.studio.ldapbrowser.core.model.Control> controlList = new ArrayList<org.apache.directory.studio.ldapbrowser.core.model.Control>();
for ( int i = 0; i < controls.length; i++ )
{
if ( suppportedConrolSet.contains( controls[i].getOid().toLowerCase() ) )
{
controlList.add( controls[i] );
}
}
searchParameter.setControls( controlList
.toArray( new org.apache.directory.studio.ldapbrowser.core.model.Control[controlList.size()] ) );
}
return searchParameter;
}