You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/06/02 19:20:34 UTC
svn commit: r543762 -
/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
Author: elecharny
Date: Sat Jun 2 10:20:33 2007
New Revision: 543762
URL: http://svn.apache.org/viewvc?view=rev&rev=543762
Log:
Added a utility method to convert a BasicAttributes() to a BasicAttributes( true )
if needed.
Modified:
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java?view=diff&rev=543762&r1=543761&r2=543762
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java Sat Jun 2 10:20:33 2007
@@ -30,6 +30,7 @@
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -608,6 +609,54 @@
return attr;
}
+ /**
+ * 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)
+ *
+ * @param attributes The Attributes to check
+ */
+ public static Attributes toCaseInsensitive( Attributes attributes )
+ {
+ if ( attributes == null )
+ {
+ return attributes;
+ }
+
+ if ( attributes instanceof BasicAttributes )
+ {
+ if ( attributes.isCaseIgnored() )
+ {
+ // Just do nothing if the Attributes is already case insensitive
+ return attributes;
+ }
+ else
+ {
+ // Ok, bad news : we have to create a new BasicAttributes
+ // whiwh will be case insensitive
+ Attributes newAttrs = new BasicAttributes( true );
+
+ NamingEnumeration attrs = attributes.getAll();
+
+ if ( attrs != null )
+ {
+ // Iterate through the attributes now
+ while ( attrs.hasMoreElements() )
+ {
+ newAttrs.put( (Attribute)attrs.nextElement() );
+ }
+ }
+
+ return newAttrs;
+ }
+ }
+ else
+ {
+ // we can safely return the attributes if it's not a BasicAttributes
+ return attributes;
+ }
+ }
+
/**
* Return a string representing the attributes with tabs in front of the