Search in sources :

Example 86 with StringTokenizer

use of java.util.StringTokenizer 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 87 with StringTokenizer

use of java.util.StringTokenizer in project pcgen by PCGen.

the class ExportHandler method processSpellcasterExpression.

/**
	 * Deal with SPELLCASTER.
	 *  
	 * Could look like one of the following:
	 * 
	 * Arcane
	 * Chaos
	 * Divine
	 * EleMage
	 * Psionic
	 * Wizard
	 * Prepare
	 * !Prepare
	 * 0=Wizard    (%classNum=className)
	 * 0=Divine    (%classNum=spell_type)
	 * 0=Prepare   (%classNum=preparation_type)
	 *
	 * @param expr1 Expression to evaluate
	 * @param aPC PC containing values to help evaluate the expression
	 * @return true if the expression was evaluated successfully, else false
	 */
private static boolean processSpellcasterExpression(String expr1, PlayerCharacter aPC) {
    final String fString = expr1.substring(12).trim();
    // If the SPELLCASTER expression has an '=' sign
    if (fString.indexOf('=') != -1) {
        final StringTokenizer aTok = new StringTokenizer(fString, "=", false);
        final int i = Integer.parseInt(aTok.nextToken());
        final String cs = aTok.nextToken();
        final List<PCClass> cList = aPC.getClassList();
        if (i >= cList.size()) {
            return false;
        }
        final PCClass aClass = cList.get(i);
        if (cs.equalsIgnoreCase(aClass.getSpellType())) {
            return true;
        }
        if (cs.equalsIgnoreCase(aClass.getKeyName())) {
            return true;
        }
        if ("!Prepare".equalsIgnoreCase(cs) && aClass.getSafe(ObjectKey.MEMORIZE_SPELLS)) {
            return true;
        }
        if ("Prepare".equalsIgnoreCase(cs) && (!aClass.getSafe(ObjectKey.MEMORIZE_SPELLS))) {
            return true;
        }
    } else {
        for (final PCClass pcClass : aPC.getClassSet()) {
            if (fString.equalsIgnoreCase(pcClass.getSpellType())) {
                return true;
            }
            if (fString.equalsIgnoreCase(pcClass.getKeyName())) {
                return true;
            }
            if ("!Prepare".equalsIgnoreCase(fString) && pcClass.getSafe(ObjectKey.MEMORIZE_SPELLS)) {
                return true;
            }
            if ("Prepare".equalsIgnoreCase(fString) && (!pcClass.getSafe(ObjectKey.MEMORIZE_SPELLS))) {
                return true;
            }
        }
    }
    Logging.errorPrint("Should have exited before this in ExportHandler::processSpellcasterExpression");
    return false;
}
Also used : StringTokenizer(java.util.StringTokenizer) PCClass(pcgen.core.PCClass)

Example 88 with StringTokenizer

use of java.util.StringTokenizer in project pcgen by PCGen.

the class ExportHandler method parseFORs.

/**
	 * Helper method to parse |FOR tokens (pre-processing for a template)
	 * 
	 * @param forLine
	 * @param tokens
	 * @return A FORNode of the parsed tokens
	 */
