コード例 #1
0
  /**
   * Transforms {@link MergeTaskCliArguments} to {@link MergeParameters}
   *
   * @param taskCliArguments
   * @return populated task parameters
   */
  public MergeParameters toTaskParameters(MergeTaskCliArguments taskCliArguments) {
    MergeParameters parameters =
        new MergeParameters(taskCliArguments.isCopyFields(), taskCliArguments.isAddBlanks());
    parameters.setOutlinePolicy(taskCliArguments.getBookmarks().getEnumValue());
    populateAbstractParameters(parameters, taskCliArguments);
    populateOutputTaskParameters(parameters, taskCliArguments);

    MultiplePdfMergeInputAdapter mergeInputsAdapter = extractPdfMergeInputs(taskCliArguments);

    for (PdfMergeInput eachMergeInput : mergeInputsAdapter.getPdfMergeInputs()) {
      parameters.addInput(eachMergeInput);
    }

    return parameters;
  }
コード例 #2
0
  private MultiplePdfMergeInputAdapter extractPdfMergeInputs(
      MergeTaskCliArguments taskCliArguments) {
    // input files can be specified in 3 ways: explicitly, via a folder or via a config file
    List<PdfFileSource> inputFiles = null;
    if (taskCliArguments.isDirectory()) {
      if (taskCliArguments.isMatchingRegEx()) {
        inputFiles =
            taskCliArguments
                .getDirectory()
                .filter(taskCliArguments.getMatchingRegEx())
                .getFileSourceList();
      } else {
        inputFiles = taskCliArguments.getDirectory().getFileSourceList();
      }

    } else if (taskCliArguments.isFiles()) {
      inputFiles = extractFiles(taskCliArguments.getFiles());
    } else if (taskCliArguments.isFilesListConfig()) {
      inputFiles = taskCliArguments.getFilesListConfig().getFileSourceList();
    }

    if (!BooleanUtils.xor(
        new boolean[] {
          taskCliArguments.isDirectory(),
          taskCliArguments.isFiles(),
          taskCliArguments.isFilesListConfig()
        })) {
      throw new SejdaRuntimeException(
          "Too many options given for input. Please use only one of the following options: --directory --filesListConfig --file");
    }

    if (inputFiles == null) {
      throw new SejdaRuntimeException("No input files specified");
    }

    MultiplePdfMergeInputAdapter mergeInputsAdapter =
        new MultiplePdfMergeInputAdapter(inputFiles, taskCliArguments.getPageSelection().ranges());
    return mergeInputsAdapter;
  }