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