Search in sources :

Example 1 with UserChooseInformation

use of pcgen.cdom.base.UserChooseInformation in project pcgen by PCGen.

the class UserInputToken method parseToken.

@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
    UserChooseInformation ci = new UserChooseInformation();
    if (value != null) {
        int pipeLoc = value.indexOf('|');
        String titleString;
        if (pipeLoc == -1) {
            titleString = value;
        } else {
            String countString = value.substring(0, pipeLoc);
            Logging.deprecationPrint("CHOOSE:USERINPUT with count is deprecated, " + "please use SELECT: to identify the quantity of selections", context);
            int firstarg;
            try {
                firstarg = Integer.parseInt(countString);
            } catch (NumberFormatException nfe) {
                return new ParseResult.Fail("If CHOOSE:" + getTokenName() + " contains a pipe, " + "first argument must be an Integer : " + value, context);
            }
            Formula count = FormulaFactory.getFormulaFor(firstarg);
            context.getObjectContext().put(obj, FormulaKey.NUMCHOICES, count);
            context.getObjectContext().put(obj, FormulaKey.SELECT, count);
            titleString = value.substring(pipeLoc + 1);
        }
        if (!titleString.startsWith("TITLE=")) {
            return new ParseResult.Fail("CHOOSE:" + getTokenName() + " in " + obj.getClass() + " " + obj.getKeyName() + " had invalid arguments: " + value, context);
        }
        String title = titleString.substring(6);
        if (title.startsWith("\"")) {
            title = title.substring(1, title.length() - 1);
        }
        ci.setTitle(title);
    } else {
        ci.setTitle(getDefaultTitle());
    }
    // No args - legal
    context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, ci);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ParseResult(pcgen.rules.persistence.token.ParseResult) UserChooseInformation(pcgen.cdom.base.UserChooseInformation)

Aggregations

Formula (pcgen.base.formula.Formula)1 UserChooseInformation (pcgen.cdom.base.UserChooseInformation)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1