directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r406555 - /directory/branches/elecharny/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java
Date Mon, 15 May 2006 06:46:09 GMT
Author: elecharny
Date: Sun May 14 23:46:08 2006
New Revision: 406555

URL: http://svn.apache.org/viewcvs?rev=406555&view=rev
Log:
Added a method to read the entry in server.xml : this is not a ldif file !

Modified:
    directory/branches/elecharny/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java

Modified: directory/branches/elecharny/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java
URL: http://svn.apache.org/viewcvs/directory/branches/elecharny/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java?rev=406555&r1=406554&r2=406555&view=diff
==============================================================================
--- directory/branches/elecharny/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java
(original)
+++ directory/branches/elecharny/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/AttributesPropertyEditor.java
Sun May 14 23:46:08 2006
@@ -21,8 +21,10 @@
 
 import java.beans.PropertyEditor;
 import java.beans.PropertyEditorSupport;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -30,14 +32,15 @@
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
 
 import org.apache.commons.collections.MultiHashMap;
 import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.shared.ldap.ldif.Entry;
 import org.apache.directory.shared.ldap.ldif.LdifComposer;
 import org.apache.directory.shared.ldap.ldif.LdifComposerImpl;
 import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.util.MultiMap;
+import org.apache.directory.shared.ldap.util.StringTools;
 
 
 /**
@@ -183,6 +186,64 @@
         }
     }
 
+    /**
+     * Read an entry (without DN)
+     * @param text The ldif format file
+     * @return An Attributes.
+     */
+	private Attributes readEntry( String text )
+	{
+		StringReader strIn = new StringReader( text );
+        BufferedReader in = new BufferedReader( strIn );
+		
+		String line = null;
+		Attributes attributes = new BasicAttributes();
+		
+		try
+		{
+			while ( ( line = ((BufferedReader)in).readLine() ) != null )
+			{
+				if ( line.length() == 0 )
+				{
+					continue;
+				}
+
+				String addedLine = line.trim();
+
+				if ( StringTools.isEmpty( addedLine ) )
+				{
+					continue;
+				}
+				
+				Attribute attribute = LdifReader.parseAttributeValue( addedLine );
+				Attribute oldAttribute = attributes.get( attribute.getID() );
+				
+				if ( oldAttribute != null )
+				{
+					try
+					{
+						oldAttribute.add( attribute.get() );
+						attributes.put( oldAttribute );
+					}
+					catch (NamingException ne )
+					{
+						// Do nothing
+					}
+				}
+				else
+				{
+					attributes.put( attribute );
+				}
+			}
+		}
+		catch ( IOException ioe )
+		{
+			// Do nothing : we can't reach this point !
+		}
+
+		return attributes;
+	}
+
 
     /**
      * Converts the specified LDIF string into {@link Attributes}.
@@ -194,25 +255,6 @@
             text = "";
         }
 
-        LdifReader parser = new LdifReader();
-        
-        try
-        {
-        	List entries = parser.parseLdif( text );
-        	
-        	if ( entries.size() != 0 )
-        	{
-        		Entry entry = (Entry)entries.get( 0 );
-        		
-        		if ( entry.isEntry() )
-        		{
-        			setValue( entry.getAttributes() );
-        		}
-        	}
-        }
-        catch ( NamingException e )
-        {
-            throw ( IllegalArgumentException ) new IllegalArgumentException().initCause(
e );
-        }
+       	setValue( readEntry( text ) );
     }
 }



Mime
View raw message