Search in sources :

Example 1 with TokenProcessEvent

use of pcgen.gui2.converter.event.TokenProcessEvent in project pcgen by PCGen.

the class ClassLoader method processToken.

private List<CDOMObject> processToken(StringBuilder sb, String firstToken, CDOMObject obj, CDOMObject alt, String token, ConversionDecider decider, int line) throws PersistenceLayerException, InterruptedException {
    final int colonLoc = token.indexOf(':');
    if (colonLoc == -1) {
        Logging.errorPrint("Invalid Token - does not contain a colon: " + token);
        return null;
    } else if (colonLoc == 0) {
        Logging.errorPrint("Invalid Token - starts with a colon: " + token);
        return null;
    }
    String key = token.substring(0, colonLoc);
    String value = (colonLoc == token.length() - 1) ? null : token.substring(colonLoc + 1);
    TokenProcessEvent tpe = new TokenProcessEvent(context, decider, key, value, firstToken, obj);
    String error = TokenConverter.process(tpe);
    if (!tpe.isConsumed() && alt != null) {
        tpe = new TokenProcessEvent(context, decider, key, value, firstToken, alt);
        error += TokenConverter.process(tpe);
    }
    if (tpe.isConsumed()) {
        if (!token.equals(tpe.getResult())) {
            try {
                changeLogWriter.append("Line " + line + " converted '" + token + "' to '" + tpe.getResult() + "'.\n");
            } catch (IOException e) {
                Logging.errorPrint("Unable to log change", e);
            }
        }
        sb.append(tpe.getResult());
    } else {
        Logging.errorPrint(error);
    }
    return tpe.getInjected();
}
Also used : TokenProcessEvent(pcgen.gui2.converter.event.TokenProcessEvent) IOException(java.io.IOException)

Example 2 with TokenProcessEvent

use of pcgen.gui2.converter.event.TokenProcessEvent in project pcgen by PCGen.

the class TokenConverter method process.

public static String process(TokenProcessEvent tpe) {
    Class<?> cl = tpe.getPrimary().getClass();
    String key = tpe.getKey();
    ensureCategoryExists(tpe);
    List<TokenProcessorPlugin> tokens = getTokens(cl, key);
    String error = "";
    try {
        if (tokens != null) {
            for (TokenProcessorPlugin converter : tokens) {
                error += converter.process(tpe);
                if (tpe.isConsumed()) {
                    break;
                }
            }
        }
        if (!tpe.isConsumed()) {
            error += defaultProc.process(tpe);
        }
    } catch (Exception ex) {
        Logging.errorPrint("Parse of " + tpe.getKey() + ":" + tpe.getValue() + " failed");
        ex.printStackTrace();
    }
    return tpe.isConsumed() ? null : error;
}
Also used : TokenProcessorPlugin(pcgen.gui2.converter.event.TokenProcessorPlugin) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with TokenProcessEvent

use of pcgen.gui2.converter.event.TokenProcessEvent in project pcgen by PCGen.

the class BasicLoader method processToken.

private List<CDOMObject> processToken(StringBuilder sb, String objectName, CDOMObject obj, String token, ConversionDecider decider, int line) throws PersistenceLayerException, InterruptedException {
    final int colonLoc = token.indexOf(':');
    if (colonLoc == -1) {
        Logging.errorPrint("Invalid Token - does not contain a colon: " + token);
        return null;
    } else if (colonLoc == 0) {
        Logging.errorPrint("Invalid Token - starts with a colon: " + token);
        return null;
    }
    String key = token.substring(0, colonLoc);
    String value = (colonLoc == token.length() - 1) ? null : token.substring(colonLoc + 1);
    TokenProcessEvent tpe = new TokenProcessEvent(context, decider, key, value, objectName, obj);
    String error = TokenConverter.process(tpe);
    if (tpe.isConsumed()) {
        if (!token.equals(tpe.getResult())) {
            try {
                changeLogWriter.append("Line " + line + " converted '" + token + "' to '" + tpe.getResult() + "'.\n");
            } catch (IOException e) {
                Logging.errorPrint("Unable to log change", e);
            }
        }
        sb.append(tpe.getResult());
    } else {
        Logging.errorPrint(error);
    }
    return tpe.getInjected();
}
Also used : TokenProcessEvent(pcgen.gui2.converter.event.TokenProcessEvent) IOException(java.io.IOException)

Example 4 with TokenProcessEvent

use of pcgen.gui2.converter.event.TokenProcessEvent in project pcgen by PCGen.

the class EquipmentLoader method processToken.

private List<CDOMObject> processToken(StringBuilder sb, String objectName, CDOMObject obj, String token, ConversionDecider decider, int line) throws PersistenceLayerException, InterruptedException {
    final int colonLoc = token.indexOf(':');
    if (colonLoc == -1) {
        Logging.errorPrint("Invalid Token - does not contain a colon: " + token);
        return null;
    } else if (colonLoc == 0) {
        Logging.errorPrint("Invalid Token - starts with a colon: " + token);
        return null;
    }
    String key = token.substring(0, colonLoc);
    String value = (colonLoc == token.length() - 1) ? null : token.substring(colonLoc + 1);
    TokenProcessEvent tpe = new TokenProcessEvent(context, decider, key, value, objectName, obj);
    String error = TokenConverter.process(tpe);
    if (tpe.isConsumed()) {
        if (!token.equals(tpe.getResult())) {
            try {
                changeLogWriter.append("Line " + line + " converted '" + token + "' to '" + tpe.getResult() + "'.\n");
            } catch (IOException e) {
                Logging.errorPrint("Unable to log change", e);
            }
        }
        sb.append(tpe.getResult());
    } else {
        Logging.errorPrint(error);
    }
    return tpe.getInjected();
}
Also used : TokenProcessEvent(pcgen.gui2.converter.event.TokenProcessEvent) IOException(java.io.IOException)

Example 5 with TokenProcessEvent

use of pcgen.gui2.converter.event.TokenProcessEvent in project pcgen by PCGen.

the class BonusConvertPlugin method process.

private String process(EditorLoadContext context, ConversionDecider decider, String objectName, String token) {
    final int colonLoc = token.indexOf(':');
    if (colonLoc == -1) {
        Logging.errorPrint("Invalid Token - does not contain a colon: " + token);
        return null;
    } else if (colonLoc == 0) {
        Logging.errorPrint("Invalid Token - starts with a colon: " + token);
        return null;
    }
    String key = token.substring(0, colonLoc);
    String value = (colonLoc == token.length() - 1) ? null : token.substring(colonLoc + 1);
    CDOMObject cdo = new ObjectCache();
    cdo.setName("BONUS" + bonusCount++);
    TokenProcessEvent tpe = new TokenProcessEvent(context, decider, key, value, objectName, cdo);
    String error = TokenConverter.process(tpe);
    context.purge(cdo);
    TokenConverter.clearConstants();
    if (tpe.isConsumed()) {
        return tpe.getResult();
    } else {
        Logging.errorPrint(error);
    }
    return null;
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) ObjectCache(pcgen.cdom.inst.ObjectCache) TokenProcessEvent(pcgen.gui2.converter.event.TokenProcessEvent)

Aggregations

TokenProcessEvent (pcgen.gui2.converter.event.TokenProcessEvent)4 IOException (java.io.IOException)3 NoSuchElementException (java.util.NoSuchElementException)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 ObjectCache (pcgen.cdom.inst.ObjectCache)1 TokenProcessorPlugin (pcgen.gui2.converter.event.TokenProcessorPlugin)1