// pull out the first token from the bottom of the stack and check arguments exist
String first = stack.firstElement();
stack.removeElementAt(0);
if (stack.isEmpty())
{
throw new ConfigurationException(String.format(NOT_ENOUGH_TOKENS_MSG, getLine()));
}
// check for and parse optional initial number for ACL lines
Integer number = null;
if (StringUtils.isNumeric(first))
{
// set the acl number and get the next element
number = Integer.valueOf(first);
first = stack.firstElement();
stack.removeElementAt(0);
}
if (StringUtils.equalsIgnoreCase(ACL, first))
{
parseAcl(number, stack);
}
else if (number == null)
{
if(StringUtils.equalsIgnoreCase("GROUP", first))
{
throw new ConfigurationException(String.format("GROUP keyword not supported. Groups should defined via a Group Provider, not in the ACL file.", getLine()));
}
else if (StringUtils.equalsIgnoreCase(CONFIG, first))
{
parseConfig(stack);
}
else
{
throw new ConfigurationException(String.format(UNRECOGNISED_INITIAL_MSG, first, getLine()));
}
}
else
{
throw new ConfigurationException(String.format(NUMBER_NOT_ALLOWED_MSG, first, getLine()));
}
// reset stack, start next line
stack.clear();
break;
case StreamTokenizer.TT_NUMBER:
stack.push(Integer.toString(Double.valueOf(_st.nval).intValue()));
break;
case StreamTokenizer.TT_WORD:
stack.push(_st.sval); // token
break;
default:
if (_st.ttype == CONTINUATION)
{
int next = _st.nextToken();
if (next == StreamTokenizer.TT_EOL)
{
break; // continue reading next line
}
// invalid location for continuation character (add one to line beacuse we ate the EOL)
throw new ConfigurationException(String.format(PREMATURE_CONTINUATION_MSG, getLine() + 1));
}
else if (_st.ttype == '\'' || _st.ttype == '"')
{
stack.push(_st.sval); // quoted token
}
else
{
stack.push(Character.toString((char) _st.ttype)); // single character
}
}
} while (current != StreamTokenizer.TT_EOF);
if (!stack.isEmpty())
{
throw new ConfigurationException(String.format(PREMATURE_EOF_MSG, getLine()));
}
}
catch (IllegalArgumentException iae)
{
throw new ConfigurationException(String.format(PARSE_TOKEN_FAILED_MSG, getLine()), iae);
}
catch (FileNotFoundException fnfe)
{
throw new ConfigurationException(String.format(CONFIG_NOT_FOUND_MSG, file.getName()), fnfe);
}
catch (IOException ioe)
{
throw new ConfigurationException(String.format(CANNOT_LOAD_MSG, file.getName()), ioe);
}
finally
{
if(fileReader != null)
{
try
{
fileReader.close();
}
catch (IOException e)
{
throw new ConfigurationException(String.format(CANNOT_CLOSE_MSG, file.getName()), e);
}
}
}