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/10/12 14:44:35 UTC
svn commit: r584150 - in /directory/shared/branches/bigbang/ldap/src:
main/java/org/apache/directory/shared/ldap/ldif/
main/java/org/apache/directory/shared/ldap/message/
test/java/org/apache/directory/shared/ldap/ldif/
Author: elecharny
Date: Fri Oct 12 05:44:30 2007
New Revision: 584150
URL: http://svn.apache.org/viewvc?rev=584150&view=rev
Log:
Removed warnings by using generics
Fixed a bug with null values in Ldif writer
Modified:
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/Referral.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/ReferralImpl.java
directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=584150&r1=584149&r2=584150&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java Fri Oct 12 05:44:30 2007
@@ -42,6 +42,9 @@
/** The array that will be used to match the other chars.*/
private static boolean[] LDIF_SAFE_OTHER_CHARS_ALPHABET = new boolean[128];
+ /** The default length for a line in a ldif file */
+ private static final int DEFAULT_LINE_LENGTH = 80;
+
static
{
// Initialization of the array that will be used to match the first char.
@@ -128,14 +131,14 @@
*/
public static String convertToLdif( Attributes attrs ) throws NamingException
{
- return convertToLdif( attrs, 80 );
+ return convertToLdif( attrs, DEFAULT_LINE_LENGTH );
}
/**
* Convert an Attributes as LDIF
* @param attrs the Attributes to convert
- * @param length the expectend line length
+ * @param length the expected line length
* @return the corresponding LDIF code as a String
* @throws NamingException If a naming exception is encountered.
*/
@@ -143,7 +146,7 @@
{
StringBuilder sb = new StringBuilder();
- NamingEnumeration ne = attrs.getAll();
+ NamingEnumeration<? extends Attribute> ne = attrs.getAll();
while ( ne.hasMore() )
{
@@ -166,7 +169,7 @@
*/
public static String convertToLdif( Entry entry ) throws NamingException
{
- return convertToLdif( entry, 80 );
+ return convertToLdif( entry, DEFAULT_LINE_LENGTH );
}
/**
@@ -197,11 +200,11 @@
sb.append( '\n' );
// Now, iterate through all the attributes
- NamingEnumeration ne = entry.getAttributes().getAll();;
+ NamingEnumeration<? extends Attribute> ne = entry.getAttributes().getAll();
while ( ne.hasMore() )
{
- Attribute attribute = (Attribute)ne.next();
+ Attribute attribute = ne.next();
sb.append( convertToLdif( (Attribute) attribute, length ) );
}
@@ -230,6 +233,7 @@
return new String( encoded );
}
+
/**
* Converts an Attribute as LDIF
@@ -237,7 +241,20 @@
* @return the corresponding LDIF code as a String
* @throws NamingException If a naming exception is encountered.
*/
- private static String convertToLdif( Attribute attr, int length ) throws NamingException
+ public static String convertToLdif( Attribute attr ) throws NamingException
+ {
+ return convertToLdif( attr, DEFAULT_LINE_LENGTH );
+ }
+
+
+ /**
+ * Converts an Attribute as LDIF
+ * @param attr the Attribute to convert
+ * @param length the expected line length
+ * @return the corresponding LDIF code as a String
+ * @throws NamingException If a naming exception is encountered.
+ */
+ public static String convertToLdif( Attribute attr, int length ) throws NamingException
{
StringBuilder sb = new StringBuilder();
@@ -250,8 +267,12 @@
Object value = attr.get( i );
- // Checking if the value is binary
- if ( value instanceof byte[] )
+ // First, deal with null value (which is valid)
+ if ( value == null )
+ {
+ lineBuffer.append( ':' );
+ }
+ else if ( value instanceof byte[] )
{
// It is binary, so we have to encode it using Base64 before adding it
char[] encoded = Base64.encode( ( byte[] ) value );
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/Referral.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/Referral.java?rev=584150&r1=584149&r2=584150&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/Referral.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/Referral.java Fri Oct 12 05:44:30 2007
@@ -93,7 +93,7 @@
*
* @return the alternative url objects.
*/
- Collection getLdapUrls();
+ Collection<String> getLdapUrls();
/**
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/ReferralImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/ReferralImpl.java?rev=584150&r1=584149&r2=584150&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/ReferralImpl.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/ReferralImpl.java Fri Oct 12 05:44:30 2007
@@ -52,7 +52,7 @@
*
* @return the alternative url objects.
*/
- public Collection getLdapUrls()
+ public Collection<String> getLdapUrls()
{
return Collections.unmodifiableCollection( urls );
}
@@ -102,7 +102,7 @@
if ( obj instanceof Referral )
{
- Collection refs = ( ( Referral ) obj ).getLdapUrls();
+ Collection<String> refs = ( ( Referral ) obj ).getLdapUrls();
// if their sizes do not match they are not equal
if ( refs.size() != urls.size() )
@@ -110,7 +110,8 @@
return false;
}
- Iterator list = urls.iterator();
+ Iterator<String> list = urls.iterator();
+
while ( list.hasNext() )
{
// if one of our urls is not contained in the obj return false
Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java?rev=584150&r1=584149&r2=584150&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java (original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java Fri Oct 12 05:44:30 2007
@@ -234,7 +234,7 @@
/**
- * Tests that unsave characters are encoded using UTF-8 charset.
+ * Tests that unsafe characters are encoded using UTF-8 charset.
*
* @throws NamingException
*/
@@ -244,6 +244,20 @@
String ldif = LdifUtils.convertToLdif( attributes );
assertEquals( "cn:: U2FhcmJyw7xja2Vu\n", ldif );
}
+
+
+ /**
+ * Tests that null values are correctly encoded
+ *
+ * @throws NamingException
+ */
+ public void testConvertToLdifAttrWithNullValues() throws NamingException
+ {
+ Attributes attributes = new BasicAttributes( "cn", null );
+ String ldif = LdifUtils.convertToLdif( attributes );
+ assertEquals( "cn:\n", ldif );
+ }
+
public void testConvertEntryToLdif() throws NamingException
{