directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r1051130 [7/7] - in /directory: apacheds/branches/alex_refactoring/core-api/src/main/java/org/apache/directory/server/core/ apacheds/branches/alex_refactoring/core-api/src/main/java/org/apache/directory/server/core/entry/ apacheds/branches/...
Date Mon, 20 Dec 2010 14:31:36 GMT
Modified: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/AVATest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/AVATest.java?rev=1051130&r1=1051129&r2=1051130&view=diff
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/AVATest.java
(original)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/AVATest.java
Mon Dec 20 14:31:29 2010
@@ -29,11 +29,12 @@ import java.io.ObjectOutputStream;
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
 import org.apache.directory.shared.ldap.exception.LdapException;
-import org.apache.directory.shared.ldap.util.StringTools;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+
+import org.apache.directory.shared.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -279,8 +280,8 @@ public class AVATest
     @Test
     public void testBinaryAtavSerialization() throws LdapException, IOException, ClassNotFoundException
     {
-        byte[] upValue = StringTools.getBytesUtf8( "  Test  " );
-        byte[] normValue = StringTools.getBytesUtf8( "Test" );
+        byte[] upValue = Strings.getBytesUtf8("  Test  ");
+        byte[] normValue = Strings.getBytesUtf8("Test");
 
         AVA atav = new AVA( "cn", "CN", upValue, normValue );
 
@@ -439,8 +440,8 @@ public class AVATest
     @Test
     public void testBinaryAtavStaticSerialization() throws LdapException, IOException, ClassNotFoundException
     {
-        byte[] upValue = StringTools.getBytesUtf8( "  Test  " );
-        byte[] normValue = StringTools.getBytesUtf8( "Test" );
+        byte[] upValue = Strings.getBytesUtf8("  Test  ");
+        byte[] normValue = Strings.getBytesUtf8("Test");
 
         AVA atav = new AVA( "cn", "CN", upValue, normValue );
 

Modified: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java?rev=1051130&r1=1051129&r2=1051130&view=diff
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java
(original)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java
Mon Dec 20 14:31:29 2010
@@ -49,7 +49,7 @@ import org.apache.directory.junit.tools.
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.schema.normalizers.DeepTrimToLowerNormalizer;
 import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
-import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -1579,9 +1579,9 @@ public class DNTest
     @Test
     public void testStringParser() throws Exception
     {
-        String dn = StringTools.utf8ToString( new byte[]
-            { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ',
'L', ( byte ) 0xc3,
-                ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
+        String dn = Strings.utf8ToString(new byte[]
+                {'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', '
', 'L', (byte) 0xc3,
+                        (byte) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y'});
 
         DN name = DnParser.getNameParser().parse( dn );
 
@@ -3322,7 +3322,7 @@ public class DNTest
         AVA atav3 = dn3.getRdn().getAVA();
         assertEquals( "cn", atav3.getUpType() );
         assertEquals( "ABC", atav3.getUpValue().getString() );
-        assertTrue( Arrays.equals( StringTools.getBytesUtf8( "ABC" ), atav3.getNormValue().getBytes()
) );
+        assertTrue( Arrays.equals( Strings.getBytesUtf8("ABC"), atav3.getNormValue().getBytes()
) );
 
         // antlr parser:
         DN dn4 = new DN( " cn = \\41\\42\\43 , ou=system " );

Modified: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/DnParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/DnParserTest.java?rev=1051130&r1=1051129&r2=1051130&view=diff
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/DnParserTest.java
(original)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/DnParserTest.java
Mon Dec 20 14:31:29 2010
@@ -24,7 +24,7 @@ import org.apache.directory.junit.tools.
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
-import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -285,16 +285,16 @@ public class DnParserTest
         byte[] bytes = DN.getBytes( dn );
 
         assertEquals( 30, bytes.length );
-        assertEquals( "cn=John,ou=People,ou=Marketing", StringTools.utf8ToString( bytes )
);
+        assertEquals( "cn=John,ou=People,ou=Marketing", Strings.utf8ToString(bytes) );
     }
 
 
     @Test
     public void testStringParser() throws LdapException
     {
-        String dn = StringTools.utf8ToString( new byte[]
-            { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ',
'L', ( byte ) 0xc3,
-                ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
+        String dn = Strings.utf8ToString(new byte[]
+                {'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', '
', 'L', (byte) 0xc3,
+                        (byte) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y'});
 
         DnParser dnParser = DnParser.getNameParser();
         DN name = ( DN ) dnParser.parse( dn );
@@ -307,8 +307,8 @@ public class DnParserTest
     @Test
     public void testStringParserShort() throws LdapException
     {
-        String dn = StringTools.utf8ToString( new byte[]
-            { 'C', '=', ' ', 'E', ( byte ) 0xc3, ( byte ) 0xa9, 'c' } );
+        String dn = Strings.utf8ToString(new byte[]
+                {'C', '=', ' ', 'E', (byte) 0xc3, (byte) 0xa9, 'c'});
 
         DnParser dnParser = DnParser.getNameParser();
         DN name = ( DN ) dnParser.parse( dn );

Modified: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/FastDnParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/FastDnParserTest.java?rev=1051130&r1=1051129&r2=1051130&view=diff
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/FastDnParserTest.java
(original)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/FastDnParserTest.java
Mon Dec 20 14:31:29 2010
@@ -23,7 +23,7 @@ package org.apache.directory.shared.ldap
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
 import org.apache.directory.shared.ldap.exception.LdapException;
-import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -412,16 +412,16 @@ public class FastDnParserTest
         byte[] bytes = DN.getBytes( dn );
 
         assertEquals( 30, bytes.length );
-        assertEquals( "cn=John,ou=People,ou=Marketing", StringTools.utf8ToString( bytes )
);
+        assertEquals( "cn=John,ou=People,ou=Marketing", Strings.utf8ToString(bytes) );
     }
 
 
     @Test
     public void testStringParser() throws LdapException
     {
-        String dn = StringTools.utf8ToString( new byte[]
-            { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ',
'L', ( byte ) 0xc3,
-                ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
+        String dn = Strings.utf8ToString(new byte[]
+                {'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', '
', 'L', (byte) 0xc3,
+                        (byte) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y'});
 
         FastDnParser dnParser = FastDnParser.getNameParser();
         DN name = ( DN ) dnParser.parse( dn );
@@ -434,8 +434,8 @@ public class FastDnParserTest
     @Test
     public void testStringParserShort() throws LdapException
     {
-        String dn = StringTools.utf8ToString( new byte[]
-            { 'C', '=', ' ', 'E', ( byte ) 0xc3, ( byte ) 0xa9, 'c' } );
+        String dn = Strings.utf8ToString(new byte[]
+                {'C', '=', ' ', 'E', (byte) 0xc3, (byte) 0xa9, 'c'});
 
         FastDnParser dnParser = FastDnParser.getNameParser();
         DN name = ( DN ) dnParser.parse( dn );

Modified: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java?rev=1051130&r1=1051129&r2=1051130&view=diff
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
(original)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
Mon Dec 20 14:31:29 2010
@@ -36,7 +36,6 @@ import java.util.Iterator;
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
 import org.apache.directory.shared.ldap.exception.LdapException;
-import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.directory.shared.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -219,9 +218,9 @@ public class RdnTest
     @Test
     public void testRdnPairCharAttributeValue() throws LdapException
     {
-        String rdn = StringTools.utf8ToString( new byte[]
-            { 'a', '=', '\\', ',', '=', '\\', '+', '\\', '<', '\\', '>', '#', '\\',
';', '\\', '\\', '\\', '"', '\\',
-                'C', '3', '\\', 'A', '9' } );
+        String rdn = Strings.utf8ToString(new byte[]
+                {'a', '=', '\\', ',', '=', '\\', '+', '\\', '<', '\\', '>', '#', '\\',
';', '\\', '\\', '\\', '"', '\\',
+                        'C', '3', '\\', 'A', '9'});
         assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\u00E9", new RDN( rdn ).getNormName()
);
     }
 
@@ -786,7 +785,7 @@ public class RdnTest
     @Test
     public void testEscapeValueString()
     {
-        String res = RDN.escapeValue( StringTools.getBytesUtf8( "azerty" ) );
+        String res = RDN.escapeValue( Strings.getBytesUtf8("azerty") );
 
         assertEquals( "azerty", res );
     }
@@ -795,7 +794,7 @@ public class RdnTest
     @Test
     public void testEscapeValueStringSpecial()
     {
-        String res = RDN.escapeValue( StringTools.getBytesUtf8( "\\#,+;<>=\" " ) );
+        String res = RDN.escapeValue( Strings.getBytesUtf8("\\#,+;<>=\" ") );
 
         assertEquals( "\\\\#\\,\\+\\;\\<\\>\\=\\\"\\ ", res );
     }

Modified: directory/shared/branches/alex_refactoring/util/src/main/java/org/apache/directory/shared/util/Strings.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/util/src/main/java/org/apache/directory/shared/util/Strings.java?rev=1051130&r1=1051129&r2=1051130&view=diff
==============================================================================
--- directory/shared/branches/alex_refactoring/util/src/main/java/org/apache/directory/shared/util/Strings.java
(original)
+++ directory/shared/branches/alex_refactoring/util/src/main/java/org/apache/directory/shared/util/Strings.java
Mon Dec 20 14:31:29 2010
@@ -20,6 +20,8 @@
 package org.apache.directory.shared.util;
 
 
+import java.io.UnsupportedEncodingException;
+
 /**
  * Various string manipulation methods that are more efficient then chaining
  * string operations: all is done in the same buffer without creating a bunch of
@@ -106,4 +108,140 @@ public class Strings
     {
         return ( ( c > 127 ) || CharConstants.UNICODE_SUBSET[c] );
     }
+
+    /**
+     * <p>
+     * Checks if a String is empty ("") or null.
+     * </p>
+     *
+     * <pre>
+     *  StringUtils.isEmpty(null)      = true
+     *  StringUtils.isEmpty(&quot;&quot;)        = true
+     *  StringUtils.isEmpty(&quot; &quot;)       = false
+     *  StringUtils.isEmpty(&quot;bob&quot;)     = false
+     *  StringUtils.isEmpty(&quot;  bob  &quot;) = false
+     * </pre>
+     *
+     * <p>
+     * NOTE: This method changed in Lang version 2.0. It no longer trims the
+     * String. That functionality is available in isBlank().
+     * </p>
+     *
+     * @param str the String to check, may be null
+     * @return <code>true</code> if the String is empty or null
+     */
+    public static boolean isEmpty( String str )
+    {
+        return str == null || str.length() == 0;
+    }
+
+    /**
+     * Checks if a bytes array is empty or null.
+     *
+     * @param bytes The bytes array to check, may be null
+     * @return <code>true</code> if the bytes array is empty or null
+     */
+    public static boolean isEmpty( byte[] bytes )
+    {
+        return bytes == null || bytes.length == 0;
+    }
+
+    /**
+     * Return an UTF-8 encoded String
+     *
+     * @param bytes The byte array to be transformed to a String
+     * @return A String.
+     */
+    public static String utf8ToString( byte[] bytes )
+    {
+        if ( bytes == null )
+        {
+            return "";
+        }
+
+        try
+        {
+            return new String( bytes, "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException uee )
+        {
+            // if this happens something is really strange
+            throw new RuntimeException( uee );
+        }
+    }
+
+    /**
+     * Return an UTF-8 encoded String
+     *
+     * @param bytes The byte array to be transformed to a String
+     * @param length The length of the byte array to be converted
+     * @return A String.
+     */
+    public static String utf8ToString( byte[] bytes, int length )
+    {
+        if ( bytes == null )
+        {
+            return "";
+        }
+
+        try
+        {
+            return new String( bytes, 0, length, "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException uee )
+        {
+            // if this happens something is really strange
+            throw new RuntimeException( uee );
+        }
+    }
+
+    /**
+     * Return an UTF-8 encoded String
+     *
+     * @param bytes  The byte array to be transformed to a String
+     * @param start the starting position in the byte array
+     * @param length The length of the byte array to be converted
+     * @return A String.
+     */
+    public static String utf8ToString( byte[] bytes, int start, int length )
+    {
+        if ( bytes == null )
+        {
+            return "";
+        }
+
+        try
+        {
+            return new String( bytes, start, length, "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException uee )
+        {
+            // if this happens something is really strange
+            throw new RuntimeException( uee );
+        }
+    }
+
+    /**
+     * Return UTF-8 encoded byte[] representation of a String
+     *
+     * @param string The string to be transformed to a byte array
+     * @return The transformed byte array
+     */
+    public static byte[] getBytesUtf8( String string )
+    {
+        if ( string == null )
+        {
+            return new byte[0];
+        }
+
+        try
+        {
+            return string.getBytes( "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException uee )
+        {
+            // if this happens something is really strange
+            throw new RuntimeException( uee );
+        }
+    }
 }



Mime
View raw message