Code with Finding: |
class ConfigFileReader {
protected Category parseCategoryHeader(String configfile, int lineno, String line) throws ConfigParseException
{
final Category category;
final String name;
final int nameEndPos;
/* format is one of the following:
* [foo] define a new category named 'foo'
* [foo](!) define a new template category named 'foo'
* [foo](+) append to category 'foo', error if foo does not exist.
* [foo](a) define a new category and inherit from template a.
* You can put a comma-separated list of templates and '!' and '+'
* between parentheses, with obvious meaning.
*/
nameEndPos = line.indexOf(']');
if (nameEndPos == -1)
{
throw new ConfigParseException(configfile, lineno,
"parse error: no closing ']', line %d of %s", lineno, configfile);
}
name = line.substring(1, nameEndPos);
category = new Category(configfile, lineno, name);
/* Handle options or categories to inherit from if available */
if (line.length() > nameEndPos + 1 && line.charAt(nameEndPos + 1) == '(')
{
final String[] options;
final String optionsString;
final int optionsEndPos;
optionsString = line.substring(nameEndPos + 1);
optionsEndPos = optionsString.indexOf(')');
if (optionsEndPos == -1)
{
throw new ConfigParseException(configfile, lineno,
"parse error: no closing ')', line %d of %s", lineno, configfile);
}
options = optionsString.substring(1, optionsEndPos).split(",");
for (String cur : options)
{
if ("!".equals(cur)) // category template
{
category.markAsTemplate();
}
else if ("+".equals(cur)) // category addition
{
final Category categoryToAddTo;
categoryToAddTo = categories.get(name);
if (categoryToAddTo == null)
{
throw new ConfigParseException(configfile, lineno,
"Category addition requested, but category '%s' does not exist, line %d of %s",
name, lineno, configfile);
}
//todo implement category addition
//category = categoryToAddTo;
}
else
{
final Category baseCategory;
baseCategory = categories.get(cur);
if (baseCategory == null)
{
throw new ConfigParseException(configfile, lineno,
"Inheritance requested, but category '%s' does not exist, line %d of %s",
cur, lineno, configfile);
}
inheritCategory(category, baseCategory);
}
}
}
appendCategory(category);
return category;
}
}
class ConfigFileReader {
protected ConfigVariable parseVariable(String configfile, int lineno, String line) throws ConfigParseException
{
int pos;
String name;
String value;
pos = line.indexOf('=');
if (pos == -1)
{
throw new MissingEqualSignException(configfile, lineno,
"No '=' (equal sign) in line %d of %s", lineno, configfile);
}
name = line.substring(0, pos).trim();
// Ignore > in =>
if (line.length() > pos + 1 && line.charAt(pos + 1) == '>')
{
pos++;
}
value = (line.length() > pos + 1) ? line.substring(pos + 1).trim() : "";
return new ConfigVariable(configfile, lineno, name, value);
}
}
|