From 06b900642342afb680aab3b36fba9247e1e29aa9 Mon Sep 17 00:00:00 2001 From: pdanner Date: Fri, 26 Nov 2010 12:02:47 +0000 Subject: Placeholder-image handling git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@613 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../java/at/gv/egiz/pdfas/commandline/Main.java | 95 ++++++++++++++++++++-- 1 file changed, 89 insertions(+), 6 deletions(-) (limited to 'src/main/java/at/gv/egiz/pdfas/commandline') diff --git a/src/main/java/at/gv/egiz/pdfas/commandline/Main.java b/src/main/java/at/gv/egiz/pdfas/commandline/Main.java index 161dee8..40d0e5a 100644 --- a/src/main/java/at/gv/egiz/pdfas/commandline/Main.java +++ b/src/main/java/at/gv/egiz/pdfas/commandline/Main.java @@ -79,6 +79,7 @@ import at.knowcenter.wag.egov.egiz.web.servlets.VerifyServlet; */ public abstract class Main { +// 23.11.2010 changed by exthex - added parameters for placeholder handling /** * Command line parameter setting the application mode sign|verify */ @@ -113,6 +114,21 @@ public abstract class Main * Command line parameter selecting the position of the signature. */ protected static final String PARAMETER_POS = "-pos"; + + /** + * Command line parameter signaling to search the source document for a placeholder for the signature + */ + protected static final String PARAMETER_SEARCH_PLACEHOLDER = "-checkforplaceholder"; + + /** + * Command line parameter selecting the id of the placeholder to use + */ + protected static final String PARAMETER_PLACEHOLDER_ID = "-placeholder_id"; + + /** + * Command line parameter selecting the match mode for the placeholder + */ + protected static final String PARAMETER_PLACEHOLDER_MATCH_MODE = "-placeholder_matchmode"; /** * Command line parameter selecting the signature which is going to be @@ -157,6 +173,21 @@ public abstract class Main */ public static final String VALUE_SIGNATURE_MODE_DETACHED_TEXT = "detachedtextual"; + /** + * The placeholder match mode STRICT + */ + public static final String VALUE_PLACEHOLDER_MATCH_MODE_STRICT = "strict"; + + /** + * The placeholder match mode STRICT + */ + public static final String VALUE_PLACEHOLDER_MATCH_MODE_MODERATE = "moderate"; + + /** + * The placeholder match mode STRICT + */ + public static final String VALUE_PLACEHOLDER_MATCH_MODE_LENIENT = "lenient"; + /** * The log. */ @@ -207,6 +238,10 @@ public abstract class Main String user_name = null; String user_password = null; String pos_string = null; + + boolean search_placeholder = false; + String placeholderId = null; + int placeholderMatchMode = SignParameters.PLACEHOLDER_MATCH_MODE_MODERATE; int verify_which = -1; @@ -300,6 +335,44 @@ public abstract class Main continue; } + if (cur_arg.equals(PARAMETER_SEARCH_PLACEHOLDER)) + { + search_placeholder = true; + continue; + } + + if (cur_arg.equals(PARAMETER_PLACEHOLDER_ID)) + { + i++; + if (i >= args.length) + { + printNoValue(PARAMETER_PLACEHOLDER_ID); + return; + } + placeholderId = args[i]; + continue; + } + + if (cur_arg.equals(PARAMETER_PLACEHOLDER_MATCH_MODE)) + { + i++; + if (i >= args.length) + { + printNoValue(PARAMETER_PLACEHOLDER_MATCH_MODE); + return; + } + String matchMode = args[i]; + if (matchMode.equals(VALUE_PLACEHOLDER_MATCH_MODE_LENIENT)) + placeholderMatchMode = SignParameters.PLACEHOLDER_MATCH_MODE_LENIENT; + else if (matchMode.equals(VALUE_PLACEHOLDER_MATCH_MODE_MODERATE)) + placeholderMatchMode = SignParameters.PLACEHOLDER_MATCH_MODE_MODERATE; + else if (matchMode.equals(VALUE_PLACEHOLDER_MATCH_MODE_STRICT)) + placeholderMatchMode = SignParameters.PLACEHOLDER_MATCH_MODE_STRICT; + else + printUnrecognizedValue(PARAMETER_PLACEHOLDER_MATCH_MODE, args[i]); + continue; + } + if (cur_arg.equals(PARAMETER_USER_NAME)) { i++; @@ -435,7 +508,7 @@ public abstract class Main output = generateOutputFileNameFromInput(input, signature_mode); } - carryOutCommand(mode, signature_mode, connector, signature_type, user_name, user_password, verify_which, input, output, pos_string); + carryOutCommand(mode, signature_mode, connector, signature_type, user_name, user_password, verify_which, input, output, pos_string, search_placeholder, placeholderId, placeholderMatchMode); } catch (PdfAsException e) @@ -460,7 +533,7 @@ public abstract class Main } protected static void carryOutCommand(final String mode, final String signature_mode, final String connector, final String signature_type, final String user_name, final String user_password, - final int verify_which, final String input, String output, final String pos_string) throws PdfAsException + final int verify_which, final String input, String output, final String pos_string, boolean search_placeholder, String placeholderId, int placeholderMatchMode) throws PdfAsException { // File file = new File(input); // @@ -481,7 +554,7 @@ public abstract class Main if (mode.equals(VALUE_MODE_SIGN)) { - carryOutSign(input, connector, signature_mode, signature_type, pos_string, user_name, user_password, output, messageOutput); + carryOutSign(input, connector, signature_mode, signature_type, pos_string, user_name, user_password, output, messageOutput, search_placeholder, placeholderId, placeholderMatchMode); } else { @@ -491,7 +564,7 @@ public abstract class Main } public static void carryOutSign(String input, String connector, String signature_mode, String signature_type, String pos_string, String user_name, String user_password, String output, - PrintWriter messageOutput) throws PdfAsException + PrintWriter messageOutput, boolean search_placeholder, String placeholderId, int placeholderMatchMode) throws PdfAsException { messageOutput.println("Signing " + input + "..."); @@ -532,7 +605,7 @@ public abstract class Main } try { - processSign(dataSource, connector, signature_mode, signature_type, pos_string, dataSink); + processSign(dataSource, connector, signature_mode, signature_type, pos_string, search_placeholder, placeholderId, placeholderMatchMode, dataSink); } catch (Exception e) { // Exception caught in order to delete file based datasink if (outputFile != null && outputFile.exists()) @@ -626,7 +699,7 @@ public abstract class Main } - public static void processSign(DataSource dataSource, String connector, String signature_mode, String signature_type, String pos_string, DataSink dataSink) throws PdfAsException + public static void processSign(DataSource dataSource, String connector, String signature_mode, String signature_type, String pos_string, boolean search_placeholder, String placeholderId, int placeholderMatchMode, DataSink dataSink) throws PdfAsException { TablePos pos = null; if (pos_string != null) @@ -678,6 +751,9 @@ public abstract class Main sp.setSignatureDevice(connector); sp.setSignatureProfileId(signature_type); sp.setSignaturePositioning(posi); + sp.setCheckForPlaceholder(search_placeholder); + sp.setPlaceholderId(placeholderId); + sp.setPlaceholderMatchMode(placeholderMatchMode); pdfAs.sign(sp); } @@ -979,6 +1055,13 @@ public abstract class Main writer.println(" 'new' ... new page"); writer.println(" intvalue ... pagenumber must be > 0 if p>number of pages in document p-->handled like p:'new'"); writer.println(" f_algo floatvalue ... consider footerline must be >= 0 (only if y_algo is auto and p_algo is not 'new')"); + + writer.println(" " + PARAMETER_SEARCH_PLACEHOLDER + " ... [optional] if set, the source document will be scanned for signature placeholder images"); + writer.println(" " + PARAMETER_PLACEHOLDER_ID + " ... [optional] search for signature placeholder images containing the given id"); + writer.println(" " + PARAMETER_PLACEHOLDER_MATCH_MODE + " <" + VALUE_PLACEHOLDER_MATCH_MODE_LENIENT + "|" + VALUE_PLACEHOLDER_MATCH_MODE_MODERATE + "|" + VALUE_PLACEHOLDER_MATCH_MODE_STRICT + "> ... [optional] specify the behaviour if no matching placeholder could be found. Default is ."); + writer.println(" " + VALUE_PLACEHOLDER_MATCH_MODE_LENIENT + " ... sign in place of the first found placeholder, regardless if it matches exactly, or at the end of the document if none is found."); + writer.println(" " + VALUE_PLACEHOLDER_MATCH_MODE_MODERATE + " ... sign in place of the first found placeholder which has no explicit id set, or at the end of the document if none is found."); + writer.println(" " + VALUE_PLACEHOLDER_MATCH_MODE_STRICT + " ... throws a PlaceholderExtractionException."); writer.println(" OPTIONS for verification:"); writer.println(" " + PARAMETER_VERIFY_WHICH + " ... [optional] zero based number of the signature"); -- cgit v1.2.3