|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.directory.shared.ldap.util.AttributeUtils
public class AttributeUtils
A set of utility fuctions for working with Attributes.
Constructor Summary | |
---|---|
AttributeUtils()
|
Method Summary | |
---|---|
static void |
applyModification(Entry entry,
Modification modification)
A method to apply a modification to an existing entry. |
static java.lang.Object |
cloneValue(java.lang.Object value)
Clone the value. |
static boolean |
containsValue(javax.naming.directory.Attribute attr,
Value<?> compared,
AttributeType type)
Check if an attribute contains a specific value, using the associated matchingRule for that |
static boolean |
containsValueCaseIgnore(javax.naming.directory.Attribute attr,
java.lang.Object value)
Check if an attribute contains a value. |
static boolean |
equals(java.lang.Object value1,
java.lang.Object value2)
Compare two values and return true if they are equal. |
static javax.naming.directory.Attribute |
getAttribute(javax.naming.directory.Attributes attrs,
AttributeType type)
Utility method to extract an attribute from Attributes object using all combinationos of the name including aliases. |
static javax.naming.directory.Attribute |
getDifference(javax.naming.directory.Attribute attr0,
javax.naming.directory.Attribute attr1)
Creates a new attribute which contains the values representing the difference of two attributes. |
static javax.naming.directory.Attribute |
getUnion(javax.naming.directory.Attribute attr0,
javax.naming.directory.Attribute attr1)
Creates a new attribute which contains the values representing the union of two attributes. |
static java.lang.String |
parseAttribute(java.lang.String str,
Position pos,
boolean withOption)
Parse an attribute. |
static void |
parseOID(java.lang.String str,
Position pos)
Parse an OID. |
static javax.naming.directory.Attribute |
removeAttribute(AttributeType type,
javax.naming.directory.Attributes entry)
Correctly removes an attribute from an entry using it's attributeType information. |
static javax.naming.directory.Attribute |
toAttribute(EntryAttribute entryAttribute)
Converts an EntryAttribute to an Attribute . |
static javax.naming.directory.Attributes |
toAttributes(Entry entry)
Converts an Entry to an Attributes . |
static javax.naming.directory.Attribute |
toBasicAttribute(javax.naming.directory.Attribute attribute)
Switch from a BasicAttribute to a AttributeImpl. |
static javax.naming.directory.Attributes |
toCaseInsensitive(javax.naming.directory.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 EntryAttribute |
toClientAttribute(javax.naming.directory.Attribute attribute)
Convert a BasicAttribute or a AttributeImpl to a EntryAttribute |
static Entry |
toClientEntry(javax.naming.directory.Attributes attributes,
DN dn)
Check if an attribute contains a specific value and remove it using the associated matchingRule for the attribute type supplied. |
static java.lang.String |
toString(javax.naming.directory.Attribute attribute)
Return a string representing the attribute |
static java.lang.String |
toString(javax.naming.directory.Attributes attributes)
Return a string representing the attributes |
static java.lang.String |
toString(java.lang.String tabs,
javax.naming.directory.Attribute attribute)
Return a string representing the attributes with tabs in front of the string |
static java.lang.String |
toString(java.lang.String tabs,
javax.naming.directory.Attributes attributes)
Return a string representing the attributes with tabs in front of the string |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AttributeUtils()
Method Detail |
---|
public static javax.naming.directory.Attribute removeAttribute(AttributeType type, javax.naming.directory.Attributes entry)
type
- the attributeType of the attribute to removeentry
- the entry to remove the attribute from
public static final boolean equals(java.lang.Object value1, java.lang.Object value2)
value1
- The first valuevalue2
- The second value
public static java.lang.Object cloneValue(java.lang.Object value)
value
- The value to clone
public static final javax.naming.directory.Attribute toBasicAttribute(javax.naming.directory.Attribute attribute)
attribute
- The attribute to transform
public static final javax.naming.directory.Attribute getAttribute(javax.naming.directory.Attributes attrs, AttributeType type)
attrs
- the Attributes to get the Attribute object fromtype
- the attribute type specification
public static boolean containsValue(javax.naming.directory.Attribute attr, Value<?> compared, AttributeType type) throws LdapException
attr
- The attribute we are searching incompared
- The object we are looking fortype
- The attribute type
true
if the value exists in the attribute
LdapException
- If something went wrong while accessing the datapublic static boolean containsValueCaseIgnore(javax.naming.directory.Attribute attr, java.lang.Object value)
attr
- The attribute to checkvalue
- The value to look for
public static javax.naming.directory.Attribute getDifference(javax.naming.directory.Attribute attr0, javax.naming.directory.Attribute attr1) throws javax.naming.NamingException
IllegalArgumentException
is
raised. Note that the order of arguments makes a difference.
attr0
- the first attributeattr1
- the second attribute
javax.naming.NamingException
- if there are problems accessing attribute valuespublic static javax.naming.directory.Attribute getUnion(javax.naming.directory.Attribute attr0, javax.naming.directory.Attribute attr1) throws javax.naming.NamingException
IllegalArgumentException
is raised.
attr0
- the first attributeattr1
- the second attribute
javax.naming.NamingException
- if there are problems accessing attribute valuespublic static javax.naming.directory.Attributes toCaseInsensitive(javax.naming.directory.Attributes attributes)
attributes
- The Attributes to checkpublic static java.lang.String toString(java.lang.String tabs, javax.naming.directory.Attribute attribute)
tabs
- Spaces to be added before the stringattribute
- The attribute to print
public static java.lang.String toString(javax.naming.directory.Attribute attribute)
attribute
- The attribute to print
public static java.lang.String toString(java.lang.String tabs, javax.naming.directory.Attributes attributes)
tabs
- Spaces to be added before the stringattributes
- The attributes to print
public static void parseOID(java.lang.String str, Position pos) throws java.text.ParseException
str
- The OID to parsepos
- The current position in the string
java.text.ParseException
- If we don't have a valid OIDpublic static java.lang.String parseAttribute(java.lang.String str, Position pos, boolean withOption) throws java.text.ParseException
str
- The parsed attribute,pos
- The position of the attribute in the current string
java.text.ParseException
public static java.lang.String toString(javax.naming.directory.Attributes attributes)
attributes
- The attributes to print
public static void applyModification(Entry entry, Modification modification) throws LdapException
entry
- The entry on which we want to apply a modificationmodification
- the Modification to be applied
LdapException
- if some operation fails.public static Entry toClientEntry(javax.naming.directory.Attributes attributes, DN dn) throws LdapException
attr
- the attribute we are searching incompared
- the object we are looking fortype
- the attribute typeattributes
- the BasicAttributes or AttributesImpl instance to convertregistries
- The registries, needed ro build a ServerEntrydn
- The DN which is needed by the ServerEntry
javax.naming.NamingException
- if something went wrong while removing the value
public static Object removeValue( Attribute attr, Object compared, AttributeType type ) throws NamingException
{
// quick bypass test
if ( attr.contains( compared ) )
{
return attr.remove( compared );
}
MatchingRule matchingRule = type.getEquality();
Normalizer normalizer;
if ( matchingRule != null )
{
normalizer = type.getEquality().getNormalizer();
}
else
{
normalizer = new NoOpNormalizer();
}
if ( type.getSyntax().isHumanReadable() )
{
String comparedStr = ( String ) normalizer.normalize( compared );
for ( NamingEnumeration> values = attr.getAll(); values.hasMoreElements(); )
{
String value = ( String ) values.nextElement();
if ( comparedStr.equals( normalizer.normalize( value ) ) )
{
return attr.remove( value );
}
}
}
else
{
byte[] comparedBytes = null;
if ( compared instanceof String )
{
if ( ( ( String ) compared ).length() < 3 )
{
return null;
}
// Tansform the String to a byte array
int state = 1;
comparedBytes = new byte[( ( String ) compared ).length() / 3];
int pos = 0;
for ( char c : ( ( String ) compared ).toCharArray() )
{
switch ( state )
{
case 1:
if ( c != '\\' )
{
return null;
}
state++;
break;
case 2:
int high = StringTools.getHexValue( c );
if ( high == -1 )
{
return null;
}
comparedBytes[pos] = ( byte ) ( high << 4 );
state++;
break;
case 3:
int low = StringTools.getHexValue( c );
if ( low == -1 )
{
return null;
}
comparedBytes[pos] += ( byte ) low;
pos++;
state = 1;
break;
}
}
}
else
{
comparedBytes = ( byte[] ) compared;
}
for ( NamingEnumeration> values = attr.getAll(); values.hasMoreElements(); )
{
Object value = values.nextElement();
if ( value instanceof byte[] )
{
if ( ArrayUtils.isEquals( comparedBytes, value ) )
{
return attr.remove( value );
}
}
}
}
return null;
}
/**
Convert a BasicAttributes or a AttributesImpl to a ServerEntry
javax.naming.directory.InvalidAttributeIdentifierException
- If we get an invalid attribute
LdapException
public static javax.naming.directory.Attributes toAttributes(Entry entry)
Entry
to an Attributes
.
entry
- the Entry
to convert
Attributes
public static javax.naming.directory.Attribute toAttribute(EntryAttribute entryAttribute)
EntryAttribute
to an Attribute
.
entryAttribute
- the EntryAttribute
to convert
Attribute
public static EntryAttribute toClientAttribute(javax.naming.directory.Attribute attribute)
attribute
- the BasicAttributes or AttributesImpl instance to convertattributeType
-
javax.naming.directory.InvalidAttributeIdentifierException
- If we had an incorrect attribute
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |