directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r406556 - /directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
Date Mon, 15 May 2006 06:47:46 GMT
Author: elecharny
Date: Sun May 14 23:47:36 2006
New Revision: 406556

URL: http://svn.apache.org/viewcvs?rev=406556&view=rev
Log:
Added two static methods to parse attributeType/attributeValue 

Modified:
    directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java

Modified: directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
URL: http://svn.apache.org/viewcvs/directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java?rev=406556&r1=406555&r2=406556&view=diff
==============================================================================
--- directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
(original)
+++ directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
Sun May 14 23:47:36 2006
@@ -21,6 +21,8 @@
 
 import javax.naming.InvalidNameException;
 import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.DirContext;
 import javax.naming.ldap.Control;
 
@@ -495,6 +497,35 @@
 	 * @param line The line which contains the value
 	 * @param pos The starting position in the line
 	 * @return A String or a byte[], depending of the kind of value we get
+	 */
+	private static Object parseSimpleValue( String line, int pos )
+	{
+		if ( line.length() > pos + 1 )
+		{
+			char c = line.charAt( pos + 1 );
+			
+			if ( c == ':' )
+			{
+				String value = StringTools.trim( line.substring( pos + 2 ) );
+				
+				return Base64.decode( value.toCharArray() );
+			}
+			else
+			{
+				return StringTools.trim( line.substring( pos + 1 ) );
+			}
+		}
+		else
+		{
+			return null;
+		}
+	}
+	
+	/**
+	 * Parse the value part.
+	 * @param line The line which contains the value
+	 * @param pos The starting position in the line
+	 * @return A String or a byte[], depending of the kind of value we get
 	 * @throws NamingException If something went wrong
 	 */
 	private Object parseValue( String line, int pos ) throws NamingException
@@ -719,12 +750,37 @@
 	/**
 	 * Parse an AttributeType/AttributeValue
 	 * 
+	 * @param attribute The create attribute
+	 * @param line The line to parse
+	 * @param lowerLine The same line, lowercased
+	 */
+	public static Attribute parseAttributeValue( String line )
+	{
+		int colonIndex = line.indexOf( ':' );
+		
+		if ( colonIndex != -1 )
+		{
+			String attributeType = line.toLowerCase().substring( 0, colonIndex );
+			Object attributeValue = parseSimpleValue( line, colonIndex );
+	
+			// Create an attribute
+			return new BasicAttribute( attributeType, attributeValue );
+		}
+		else
+		{
+			return null;
+		}
+	}
+
+	/**
+	 * Parse an AttributeType/AttributeValue
+	 * 
 	 * @param entry The entry where to store the value
 	 * @param line The line to parse
 	 * @param lowerLine The same line, lowercased
 	 * @throws NamingException If anything goes wrong
 	 */
-	private void parseAttributeValue( Entry entry, String line, String lowerLine ) throws NamingException
+	public void parseAttributeValue( Entry entry, String line, String lowerLine ) throws NamingException
 	{
 		int colonIndex = line.indexOf( ':' );
 		



Mime
View raw message