private FORNode parseFORs(String forLine, StringTokenizer tokens) {
    final List<String> forVars = getParameters(forLine);
    final String var = forVars.get(1);
    final String min = forVars.get(2);
    final String max = forVars.get(3);
    final String step = forVars.get(4);
    final String eTest = forVars.get(5);
    boolean exists = false;
    if (((!eTest.isEmpty()) && (eTest.charAt(0) == '1')) || ((!eTest.isEmpty()) && (eTest.charAt(0) == '2'))) {
        exists = true;
    }
    final FORNode node = new FORNode(var, min, max, step, exists);
    while (tokens.hasMoreTokens()) {
        final String line = tokens.nextToken();
        if (line.startsWith("|FOR")) {
            StringTokenizer newFor = new StringTokenizer(line, ",");
            newFor.nextToken();
            if (newFor.nextToken().startsWith("%")) {
                node.addChild(parseFORs(line, tokens));
            } else {
                node.addChild(line);
            }
        } else if (line.startsWith("|IIF(") && (line.lastIndexOf(',') == -1)) {
            String expr = line.substring(5, line.lastIndexOf(')'));
            node.addChild(parseIIFs(expr, tokens));
        } else if (line.startsWith("|ENDFOR|")) {
            return node;
        } else {
            node.addChild(line);
        }
    }
    return node;
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 89 with StringTokenizer

use of java.util.StringTokenizer in project pcgen by PCGen.

the class ExportHandler method replaceLine.

/**
	 * This method performs some work on a given character sheet template line, 
	 * namely replacing tokens, dealing with Malformed lines and simply outputting 
	 * plain text.
	 *  
	 * @param aLine The line to do the work on
	 * @param output The output buffer that is effectively the character sheet template
	 * @param aPC The PC that we are outputting
	 */
private void replaceLine(String aLine, BufferedWriter output, PlayerCharacter aPC) {
    // Find the last index of the | character
    int lastIndex = aLine.lastIndexOf('|');
    // If there are no pipes and it's a non empty string, just output the fixed text
    if (lastIndex < 0 && !aLine.isEmpty()) {
        outputNonToken(aLine, output);
    }
    /*
		 * When the line starts with a pipe and that pipe is the only
		 * one on the line, this operation ignores the line.  This is
		 * because the token is malformed.  Malformed because it should be
		 * between pipes.
		 */
    if (lastIndex >= 1) {
        final StringTokenizer aTok = new StringTokenizer(aLine, "|", false);
        boolean inPipe = false;
        if (aLine.charAt(0) == '|') {
            inPipe = true;
        }
        boolean lastIsPipe = false;
        if (aLine.charAt(aLine.length() - 1) == '|') {
            lastIsPipe = true;
        }
        while (aTok.hasMoreTokens()) {
            String tok = aTok.nextToken();
            if (inPipe) {
                if (aTok.hasMoreTokens() || lastIsPipe) {
                    replaceToken(tok, output, aPC);
                }
            /*
					 * No else condition because we should be between
					 * pipes at this point i.e. this should be a token but
					 * it appears to be malformed.  Malformed because there
					 * are no more tokens and the last character of the string
					 * is not a pipe
					 */
            } else {
                outputNonToken(tok, output);
            }
            // take the other decision path
            if (aTok.hasMoreTokens()) {
                inPipe = !inPipe;
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 90 with StringTokenizer

use of java.util.StringTokenizer in project pcgen by PCGen.

the class ExportHandler method processPipedLine.

/**
	 * Helper method to process a line that begins with a | (and may end with a |)
	 * 
	 * @param PCs List of PCs to output
	 * @param aLine Line to parse
	 * @param buf 
	 * @param out character sheet we are building up
	 * @param between Whether we are processing a line between pipes
	 * @return true if we processed successfully
	 */
private boolean processPipedLine(PlayerCharacter[] PCs, String aLine, StringBuilder buf, BufferedWriter out, boolean between) {
    final StringTokenizer aTok = new StringTokenizer(aLine, "|", false);
    boolean noPipes = false;
    if (aTok.countTokens() == 1) {
        noPipes = true;
    }
    boolean betweenPipes = between;
    while (aTok.hasMoreTokens()) {
        String tok = aTok.nextToken();
        // removing tab characters if asked to do so
        if (!betweenPipes) {
            if (manualWhitespace) {
                tok = tok.replaceAll("[ \\t]", "");
            }
            FileAccess.write(out, tok);
        } else // Guaranteed to be between pipes here
        if (!noPipes && !aTok.hasMoreTokens()) {
            buf.append(tok);
        } else {
            buf.append(tok);
            String aString = buf.toString();
            // We have finished dealing with section
            // between the pipe characters so clear out the
            // StringBuilder
            int l = buf.length();
            buf.delete(0, l);
            if (aString.startsWith("FOR.")) {
                doPartyForToken(PCs, out, aString);
            } else {
                Matcher mat = Pattern.compile("^(\\d+)").matcher(aString);
                int charNum = mat.matches() ? Integer.parseInt(mat.group()) : -1;
                // just be written to the output verbatim
                if ((charNum >= 0) && (charNum < Globals.getPCList().size())) {
                    PlayerCharacter currPC = PCs[charNum];
                    replaceToken(aString, out, currPC);
                } else if (aString.startsWith("EXPORT")) {
                    // We can safely do EXPORT tags with no PC
                    replaceToken(aString, out, null);
                }
            }
        }
        if (aTok.hasMoreTokens() || noPipes) {
            betweenPipes = !betweenPipes;
        }
    }
    return betweenPipes;
}
Also used : StringTokenizer(java.util.StringTokenizer) PlayerCharacter(pcgen.core.PlayerCharacter) Matcher(java.util.regex.Matcher)

Aggregations

StringTokenizer (java.util.StringTokenizer)4881 ArrayList (java.util.ArrayList)1083 IOException (java.io.IOException)506 File (java.io.File)392 BufferedReader (java.io.BufferedReader)380 HashMap (java.util.HashMap)375 HashSet (java.util.HashSet)263 FileReader (java.io.FileReader)224 List (java.util.List)200 InputStreamReader (java.io.InputStreamReader)191 Map (java.util.Map)152 FileInputStream (java.io.FileInputStream)135 Iterator (java.util.Iterator)114 Set (java.util.Set)114 URL (java.net.URL)108 NoSuchElementException (java.util.NoSuchElementException)90 Properties (java.util.Properties)84 InputStream (java.io.InputStream)83 BufferedWriter (java.io.BufferedWriter)80 FileNotFoundException (java.io.FileNotFoundException)78