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 "";
}
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;
}
}
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 };
}
};
}
Aggregations