Exemple #1
0
  /**
   * 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);
    }
  }