in ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/syntaxCheckers/OidLenSyntaxChecker.java [109:242]
public boolean isValidSyntax( Object value )
{
String strValue;
if ( value == null )
{
if ( LOG.isDebugEnabled() )
{
LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, "null" ) );
}
return false;
}
if ( value instanceof String )
{
strValue = ( String ) value;
}
else if ( value instanceof byte[] )
{
strValue = Strings.utf8ToString( ( byte[] ) value );
}
else
{
strValue = value.toString();
}
if ( strValue.length() == 0 )
{
if ( LOG.isDebugEnabled() )
{
LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
}
return false;
}
// We are looking at the first position of the len part
int pos = strValue.indexOf( '{' );
if ( pos < 0 )
{
// Not found ... but it may still be a valid OID
boolean result = Oid.isOid( strValue );
if ( LOG.isDebugEnabled() )
{
if ( result )
{
LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) );
}
else
{
LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
}
}
return result;
}
else
{
// we should have a len value. First check that the OID is valid
String oid = strValue.substring( 0, pos );
if ( !Oid.isOid( oid ) )
{
if ( LOG.isDebugEnabled() )
{
LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
}
return false;
}
String len = strValue.substring( pos );
// We must have a number and a '}' at the end
if ( len.charAt( len.length() - 1 ) != '}' )
{
// No final '}'
if ( LOG.isDebugEnabled() )
{
LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
}
return false;
}
for ( int i = 1; i < len.length() - 1; i++ )
{
switch ( len.charAt( i ) )
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
break;
default:
if ( LOG.isDebugEnabled() )
{
LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
}
return false;
}
}
if ( ( len.charAt( 1 ) == '0' ) && len.length() > 3 )
{
// A number can't start with a '0' unless it's the only
// number
if ( LOG.isDebugEnabled() )
{
LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
}
return false;
}
if ( LOG.isDebugEnabled() )
{
LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) );
}
return true;
}
}