Class FilterBuilder
java.lang.Object
org.apache.directory.ldap.client.api.search.FilterBuilder
- Direct Known Subclasses:
MatchingRuleAssertionFilterBuilder
A builder for constructing well formed search filters according to
RFC 4515. This
builder is most convenient when you use static imports. For example:
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()
- Author:
- Apache Directory Project
-
Method Summary
Modifier and TypeMethodDescriptionstatic FilterBuilderand(FilterBuilder... filters) Returns a new FilterBuilder that will&together all of the supplied filters.static FilterBuilderapproximatelyEqual(String attribute, String value) Returns a new FilterBuilder for testing the approximate equality of an attribute.static FilterBuilderReturns a new FilterBuilder that will construct a SubString filter, with zero to N any parts, but no initial or final parts.static FilterBuilderReturns a new FilterBuilder that will construct a SubString filter, with an initial part, and zero to N any parts, but no final part.static FilterBuilderReturns a new FilterBuilder for testing equality of an attribute.extensible(String value) Creates an extensible match filter by callingextensible(null, value).extensible(String attribute, String value) Creates an extensible match filter.static FilterBuildergreaterThanOrEqual(String attribute, String value) Returns a new FilterBuilder for testing lexicographical greater than.static FilterBuilderlessThanOrEqual(String attribute, String value) Returns a new FilterBuilder for testing lexicographical less than.static FilterBuildernot(FilterBuilder builder) Returns a new FilterBuilder for negating another filter.static FilterBuilderor(FilterBuilder... builders) Returns a new FilterBuilder that will|together all of the supplied filters.static FilterBuilderReturns a new FilterBuilder for testing the presence of an attributes.static FilterBuilderstartsWith(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 FilterBuilderReturns a new FilterBuilder that will construct a SubString filter, with a initial part, zero to N any parts, and a final part.toString()Returns the string version of the filter represented by this FilterBuilder.
-
Method Details
-
and
Returns a new FilterBuilder that will&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 ofkermitand a surnamethe frog.- Parameters:
filters- The filters to and together- Returns:
- A new FilterBuilder
-
approximatelyEqual
Returns a new FilterBuilder for testing the approximate equality of an attribute. For example:approximatelyEqual( "l", "san fransico" ).toString();
would result in the string:(l~=san fransico)
Which MIGHT match results whose locality isSan Francisco. The matching rule used to apply this filter is dependent on the server implementation.- Parameters:
attribute- The attributevalue- The value- Returns:
- A new FilterBuilder
-
equal
Returns a new FilterBuilder for testing equality of an attribute. For example:equal( "cn", "Kermit The Frog" ).toString();
would result in the string:(cn>=Kermit The Frog)
Which would match entries with the common nameKermit The Frog.- Parameters:
attribute- The attributevalue- The value- Returns:
- A new FilterBuilder
-
extensible
Creates an extensible match filter by callingextensible(null, value).- Parameters:
value- The value to test for- Returns:
- A new MatchingRuleAssertionFilterBuilder
-
extensible
Creates an extensible match filter. This filter can be used to specify that dn attributes should be included in the match, which matcher to use, or that all attributes that support a specific matcher will be checked. For example: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();- Parameters:
attribute- The attribute to testvalue- The value to test for- Returns:
- A new MatchingRuleAssertionFilterBuilder
-
greaterThanOrEqual
Returns a new FilterBuilder for testing lexicographical greater than. For example: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.- Parameters:
attribute- The attributevalue- The value- Returns:
- A new FilterBuilder
-
lessThanOrEqual
Returns a new FilterBuilder for testing lexicographical less than. For example: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 anmfollowed by sixz's...- Parameters:
attribute- The attributevalue- The value- Returns:
- A new FilterBuilder
-
not
Returns a new FilterBuilder for negating another filter. For example:not( present( "givenName" ) ).toString();
would result in the string:(!(givenName=*))
- Parameters:
builder- The filter to negate- Returns:
- A new FilterBuilder
-
or
Returns a new FilterBuilder that will|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 thegivenNameof eitherkermitorwalter.- Parameters:
builders- The filters to or together- Returns:
- A new FilterBuilder
-
present
Returns a new FilterBuilder for testing the presence of an attributes. For example:present( "givenName" ).toString();
would result in the string:(givenName=*)
Which would match any entry that has agivenNameattribute.- Parameters:
attribute- The attribute to test the presence of- Returns:
- A new FilterBuilder
-
startsWith
Returns a new FilterBuilder that will construct a SubString filter, with an initial part, and zero to N any part, but no final part. For instance:startswith( "sn", "Th", "Soft", "Foun" )).toString()
would result in the string:(sn=Th*Soft*Foun*)
Which would match any entry with thesnstarting with'Th', and having aSoftandFounstrings in the middle, like 'The Apache Software Foundation'.- Parameters:
attribute- The attribute to use in the filterparts- The sub elements to use in the filter- Returns:
- A new FilterBuilder
-
endsWith
Returns a new FilterBuilder that will construct a SubString filter, with an initial part, and zero to N any parts, but no final part. For instance:startswith( "sn", "Th", "Soft", "Foun" ).toString()
would result in the string:(sn=Th*Soft*Foun*)
Which would match any entry with thesnstarting with'Th', and having aSoftandFounstrings in the middle, like 'The Apache Software Foundation'.- Parameters:
attribute- The attribute to use in the filterparts- The sub elements to use in the filter- Returns:
- A new FilterBuilder
-
contains
Returns a new FilterBuilder that will construct a SubString filter, with zero to N any parts, but no initial or final parts. For instance:contains( "sn", "Soft", "Foun" )).toString()
would result in the string:(sn=*Soft*Foun*)
Which would match any entry with thesnhaving aSoftandFounstrings in the middle, like 'The Apache Software Foundation'.- Parameters:
attribute- The attribute to use in the filterparts- The sub elements to use in the filter- Returns:
- A new FilterBuilder
-
substring
Returns a new FilterBuilder that will construct a SubString filter, with a initial part, zero to N any parts, and a final part. For instance:substring( "sn", "The", "Soft", "Foun", "ion" )).toString()
would result in the string:(sn=The*Soft*Foun*ion)
Which would match any entry with thesnhaving aSoftandFounstrings in the middle, starts withTheand ends withionlike '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)
- Parameters:
attribute- The attribute to use in the filterparts- The sub elements to use in the filter- Returns:
- A new FilterBuilder
-
toString
-