Package org.ldaptive
Class FilterTemplate
- java.lang.Object
-
- org.ldaptive.FilterTemplate
-
public class FilterTemplate extends Object
Class for producing an LDAP search filter from a filter template. Templates can use either index based parameters or name based parameters for substitutions. Parameters are encoded according to RFC 4515.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FilterTemplate.Builder
-
Field Summary
Fields Modifier and Type Field Description private static int
HASH_CODE_SEED
hash code seed.private Map<String,Object>
parameters
filter parameters.private String
searchFilter
filter.
-
Constructor Summary
Constructors Constructor Description FilterTemplate()
Default constructor.FilterTemplate(String filter)
Creates a new search filter with the supplied filter.FilterTemplate(String filter, Object[] params)
Creates a new search filter with the supplied filter and parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FilterTemplate.Builder
builder()
Creates a builder for this class.static FilterTemplate
copy(FilterTemplate template)
Returns a new filter template with the same properties as the supplied template.protected static String
encode(Object obj)
Hex encodes the supplied object if it is of type byte[], otherwise the string format of the object is escaped.static String
encodeValue(byte[] value)
Hex encodes the supplied byte array for use in a search filter.static String
encodeValue(String value)
Encodes the supplied attribute value for use in a search filter.boolean
equals(Object o)
String
format()
Returns this filter with its parameters encoded and replaced.String
getFilter()
Gets the filter.Map<String,Object>
getParameters()
Gets the filter parameters.int
hashCode()
void
setFilter(String filter)
Sets the filter.void
setParameter(int position, Object value)
Sets a positional filter parameter.void
setParameter(String name, Object value)
Sets a named filter parameter.void
setParameters(Object[] values)
Sets positional filter parameters.String
toString()
-
-
-
Field Detail
-
HASH_CODE_SEED
private static final int HASH_CODE_SEED
hash code seed.- See Also:
- Constant Field Values
-
searchFilter
private String searchFilter
filter.
-
-
Constructor Detail
-
FilterTemplate
public FilterTemplate()
Default constructor.
-
FilterTemplate
public FilterTemplate(String filter)
Creates a new search filter with the supplied filter.- Parameters:
filter
- to set
-
-
Method Detail
-
getFilter
public String getFilter()
Gets the filter.- Returns:
- filter
-
setFilter
public void setFilter(String filter)
Sets the filter.- Parameters:
filter
- to set
-
getParameters
public Map<String,Object> getParameters()
Gets the filter parameters.- Returns:
- unmodifiable map of filter parameters
-
setParameter
public void setParameter(int position, Object value)
Sets a positional filter parameter.- Parameters:
position
- of the parameter in the filtervalue
- to set
-
setParameter
public void setParameter(String name, Object value)
Sets a named filter parameter.- Parameters:
name
- of the parameter in the filtervalue
- to set
-
setParameters
public void setParameters(Object[] values)
Sets positional filter parameters.- Parameters:
values
- to set
-
format
public String format()
Returns this filter with its parameters encoded and replaced. Seeencode(Object)
.- Returns:
- formatted and encoded filter
-
encodeValue
public static String encodeValue(byte[] value)
Hex encodes the supplied byte array for use in a search filter.- Parameters:
value
- to encode- Returns:
- encoded value or null if supplied value is null
-
encodeValue
public static String encodeValue(String value)
Encodes the supplied attribute value for use in a search filter. SeeFilterUtils.escape(String)
.- Parameters:
value
- to encode- Returns:
- encoded value or null if supplied value is null
-
encode
protected static String encode(Object obj)
Hex encodes the supplied object if it is of type byte[], otherwise the string format of the object is escaped. SeeFilterUtils.escape(String)
.- Parameters:
obj
- to encode- Returns:
- encoded object
-
copy
public static FilterTemplate copy(FilterTemplate template)
Returns a new filter template with the same properties as the supplied template.- Parameters:
template
- to copy- Returns:
- copy of the supplied filter template
-
builder
public static FilterTemplate.Builder builder()
Creates a builder for this class.- Returns:
- new builder
-
-