Search in sources :

Example 11 with ExportHandler

use of pcgen.io.ExportHandler in project pcgen by PCGen.

the class VAbilityTokenTest method testAssociated.

/**
	 * Tests the associated subtoken of VABILITY.
	 */
public void testAssociated() {
    VAbilityToken tok = new VAbilityToken();
    ExportHandler eh = new ExportHandler(null);
    PlayerCharacter character = getCharacter();
    assertEquals("", tok.getToken("VABILITY.FEAT.0.ASSOCIATED", character, eh));
    assertEquals("Bluff,Listen", tok.getToken("VABILITY.FEAT.1.ASSOCIATED", character, eh));
    assertEquals("Bluff", tok.getToken("VABILITY.FEAT.1.ASSOCIATED.0", character, eh));
    assertEquals("Listen", tok.getToken("VABILITY.FEAT.1.ASSOCIATED.1", character, eh));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) ExportHandler(pcgen.io.ExportHandler)

Example 12 with ExportHandler

use of pcgen.io.ExportHandler in project pcgen by PCGen.

the class VAbilityTokenTest method testSingleAspect.

/**
	 * Tests the ASPECT subtoken of VABILITY with an aspect specified.
	 */
public void testSingleAspect() {
    VAbilityToken tok = new VAbilityToken();
    ExportHandler eh = new ExportHandler(null);
    PlayerCharacter character = getCharacter();
    assertEquals("Shape: Icosahedron", tok.getToken("VABILITY.FEAT.0.ASPECT.2", character, eh));
    assertEquals("20", tok.getToken("VABILITY.FEAT.0.ASPECT.Sides", character, eh));
    assertEquals("Green", tok.getToken("VABILITY.FEAT.0.ASPECT.Colour", character, eh));
    assertEquals("2000", tok.getToken("VABILITY.FEAT.0.ASPECT.Age In Years", character, eh));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) ExportHandler(pcgen.io.ExportHandler)

Example 13 with ExportHandler

use of pcgen.io.ExportHandler in project pcgen by PCGen.

the class VAbilityTokenTest method testAssociatedCount.

/**
	 * Tests the ASSOCIATEDCOUNT subtoken of VABILITY.
	 */
public void testAssociatedCount() {
    VAbilityToken tok = new VAbilityToken();
    ExportHandler eh = new ExportHandler(null);
    PlayerCharacter character = getCharacter();
    assertEquals("0", tok.getToken("VABILITY.FEAT.0.ASSOCIATEDCOUNT", character, eh));
    assertEquals("2", tok.getToken("VABILITY.FEAT.1.ASSOCIATEDCOUNT", character, eh));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) ExportHandler(pcgen.io.ExportHandler)

Example 14 with ExportHandler

use of pcgen.io.ExportHandler in project pcgen by PCGen.

the class BatchExporter method exportParty.

/**
	 * Write a party sheet for the characters in the party to the outputStream. The party sheet will
	 * be selected based on the selected game mode and pcgen preferences.
	 *
	 * @param party the party to be output
	 * @param outputStream the stream to output the party sheet to.
	 * @throws IOException
	 * @throws ExportException
	 */
private static void exportParty(PartyFacade party, OutputStream outputStream) throws IOException, ExportException {
    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"))) {
        for (final CharacterFacade character : party) {
            File templateFile = getXMLTemplate(character);
            character.export(new ExportHandler(templateFile), bw);
        }
    }
}
Also used : ExportHandler(pcgen.io.ExportHandler) OutputStreamWriter(java.io.OutputStreamWriter) CharacterFacade(pcgen.facade.core.CharacterFacade) PCGFile(pcgen.io.PCGFile) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 15 with ExportHandler

use of pcgen.io.ExportHandler in project pcgen by PCGen.

the class BatchExporter method exportCharacterToNonPDF.

/**
	 * Write a non PDF (e.g. html, text) character sheet for the character to 
	 * the output file. The character sheet will be built according to the 
	 * template file. If the output file exists it will be overwritten.
	 *    
	 * @param character The already loaded character to be output.
	 * @param outFile The file to which the character sheet is to be written. 
	 * @param templateFile The file that has the export template definition.  
	 * @return true if the export was successful, false if it failed in some way.
	 */
public static boolean exportCharacterToNonPDF(CharacterFacade character, File outFile, File templateFile) {
    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"))) {
        character.export(new ExportHandler(templateFile), bw);
        character.setDefaultOutputSheet(false, templateFile);
        return true;
    } catch (final UnsupportedEncodingException e) {
        Logging.errorPrint("Unable to create output file " + outFile.getAbsolutePath(), e);
        return false;
    } catch (final IOException e) {
        Logging.errorPrint("Unable to create output file " + outFile.getAbsolutePath(), e);
        return false;
    } catch (final ExportException e) {
        // Error will already be reported to the log
        return false;
    }
}
Also used : ExportHandler(pcgen.io.ExportHandler) FileOutputStream(java.io.FileOutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) ExportException(pcgen.io.ExportException)

Aggregations

ExportHandler (pcgen.io.ExportHandler)31 PlayerCharacter (pcgen.core.PlayerCharacter)24 File (java.io.File)7 BufferedWriter (java.io.BufferedWriter)6 StringWriter (java.io.StringWriter)4 IOException (java.io.IOException)3 TextToken (plugin.exporttokens.TextToken)3 OutputStreamWriter (java.io.OutputStreamWriter)2 Test (org.junit.Test)2 FileOutputStream (java.io.FileOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CharacterFacade (pcgen.facade.core.CharacterFacade)1 ExportException (pcgen.io.ExportException)1 PCGFile (pcgen.io.PCGFile)1