directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r543737 - /directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
Date Sat, 02 Jun 2007 13:34:33 GMT
Author: elecharny
Date: Sat Jun  2 06:34:32 2007
New Revision: 543737

URL: http://svn.apache.org/viewvc?view=rev&rev=543737
Log:
Added a utility method to convert a BasicAttributes() to a BasicAttributes( true )
if needed.

Modified:
    directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java

Modified: directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java?view=diff&rev=543737&r1=543736&r2=543737
==============================================================================
--- directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
(original)
+++ directory/shared/branches/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
Sat Jun  2 06:34:32 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;
 
@@ -133,6 +134,54 @@
             {
                 return newAttribute;
             }
+        }
+    }
+    
+    /**
+     * 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;
         }
     }
     



Mime
View raw message