in plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/LogLevelEnum.java [312:686]
public static int parseLogLevel( String logLevelString )
{
if ( ( logLevelString == null ) || ( logLevelString.length() == 0 ) )
{
return 0;
}
int currentPos = 0;
char[] chars = logLevelString.toCharArray();
int logLevel = 0;
while ( currentPos < chars.length )
{
// Skip the ' ' at the beginning
while ( ( currentPos < chars.length ) && ( chars[currentPos] == ' ' ) )
{
currentPos++;
}
if ( currentPos >= chars.length )
{
break;
}
// Now, start analysing what's next
switch ( chars[currentPos] )
{
case 'a' :
case 'A' :
// ACL, ANY or ARGS
if ( parseName( chars, currentPos, "ACL" ) )
{
// ACL
currentPos += 3;
logLevel |= ACL.value;
}
else if ( parseName( chars, currentPos, "ANY" ) )
{
// ANY
currentPos += 3;
logLevel |= ANY.value;
}
else if ( parseName( chars, currentPos, "ARGS" ) )
{
// ARGS
currentPos += 4;
logLevel |= ARGS.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 'b' :
case 'B' :
// BER
if ( parseName( chars, currentPos, "BER" ) )
{
// BER
currentPos += 3;
logLevel |= BER.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 'c' :
case 'C' :
// CONFIG or CONNS
if ( parseName( chars, currentPos, "CONFIG" ) )
{
// CONFIG
currentPos += 6;
logLevel |= CONFIG.value;
}
else if ( parseName( chars, currentPos, "CONNS" ) )
{
// CONNS
currentPos += 5;
logLevel |= CONNS.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 'f' :
case 'F' :
// FILTER
if ( parseName( chars, currentPos, "FILTER" ) )
{
// FILTER
currentPos += 6;
logLevel |= FILTER.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 'n' :
case 'N' :
// NONE
if ( parseName( chars, currentPos, "NONE" ) )
{
// NONE
currentPos += 4;
logLevel |= NONE.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 'p' :
case 'P' :
// PACKETS or PARSE
if ( parseName( chars, currentPos, "PACKETS" ) )
{
// PACKETS
currentPos += 7;
logLevel |= PACKETS.value;
}
else if ( parseName( chars, currentPos, "PARSE" ) )
{
// PARSE
currentPos += 5;
logLevel |= PARSE.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 's' :
case 'S' :
// SHELL, STATS, STATS2 or SYNC
if ( parseName( chars, currentPos, "SHELL" ) )
{
// SHELL
currentPos += 5;
logLevel |= SHELL.value;
}
else if ( parseName( chars, currentPos, "STATS" ) )
{
// STATS
currentPos += 5;
logLevel |= STATS.value;
}
else if ( parseName( chars, currentPos, "STATS2" ) )
{
// STATS2
currentPos += 6;
logLevel |= STATS2.value;
}
else if ( parseName( chars, currentPos, "SYNC" ) )
{
// SYNC
currentPos += 4;
logLevel |= SYNC.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 't' :
case 'T' :
// TRACE
if ( parseName( chars, currentPos, "TRACE" ) )
{
// TRACE
currentPos += 5;
logLevel |= TRACE.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case '0' :
// Numeric or hexa ?
currentPos++;
if ( currentPos < chars.length )
{
if ( ( chars[currentPos] == 'x' ) || ( chars[currentPos] == 'X' ) )
{
// Hex
currentPos++;
boolean done = false;
int numValue = 0;
while ( ( currentPos < chars.length ) && !done )
{
switch ( chars[currentPos] )
{
case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
numValue = numValue*16 + chars[currentPos] - '0';
currentPos++;
break;
case 'a' :
case 'b' :
case 'c' :
case 'd' :
case 'e' :
case 'f' :
numValue = numValue*16 + 10 + chars[currentPos] - 'a';
currentPos++;
break;
case 'A' :
case 'B' :
case 'C' :
case 'D' :
case 'E' :
case 'F' :
numValue = numValue*16 + 10 + chars[currentPos] - 'A';
currentPos++;
break;
case ' ' :
logLevel |= numValue;
done = true;
break;
default :
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
// Special case : we are at the end of the STring
if ( !done )
{
logLevel |= numValue;
}
}
}
else
{
// decimal value
boolean done = false;
int numValue = 0;
while ( ( currentPos < chars.length ) && !done )
{
switch ( chars[currentPos] )
{
case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
numValue = numValue*10 + chars[currentPos] - '0';
currentPos++;
break;
case ' ' :
logLevel |= numValue;
done = true;
break;
default :
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
}
// Special case : we are at the end of the STring
if ( !done )
{
logLevel |= numValue;
}
}
}
break;
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
// Numeric
int numValue = chars[currentPos] - '0';
currentPos++;
boolean done = false;
while ( ( currentPos < chars.length ) && !done )
{
switch ( chars[currentPos] )
{
case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
numValue = numValue*10 + chars[currentPos] - '0';
currentPos++;
break;
case ' ' :
logLevel |= numValue;
done = true;
break;
default :
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
}
// Special case : we are at the end of the STring
if ( !done )
{
logLevel |= numValue;
}
break;
default :
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
}
return logLevel;
}