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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
applyModification(Entry entry, Modification modification)
A method to apply a modification to an existing entry.static boolean
containsValueCaseIgnore(Attribute attr, Object value)
Check if an attribute contains a value.static String
parseAttribute(byte[] bytes, Position pos, boolean withOption, boolean relaxed)
Parse an attribute.static String
parseAttribute(char[] str, Position pos, boolean withOption, boolean relaxed)
Parse an attribute.static Attribute
toApiAttribute(Attribute jndiAttribute)
Convert a JNDI Attribute to an LDAP API Attributestatic Attributes
toAttributes(Entry entry)
Converts anEntry
to anAttributes
.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.static Entry
toEntry(Attributes attributes, Dn dn)
Convert a BasicAttributes or a AttributesImpl to an Entrystatic Attribute
toJndiAttribute(Attribute attribute)
Converts anAttribute
to a JNDI Attribute.
-
-
-
Method Detail
-
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 checkvalue
- 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, 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, 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
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 modificationmodification
- 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 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
public static Attributes toAttributes(Entry entry)
Converts anEntry
to anAttributes
.- Parameters:
entry
- theEntry
to convert- Returns:
- the equivalent
Attributes
-
toJndiAttribute
public static Attribute toJndiAttribute(Attribute attribute)
Converts anAttribute
to a JNDI Attribute.- Parameters:
attribute
- theAttribute
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
-
-