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 classFilterTemplate.Builder
-
Field Summary
Fields Modifier and Type Field Description private static intHASH_CODE_SEEDhash code seed.private Map<String,Object>parametersfilter parameters.private StringsearchFilterfilter.
-
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.Builderbuilder()Creates a builder for this class.static FilterTemplatecopy(FilterTemplate template)Returns a new filter template with the same properties as the supplied template.protected static Stringencode(Object obj)Hex encodes the supplied object if it is of type byte[], otherwise the string format of the object is escaped.static StringencodeValue(byte[] value)Hex encodes the supplied byte array for use in a search filter.static StringencodeValue(String value)Encodes the supplied attribute value for use in a search filter.booleanequals(Object o)private static StringescapeBrackets(String s)Replaces any brackets in the supplied string with their hex encoding.Stringformat()Returns this filter with its parameters encoded and replaced.StringgetFilter()Gets the filter.Map<String,Object>getParameters()Gets the filter parameters.inthashCode()voidsetFilter(String filter)Sets the filter.voidsetParameter(int position, Object value)Sets a positional filter parameter.voidsetParameter(String name, Object value)Sets a named filter parameter.voidsetParameters(Object[] values)Sets positional filter parameters.StringtoString()
-
-
-
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
-
escapeBrackets
private static String escapeBrackets(String s)
Replaces any brackets in the supplied string with their hex encoding.- Parameters:
s- to escape- Returns:
- string with escaped brackets
-
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
-
-