Class AttributeUtils

java.lang.Object
org.apache.directory.api.ldap.model.entry.AttributeUtils

public final class AttributeUtils extends Object
A set of utility fuctions for working with Attributes.
Author:
Apache Directory Project
  • Method Details

    • containsValueCaseIgnore

      public static boolean containsValueCaseIgnore(Attribute attr, Object value)
      Check if an attribute contains a value. The test is case insensitive, and the value is supposed to be a String. If the value is a byte[], then the case sensitivity is useless.
      Parameters:
      attr - The attribute to check
      value - The value to look for
      Returns:
      true if the value is present in the attribute
    • toCaseInsensitive

      public static Attributes toCaseInsensitive(Attributes attributes)
      Check if the attributes is a BasicAttributes, and if so, switch the case sensitivity to false to avoid tricky problems in the server. (Ldap attributeTypes are *always* case insensitive)
      Parameters:
      attributes - The Attributes to check
      Returns:
      The modified Attributes
    • parseAttribute

      public static String parseAttribute(char[] str, org.apache.directory.api.util.Position pos, boolean withOption, boolean relaxed) throws ParseException
      Parse an attribute. The grammar is : attributedescription = attributetype options attributetype = oid oid = descr / numericoid descr = keystring numericoid = number 1*( '.' number ) options = *( ';' option ) option = 1*keychar keystring = leadkeychar *keychar leadkeychar = 'a'-z' | 'A'-'Z' keychar = 'a'-z' | 'A'-'Z' / '0'-'9' / '-' number = '0'-'9' / ( '1'-'9' 1*'0'-'9' )
      Parameters:
      str - The parsed attribute,
      pos - The position of the attribute in the current string
      withOption - A flag set if we want to parse the options
      relaxed - A flag set if we want to parse without being too strict
      Returns:
      The parsed attribute if valid
      Throws:
      ParseException - If we had an issue while parsing the attribute
    • parseAttribute

      public static String parseAttribute(byte[] bytes, org.apache.directory.api.util.Position pos, boolean withOption, boolean relaxed) throws ParseException
      Parse an attribute. The grammar is : attributedescription = attributetype options attributetype = oid oid = descr / numericoid descr = keystring numericoid = number 1*( '.' number ) options = *( ';' option ) option = 1*keychar keystring = leadkeychar *keychar leadkeychar = 'a'-z' | 'A'-'Z' keychar = 'a'-z' | 'A'-'Z' / '0'-'9' / '-' number = '0'-'9' / ( '1'-'9' 1*'0'-'9' )
      Parameters:
      bytes - The parsed attribute,
      pos - The position of the attribute in the current string
      withOption - A flag set if we want to parse the options
      relaxed - A flag set if we want to parse without being too strict
      Returns:
      The parsed attribute if valid
      Throws:
      ParseException - If we had an issue while parsing the attribute
    • applyModification

      public static void applyModification(Entry entry, Modification modification) throws LdapException
      A method to apply a modification to an existing entry.
      Parameters:
      entry - The entry on which we want to apply a modification
      modification - the Modification to be applied
      Throws:
      LdapException - if some operation fails.
    • toEntry

      public static Entry toEntry(Attributes attributes, Dn dn) throws LdapException
      Convert a BasicAttributes or a AttributesImpl to an Entry
      Parameters:
      attributes - the BasicAttributes or AttributesImpl instance to convert
      dn - The Dn which is needed by the Entry
      Returns:
      An instance of a Entry object
      Throws:
      LdapException - If we get an invalid attribute
    • toAttributes

      public static Attributes toAttributes(Entry entry)
      Converts an Entry to an Attributes.
      Parameters:
      entry - the Entry to convert
      Returns:
      the equivalent Attributes
    • toJndiAttribute

      public static Attribute toJndiAttribute(Attribute attribute)
      Converts an Attribute to a JNDI Attribute.
      Parameters:
      attribute - the Attribute to convert
      Returns:
      the equivalent JNDI Attribute
    • toApiAttribute

      public static Attribute toApiAttribute(Attribute jndiAttribute) throws LdapInvalidAttributeValueException
      Convert a JNDI Attribute to an LDAP API Attribute
      Parameters:
      jndiAttribute - the JNDI Attribute instance to convert
      Returns:
      An instance of a LDAP API Attribute object
      Throws:
      LdapInvalidAttributeValueException - If the attribute is invalid