Class FilterBuilder
- java.lang.Object
-
- org.apache.directory.ldap.client.api.search.FilterBuilder
-
- Direct Known Subclasses:
MatchingRuleAssertionFilterBuilder
public class FilterBuilder extends Object
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 callingextensible(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.
-
-
-
Method Detail
-
and
public static FilterBuilder and(FilterBuilder... filters)
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 ofkermit
and a surnamethe frog
.- Parameters:
filters
- The filters to and together- Returns:
- A new FilterBuilder
-
approximatelyEqual
public static FilterBuilder approximatelyEqual(String attribute, String value)
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
public static FilterBuilder equal(String attribute, String value)
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
public static MatchingRuleAssertionFilterBuilder extensible(String value)
Creates an extensible match filter by callingextensible(null, value)
.- Parameters:
value
- The value to test for- Returns:
- A new MatchingRuleAssertionFilterBuilder
-
extensible
public static MatchingRuleAssertionFilterBuilder extensible(String attribute, String value)
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
public static FilterBuilder greaterThanOrEqual(String attribute, String value)
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
public static FilterBuilder lessThanOrEqual(String attribute, String value)
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 anm
followed by sixz
's...- Parameters:
attribute
- The attributevalue
- The value- Returns:
- A new FilterBuilder
-
not
public static FilterBuilder not(FilterBuilder builder)
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
public static FilterBuilder or(FilterBuilder... builders)
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 thegivenName
of eitherkermit
orwalter
.- Parameters:
builders
- The filters to or together- Returns:
- A new FilterBuilder
-
present
public static FilterBuilder present(String attribute)
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 agivenName
attribute.- Parameters:
attribute
- The attribute to test the presence of- Returns:
- A new FilterBuilder
-
startsWith
public 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. For instance:startswith( "sn", "Th", "Soft", "Foun" )).toString()
would result in the string:(sn=Th*Soft*Foun*)
Which would match any entry with thesn
starting with'Th'
, and having aSoft
andFoun
strings 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
public 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. For instance:startswith( "sn", "Th", "Soft", "Foun" ).toString()
would result in the string:(sn=Th*Soft*Foun*)
Which would match any entry with thesn
starting with'Th'
, and having aSoft
andFoun
strings 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
public 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. For instance:contains( "sn", "Soft", "Foun" )).toString()
would result in the string:(sn=*Soft*Foun*)
Which would match any entry with thesn
having aSoft
andFoun
strings 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
public 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. 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 thesn
having aSoft
andFoun
strings in the middle, starts withThe
and ends withion
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)
- Parameters:
attribute
- The attribute to use in the filterparts
- The sub elements to use in the filter- Returns:
- A new FilterBuilder
-
-