Package org.ldaptive

Class FilterTemplate


  • public class FilterTemplate
    extends java.lang.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.
    Author:
    Middleware Services
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FilterTemplate.Builder  
    • Constructor Summary

      Constructors 
      Constructor Description
      FilterTemplate()
      Default constructor.
      FilterTemplate​(java.lang.String filter)
      Creates a new search filter with the supplied filter.
      FilterTemplate​(java.lang.String filter, java.lang.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.
      protected static java.lang.String encode​(java.lang.Object obj)
      Hex encodes the supplied object if it is of type byte[], otherwise the string format of the object is escaped.
      static java.lang.String encodeValue​(byte[] value)
      Hex encodes the supplied byte array for use in a search filter.
      static java.lang.String encodeValue​(java.lang.String value)
      Encodes the supplied attribute value for use in a search filter.
      boolean equals​(java.lang.Object o)  
      java.lang.String format()
      Returns this filter with it's parameters encoded and replaced.
      java.lang.String getFilter()
      Gets the filter.
      java.util.Map<java.lang.String,​java.lang.Object> getParameters()
      Gets the filter parameters.
      int hashCode()  
      void setFilter​(java.lang.String filter)
      Sets the filter.
      void setParameter​(int position, java.lang.Object value)
      Sets a positional filter parameter.
      void setParameter​(java.lang.String name, java.lang.Object value)
      Sets a named filter parameter.
      void setParameters​(java.lang.Object[] values)
      Sets positional filter parameters.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • FilterTemplate

        public FilterTemplate()
        Default constructor.
      • FilterTemplate

        public FilterTemplate​(java.lang.String filter)
        Creates a new search filter with the supplied filter.
        Parameters:
        filter - to set
      • FilterTemplate

        public FilterTemplate​(java.lang.String filter,
                              java.lang.Object[] params)
        Creates a new search filter with the supplied filter and parameters.
        Parameters:
        filter - to set
        params - to set
    • Method Detail

      • getFilter

        public java.lang.String getFilter()
        Gets the filter.
        Returns:
        filter
      • setFilter

        public void setFilter​(java.lang.String filter)
        Sets the filter.
        Parameters:
        filter - to set
      • getParameters

        public java.util.Map<java.lang.String,​java.lang.Object> getParameters()
        Gets the filter parameters.
        Returns:
        unmodifiable map of filter parameters
      • setParameter

        public void setParameter​(int position,
                                 java.lang.Object value)
        Sets a positional filter parameter.
        Parameters:
        position - of the parameter in the filter
        value - to set
      • setParameter

        public void setParameter​(java.lang.String name,
                                 java.lang.Object value)
        Sets a named filter parameter.
        Parameters:
        name - of the parameter in the filter
        value - to set
      • setParameters

        public void setParameters​(java.lang.Object[] values)
        Sets positional filter parameters.
        Parameters:
        values - to set
      • format

        public java.lang.String format()
        Returns this filter with it's parameters encoded and replaced. See encode(Object).
        Returns:
        formatted and encoded filter
      • encodeValue

        public static java.lang.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 java.lang.String encodeValue​(java.lang.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 java.lang.String encode​(java.lang.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
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • builder

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