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/07/26 14:12:39 UTC
svn commit: r559790 - in /directory/shared/trunk/ldap/src:
main/java/org/apache/directory/shared/ldap/codec/
main/java/org/apache/directory/shared/ldap/codec/actions/
main/java/org/apache/directory/shared/ldap/codec/util/
main/java/org/apache/directory...
Author: elecharny
Date: Thu Jul 26 05:12:37 2007
New Revision: 559790
URL: http://svn.apache.org/viewvc?view=rev&rev=559790
Log:
Fixed DIRSEVER-1009 : pb with UTF-8 based Strings
Modified:
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/AttributeDescAction.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescFilterAction.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ReferralAction.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreAnyAction.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreFinalAction.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreReferenceAction.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreTypeMatchingRuleAction.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeSerializerUtils.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributesSerializerUtils.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/codec/search/SearchResultReferenceTest.java
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java Thu Jul 26 05:12:37 2007
@@ -31,7 +31,6 @@
import org.apache.directory.shared.asn1.Asn1Object;
import org.apache.directory.shared.asn1.codec.DecoderException;
import org.apache.directory.shared.asn1.primitives.OID;
-import org.apache.directory.shared.asn1.util.Asn1StringUtils;
import org.apache.directory.shared.ldap.codec.abandon.AbandonRequest;
import org.apache.directory.shared.ldap.codec.add.AddRequest;
import org.apache.directory.shared.ldap.codec.add.AddResponse;
@@ -107,6 +106,7 @@
import org.apache.directory.shared.ldap.message.extended.GracefulShutdownRequest;
import org.apache.directory.shared.ldap.message.spi.Provider;
import org.apache.directory.shared.ldap.message.spi.TransformerSpi;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -856,15 +856,8 @@
// Snickers : String errorMessage -> Twix : LdapString errorMessage
String errorMessage = snickersLdapResult.getErrorMessage();
-
- if ( ( errorMessage == null ) || ( errorMessage.length() == 0 ) )
- {
- twixLdapResult.setErrorMessage( "" );
- }
- else
- {
- twixLdapResult.setErrorMessage( new String( snickersLdapResult.getErrorMessage().getBytes() ) );
- }
+
+ twixLdapResult.setErrorMessage( StringTools.isEmpty( errorMessage ) ? "" : errorMessage );
// Snickers : String matchedDn -> Twix : LdapDN matchedDN
twixLdapResult.setMatchedDN( snickersLdapResult.getMatchedDn() );
@@ -1244,7 +1237,7 @@
twixControl.setCriticality( control.isCritical() );
twixControl.setControlValue( control.getEncodedValue() );
twixControl.setEncodedValue( control.getEncodedValue() );
- twixControl.setControlType( new String( Asn1StringUtils.getBytesUtf8( control.getID() ) ) );
+ twixControl.setControlType( control.getID() );
twixControl.setParent( twixMessage );
}
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/AttributeDescAction.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/AttributeDescAction.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/AttributeDescAction.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/AttributeDescAction.java Thu Jul 26 05:12:37 2007
@@ -26,6 +26,7 @@
import org.apache.directory.shared.asn1.codec.DecoderException;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.search.SearchRequest;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -73,7 +74,7 @@
value = tlv.getValue().getData();
}
- attributeDescription = new String( value );
+ attributeDescription = StringTools.utf8ToString( value );
searchRequest.addAttribute( attributeDescription );
// We can have an END transition
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescFilterAction.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescFilterAction.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescFilterAction.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescFilterAction.java Thu Jul 26 05:12:37 2007
@@ -29,6 +29,7 @@
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.search.AttributeValueAssertionFilter;
import org.apache.directory.shared.ldap.codec.search.SearchRequest;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,7 +73,7 @@
}
else
{
- String type = new String( tlv.getValue().getData() );
+ String type = StringTools.utf8ToString( tlv.getValue().getData() );
assertion.setAttributeDesc( type );
AttributeValueAssertionFilter terminalFilter = ( AttributeValueAssertionFilter ) searchRequest
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ReferralAction.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ReferralAction.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ReferralAction.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ReferralAction.java Thu Jul 26 05:12:37 2007
@@ -33,6 +33,7 @@
import org.apache.directory.shared.ldap.codec.util.LdapURL;
import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -82,7 +83,7 @@
}
catch ( LdapURLEncodingException luee )
{
- String badUrl = new String( tlv.getValue().getData() );
+ String badUrl = StringTools.utf8ToString( tlv.getValue().getData() );
log.error( "The URL " + badUrl + " is not valid : " + luee.getMessage() );
throw new DecoderException( "Invalid URL : " + luee.getMessage() );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreAnyAction.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreAnyAction.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreAnyAction.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreAnyAction.java Thu Jul 26 05:12:37 2007
@@ -28,6 +28,7 @@
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.search.SearchRequest;
import org.apache.directory.shared.ldap.codec.search.SubstringFilter;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -71,7 +72,7 @@
throw new DecoderException( "The substring any filter is empty" );
}
- String any = new String( tlv.getValue().getData() );
+ String any = StringTools.utf8ToString( tlv.getValue().getData() );
substringFilter.addAnySubstrings( any );
// We now have to get back to the nearest filter which is
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreFinalAction.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreFinalAction.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreFinalAction.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreFinalAction.java Thu Jul 26 05:12:37 2007
@@ -28,6 +28,7 @@
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.search.SearchRequest;
import org.apache.directory.shared.ldap.codec.search.SubstringFilter;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -71,7 +72,7 @@
throw new DecoderException( "The substring final filter is empty" );
}
- String finalValue = new String( tlv.getValue().getData() );
+ String finalValue = StringTools.utf8ToString( tlv.getValue().getData() );
substringFilter.setFinalSubstrings( finalValue );
// We now have to get back to the nearest filter which is
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreReferenceAction.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreReferenceAction.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreReferenceAction.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreReferenceAction.java Thu Jul 26 05:12:37 2007
@@ -28,6 +28,7 @@
import org.apache.directory.shared.ldap.codec.search.SearchResultReference;
import org.apache.directory.shared.ldap.codec.util.LdapURL;
import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -82,7 +83,7 @@
}
catch ( LdapURLEncodingException luee )
{
- String badUrl = new String( tlv.getValue().getData() );
+ String badUrl = StringTools.utf8ToString( tlv.getValue().getData() );
log.error( "The URL {} is not valid : {}", badUrl, luee.getMessage() );
throw new DecoderException( "Invalid URL : " + luee.getMessage() );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreTypeMatchingRuleAction.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreTypeMatchingRuleAction.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreTypeMatchingRuleAction.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreTypeMatchingRuleAction.java Thu Jul 26 05:12:37 2007
@@ -28,6 +28,7 @@
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.search.ExtensibleMatchFilter;
import org.apache.directory.shared.ldap.codec.search.SearchRequest;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -73,7 +74,7 @@
ExtensibleMatchFilter extensibleMatchFilter = ( ExtensibleMatchFilter ) searchRequest
.getTerminalFilter();
- String type = new String( tlv.getValue().getData() );
+ String type = StringTools.utf8ToString( tlv.getValue().getData() );
extensibleMatchFilter.setType( type );
if ( IS_DEBUG )
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java Thu Jul 26 05:12:37 2007
@@ -332,16 +332,8 @@
throw new LdapURLEncodingException( "The byte array is empty : this is not a valid LdapURL." );
}
- try
- {
- string = new String( bytes, "UTF-8" );
- this.bytes = bytes;
- }
- catch ( UnsupportedEncodingException uee )
- {
- throw new LdapURLEncodingException( "The byte array is not an UTF-8 encoded Unicode String : "
- + uee.getMessage() );
- }
+ string = StringTools.utf8ToString( bytes );
+ this.bytes = bytes;
parse( string.toCharArray() );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java Thu Jul 26 05:12:37 2007
@@ -45,82 +45,6 @@
{
static transient final long serialVersionUID = 1L;
- /** This flag is used if the attribute name is not caseSensitive */
- private boolean ignoreCase;
-
- /**
- * An holder to store <Id, Attribute> couples
- */
- /*private class Holder implements Serializable, Cloneable
- {
- static transient final long serialVersionUID = 1L;
-
- // The user provided attribute ID
- private String upId;
-
- // The attribute. Should be an instance of LockableAttribute
- private Attribute attribute;
-
- /**
- * Create a new holder for the given ID
- * @param upId The attribute UP id
- * @param attribute The attribute
- * /
- private Holder( String upId, Attribute attribute )
- {
- this.upId = upId;
- this.attribute = attribute;
- }
-
- /**
- * @see Object#clone()
- * /
- public Object clone() throws CloneNotSupportedException
- {
- Holder clone = (Holder)super.clone();
-
- clone.upId = upId;
-
- if ( attribute instanceof BasicAttribute )
- {
- // The BasicAttribute clone() method does not
- // copy the values.
- clone.attribute = new AttributeImpl( attribute.getID() );
-
- try
- {
- NamingEnumeration values = attribute.getAll();
-
- while ( values.hasMoreElements() )
- {
- clone.attribute.add( AttributeUtils.cloneValue( values.nextElement() ) );
- }
- }
- catch( NamingException ne )
- {
-
- }
- }
- clone.attribute = (Attribute)attribute.clone();
-
- return clone;
- }
-
- /**
- * @see Object#toString()
- * /
- public String toString()
- {
- StringBuffer sb = new StringBuffer();
-
- sb.append( upId ).append( ": " );
-
- sb.append( attribute ).append( '\n' );
-
- return sb.toString();
- }
- }*/
-
/**
* An iterator which returns Attributes.
*/
@@ -196,7 +120,6 @@
public AttributesImpl()
{
keyMap = new HashMap<String, AttributeImpl>();
- ignoreCase = true;
}
/**
@@ -205,7 +128,6 @@
public AttributesImpl( boolean ignoreCase )
{
keyMap = new HashMap<String, AttributeImpl>();
- this.ignoreCase = ignoreCase;
}
/**
@@ -215,7 +137,6 @@
{
keyMap = new HashMap<String, AttributeImpl>();
put( id, value );
- ignoreCase = true;
}
/**
@@ -225,7 +146,6 @@
{
keyMap = new HashMap<String, AttributeImpl>();
put( id, value );
- this.ignoreCase = ignoreCase;
}
/**
@@ -239,8 +159,6 @@
}
else if ( attributes instanceof BasicAttributes )
{
- ignoreCase = attributes.isCaseIgnored();
-
NamingEnumeration attrs = attributes.getAll();
keyMap = new HashMap<String, AttributeImpl>();
@@ -265,8 +183,6 @@
AttributeImpl attribute = clone.keyMap.get( key );
keyMap.put( key, (AttributeImpl)attribute.clone() );
}
-
- ignoreCase = clone.ignoreCase;
}
else
{
@@ -366,11 +282,11 @@
* Determines whether the attribute set ignores the case of attribute
* identifiers when retrieving or adding attributes.
*
- * @return true always.
+ * @return always <code>true</code>.
*/
public boolean isCaseIgnored()
{
- return ignoreCase;
+ return true;
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java Thu Jul 26 05:12:37 2007
@@ -501,65 +501,105 @@
{
if ( value instanceof String )
{
+ // The result will be gathered in a stringBuilder
StringBuilder sb = new StringBuilder();
+
+ // First, store the type and the '=' char
sb.append( normType ).append( '=' );
+
String normalizedValue = ( String ) value;
int valueLength = normalizedValue.length();
+ boolean escaped = false;
if ( normalizedValue.length() > 0 )
{
- for ( int i = 0; i < valueLength; i++ )
- {
- char c = normalizedValue.charAt( i );
-
+ char[] chars = normalizedValue.toCharArray();
+
+ // Loop first assuming the DN won't contain any
+ // char needing to be escaped. This is the case
+ // for 99.99% of all DN (blind bet, of course ...)
+ for ( char c:chars )
+ {
if ( ( c < 0) || ( c > 128 ) )
{
- byte[] bb = StringTools.getBytesUtf8( normalizedValue.substring( i, i + 1 ) );
-
- for ( byte b:bb )
- {
- sb.append( '\\' ).
- append( StringTools.dumpHex( (byte)(( b & 0x00F0 ) >> 4) ) ).
- append( StringTools.dumpHex( b ) );
- }
+ escaped = true;
+ break;
}
- else if ( DN_ESCAPED_CHARS[ c ] )
+ else if ( DN_ESCAPED_CHARS[ c ] )
{
- if ( c == ' ' )
- {
- if ( ( i == 0 ) || ( i == valueLength - 1 ) )
- {
- sb.append( '\\' ).append( c );
- }
- else
- {
- sb.append( ' ' );
- }
-
- continue;
- }
- else if ( c == '#' )
- {
- if ( i == 0 )
- {
- sb.append( "\\#" );
- continue;
- }
- else
- {
- sb.append( '#' );
- }
-
- continue;
- }
-
- sb.append( '\\' ).append( c );
+ escaped = true;
+ break;
}
- else
- {
- sb.append( c );
- }
- }
+ }
+
+ // Here, we have a char to escape. Start again the loop...
+ if ( escaped )
+ {
+ for ( int i = 0; i < valueLength; i++ )
+ {
+ char c = chars[i];
+
+ if ( ( c < 0) || ( c > 128 ) )
+ {
+ // For chars which are not ASCII, use their hexa value prefixed by an '\'
+ byte[] bb = StringTools.getBytesUtf8( normalizedValue.substring( i, i + 1 ) );
+
+ for ( byte b:bb )
+ {
+ sb.append( '\\' ).
+ append( StringTools.dumpHex( (byte)(( b & 0x00F0 ) >> 4) ) ).
+ append( StringTools.dumpHex( b ) );
+ }
+ }
+ else if ( DN_ESCAPED_CHARS[ c ] )
+ {
+ // Some chars need to be escaped even if they are US ASCII
+ // Just prefix them with a '\'
+ // Special cases are ' ' (space), '#') which need a special
+ // treatment.
+ if ( c == ' ' )
+ {
+ if ( ( i == 0 ) || ( i == valueLength - 1 ) )
+ {
+ sb.append( '\\' ).append( c );
+ }
+ else
+ {
+ sb.append( ' ' );
+ }
+
+ continue;
+ }
+ else if ( c == '#' )
+ {
+ if ( i == 0 )
+ {
+ sb.append( "\\#" );
+ continue;
+ }
+ else
+ {
+ sb.append( '#' );
+ }
+
+ continue;
+ }
+
+ sb.append( '\\' ).append( c );
+ }
+ else
+ {
+ // Standard ASCII chars are just appended
+ sb.append( c );
+ }
+ }
+ }
+ else
+ {
+ // The String does not contain any escaped char :
+ // just append it.
+ sb.append( normalizedValue );
+ }
}
return sb.toString();
@@ -597,7 +637,7 @@
return true;
}
- if ( obj == null)
+ if ( obj == null )
{
return false;
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java Thu Jul 26 05:12:37 2007
@@ -237,17 +237,18 @@
*/
private static int parseOidPrefix( String string, Position pos )
{
- if ( ( StringTools.areEquals( string, pos.start, DNUtils.OID_LOWER ) )
- || ( StringTools.areEquals( string, pos.start, DNUtils.OID_UPPER ) ) )
- {
- pos.end += DNUtils.OID_LOWER.length();
-
- return DNUtils.PARSING_OK;
- }
- else
- {
- return DNUtils.PARSING_ERROR;
- }
+ if ( StringTools.isICharASCII( string, pos.start, 'O' ) &&
+ StringTools.isICharASCII( string, pos.start + 1, 'I' ) &&
+ StringTools.isICharASCII( string, pos.start + 2, 'D' ) &&
+ StringTools.isICharASCII( string, pos.start + 3, '.' ) )
+ {
+ pos.end += DNUtils.OID_LOWER.length();
+ return DNUtils.PARSING_OK;
+ }
+ else
+ {
+ return DNUtils.PARSING_ERROR;
+ }
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeSerializerUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeSerializerUtils.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeSerializerUtils.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeSerializerUtils.java Thu Jul 26 05:12:37 2007
@@ -21,6 +21,9 @@
import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -44,9 +47,44 @@
/** value for type parameter for string (non-binary) attributes */
static final byte STRING_TYPE = 0x00;
+
/** value for type parameter for byte array (binary) attributes */
static final byte BYTE_ARRAY_TYPE = 0x01;
+ /*
+ private class ExtensibleByteArray
+ {
+ private static final int EXTENSION = 2048;
+ private List<byte[]> array;
+ private byte[] currentData;
+ private int pos = 0;
+ private int limit = EXTENSION;
+
+ private ExtensibleByteArray()
+ {
+ array = new ArrayList<byte[]>();
+ currentData = new byte[EXTENSION];
+ array.add( currentData );
+ }
+
+ private void extend()
+ {
+ limit += EXTENSION;
+ array.add( new byte[EXTENSION] );
+ }
+
+ private void put( byte b )
+ {
+ if ( pos == limit )
+ {
+ extend();
+ currentData =
+ }
+
+
+ }
+ }*/
+
// -----------------------------------------------------------------------
// Methods for deserialization
@@ -261,6 +299,9 @@
Attribute attr = ( Attribute ) obj;
// calculate the size of the entire byte[] and allocate
+ ByteBuffer bb = ByteBuffer.allocate( 4096 );
+
+ bb.hasRemaining();
byte[] buf = new byte[calculateSize( attr )];
// write the length of the id and it's value
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributesSerializerUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributesSerializerUtils.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributesSerializerUtils.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributesSerializerUtils.java Thu Jul 26 05:12:37 2007
@@ -53,6 +53,7 @@
int pos = 0;
AttributesImpl attrs = new AttributesImpl();
+
while ( pos < buf.length )
{
String id = AttributeSerializerUtils.readString( buf, pos );
@@ -99,6 +100,7 @@
// calculate the size of the entire byte[] and allocate
byte[] buf = new byte[calculateSize( attrs )];
int pos = 0;
+
try
{
for ( NamingEnumeration ii = attrs.getAll(); ii.hasMore(); /**/)
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?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- 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 Thu Jul 26 05:12:37 2007
@@ -1512,12 +1512,9 @@
/**
* Check if a text is present at the current position in another string.
*
- * @param string1
- * The string which contains the data
- * @param index
- * Current position in the string
- * @param text
- * The text we want to check
+ * @param string1 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 final boolean areEquals( String string1, int index, String text )
@@ -1537,7 +1534,7 @@
}
else
{
- return string1.substring( index ).startsWith( text );
+ return string1.substring( index ).startsWith( text );
}
}
@@ -1633,12 +1630,9 @@
/**
* 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
+ * @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.
@@ -1659,6 +1653,35 @@
else
{
return string.charAt( index ) == car;
+ }
+ }
+
+ /**
+ * 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 final boolean isICharASCII( 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 ) | 0x20 ) & car ) == car;
}
}
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultReferenceTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultReferenceTest.java?view=diff&rev=559790&r1=559789&r2=559790
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultReferenceTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultReferenceTest.java Thu Jul 26 05:12:37 2007
@@ -240,16 +240,27 @@
// Allocate a BindRequest Container
IAsn1Container ldapMessageContainer = new LdapMessageContainer();
- try
+ long t0 = System.currentTimeMillis();
+
+ for ( int i = 0; i < 100000; i++ )
{
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
+ try
+ {
+ ((LdapMessageContainer)ldapMessageContainer).clean();
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ stream.flip();
}
+ long t1 = System.currentTimeMillis();
+ System.out.println( "Delta : " + (t1 - t0) );
+
LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
SearchResultReference searchResultReference = message.getSearchResultReference();