Class AttributeUtils
java.lang.Object
org.apache.directory.api.ldap.model.entry.AttributeUtils
A set of utility fuctions for working with Attributes.
- Author:
- Apache Directory Project
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyModification(Entry entry, Modification modification) A method to apply a modification to an existing entry.static booleancontainsValueCaseIgnore(Attribute attr, Object value) Check if an attribute contains a value.static StringparseAttribute(byte[] bytes, org.apache.directory.api.util.Position pos, boolean withOption, boolean relaxed) Parse an attribute.static StringparseAttribute(char[] str, org.apache.directory.api.util.Position pos, boolean withOption, boolean relaxed) Parse an attribute.static AttributetoApiAttribute(Attribute jndiAttribute) Convert a JNDI Attribute to an LDAP API Attributestatic AttributestoAttributes(Entry entry) Converts anEntryto anAttributes.static AttributestoCaseInsensitive(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.static EntrytoEntry(Attributes attributes, Dn dn) Convert a BasicAttributes or a AttributesImpl to an Entrystatic AttributetoJndiAttribute(Attribute attribute) Converts anAttributeto a JNDI Attribute.
-
Method Details
-
containsValueCaseIgnore
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 checkvalue- The value to look for- Returns:
- true if the value is present in the attribute
-
toCaseInsensitive
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 stringwithOption- A flag set if we want to parse the optionsrelaxed- 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 stringwithOption- A flag set if we want to parse the optionsrelaxed- 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
A method to apply a modification to an existing entry.- Parameters:
entry- The entry on which we want to apply a modificationmodification- the Modification to be applied- Throws:
LdapException- if some operation fails.
-
toEntry
Convert a BasicAttributes or a AttributesImpl to an Entry- Parameters:
attributes- the BasicAttributes or AttributesImpl instance to convertdn- The Dn which is needed by the Entry- Returns:
- An instance of a Entry object
- Throws:
LdapException- If we get an invalid attribute
-
toAttributes
Converts anEntryto anAttributes.- Parameters:
entry- theEntryto convert- Returns:
- the equivalent
Attributes
-
toJndiAttribute
-
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
-