public class FilterBuilder extends Object
import static org.apache.directory.ldap.client.api.search.FilterBuilder.and; import static org.apache.directory.ldap.client.api.search.FilterBuilder.equal; import static org.apache.directory.ldap.client.api.search.FilterBuilder.or; ... String filter = or( and( equal( "givenName", "kermit" ), equal( "sn", "the frog" ) ), and( equal( "givenName", "miss" ), equal( "sn", "piggy" ) ) ) .toString()
Modifier and Type | Method and Description |
---|---|
static FilterBuilder |
and(FilterBuilder... filters)
Returns a new FilterBuilder that will
& together all of the
supplied filters. |
static FilterBuilder |
approximatelyEqual(String attribute,
String value)
Returns a new FilterBuilder for testing the approximate equality of an
attribute.
|
static FilterBuilder |
contains(String attribute,
String... parts)
Returns a new FilterBuilder that will construct a SubString filter, with zero to N any parts,
but no initial or final parts.
|
static FilterBuilder |
endsWith(String attribute,
String... parts)
Returns a new FilterBuilder that will construct a SubString filter, with an initial part,
and zero to N any parts, but no final part.
|
static FilterBuilder |
equal(String attribute,
String value)
Returns a new FilterBuilder for testing equality of an attribute.
|
static MatchingRuleAssertionFilterBuilder |
extensible(String value)
Creates an extensible match filter by calling
extensible(null, value) . |
static MatchingRuleAssertionFilterBuilder |
extensible(String attribute,
String value)
Creates an extensible match filter.
|
static FilterBuilder |
greaterThanOrEqual(String attribute,
String value)
Returns a new FilterBuilder for testing lexicographical greater than.
|
static FilterBuilder |
lessThanOrEqual(String attribute,
String value)
Returns a new FilterBuilder for testing lexicographical less than.
|
static FilterBuilder |
not(FilterBuilder builder)
Returns a new FilterBuilder for negating another filter.
|
static FilterBuilder |
or(FilterBuilder... builders)
Returns a new FilterBuilder that will
| together all of the
supplied filters. |
static FilterBuilder |
present(String attribute)
Returns a new FilterBuilder for testing the presence of an attributes.
|
static FilterBuilder |
startsWith(String attribute,
String... parts)
Returns a new FilterBuilder that will construct a SubString filter, with an initial part,
and zero to N any part, but no final part.
|
static FilterBuilder |
substring(String attribute,
String... parts)
Returns a new FilterBuilder that will construct a SubString filter, with a initial part,
zero to N any parts, and a final part.
|
String |
toString()
Returns the string version of the filter represented by this FilterBuilder.
|
public static FilterBuilder and(FilterBuilder... filters)
&
together all of the
supplied filters. For example:
and( equal( "givenName", "kermit" ), equal( "sn", "the frog" ) ).toString()would result in the string:
(&(givenName=kermit)(sn=the frog))Which would match all entries with a given name of
kermit
and a surname the frog
.filters
- The filters to and togetherpublic static FilterBuilder approximatelyEqual(String attribute, String value)
approximatelyEqual( "l", "san fransico" ).toString();would result in the string:
(l~=san fransico)Which MIGHT match results whose locality is
San Francisco
. The matching rule used to apply this filter
is dependent on the server implementation.attribute
- The attributevalue
- The valuepublic static FilterBuilder equal(String attribute, String value)
equal( "cn", "Kermit The Frog" ).toString();would result in the string:
(cn>=Kermit The Frog)Which would match entries with the common name
Kermit The Frog
.attribute
- The attributevalue
- The valuepublic static MatchingRuleAssertionFilterBuilder extensible(String value)
extensible(null, value)
.value
- The value to test forpublic static MatchingRuleAssertionFilterBuilder extensible(String attribute, String value)
extensible( "sn", "Barney Rubble" ) .useDnAttributes() .setMatchingRule( "2.4.6.8.10" ) .toString();would result in the string:
(sn:dn:2.4.6.8.10:=Barney Rubble)Not that the specialized filter builder that is returned IS a FilterBuilder so it can be chained with other filters. For example:
and( extensible( "sn", "Rubble" ) .useDnAttributes() .setMatchingRule( "2.4.6.8.10" ), equal( "givenName", "Barney" ) ) .toString();
attribute
- The attribute to testvalue
- The value to test forpublic static FilterBuilder greaterThanOrEqual(String attribute, String value)
greaterThanOrEqual( "sn", "n" ).toString();would result in the string:
(sn>=n)which would match results whose surname starts with the second half of the alphabet.
attribute
- The attributevalue
- The valuepublic static FilterBuilder lessThanOrEqual(String attribute, String value)
lessThanOrEqual( "sn", "mzzzzzz" ).toString();would result in the string:
(sn<=mzzzzzz)which would match results whose surname starts with the first half of the alphabet. Note, this is not perfect, but if you know anybody with a last name that starts with an
m
followed by six
z
's...attribute
- The attributevalue
- The valuepublic static FilterBuilder not(FilterBuilder builder)
not( present( "givenName" ) ).toString();would result in the string:
(!(givenName=*))
builder
- The filter to negatepublic static FilterBuilder or(FilterBuilder... builders)
|
together all of the
supplied filters. For example:
or( equal( "givenName", "kermit" ), equal( "givenName", "walter" ) ).toString()would result in the string:
(|(givenName=kermit)(givenName=walter))Which would match any entry with the
givenName
of either
kermit
or walter
.builders
- The filters to or togetherpublic static FilterBuilder present(String attribute)
present( "givenName" ).toString();would result in the string:
(givenName=*)Which would match any entry that has a
givenName
attribute.attribute
- The attribute to test the presence ofpublic static FilterBuilder startsWith(String attribute, String... parts)
startswith( "sn", "Th", "Soft", "Foun" )).toString()would result in the string:
(sn=Th*Soft*Foun*)Which would match any entry with the
sn
starting with 'Th'
, and
having a Soft
and Foun
strings in the middle, like
'The Apache Software Foundation'.attribute
- The attribute to use in the filterparts
- The sub elements to use in the filterpublic static FilterBuilder endsWith(String attribute, String... parts)
startswith( "sn", "Th", "Soft", "Foun" ).toString()would result in the string:
(sn=Th*Soft*Foun*)Which would match any entry with the
sn
starting with 'Th'
, and
having a Soft
and Foun
strings in the middle, like
'The Apache Software Foundation'.attribute
- The attribute to use in the filterparts
- The sub elements to use in the filterpublic static FilterBuilder contains(String attribute, String... parts)
contains( "sn", "Soft", "Foun" )).toString()would result in the string:
(sn=*Soft*Foun*)Which would match any entry with the
sn
having a Soft
and Foun
strings in the middle, like
'The Apache Software Foundation'.attribute
- The attribute to use in the filterparts
- The sub elements to use in the filterpublic static FilterBuilder substring(String attribute, String... parts)
substring( "sn", "The", "Soft", "Foun", "ion" )).toString()would result in the string:
(sn=The*Soft*Foun*ion)Which would match any entry with the
sn
having a Soft
and Foun
strings in the middle, starts with The
and ends with ion
like
'The Apache Software Foundation'.
Note that if we have only two strings in the parts, they will be the initial and final ones :
substring( "sn", "The", "ion" )).toString()would result in the string:
(sn=The*ion)
attribute
- The attribute to use in the filterparts
- The sub elements to use in the filterCopyright © 2003–2023 The Apache Software Foundation. All rights reserved.