Search in sources :

Example 1 with Token

use of pcgen.io.exporttoken.Token in project pcgen by PCGen.

the class ExportHandler method getTokenString.

/**
	 * Get the token string
	 * 
	 * @param aPC the PC being exported
	 * @param aString The token string to convert
	 * @return token string
	 */
public static String getTokenString(final PlayerCharacter aPC, final String aString) {
    final StringTokenizer tok = new StringTokenizer(aString, ".,", false);
    final String firstToken = tok.nextToken();
    // Make sure the token list has been populated
    populateTokenMap();
    final Token token = tokenMap.get(firstToken);
    if (token != null) {
        return token.getToken(aString, aPC, null);
    }
    return "";
}
Also used : StringTokenizer(java.util.StringTokenizer) SkillToken(pcgen.io.exporttoken.SkillToken) Token(pcgen.io.exporttoken.Token) MovementToken(pcgen.io.exporttoken.MovementToken) EqToken(pcgen.io.exporttoken.EqToken) StatToken(pcgen.io.exporttoken.StatToken) GameModeToken(pcgen.io.exporttoken.GameModeToken) EqTypeToken(pcgen.io.exporttoken.EqTypeToken) WeaponhToken(pcgen.io.exporttoken.WeaponhToken) SkillpointsToken(pcgen.io.exporttoken.SkillpointsToken) BonusToken(pcgen.io.exporttoken.BonusToken) TotalToken(pcgen.io.exporttoken.TotalToken) AbilityListToken(pcgen.io.exporttoken.AbilityListToken) WeaponToken(pcgen.io.exporttoken.WeaponToken) AbilityToken(pcgen.io.exporttoken.AbilityToken)

Example 2 with Token

use of pcgen.io.exporttoken.Token in project pcgen by PCGen.

the class ExportHandler method replaceToken.

/**
	 * Replace the token with the value it represents
	 * 
	 * @param aString The string containing the token to be replaced
	 * @param output The object that will capture the output
	 * @param aPC The PC currently being exported
	 * @return value
	 */
public int replaceToken(String aString, BufferedWriter output, PlayerCharacter aPC) {
    try {
        // If it is plain text then there's no replacement necessary
        if (isPlainText(aString)) {
            return 0;
        }
        // then there is nothing to replace so return 0
        if ("%".equals(aString)) {
            inLabel = false;
            canWrite = true;
            return 0;
        }
        // and return the length of the line (minus any whitespace)
        if (aString.startsWith("${") && aString.endsWith("}")) {
            String jepString = aString.substring(2, aString.length() - 1);
            String variableValue = aPC.getVariableValue(jepString, "").toString();
            FileAccess.write(output, variableValue);
            return aString.trim().length();
        }
        // TODO Why?
        FileAccess.maxLength(-1);
        // If the string is a non empty filter and does not have a '<' or a '>' in it then replace the token
        if (isFilterToken(aString)) {
            return dealWithFilteredTokens(aString, aPC);
        }
        String tokenString = aString;
        // e.g: |SUB10.ARMOR.AC|
        if (isValidSubToken(tokenString)) {
            tokenString = replaceSubToken(tokenString);
        }
        // Now check for the rest of the tokens
        populateTokenMap();
        StringTokenizer tok = new StringTokenizer(tokenString, ".,", false);
        String firstToken = tok.nextToken();
        // Get the remaining token/test string 
        // TODO Understand this
        String testString = tokenString;
        if (testString.indexOf(',') > -1) {
            testString = testString.substring(0, testString.indexOf(','));
        }
        if (testString.indexOf('~') > -1) {
            testString = testString.substring(0, testString.indexOf('~'));
        }
        int len = 1;
        // Deal with FOR/DFOR token
        if (isForOrDForToken(tokenString)) {
            processLoopToken(tokenString, output, aPC);
            return 0;
        } else // Deal with OIF token
        if (tokenString.startsWith("OIF(")) {
            replaceTokenOIF(tokenString, output, aPC);
        } else // Deal with mathematical tokenLeave
        if (containsMathematicalToken(testString) && (!skipMath)) {
            FileAccess.maxLength(-1);
            FileAccess.write(output, mathMode(tokenString, aPC));
            return 0;
        } else // Deal with CSHEETTAG2.
        if (tokenString.startsWith("CSHEETTAG2.")) {
            csheetTag2 = tokenString.substring(11, 12);
            FileAccess.maxLength(-1);
            return 0;
        } else // Else if the token is in the list of valid output tokens
        if (tokenMap.get(firstToken) != null) {
            Token token = tokenMap.get(firstToken);
            if (token.isEncoded()) {
                FileAccess.encodeWrite(output, token.getToken(tokenString, aPC, this));
            } else {
                FileAccess.write(output, token.getToken(tokenString, aPC, this));
            }
        } else // Default case
        {
            len = tokenString.trim().length();
            if (manualWhitespace) {
                tokenString = tokenString.replaceAll("[ \\t]", "");
                if (len > 0) {
                    FileAccess.write(output, tokenString);
                }
            } else {
                FileAccess.write(output, tokenString);
            }
        }
        FileAccess.maxLength(-1);
        return len;
    } catch (Exception exc) {
        Logging.errorPrint("Error replacing " + aString, exc);
        return 0;
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) SkillToken(pcgen.io.exporttoken.SkillToken) Token(pcgen.io.exporttoken.Token) MovementToken(pcgen.io.exporttoken.MovementToken) EqToken(pcgen.io.exporttoken.EqToken) StatToken(pcgen.io.exporttoken.StatToken) GameModeToken(pcgen.io.exporttoken.GameModeToken) EqTypeToken(pcgen.io.exporttoken.EqTypeToken) WeaponhToken(pcgen.io.exporttoken.WeaponhToken) SkillpointsToken(pcgen.io.exporttoken.SkillpointsToken) BonusToken(pcgen.io.exporttoken.BonusToken) TotalToken(pcgen.io.exporttoken.TotalToken) AbilityListToken(pcgen.io.exporttoken.AbilityListToken) WeaponToken(pcgen.io.exporttoken.WeaponToken) AbilityToken(pcgen.io.exporttoken.AbilityToken) ParseException(java.text.ParseException) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException)

