From bc6073700024e4b3c95bcf5bf3e48efb6edd14ab Mon Sep 17 00:00:00 2001 From: Alexander Marsalek Date: Sat, 10 Apr 2021 22:15:18 +0200 Subject: parsing off signature block CLI parameters --- .../src/main/java/at/gv/egiz/pdfas/cli/Main.java | 29 +++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'pdf-as-cli/src/main/java') diff --git a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java index 47d06576..86769c49 100644 --- a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java +++ b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java @@ -85,6 +85,9 @@ public class Main { public static final String CLI_ARG_CONF_SHORT = "conf"; public static final String CLI_ARG_CONF = "configuration"; + public static final String CLI_ARG_SIGNATURE_BLOCK_PARAM_SHORT = "sbp"; + public static final String CLI_ARG_SIGNATURE_BLOCK_PARAM = "signature_block_parameter"; + public static final String CLI_ARG_DEPLOY_SHORT = "d"; public static final String CLI_ARG_DEPLOY = "deploy"; @@ -199,6 +202,10 @@ public class Main { true, "The output file"); cliOptions.addOption(outputOption); + Option signatureBlockParameters = new Option(CLI_ARG_SIGNATURE_BLOCK_PARAM_SHORT, CLI_ARG_SIGNATURE_BLOCK_PARAM, + true, "Parameters or signature block"); + cliOptions.addOption(signatureBlockParameters); + return cliOptions; } @@ -434,12 +441,22 @@ public class Main { System.out.println("Starting signature for " + pdfFile); System.out.println("Selected signature Profile " + profilID); - //TODO get values from CLI - Map test = new HashMap<>(); - test.put("schoolName", "EGIZ testschule"); - - test.put("subject","bbDbb"); - signParameter.setDynamicSignatureBlockArguments(test); + // get console parameters related to signature block + String[] signatureBlockParameters = null; + if (cli.hasOption(CLI_ARG_SIGNATURE_BLOCK_PARAM_SHORT)) { + signatureBlockParameters = cli.getOptionValues(CLI_ARG_SIGNATURE_BLOCK_PARAM_SHORT); + } + Map signatureBlockParametersMap = new HashMap<>(); + if(signatureBlockParameters != null && signatureBlockParameters.length > 0) { + for(String s : signatureBlockParameters) { + if(!s.contains("=")) { + throw new Exception("Invalid parameter: "+s); + } + String[] values = s.split("=", 2); + signatureBlockParametersMap.put(values[0], values[1]); + } + } + signParameter.setDynamicSignatureBlockArguments(signatureBlockParametersMap); SignResult result = null; try { -- cgit v1.2.3