Search in sources :

Example 1 with SourceFileLoader

use of pcgen.persistence.SourceFileLoader in project pcgen by PCGen.

the class BatchExporter method exportCharacter.

/**
	 * Export a character sheet for the character to the output file using the 
	 * pre-registered template. If the output file is null then a default file 
	 * will be used based on the character file name and the type of export 
	 * template in use. If the output file exists it will be overwritten.
	 * <p>
	 * This method will load the required data for the character, load the 
	 * character and then export the character sheet.
	 * 
	 * @param characterFilename The path to the character PCG file.
	 * @param outputFile The path to the output file to be created. May be null.
	 * @return true if the export was successful, false if it failed in some way.
	 */
boolean exportCharacter(String characterFilename, String outputFile) {
    File file = new File(characterFilename);
    if (!PCGFile.isPCGenCharacterFile(file)) {
        Logging.errorPrint("Invalid character file specified: " + file.getAbsolutePath());
        return false;
    }
    String outFilename = outputFile;
    if (outFilename == null) {
        outFilename = generateOutputFilename(characterFilename);
    }
    Logging.log(Logging.INFO, "Started export of " + file.getAbsolutePath() + " using " + exportTemplateFilename + " to " + outFilename);
    // Load data
    SourceSelectionFacade sourcesForCharacter = CharacterManager.getRequiredSourcesForCharacter(file, uiDelegate);
    Logging.log(Logging.INFO, "Loading sources " + sourcesForCharacter.getCampaigns() + " using game mode " + sourcesForCharacter.getGameMode());
    SourceFileLoader loader = new SourceFileLoader(sourcesForCharacter, uiDelegate);
    loader.execute();
    // Load character
    CharacterFacade character = CharacterManager.openCharacter(file, uiDelegate, loader.getDataSetFacade());
    if (character == null) {
        return false;
    }
    // Export character
    File templateFile = new File(exportTemplateFilename);
    File outFile = new File(outFilename);
    if (isPdf) {
        return exportCharacterToPDF(character, outFile, templateFile);
    } else {
        return exportCharacterToNonPDF(character, outFile, templateFile);
    }
}
Also used : SourceSelectionFacade(pcgen.facade.core.SourceSelectionFacade) SourceFileLoader(pcgen.persistence.SourceFileLoader) PCGFile(pcgen.io.PCGFile) File(java.io.File) CharacterFacade(pcgen.facade.core.CharacterFacade)

Example 2 with SourceFileLoader

use of pcgen.persistence.SourceFileLoader in project pcgen by PCGen.

the class FtlMigrationTest method loadCharacter.

/**
	 * @param characterFile
	 * @return
	 */
private CharacterFacade loadCharacter(String characterFilename) {
    File file = new File(characterFilename);
    if (!PCGFile.isPCGenCharacterFile(file)) {
        Logging.errorPrint("Invalid character file specified: " + file.getAbsolutePath());
        return null;
    }
    // Load data
    UIDelegate uiDelegate = new ConsoleUIDelegate();
    SourceSelectionFacade sourcesForCharacter = CharacterManager.getRequiredSourcesForCharacter(file, uiDelegate);
    Logging.log(Logging.INFO, "Loading sources " + sourcesForCharacter.getCampaigns() + " using game mode " + sourcesForCharacter.getGameMode());
    SourceFileLoader loader = new SourceFileLoader(sourcesForCharacter, uiDelegate);
    loader.execute();
    // Load character
    CharacterFacade character = CharacterManager.openCharacter(file, uiDelegate, loader.getDataSetFacade());
    return character;
}
Also used : ConsoleUIDelegate(pcgen.system.ConsoleUIDelegate) SourceSelectionFacade(pcgen.facade.core.SourceSelectionFacade) SourceFileLoader(pcgen.persistence.SourceFileLoader) PCGFile(pcgen.io.PCGFile) File(java.io.File) CharacterFacade(pcgen.facade.core.CharacterFacade) ConsoleUIDelegate(pcgen.system.ConsoleUIDelegate) UIDelegate(pcgen.facade.core.UIDelegate)

Example 3 with SourceFileLoader

use of pcgen.persistence.SourceFileLoader in project pcgen by PCGen.

the class BatchExporter method exportParty.