Example 3 with Token

use of pcgen.io.exporttoken.Token in project pcgen by PCGen.

the class ExportHandler method getPluginLoader.

public static PluginLoader getPluginLoader() {
    return new PluginLoader() {

        @Override
        public void loadPlugin(Class<?> clazz) throws Exception {
            Token pl = (Token) clazz.newInstance();
            addToTokenMap(pl);
        }

        @Override
        public Class[] getPluginClasses() {
            return new Class[] { Token.class };
        }
    };
}
Also used : PCClass(pcgen.core.PCClass) SkillToken(pcgen.io.exporttoken.SkillToken) Token(pcgen.io.exporttoken.Token) MovementToken(pcgen.io.exporttoken.MovementToken) EqToken(pcgen.io.exporttoken.EqToken) StatToken(pcgen.io.exporttoken.StatToken) GameModeToken(pcgen.io.exporttoken.GameModeToken) EqTypeToken(pcgen.io.exporttoken.EqTypeToken) WeaponhToken(pcgen.io.exporttoken.WeaponhToken) SkillpointsToken(pcgen.io.exporttoken.SkillpointsToken) BonusToken(pcgen.io.exporttoken.BonusToken) TotalToken(pcgen.io.exporttoken.TotalToken) AbilityListToken(pcgen.io.exporttoken.AbilityListToken) WeaponToken(pcgen.io.exporttoken.WeaponToken) AbilityToken(pcgen.io.exporttoken.AbilityToken) PluginLoader(pcgen.system.PluginLoader)

Aggregations

AbilityListToken (pcgen.io.exporttoken.AbilityListToken)3 AbilityToken (pcgen.io.exporttoken.AbilityToken)3 BonusToken (pcgen.io.exporttoken.BonusToken)3 EqToken (pcgen.io.exporttoken.EqToken)3 EqTypeToken (pcgen.io.exporttoken.EqTypeToken)3 GameModeToken (pcgen.io.exporttoken.GameModeToken)3 MovementToken (pcgen.io.exporttoken.MovementToken)3 SkillToken (pcgen.io.exporttoken.SkillToken)3 SkillpointsToken (pcgen.io.exporttoken.SkillpointsToken)3 StatToken (pcgen.io.exporttoken.StatToken)3 Token (pcgen.io.exporttoken.Token)3 TotalToken (pcgen.io.exporttoken.TotalToken)3 WeaponToken (pcgen.io.exporttoken.WeaponToken)3 WeaponhToken (pcgen.io.exporttoken.WeaponhToken)3 StringTokenizer (java.util.StringTokenizer)2 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 PCClass (pcgen.core.PCClass)1 PluginLoader (pcgen.system.PluginLoader)1