Package org.ldaptive

Class 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.
    • 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.
      • parameters

        private final Map<String,​Object> parameters
        filter parameters.
    • 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
      • FilterTemplate

        public FilterTemplate​(String filter,
                              Object[] params)
        Creates a new search filter with the supplied filter and parameters.
        Parameters:
        filter - to set
        params - 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 filter
        value - to set
      • setParameter

        public void setParameter​(String name,
                                 Object value)
        Sets a named filter parameter.
        Parameters:
        name - of the parameter in the filter
        value - 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. See encode(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. See FilterUtils.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. See FilterUtils.escape(String).
        Parameters:
        obj - to encode
        Returns:
        encoded object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • builder

        public static FilterTemplate.Builder builder()
        Creates a builder for this class.
        Returns:
        new builder