directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1062075 - in /directory: apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/ apacheds/trunk/server-jndi/src/main/java/or...
Date Sat, 22 Jan 2011 00:13:18 GMT
Author: elecharny
Date: Sat Jan 22 00:13:17 2011
New Revision: 1062075

URL: http://svn.apache.org/viewvc?rev=1062075&view=rev
Log:
Migrated some methods from StringTools to Strings

Modified:
    directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java
    directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
    directory/apacheds/trunk/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java
    directory/apacheds/trunk/xdbm-tools/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java
    directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVA.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectIdentifierFirstComponentComparator.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/BitStringSyntaxChecker.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/DeliveryMethodSyntaxChecker.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/IntegerSyntaxChecker.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaByteSyntaxChecker.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaIntegerSyntaxChecker.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaLongSyntaxChecker.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaShortSyntaxChecker.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java
    directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java

Modified: directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java (original)
+++ directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java Sat Jan 22 00:13:17 2011
@@ -79,7 +79,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.name.RDN;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.JndiUtils;
-import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 
 
 /**
@@ -975,7 +975,7 @@ public abstract class ServerDirContext e
             }
             else if ( filterArgs[index] instanceof byte[] )
             {
-                String hexstr = "#" + StringTools.toHexString( ( byte[] ) filterArgs[index] );
+                String hexstr = "#" + Strings.toHexString( ( byte[] ) filterArgs[index] );
                 buf.replace( start, ii + 1, hexstr );
             }
             else

Modified: directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java (original)
+++ directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java Sat Jan 22 00:13:17 2011
@@ -53,7 +53,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.name.RDN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -685,8 +685,8 @@ public class LdifPartition extends Abstr
                 case '\\': // 0x5C
                 case ']': // 0x5D
                 case '|': // 0x7C
-                    sb.append( "%" ).append( StringTools.dumpHex( ( byte ) ( c >> 4 ) ) )
-                                    .append( StringTools.dumpHex( ( byte ) ( c & 0xF ) ) );
+                    sb.append( "%" ).append( Strings.dumpHex( ( byte ) ( c >> 4 ) ) )
+                                    .append( Strings.dumpHex( ( byte ) ( c & 0xF ) ) );
                     break;
 
                 default:

Modified: directory/apacheds/trunk/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/apacheds/trunk/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java (original)
+++ directory/apacheds/trunk/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java Sat Jan 22 00:13:17 2011
@@ -56,6 +56,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
 import org.apache.directory.shared.ldap.util.LdapExceptionUtils;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -296,7 +297,7 @@ public class ApacheDS
 
         return  new DN( fileSep + 
                 "=" + 
-                StringTools.dumpHexPairs( StringTools.getBytesUtf8( getCanonical( ldif ) ) ) + 
+                Strings.dumpHexPairs( StringTools.getBytesUtf8( getCanonical( ldif ) ) ) + 
                 "," + 
                 ServerDNConstants.LDIF_FILES_DN ); 
     }

Modified: directory/apacheds/trunk/xdbm-tools/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-tools/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-tools/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java (original)
+++ directory/apacheds/trunk/xdbm-tools/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/PartitionFrame.java Sat Jan 22 00:13:17 2011
@@ -75,7 +75,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
-import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -466,7 +466,7 @@ public class PartitionFrame extends JFra
             {
                 String updn = entry.getDn().getName();
 
-                DN ndn = new DN( StringTools.deepTrimToLower( updn ) );
+                DN ndn = new DN( Strings.deepTrimToLower( updn ) );
 
                 Entry attrs = new DefaultEntry( schemaManager, entry.getEntry() );
 

Modified: directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g (original)
+++ directory/shared/trunk/ldap/src/main/antlr/distinguishedName.g Sat Jan 22 00:13:17 2011
@@ -32,6 +32,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.BinaryValue;
 import org.apache.directory.shared.ldap.schema.parsers.ParserMonitor;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 
 }
 
@@ -478,7 +479,7 @@ hexstring [UpAndNormValue value]
     {
         // convert to byte[]
         value.rawValue = "#" + hexValue.getText();
-        value.value = StringTools.toByteArray( hexValue.getText() ); 
+        value.value = Strings.toByteArray( hexValue.getText() ); 
     }
     ;
 
@@ -687,7 +688,7 @@ pair [UpAndNormValue value] returns [byt
         hexpair:HEXPAIR 
         { 
             value.rawValue += "\\" + hexpair.getText();
-            pair = StringTools.toByteArray( hexpair.getText() ); 
+            pair = Strings.toByteArray( hexpair.getText() ); 
         } 
     )
     ;

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java Sat Jan 22 00:13:17 2011
@@ -31,6 +31,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.Position;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 
 
 /**
@@ -80,7 +81,7 @@ public class FilterParser
         if ( attribute != null )
         {
             // First check if we have a ":dn"
-            if ( StringTools.areEquals( filter, pos.start, "dn" ) )
+            if ( Strings.areEquals( filter, pos.start, "dn" ) )
             {
                 // Set the dnAttributes flag and move forward in the string
                 node.setDnAttributes( true );
@@ -113,7 +114,7 @@ public class FilterParser
 
                     node.setMatchingRuleId( filter.substring( start, pos.start ) );
 
-                    if ( StringTools.areEquals( filter, pos.start, ":=" ) )
+                    if ( Strings.areEquals( filter, pos.start, ":=" ) )
                     {
                         pos.start += 2;
 
@@ -138,7 +139,7 @@ public class FilterParser
             boolean oidRequested = false;
 
             // First check if we have a ":dn"
-            if ( StringTools.areEquals( filter, pos.start, ":dn" ) )
+            if ( Strings.areEquals( filter, pos.start, ":dn" ) )
             {
                 // Set the dnAttributes flag and move forward in the string
                 node.setDnAttributes( true );
@@ -175,7 +176,7 @@ public class FilterParser
 
                     node.setMatchingRuleId( filter.substring( start, pos.start ) );
 
-                    if ( StringTools.areEquals( filter, pos.start, ":=" ) )
+                    if ( Strings.areEquals( filter, pos.start, ":=" ) )
                     {
                         pos.start += 2;
 
@@ -246,7 +247,7 @@ public class FilterParser
                 value[current++] = (byte)c;
                 pos.start++;
             }
-            else if ( StringTools.isCharASCII( filter, pos.start, '\\' ) )
+            else if ( Strings.isCharASCII( filter, pos.start, '\\' ) )
             {
                 // Maybe an escaped 
                 pos.start++;
@@ -300,7 +301,7 @@ public class FilterParser
     private static ExprNode parseSubstring( SchemaManager schemaManager, String attribute, Value<?> initial, String filter, Position pos )
         throws ParseException, LdapException
     {
-        if ( StringTools.isCharASCII( filter, pos.start, '*' ) )
+        if ( Strings.isCharASCII( filter, pos.start, '*' ) )
         {
             // We have found a '*' : this is a substring
             SubstringNode node = null;
@@ -339,7 +340,7 @@ public class FilterParser
                 Value<?> assertionValue = parseAssertionValue( filter, pos );
 
                 // Is there anything else but a ')' after the value ?
-                if ( StringTools.isCharASCII( filter, pos.start, ')' ) )
+                if ( Strings.isCharASCII( filter, pos.start, ')' ) )
                 {
                     // Nope : as we have had [initial] '*' (any '*' ) *,
                     // this is the final
@@ -351,7 +352,7 @@ public class FilterParser
 
                     return node;
                 }
-                else if ( StringTools.isCharASCII( filter, pos.start, '*' ) )
+                else if ( Strings.isCharASCII( filter, pos.start, '*' ) )
                 {
                     // We have a '*' : it's an any
                     // If the value is empty, that means we have more than 
@@ -406,12 +407,12 @@ public class FilterParser
     private static ExprNode parsePresenceEqOrSubstring( SchemaManager schemaManager, String attribute, String filter, Position pos )
         throws ParseException, LdapException
     {
-        if ( StringTools.isCharASCII( filter, pos.start, '*' ) )
+        if ( Strings.isCharASCII( filter, pos.start, '*' ) )
         {
             // To be a present node, the next char should be a ')'
             pos.start++;
 
-            if ( StringTools.isCharASCII( filter, pos.start, ')' ) )
+            if ( Strings.isCharASCII( filter, pos.start, ')' ) )
             {
                 // This is a present node
                 if ( schemaManager != null )
@@ -440,7 +441,7 @@ public class FilterParser
                 return parseSubstring( schemaManager, attribute, null, filter, pos );
             }
         }
-        else if ( StringTools.isCharASCII( filter, pos.start, ')' ) )
+        else if ( Strings.isCharASCII( filter, pos.start, ')' ) )
         {
             // An empty equality Node
             if ( schemaManager != null )
@@ -468,7 +469,7 @@ public class FilterParser
             Value<?> value = parseAssertionValue( filter, pos );
 
             // Is there anything else but a ')' after the value ?
-            if ( StringTools.isCharASCII( filter, pos.start, ')' ) )
+            if ( Strings.isCharASCII( filter, pos.start, ')' ) )
             {
                 // This is an equality node
                 if ( schemaManager != null )
@@ -543,7 +544,7 @@ public class FilterParser
                     pos.start++;
 
                     // Check that we have a '='
-                    if ( !StringTools.isCharASCII( filter, pos.start, '=' ) )
+                    if ( !Strings.isCharASCII( filter, pos.start, '=' ) )
                     {
                         throw new ParseException( I18n.err( I18n.ERR_04152 ), pos.start );
                     }
@@ -574,7 +575,7 @@ public class FilterParser
                     pos.start++;
 
                     // Check that we have a '='
-                    if ( !StringTools.isCharASCII( filter, pos.start, '=' ) )
+                    if ( !Strings.isCharASCII( filter, pos.start, '=' ) )
                     {
                         throw new ParseException( I18n.err( I18n.ERR_04152 ), pos.start );
                     }
@@ -605,7 +606,7 @@ public class FilterParser
                     pos.start++;
 
                     // Check that we have a '='
-                    if ( !StringTools.isCharASCII( filter, pos.start, '=' ) )
+                    if ( !Strings.isCharASCII( filter, pos.start, '=' ) )
                     {
                         throw new ParseException( I18n.err( I18n.ERR_04152 ), pos.start );
                     }
@@ -774,7 +775,7 @@ public class FilterParser
         throws ParseException, LdapException
     {
         // Check for the left '('
-        if ( !StringTools.isCharASCII( filter, pos.start, '(' ) )
+        if ( !Strings.isCharASCII( filter, pos.start, '(' ) )
         {
             // No more node, get out
             if ( ( pos.start == 0 ) && ( pos.length != 0 ) )
@@ -798,7 +799,7 @@ public class FilterParser
         }
 
         // Check that we have a right ')'
-        if ( !StringTools.isCharASCII( filter, pos.start, ')' ) )
+        if ( !Strings.isCharASCII( filter, pos.start, ')' ) )
         {
             throw new ParseException( I18n.err( I18n.ERR_04157 ), pos.start );
         }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVA.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVA.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVA.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVA.java Sat Jan 22 00:13:17 2011
@@ -34,6 +34,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.directory.shared.ldap.util.UTFUtils;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -624,7 +625,7 @@ public class AVA implements Cloneable, C
         else
         {
             return normType + "=#"
-                + StringTools.dumpHexPairs( normValue .getBytes() );
+                + Strings.dumpHexPairs( normValue .getBytes() );
         }
     }
 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java Sat Jan 22 00:13:17 2011
@@ -42,6 +42,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.directory.shared.ldap.util.UTFUtils;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -466,7 +467,7 @@ public class RDN implements Cloneable, C
                 }
                 else
                 {
-                    normName = atav.getNormType() + "=#" + StringTools.dumpHexPairs( atav.getNormValue().getBytes() );
+                    normName = atav.getNormType() + "=#" + Strings.dumpHexPairs( atav.getNormValue().getBytes() );
                 }
 
                 break;
@@ -1396,7 +1397,7 @@ public class RDN implements Cloneable, C
                 case 0x0F:
                     newChars[pos++] = '\\';
                     newChars[pos++] = '0';
-                    newChars[pos++] = StringTools.dumpHex( ( byte ) ( chars[i] & 0x0F ) );
+                    newChars[pos++] = Strings.dumpHex( ( byte ) ( chars[i] & 0x0F ) );
                     break;
 
                 case 0x10:
@@ -1417,7 +1418,7 @@ public class RDN implements Cloneable, C
                 case 0x1F:
                     newChars[pos++] = '\\';
                     newChars[pos++] = '1';
-                    newChars[pos++] = StringTools.dumpHex( ( byte ) ( chars[i] & 0x0F ) );
+                    newChars[pos++] = Strings.dumpHex( ( byte ) ( chars[i] & 0x0F ) );
                     break;
 
                 default:

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectIdentifierFirstComponentComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectIdentifierFirstComponentComparator.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectIdentifierFirstComponentComparator.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectIdentifierFirstComponentComparator.java Sat Jan 22 00:13:17 2011
@@ -23,6 +23,7 @@ package org.apache.directory.shared.ldap
 import org.apache.directory.shared.asn1.util.OID;
 import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -58,19 +59,19 @@ public class ObjectIdentifierFirstCompon
         // Get the OID from the strings now
         int pos = 0;
         
-        if ( !StringTools.isCharASCII( s, pos++, '(' ) )
+        if ( !Strings.isCharASCII( s, pos++, '(' ) )
         {
             return null;
         }
         
-        while ( StringTools.isCharASCII( s, pos, ' ' ) )
+        while ( Strings.isCharASCII( s, pos, ' ' ) )
         {
             pos++;
         }
         
         int start = pos;
         
-        while ( StringTools.isDigit( s, pos ) || StringTools.isCharASCII( s, pos, '.' ) )
+        while ( StringTools.isDigit( s, pos ) || Strings.isCharASCII( s, pos, '.' ) )
         {
             pos++;
         }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/BitStringSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/BitStringSyntaxChecker.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/BitStringSyntaxChecker.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/BitStringSyntaxChecker.java Sat Jan 22 00:13:17 2011
@@ -23,6 +23,7 @@ package org.apache.directory.shared.ldap
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -78,7 +79,7 @@ public class BitStringSyntaxChecker exte
         int pos = 0;
         
         // Check that the String respect the syntax : ' ([01]+) ' B
-        if ( ! StringTools.isCharASCII( strValue, pos++, '\'' ) )
+        if ( ! Strings.isCharASCII( strValue, pos++, '\'' ) )
         {
             LOG.debug( "Syntax invalid for '{}'", strValue );
             return false;
@@ -98,14 +99,14 @@ public class BitStringSyntaxChecker exte
         }
 
         // Now, we must have a simple quote 
-        if ( ! StringTools.isCharASCII( strValue, pos++, '\'' ) )
+        if ( ! Strings.isCharASCII( strValue, pos++, '\'' ) )
         {
             LOG.debug( "Syntax invalid for '{}'", strValue );
             return false;
         }
 
         // followed by a 'B'
-        if ( ! StringTools.isCharASCII( strValue, pos, 'B' ) )
+        if ( ! Strings.isCharASCII( strValue, pos, 'B' ) )
         {
             LOG.debug( "Syntax invalid for '{}'", strValue );
             return false;

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/DeliveryMethodSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/DeliveryMethodSyntaxChecker.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/DeliveryMethodSyntaxChecker.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/DeliveryMethodSyntaxChecker.java Sat Jan 22 00:13:17 2011
@@ -26,6 +26,7 @@ import java.util.Set;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -183,12 +184,12 @@ public class DeliveryMethodSyntaxChecker
         while ( pos < length )
         {
             // Skip spaces
-            while ( StringTools.isCharASCII( strValue, pos, ' ' ) )
+            while ( Strings.isCharASCII( strValue, pos, ' ' ) )
             {
                 pos++;
             }
             
-            if ( ! StringTools.isCharASCII( strValue, pos, '$' ) )
+            if ( ! Strings.isCharASCII( strValue, pos, '$' ) )
             {
                 // A '$' was expected
                 LOG.debug( "Syntax invalid for '{}'", value );
@@ -200,7 +201,7 @@ public class DeliveryMethodSyntaxChecker
             }
             
             // Skip spaces
-            while ( StringTools.isCharASCII( strValue, pos, ' ' ) )
+            while ( Strings.isCharASCII( strValue, pos, ' ' ) )
             {
                 pos++;
             }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/IntegerSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/IntegerSyntaxChecker.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/IntegerSyntaxChecker.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/IntegerSyntaxChecker.java Sat Jan 22 00:13:17 2011
@@ -23,6 +23,7 @@ package org.apache.directory.shared.ldap
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -126,7 +127,7 @@ public class IntegerSyntaxChecker extend
             LOG.debug( "Syntax invalid for '{}'", value );
             return false;
         }
-        else if ( StringTools.isCharASCII( strValue, pos, '0' ) )
+        else if ( Strings.isCharASCII( strValue, pos, '0' ) )
         {
             LOG.debug( "Syntax invalid for '{}'", value );
             return false;

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaByteSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaByteSyntaxChecker.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaByteSyntaxChecker.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaByteSyntaxChecker.java Sat Jan 22 00:13:17 2011
@@ -22,6 +22,7 @@ package org.apache.directory.shared.ldap
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -126,7 +127,7 @@ public class JavaByteSyntaxChecker exten
             LOG.debug( "Syntax invalid for '{}'", value );
             return false;
         }
-        else if ( StringTools.isCharASCII( strValue, pos, '0' ) )
+        else if ( Strings.isCharASCII( strValue, pos, '0' ) )
         {
             LOG.debug( "Syntax invalid for '{}'", value );
             return false;

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaIntegerSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaIntegerSyntaxChecker.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaIntegerSyntaxChecker.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaIntegerSyntaxChecker.java Sat Jan 22 00:13:17 2011
@@ -22,6 +22,7 @@ package org.apache.directory.shared.ldap
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -129,7 +130,7 @@ public class JavaIntegerSyntaxChecker ex
             LOG.debug( "Syntax invalid for '{}'", value );
             return false;
         }
-        else if ( StringTools.isCharASCII( strValue, pos, '0' ) )
+        else if ( Strings.isCharASCII( strValue, pos, '0' ) )
         {
             LOG.debug( "Syntax invalid for '{}'", value );
             return false;

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaLongSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaLongSyntaxChecker.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaLongSyntaxChecker.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaLongSyntaxChecker.java Sat Jan 22 00:13:17 2011
@@ -22,6 +22,7 @@ package org.apache.directory.shared.ldap
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -126,7 +127,7 @@ public class JavaLongSyntaxChecker exten
             LOG.debug( "Syntax invalid for '{}'", value );
             return false;
         }
-        else if ( StringTools.isCharASCII( strValue, pos, '0' ) )
+        else if ( Strings.isCharASCII( strValue, pos, '0' ) )
         {
             LOG.debug( "Syntax invalid for '{}'", value );
             return false;

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaShortSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaShortSyntaxChecker.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaShortSyntaxChecker.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/JavaShortSyntaxChecker.java Sat Jan 22 00:13:17 2011
@@ -22,6 +22,7 @@ package org.apache.directory.shared.ldap
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -126,7 +127,7 @@ public class JavaShortSyntaxChecker exte
             LOG.debug( "Syntax invalid for '{}'", value );
             return false;
         }
-        else if ( StringTools.isCharASCII( strValue, pos, '0' ) )
+        else if ( Strings.isCharASCII( strValue, pos, '0' ) )
         {
             LOG.debug( "Syntax invalid for '{}'", value );
             return false;

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java Sat Jan 22 00:13:17 2011
@@ -778,7 +778,7 @@ public final class AttributeUtils
      */
     private static void parseOptions( String str, Position pos ) throws ParseException
     {
-        while ( StringTools.isCharASCII( str, pos.start, ';' ) )
+        while ( Strings.isCharASCII( str, pos.start, ';' ) )
         {
             pos.start++;
 
@@ -861,7 +861,7 @@ public final class AttributeUtils
         parseNumber( str, pos );
 
         // We must have at least one '.' number
-        if ( !StringTools.isCharASCII( str, pos.start, '.' ) )
+        if ( !Strings.isCharASCII( str, pos.start, '.' ) )
         {
             throw new ParseException( I18n.err( I18n.ERR_04344 ), pos.start );
         }
@@ -876,7 +876,7 @@ public final class AttributeUtils
         while ( true )
         {
             // Break if we get something which is not a '.'
-            if ( !StringTools.isCharASCII( str, pos.start, '.' ) )
+            if ( !Strings.isCharASCII( str, pos.start, '.' ) )
             {
                 break;
             }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Sat Jan 22 00:13:17 2011
@@ -69,7 +69,7 @@ public final class StringTools
     // -----------------------------------------------------------------
 
     /** Hex chars */
-    private static final byte[] HEX_CHAR = new byte[]
+    public static final byte[] HEX_CHAR = new byte[]
         { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
 
     private static final int UTF8_MULTI_BYTES_MASK = 0x0080;
@@ -398,211 +398,6 @@ public final class StringTools
         {};
 
     /**
-     * Trims several consecutive characters into one.
-     * 
-     * @param str
-     *            the string to trim consecutive characters of
-     * @param ch
-     *            the character to trim down
-     * @return the newly trimmed down string
-     */
-    public static String trimConsecutiveToOne( String str, char ch )
-    {
-        if ( ( null == str ) || ( str.length() == 0 ) )
-        {
-            return "";
-        }
-
-        char[] buffer = str.toCharArray();
-        char[] newbuf = new char[buffer.length];
-        int pos = 0;
-        boolean same = false;
-
-        for ( int i = 0; i < buffer.length; i++ )
-        {
-            char car = buffer[i];
-
-            if ( car == ch )
-            {
-                if ( same )
-                {
-                    continue;
-                }
-                else
-                {
-                    same = true;
-                    newbuf[pos++] = car;
-                }
-            }
-            else
-            {
-                same = false;
-                newbuf[pos++] = car;
-            }
-        }
-
-        return new String( newbuf, 0, pos );
-    }
-
-
-    /**
-     * A deep trim of a string remove whitespace from the ends as well as
-     * excessive whitespace within the inside of the string between
-     * non-whitespace characters. A deep trim reduces internal whitespace down
-     * to a single space to perserve the whitespace separated tokenization order
-     * of the String.
-     * 
-     * @param string the string to deep trim.
-     * @return the trimmed string.
-     */
-    public static String deepTrim( String string )
-    {
-        return deepTrim( string, false );
-    }
-
-
-    /**
-     * This does the same thing as a trim but we also lowercase the string while
-     * performing the deep trim within the same buffer. This saves us from
-     * having to create multiple String and StringBuffer objects and is much
-     * more efficient.
-     * 
-     * @see StringTools#deepTrim( String )
-     */
-    public static String deepTrimToLower( String string )
-    {
-        return deepTrim( string, true );
-    }
-
-
-    /**
-     * Put common code to deepTrim(String) and deepTrimToLower here.
-     * 
-     * @param str the string to deep trim
-     * @param toLowerCase how to normalize for case: upper or lower
-     * @return the deep trimmed string
-     * @see StringTools#deepTrim( String )
-     * 
-     * TODO Replace the toCharArray() by substring manipulations
-     */
-    public static String deepTrim( String str, boolean toLowerCase )
-    {
-        if ( ( null == str ) || ( str.length() == 0 ) )
-        {
-            return "";
-        }
-
-        char ch;
-        char[] buf = str.toCharArray();
-        char[] newbuf = new char[buf.length];
-        boolean wsSeen = false;
-        boolean isStart = true;
-        int pos = 0;
-
-        for ( int i = 0; i < str.length(); i++ )
-        {
-            ch = buf[i];
-
-            // filter out all uppercase characters
-            if ( toLowerCase && Character.isUpperCase( ch ) )
-            {
-                ch = Character.toLowerCase( ch );
-            }
-
-            // Check to see if we should add space
-            if ( Character.isWhitespace( ch ) )
-            {
-                // If the buffer has had characters added already check last
-                // added character. Only append a spc if last character was
-                // not whitespace.
-                if ( wsSeen )
-                {
-                    continue;
-                }
-                else
-                {
-                    wsSeen = true;
-
-                    if ( isStart )
-                    {
-                        isStart = false;
-                    }
-                    else
-                    {
-                        newbuf[pos++] = ch;
-                    }
-                }
-            }
-            else
-            {
-                // Add all non-whitespace
-                wsSeen = false;
-                isStart = false;
-                newbuf[pos++] = ch;
-            }
-        }
-
-        return ( pos == 0 ? "" : new String( newbuf, 0, ( wsSeen ? pos - 1 : pos ) ) );
-    }
-
-    /**
-     * Truncates large Strings showing a portion of the String's head and tail
-     * with the center cut out and replaced with '...'. Also displays the total
-     * length of the truncated string so size of '...' can be interpreted.
-     * Useful for large strings in UIs or hex dumps to log files.
-     * 
-     * @param str the string to truncate
-     * @param head the amount of the head to display
-     * @param tail the amount of the tail to display
-     * @return the center truncated string
-     */
-    public static String centerTrunc( String str, int head, int tail )
-    {
-        StringBuffer buf = null;
-
-        // Return as-is if String is smaller than or equal to the head plus the
-        // tail plus the number of characters added to the trunc representation
-        // plus the number of digits in the string length.
-        if ( str.length() <= ( head + tail + 7 + str.length() / 10 ) )
-        {
-            return str;
-        }
-
-        buf = new StringBuffer();
-        buf.append( '[' ).append( str.length() ).append( "][" );
-        buf.append( str.substring( 0, head ) ).append( "..." );
-        buf.append( str.substring( str.length() - tail ) );
-        buf.append( ']' );
-        return buf.toString();
-    }
-
-
-    /**
-     * Gets a hex string from byte array.
-     * 
-     * @param res
-     *            the byte array
-     * @return the hex string representing the binary values in the array
-     */
-    public static String toHexString( byte[] res )
-    {
-        StringBuffer buf = new StringBuffer( res.length << 1 );
-        
-        for ( int ii = 0; ii < res.length; ii++ )
-        {
-            String digit = Integer.toHexString( 0xFF & res[ii] );
-            
-            if ( digit.length() == 1 )
-            {
-                digit = '0' + digit;
-            }
-            
-            buf.append( digit );
-        }
-        return buf.toString().toUpperCase();
-    }
-
-    /**
      * Rewrote the toLowercase method to improve performances.
      * In Ldap, attributesType are supposed to use ASCII chars :
      * 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only.
@@ -653,120 +448,6 @@ public final class StringTools
     }
     
     /**
-     * Get byte array from hex string
-     * 
-     * @param hexString
-     *            the hex string to convert to a byte array
-     * @return the byte form of the hex string.
-     */
-    public static byte[] toByteArray( String hexString )
-    {
-        int arrLength = hexString.length() >> 1;
-        byte [] buf = new byte[arrLength];
-        
-        for ( int ii = 0; ii < arrLength; ii++ )
-        {
-            int index = ii << 1;
-            
-            String digit = hexString.substring( index, index + 2 );
-            buf[ii] = ( byte ) Integer.parseInt( digit, 16 );
-        }
-        
-        return buf;
-    }
-
-
-    /**
-     * This method is used to insert HTML block dynamically
-     * 
-     * @param source the HTML code to be processes
-     * @param replaceNl if true '\n' will be replaced by &lt;br>
-     * @param replaceTag if true '<' will be replaced by &lt; and '>' will be replaced
-     *            by &gt;
-     * @param replaceQuote if true '\"' will be replaced by &quot;
-     * @return the formated html block
-     */
-    public static String formatHtml( String source, boolean replaceNl, boolean replaceTag,
-        boolean replaceQuote )
-    {
-        StringBuffer buf = new StringBuffer();
-        int len = source.length();
-
-        for ( int ii = 0; ii < len; ii++ )
-        {
-            char ch = source.charAt( ii );
-            
-            switch ( ch )
-            {
-                case '\"':
-                    if ( replaceQuote )
-                    {
-                        buf.append( "&quot;" );
-                    }
-                    else
-                    {
-                        buf.append( ch );
-                    }
-                    break;
-
-                case '<':
-                    if ( replaceTag )
-                    {
-                        buf.append( "&lt;" );
-                    }
-                    else
-                    {
-                        buf.append( ch );
-                    }
-                    break;
-
-                case '>':
-                    if ( replaceTag )
-                    {
-                        buf.append( "&gt;" );
-                    }
-                    else
-                    {
-                        buf.append( ch );
-                    }
-                    break;
-
-                case '\n':
-                    if ( replaceNl )
-                    {
-                        if ( replaceTag )
-                        {
-                            buf.append( "&lt;br&gt;" );
-                        }
-                        else
-                        {
-                            buf.append( "<br>" );
-                        }
-                    }
-                    else
-                    {
-                        buf.append( ch );
-                    }
-                    break;
-
-                case '\r':
-                    break;
-
-                case '&':
-                    buf.append( "&amp;" );
-                    break;
-
-                default:
-                    buf.append( ch );
-                    break;
-            }
-        }
-
-        return buf.toString();
-    }
-
-
-    /**
      * Creates a regular expression from an LDAP substring assertion filter
      * specification.
      * 
@@ -965,31 +646,6 @@ public final class StringTools
     // ------------------------------------------------------------------------------------
 
     /**
-     * Helper function that dump a byte in hex form
-     * 
-     * @param octet The byte to dump
-     * @return A string representation of the byte
-     */
-    public static String dumpByte( byte octet )
-    {
-        return new String( new byte[]
-            { '0', 'x', HEX_CHAR[( octet & 0x00F0 ) >> 4], HEX_CHAR[octet & 0x000F] } );
-    }
-
-
-    /**
-     * Helper function that returns a char from an hex
-     * 
-     * @param hex The hex to dump
-     * @return A char representation of the hex
-     */
-    public static char dumpHex( byte hex )
-    {
-        return ( char ) HEX_CHAR[hex & 0x000F];
-    }
-
-
-    /**
      * 
      * Helper method to render an object which can be a String or a byte[]
      *
@@ -1027,31 +683,6 @@ public final class StringTools
     }
 
     /**
-     * Helper function that dump an array of bytes in hex pair form, 
-     * without '0x' and space chars
-     * 
-     * @param buffer The bytes array to dump
-     * @return A string representation of the array of bytes
-     */
-    public static String dumpHexPairs( byte[] buffer )
-    {
-        if ( buffer == null )
-        {
-            return "";
-        }
-
-        char[] str = new char[buffer.length << 1];
-
-        for ( int i = 0, pos = 0; i < buffer.length; i++ )
-        {
-            str[pos++] = ( char ) ( HEX_CHAR[( buffer[i] & 0x00F0 ) >> 4] );
-            str[pos++] = ( char ) ( HEX_CHAR[buffer[i] & 0x000F] );
-        }
-
-        return new String( str );
-    }
-
-    /**
      * Return the Unicode char which is coded in the bytes at position 0.
      * 
      * @param bytes The byte[] represntation of an Unicode string.
@@ -1485,36 +1116,6 @@ public final class StringTools
     }
 
     /**
-     * Check if a text is present at the current position in another string.
-     * 
-     * @param string The string which contains the data
-     * @param index Current position in the string
-     * @param text The text we want to check
-     * @return <code>true</code> if the string contains the text.
-     */
-    public static boolean areEquals( String string, int index, String text )
-    {
-        if ( ( string == null ) || ( text == null ) ) 
-        {
-            return false;
-        }
-        
-        int length1 = string.length();
-        int length2 = text.length();
-
-        if ( ( length1 == 0 ) || ( length1 <= index ) || ( index < 0 )
-            || ( length2 == 0 ) || ( length2 > ( length1 + index ) ) )
-        {
-            return false;
-        }
-        else
-        {
-            return string.substring( index ).startsWith( text );
-        }
-    }
-    
-
-    /**
      * Check if a text is present at the current position in a buffer.
      * 
      * @param bytes The buffer which contains the data
@@ -1546,46 +1147,14 @@ public final class StringTools
     }
 
 
-    /**
-     * Test if the current character is equal to a specific character. This
-     * function works only for character between 0 and 127, as it does compare a
-     * byte and a char (which is 16 bits wide)
-     * 
-     * @param byteArray
-     *            The buffer which contains the data
-     * @param index
-     *            Current position in the buffer
-     * @param car
-     *            The character we want to compare with the current buffer
-     *            position
-     * @return <code>true</code> if the current character equals the given
-     *         character.
-     */
-    public static boolean isCharASCII( byte[] byteArray, int index, char car )
-    {
-        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) || ( index >= byteArray.length ) )
-        {
-            return false;
-        }
-        else
-        {
-            return ( ( byteArray[index] == car ) ? true : false );
-        }
-    }
-
-
-    /**
+    /* *
      * Test if the current character is equal to a specific character.
      * 
-     * @param chars
-     *            The buffer which contains the data
+     * @param chars The buffer which contains the data
      * @param index
      *            Current position in the buffer
-     * @param car
-     *            The character we want to compare with the current buffer
-     *            position
-     * @return <code>true</code> if the current character equals the given
-     *         character.
+     * @param car The character we want to compare with the current buffer position
+     * @return <code>true</code> if the current character equals the given character.
      */
     public static boolean isCharASCII( char[] chars, int index, char car )
     {

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java Sat Jan 22 00:13:17 2011
@@ -70,27 +70,27 @@ public class StringToolsTest
         String result = null;
 
         input = "akarasulu**";
-        result = StringTools.trimConsecutiveToOne( input, '*' );
+        result = Strings.trimConsecutiveToOne( input, '*' );
         assertEquals( "akarasulu*", result );
 
         input = "*****akarasulu**";
-        result = StringTools.trimConsecutiveToOne( input, '*' );
+        result = Strings.trimConsecutiveToOne( input, '*' );
         assertEquals( "*akarasulu*", result );
 
         input = "**akarasulu";
-        result = StringTools.trimConsecutiveToOne( input, '*' );
+        result = Strings.trimConsecutiveToOne( input, '*' );
         assertEquals( "*akarasulu", result );
 
         input = "**akar****asulu**";
-        result = StringTools.trimConsecutiveToOne( input, '*' );
+        result = Strings.trimConsecutiveToOne( input, '*' );
         assertEquals( "*akar*asulu*", result );
 
         input = "akarasulu";
-        result = StringTools.trimConsecutiveToOne( input, '*' );
+        result = Strings.trimConsecutiveToOne( input, '*' );
         assertEquals( "akarasulu", result );
 
         input = "*a*k*a*r*a*s*u*l*u*";
-        result = StringTools.trimConsecutiveToOne( input, '*' );
+        result = Strings.trimConsecutiveToOne( input, '*' );
         assertEquals( "*a*k*a*r*a*s*u*l*u*", result );
 
     }
@@ -333,19 +333,19 @@ public class StringToolsTest
     @Test
     public void testDeepTrim()
     {
-        assertEquals( "", StringTools.deepTrim( " ", false ) );
-        assertEquals( "ab", StringTools.deepTrim( " ab ", false ) );
-        assertEquals( "a b", StringTools.deepTrim( " a b ", false ) );
-        assertEquals( "a b", StringTools.deepTrim( " a  b ", false ) );
-        assertEquals( "a b", StringTools.deepTrim( "  a  b  ", false ) );
-        assertEquals( "ab", StringTools.deepTrim( "ab ", false ) );
-        assertEquals( "ab", StringTools.deepTrim( " ab", false ) );
-        assertEquals( "ab", StringTools.deepTrim( "ab  ", false ) );
-        assertEquals( "ab", StringTools.deepTrim( "  ab", false ) );
-        assertEquals( "a b", StringTools.deepTrim( "a b", false ) );
-        assertEquals( "a b", StringTools.deepTrim( "a  b", false ) );
-        assertEquals( "a b", StringTools.deepTrim( " a b", false ) );
-        assertEquals( "a b", StringTools.deepTrim( "a b ", false ) );
+        assertEquals( "", Strings.deepTrim( " ", false ) );
+        assertEquals( "ab", Strings.deepTrim( " ab ", false ) );
+        assertEquals( "a b", Strings.deepTrim( " a b ", false ) );
+        assertEquals( "a b", Strings.deepTrim( " a  b ", false ) );
+        assertEquals( "a b", Strings.deepTrim( "  a  b  ", false ) );
+        assertEquals( "ab", Strings.deepTrim( "ab ", false ) );
+        assertEquals( "ab", Strings.deepTrim( " ab", false ) );
+        assertEquals( "ab", Strings.deepTrim( "ab  ", false ) );
+        assertEquals( "ab", Strings.deepTrim( "  ab", false ) );
+        assertEquals( "a b", Strings.deepTrim( "a b", false ) );
+        assertEquals( "a b", Strings.deepTrim( "a  b", false ) );
+        assertEquals( "a b", Strings.deepTrim( " a b", false ) );
+        assertEquals( "a b", Strings.deepTrim( "a b ", false ) );
     }
 
     @Test

Modified: directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java?rev=1062075&r1=1062074&r2=1062075&view=diff
==============================================================================
--- directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java (original)
+++ directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java Sat Jan 22 00:13:17 2011
@@ -20,7 +20,6 @@
 package org.apache.directory.shared.util;
 
 
-
 /**
  * Various string manipulation methods that are more efficient then chaining
  * string operations: all is done in the same buffer without creating a bunch of
@@ -30,26 +29,22 @@ package org.apache.directory.shared.util
  */
 public final class Strings
 {
-    /**
-     * Private constructor
-     */
-    private Strings()
-    {
-    }
-
     /** The default charset, because it's not provided by JDK 1.5 */
     static String defaultCharset = null;
     
 
-    
-    // ~ Static fields/initializers
-    // -----------------------------------------------------------------
-
     /** Hex chars */
     private static final byte[] HEX_CHAR = new byte[]
         { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
 
     /**
+     * Private constructor
+     */
+    private Strings()
+    {
+    }
+
+    /**
      * Helper function that dump an array of bytes in hex form
      *
      * @param buffer The bytes array to dump
@@ -72,4 +67,452 @@ public final class Strings
 
         return sb.toString();
     }
+    
+
+    /**
+     * Helper function that dump a byte in hex form
+     * 
+     * @param octet The byte to dump
+     * @return A string representation of the byte
+     */
+    public static String dumpByte( byte octet )
+    {
+        return new String( new byte[]
+            { '0', 'x', HEX_CHAR[( octet & 0x00F0 ) >> 4], HEX_CHAR[octet & 0x000F] } );
+    }
+
+
+    /**
+     * Helper function that returns a char from an hex
+     * 
+     * @param hex The hex to dump
+     * @return A char representation of the hex
+     */
+    public static char dumpHex( byte hex )
+    {
+        return ( char ) HEX_CHAR[hex & 0x000F];
+    }
+
+
+    /**
+     * Helper function that dump an array of bytes in hex pair form, 
+     * without '0x' and space chars
+     * 
+     * @param buffer The bytes array to dump
+     * @return A string representation of the array of bytes
+     */
+    public static String dumpHexPairs( byte[] buffer )
+    {
+        if ( buffer == null )
+        {
+            return "";
+        }
+    
+        char[] str = new char[buffer.length << 1];
+    
+        for ( int i = 0, pos = 0; i < buffer.length; i++ )
+        {
+            str[pos++] = ( char ) ( HEX_CHAR[( buffer[i] & 0x00F0 ) >> 4] );
+            str[pos++] = ( char ) ( HEX_CHAR[buffer[i] & 0x000F] );
+        }
+    
+        return new String( str );
+    }
+
+
+    /**
+     * Put common code to deepTrim(String) and deepTrimToLower here.
+     * 
+     * @param str the string to deep trim
+     * @param toLowerCase how to normalize for case: upper or lower
+     * @return the deep trimmed string
+     * @see StringTools#deepTrim( String )
+     * 
+     * TODO Replace the toCharArray() by substring manipulations
+     */
+    public static String deepTrim( String str, boolean toLowerCase )
+    {
+        if ( ( null == str ) || ( str.length() == 0 ) )
+        {
+            return "";
+        }
+    
+        char ch;
+        char[] buf = str.toCharArray();
+        char[] newbuf = new char[buf.length];
+        boolean wsSeen = false;
+        boolean isStart = true;
+        int pos = 0;
+    
+        for ( int i = 0; i < str.length(); i++ )
+        {
+            ch = buf[i];
+    
+            // filter out all uppercase characters
+            if ( toLowerCase && Character.isUpperCase( ch ) )
+            {
+                ch = Character.toLowerCase( ch );
+            }
+    
+            // Check to see if we should add space
+            if ( Character.isWhitespace( ch ) )
+            {
+                // If the buffer has had characters added already check last
+                // added character. Only append a spc if last character was
+                // not whitespace.
+                if ( wsSeen )
+                {
+                    continue;
+                }
+                else
+                {
+                    wsSeen = true;
+    
+                    if ( isStart )
+                    {
+                        isStart = false;
+                    }
+                    else
+                    {
+                        newbuf[pos++] = ch;
+                    }
+                }
+            }
+            else
+            {
+                // Add all non-whitespace
+                wsSeen = false;
+                isStart = false;
+                newbuf[pos++] = ch;
+            }
+        }
+    
+        return ( pos == 0 ? "" : new String( newbuf, 0, ( wsSeen ? pos - 1 : pos ) ) );
+    }
+
+
+    /**
+     * This does the same thing as a trim but we also lowercase the string while
+     * performing the deep trim within the same buffer. This saves us from
+     * having to create multiple String and StringBuffer objects and is much
+     * more efficient.
+     * 
+     * @see StringTools#deepTrim( String )
+     */
+    public static String deepTrimToLower( String string )
+    {
+        return deepTrim( string, true );
+    }
+
+
+    /**
+     * A deep trim of a string remove whitespace from the ends as well as
+     * excessive whitespace within the inside of the string between
+     * non-whitespace characters. A deep trim reduces internal whitespace down
+     * to a single space to perserve the whitespace separated tokenization order
+     * of the String.
+     * 
+     * @param string the string to deep trim.
+     * @return the trimmed string.
+     */
+    public static String deepTrim( String string )
+    {
+        return deepTrim( string, false );
+    }
+
+
+    /**
+     * Trims several consecutive characters into one.
+     * 
+     * @param str the string to trim consecutive characters of
+     * @param ch the character to trim down
+     * @return the newly trimmed down string
+     */
+    public static String trimConsecutiveToOne( String str, char ch )
+    {
+        if ( ( null == str ) || ( str.length() == 0 ) )
+        {
+            return "";
+        }
+    
+        char[] buffer = str.toCharArray();
+        char[] newbuf = new char[buffer.length];
+        int pos = 0;
+        boolean same = false;
+    
+        for ( int i = 0; i < buffer.length; i++ )
+        {
+            char car = buffer[i];
+    
+            if ( car == ch )
+            {
+                if ( same )
+                {
+                    continue;
+                }
+                else
+                {
+                    same = true;
+                    newbuf[pos++] = car;
+                }
+            }
+            else
+            {
+                same = false;
+                newbuf[pos++] = car;
+            }
+        }
+    
+        return new String( newbuf, 0, pos );
+    }
+    
+
+    /**
+     * Truncates large Strings showing a portion of the String's head and tail
+     * with the center cut out and replaced with '...'. Also displays the total
+     * length of the truncated string so size of '...' can be interpreted.
+     * Useful for large strings in UIs or hex dumps to log files.
+     * 
+     * @param str the string to truncate
+     * @param head the amount of the head to display
+     * @param tail the amount of the tail to display
+     * @return the center truncated string
+     */
+    public static String centerTrunc( String str, int head, int tail )
+    {
+        StringBuffer buf = null;
+    
+        // Return as-is if String is smaller than or equal to the head plus the
+        // tail plus the number of characters added to the trunc representation
+        // plus the number of digits in the string length.
+        if ( str.length() <= ( head + tail + 7 + str.length() / 10 ) )
+        {
+            return str;
+        }
+    
+        buf = new StringBuffer();
+        buf.append( '[' ).append( str.length() ).append( "][" );
+        buf.append( str.substring( 0, head ) ).append( "..." );
+        buf.append( str.substring( str.length() - tail ) );
+        buf.append( ']' );
+        return buf.toString();
+    }
+    
+
+    /**
+     * Gets a hex string from byte array.
+     * 
+     * @param res the byte array
+     * @return the hex string representing the binary values in the array
+     */
+    public static String toHexString( byte[] res )
+    {
+        StringBuffer buf = new StringBuffer( res.length << 1 );
+        
+        for ( int ii = 0; ii < res.length; ii++ )
+        {
+            String digit = Integer.toHexString( 0xFF & res[ii] );
+            
+            if ( digit.length() == 1 )
+            {
+                digit = '0' + digit;
+            }
+            
+            buf.append( digit );
+        }
+        return buf.toString().toUpperCase();
+    }
+    
+
+    /**
+     * Get byte array from hex string
+     * 
+     * @param hexString the hex string to convert to a byte array
+     * @return the byte form of the hex string.
+     */
+    public static byte[] toByteArray( String hexString )
+    {
+        int arrLength = hexString.length() >> 1;
+        byte [] buf = new byte[arrLength];
+        
+        for ( int ii = 0; ii < arrLength; ii++ )
+        {
+            int index = ii << 1;
+            
+            String digit = hexString.substring( index, index + 2 );
+            buf[ii] = ( byte ) Integer.parseInt( digit, 16 );
+        }
+        
+        return buf;
+    }
+    
+
+    /**
+     * This method is used to insert HTML block dynamically
+     * 
+     * @param source the HTML code to be processes
+     * @param replaceNl if true '\n' will be replaced by &lt;br>
+     * @param replaceTag if true '<' will be replaced by &lt; and '>' will be replaced
+     *            by &gt;
+     * @param replaceQuote if true '\"' will be replaced by &quot;
+     * @return the formated html block
+     */
+    public static String formatHtml( String source, boolean replaceNl, boolean replaceTag,
+        boolean replaceQuote )
+    {
+        StringBuffer buf = new StringBuffer();
+        int len = source.length();
+    
+        for ( int ii = 0; ii < len; ii++ )
+        {
+            char ch = source.charAt( ii );
+            
+            switch ( ch )
+            {
+                case '\"':
+                    if ( replaceQuote )
+                    {
+                        buf.append( "&quot;" );
+                    }
+                    else
+                    {
+                        buf.append( ch );
+                    }
+                    break;
+    
+                case '<':
+                    if ( replaceTag )
+                    {
+                        buf.append( "&lt;" );
+                    }
+                    else
+                    {
+                        buf.append( ch );
+                    }
+                    break;
+    
+                case '>':
+                    if ( replaceTag )
+                    {
+                        buf.append( "&gt;" );
+                    }
+                    else
+                    {
+                        buf.append( ch );
+                    }
+                    break;
+    
+                case '\n':
+                    if ( replaceNl )
+                    {
+                        if ( replaceTag )
+                        {
+                            buf.append( "&lt;br&gt;" );
+                        }
+                        else
+                        {
+                            buf.append( "<br>" );
+                        }
+                    }
+                    else
+                    {
+                        buf.append( ch );
+                    }
+                    break;
+    
+                case '\r':
+                    break;
+    
+                case '&':
+                    buf.append( "&amp;" );
+                    break;
+    
+                default:
+                    buf.append( ch );
+                    break;
+            }
+        }
+    
+        return buf.toString();
+    }
+    
+
+    /**
+     * Check if a text is present at the current position in another string.
+     * 
+     * @param string The string which contains the data
+     * @param index Current position in the string
+     * @param text The text we want to check
+     * @return <code>true</code> if the string contains the text.
+     */
+    public static boolean areEquals( String string, int index, String text )
+    {
+        if ( ( string == null ) || ( text == null ) ) 
+        {
+            return false;
+        }
+        
+        int length1 = string.length();
+        int length2 = text.length();
+    
+        if ( ( length1 == 0 ) || ( length1 <= index ) || ( index < 0 )
+            || ( length2 == 0 ) || ( length2 > ( length1 + index ) ) )
+        {
+            return false;
+        }
+        else
+        {
+            return string.substring( index ).startsWith( text );
+        }
+    }
+    
+
+    /**
+     * Test if the current character is equal to a specific character. This
+     * function works only for character between 0 and 127, as it does compare a
+     * byte and a char (which is 16 bits wide)
+     * 
+     * @param byteArray The buffer which contains the data
+     * @param index Current position in the buffer
+     * @param car The character we want to compare with the current buffer position
+     * @return <code>true</code> if the current character equals the given character.
+     */
+    public static boolean isCharASCII( byte[] byteArray, int index, char car )
+    {
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) || ( index >= byteArray.length ) )
+        {
+            return false;
+        }
+        else
+        {
+            return ( ( byteArray[index] == car ) ? true : false );
+        }
+    }
+
+    /**
+     * Test if the current character is equal to a specific character.
+     * 
+     * @param string The String which contains the data
+     * @param index Current position in the string
+     * @param car The character we want to compare with the current string position
+     * @return <code>true</code> if the current character equals the given character.
+     */
+    public static boolean isCharASCII( String string, int index, char car )
+    {
+        if ( string == null )
+        {
+            return false;
+        }
+        
+        int length = string.length();
+        
+        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+        {
+            return false;
+        }
+        else
+        {
+            return string.charAt( index ) == car;
+        }
+    }
 }



Mime
View raw message