/**
	 * Export a party sheet for the party to the output file using the 
	 * pre-registered template. If the output file is null then a default file 
	 * will be used based on the party file name and the type of export 
	 * template in use. If the output file exists it will be overwritten.
	 * <p>
	 * This method will load the required data for the party, load the characters 
	 * in the party and then export the party sheet.
	 * 
	 * @param partyFilename The path to the party PCP file.
	 * @param outputFile The path to the output file to be created. May be null.
	 * @return true if the export was successful, false if it failed in some way.
	 */
boolean exportParty(String partyFilename, String outputFile) {
    File file = new File(partyFilename);
    if (!PCGFile.isPCGenPartyFile(file)) {
        Logging.errorPrint("Invalid party file specified: " + file.getAbsolutePath());
        return false;
    }
    String outFilename = outputFile;
    if (outFilename == null) {
        outFilename = generateOutputFilename(partyFilename);
    }
    Logging.log(Logging.INFO, "Started export of party " + file.getAbsolutePath() + " using " + exportTemplateFilename + " to " + outFilename);
    // Load data
    SourceSelectionFacade sourcesForCharacter = CharacterManager.getRequiredSourcesForParty(file, uiDelegate);
    SourceFileLoader loader = new SourceFileLoader(sourcesForCharacter, uiDelegate);
    loader.execute();
    // Load party
    PartyFacade party = CharacterManager.openParty(file, uiDelegate, loader.getDataSetFacade());
    // Export party
    File templateFile = new File(exportTemplateFilename);
    File outFile = new File(outFilename);
    if (isPdf) {
        return exportPartyToPDF(party, outFile, templateFile);
    } else {
        return exportPartyToNonPDF(party, outFile, templateFile);
    }
}
Also used : SourceSelectionFacade(pcgen.facade.core.SourceSelectionFacade) PartyFacade(pcgen.facade.core.PartyFacade) SourceFileLoader(pcgen.persistence.SourceFileLoader) PCGFile(pcgen.io.PCGFile) File(java.io.File)

Example 4 with SourceFileLoader

use of pcgen.persistence.SourceFileLoader in project pcgen by PCGen.

the class DataLoadTest method testLoadSources.

/**
	 * Test the load of the current source. This will check for any load errors or warnings but ignores deprecation warnings.  
	 */
@Test
public void testLoadSources() {
    UIDelegate uiDelegate = new MockUIDelegate();
    SourceFileLoader loader = new SourceFileLoader(sourceSelection, uiDelegate);
    errors = new ArrayList<>();
    loader.addPCGenTaskListener(this);
    loader.execute();
    List<String> errorList = new ArrayList<>();
    List<String> warningList = new ArrayList<>();
    for (LogRecord logRecord : errors) {
        if (logRecord.getLevel().intValue() > Logging.WARNING.intValue()) {
            errorList.add(logRecord.getMessage());
        } else if (logRecord.getLevel().intValue() > Logging.INFO.intValue()) {
            warningList.add(logRecord.getMessage());
        }
    }
    assertEquals("Errors encountered while loading " + sourceSelection, "", StringUtils.join(errorList, ",\n"));
    assertEquals("Warnings encountered while loading " + sourceSelection, "", StringUtils.join(errorList, ",\n"));
}
Also used : LogRecord(java.util.logging.LogRecord) MockUIDelegate(pcgen.gui2.facade.MockUIDelegate) ArrayList(java.util.ArrayList) SourceFileLoader(pcgen.persistence.SourceFileLoader) MockUIDelegate(pcgen.gui2.facade.MockUIDelegate) UIDelegate(pcgen.facade.core.UIDelegate) Test(org.junit.Test)

Aggregations

SourceFileLoader (pcgen.persistence.SourceFileLoader)4 File (java.io.File)3 SourceSelectionFacade (pcgen.facade.core.SourceSelectionFacade)3 PCGFile (pcgen.io.PCGFile)3 CharacterFacade (pcgen.facade.core.CharacterFacade)2 UIDelegate (pcgen.facade.core.UIDelegate)2 ArrayList (java.util.ArrayList)1 LogRecord (java.util.logging.LogRecord)1 Test (org.junit.Test)1 PartyFacade (pcgen.facade.core.PartyFacade)1 MockUIDelegate (pcgen.gui2.facade.MockUIDelegate)1 ConsoleUIDelegate (pcgen.system.ConsoleUIDelegate)1