From db52e4d66d60184d53a27ba4d6772461daacc03d Mon Sep 17 00:00:00 2001 From: tknall Date: Fri, 22 Mar 2013 08:57:51 +0000 Subject: Maintenance update (bugfixes, new features, cleanup...) Refer to /dok/RELEASE_NOTES-3.3.txt for further information. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/pdf-as/trunk@931 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../java/at/gv/egiz/pdfas/commandline/Main.java | 123 +++++++++------------ 1 file changed, 50 insertions(+), 73 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/commandline/Main.java') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/commandline/Main.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/commandline/Main.java index 52355f8..d5f7e2f 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/commandline/Main.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/commandline/Main.java @@ -36,6 +36,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import org.apache.commons.lang.BooleanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -78,11 +79,11 @@ import at.knowcenter.wag.egov.egiz.sig.SignatureTypes; /** * The main program entry point of the commandline tool. - * + * *

* The commandline uses the PDF-AS API. *

- * + * * @author wprinz */ public abstract class Main @@ -127,12 +128,12 @@ public abstract class Main * Command line parameter signaling to search the source document for a placeholder for the signature */ protected static final String PARAMETER_PLACEHOLDER_SEARCH = "-searchplaceholder"; - + /** * 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 */ @@ -143,7 +144,7 @@ public abstract class Main * verified. */ protected static final String PARAMETER_VERIFY_WHICH = "-verify_which"; - + /** * Command line parameter that starts the deployment of the default configuration to the current * user's home folder. @@ -195,7 +196,7 @@ public abstract class Main * The placeholder match mode STRICT */ public static final String VALUE_PLACEHOLDER_MATCH_MODE_LENIENT = "lenient"; - + /** * The log. */ @@ -203,7 +204,7 @@ public abstract class Main /** * Main program entry point. - * + * * @param args * The commandline arguments. * @throws IOException @@ -216,7 +217,7 @@ public abstract class Main for (int i = 0; i < args.length; i++) { if (args[i].trim().equals(PARAMETER_DEPLOY_DEFAULT_CONFIGURATION)) { try { - String defaultConfigurationDeployedTo = ConfigUtils.deployDefaultConfiguration(); + String defaultConfigurationDeployedTo = ConfigUtils.deployDefaultConfiguration(); if (defaultConfigurationDeployedTo != null) { System.out.println("Default configuration successfully deployed to \"" + defaultConfigurationDeployedTo + "\"."); } else { @@ -229,7 +230,7 @@ public abstract class Main } catch (ConfigUtilsException e) { System.err.println("Deployment of default configuration failed: " + e.getMessage()); System.exit(1); - } + } } } @@ -247,7 +248,8 @@ public abstract class Main String user_password = null; String pos_string = null; - boolean search_placeholder = true; + // DTI: fixed searchplaceholder parameter handling preventing consideration of respective configuration parameter + Boolean searchPlaceHolder = null; String placeholderId = null; int placeholderMatchMode = Constants.PLACEHOLDER_MATCH_MODE_MODERATE; @@ -274,7 +276,7 @@ public abstract class Main // already applied continue; } - + if (cur_arg.equals(PARAMETER_MODE)) { i++; @@ -351,7 +353,8 @@ public abstract class Main printNoValue(PARAMETER_PLACEHOLDER_SEARCH); return; } - search_placeholder = Boolean.valueOf(args[i]).booleanValue(); +// search_placeholder = Boolean.valueOf(args[i]).booleanValue(); + searchPlaceHolder = BooleanUtils.toBooleanObject(args[i]); continue; } @@ -522,7 +525,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, search_placeholder, placeholderId, placeholderMatchMode); + carryOutCommand(mode, signature_mode, connector, signature_type, user_name, user_password, verify_which, input, output, pos_string, searchPlaceHolder, placeholderId, placeholderMatchMode); } catch (PdfAsException e) @@ -549,7 +552,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, boolean search_placeholder, String placeholderId, int placeholderMatchMode) throws PdfAsException + final int verify_which, final String input, String output, final String pos_string, Boolean searchPlaceHolder, String placeholderId, int placeholderMatchMode) throws PdfAsException { // File file = new File(input); // @@ -570,7 +573,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, search_placeholder, placeholderId, placeholderMatchMode); + carryOutSign(input, connector, signature_mode, signature_type, pos_string, user_name, user_password, output, messageOutput, searchPlaceHolder, placeholderId, placeholderMatchMode); } else { @@ -580,7 +583,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, boolean search_placeholder, String placeholderId, int placeholderMatchMode) throws PdfAsException + PrintWriter messageOutput, Boolean searchPlaceHolder, String placeholderId, int placeholderMatchMode) throws PdfAsException { messageOutput.println("Signing " + input + "..."); @@ -621,7 +624,7 @@ public abstract class Main } try { - processSign(dataSource, connector, signature_mode, signature_type, pos_string, search_placeholder, placeholderId, placeholderMatchMode, dataSink); + processSign(dataSource, connector, signature_mode, signature_type, pos_string, searchPlaceHolder, placeholderId, placeholderMatchMode, dataSink); } catch (Exception e) { // Exception caught in order to delete file based datasink if (outputFile != null && outputFile.exists()) @@ -641,14 +644,6 @@ public abstract class Main } } - // for performance measurement - if (logger_.isInfoEnabled()) - { - long endTime = System.currentTimeMillis(); - String toReport = "SIGN;" + signature_mode + ";" + input + ";" + fileSize + ";" + (endTime - startTime); - logger_.info(toReport); - } - messageOutput.println("Signing was successful (" + output + ")."); } @@ -656,22 +651,10 @@ public abstract class Main { messageOutput.println("Verifying " + input + "..."); - // for performance measurement - long startTime = 0; - long fileSize = 0; - if (logger_.isInfoEnabled()) - { - startTime = System.currentTimeMillis(); - } - DataSource dataSource = null; try { File file = new File(input); - if (logger_.isDebugEnabled()) - { - fileSize = file.length(); - } String extension = extractExtension(input); if (extension != null && extension.equals("txt")) { @@ -705,23 +688,15 @@ public abstract class Main messageOutput.println("Verification results:"); formatVerifyResults(results, messageOutput); - // for performance measurement - if (logger_.isInfoEnabled()) - { - long endTime = System.currentTimeMillis(); - String toReport = "VERIFY;" + input + ";" + fileSize + ";" + (endTime - startTime) + ";" + debugVerifyResults(results); - logger_.info(toReport); - } - } - + /** * Extracts the extension from a file name string. - * + * *

* The extension of a file name is whatever text follows the last '.'. *

- * + * * @param file_name * The file name. * @return Returns the extension. If the file name ends with the '.', then an @@ -743,7 +718,7 @@ public abstract class Main return file_name.substring(dot_index + 1); } - 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 + public static void processSign(DataSource dataSource, String connector, String signature_mode, String signature_type, String pos_string, Boolean searchPlaceHolder, String placeholderId, int placeholderMatchMode, DataSink dataSink) throws PdfAsException { TablePos pos = null; if (pos_string != null) @@ -795,7 +770,7 @@ public abstract class Main sp.setSignatureDevice(connector); sp.setSignatureProfileId(signature_type); sp.setSignaturePositioning(posi); - sp.setCheckForPlaceholder(search_placeholder); + sp.setCheckForPlaceholder(searchPlaceHolder); sp.setPlaceholderId(placeholderId); sp.setPlaceholderMatchMode(placeholderMatchMode); pdfAs.sign(sp); @@ -853,7 +828,7 @@ public abstract class Main /** * Prints that the provided option was unrecognized. - * + * * @param option * The unrecognized option. * @throws PresentableException @@ -867,7 +842,7 @@ public abstract class Main /** * Prints that the provided value was unrecognized. - * + * * @param parameter * The parameter, which is missing a value. * @throws PresentableException @@ -881,7 +856,7 @@ public abstract class Main /** * Prints that the provided value was unrecognized. - * + * * @param value * The unrecognized value. * @throws PresentableException @@ -895,7 +870,7 @@ public abstract class Main /** * Prints that the provided additional commandline argument was unrecognized. - * + * * @param argument * The unrecognized argument. * @throws PresentableException @@ -909,7 +884,7 @@ public abstract class Main /** * Prints that a certain parameter was missing. - * + * * @param missing_term * A description of the missing parameter ("e.g. a mode"). * @param parameter @@ -924,7 +899,7 @@ public abstract class Main /** * Prints that something is missing. - * + * * @param missing_term * A descriptive message of the missing thing. * @throws PresentableException @@ -938,7 +913,7 @@ public abstract class Main /** * Prints out the ErrorCodeException in a descriptive form. - * + * * @param ece * The ErrorCodeException to be printed. */ @@ -974,7 +949,7 @@ public abstract class Main /** * Prints the usage text. - * + * * @param writer * The writer to print the text to. * @throws PresentableException @@ -991,7 +966,7 @@ public abstract class Main writer.print(" " + PARAMETER_CONNECTOR + " "); ConnectorInformation[] ci = ConnectorFactory.getConnectorInformationArray(); - + // prepare list of connectors available for commandline ArrayList ciList = new ArrayList(); for (int i = 0; i < ci.length; i++) { @@ -1000,7 +975,7 @@ public abstract class Main ciList.add(ci[i]); } } - + // list available connectors wrapped in <...|...> Iterator ciIt = ciList.iterator(); writer.print("<"); @@ -1012,7 +987,7 @@ public abstract class Main } writer.print(">"); writer.println(); - + // for (int i = 0; i < ci.length; i++) // { // String id = ci[i].getIdentifier(); @@ -1046,7 +1021,7 @@ public abstract class Main writer.println(" " + PARAMETER_DEPLOY_DEFAULT_CONFIGURATION + " ... deploys the default configuration to the current user's home"); - writer.println(" OPTIONS for signation:"); + writer.println(" OPTIONS for signature:"); writer.println(" " + PARAMETER_SIGNATURE_MODE + " <" + VALUE_SIGNATURE_MODE_BINARY + "|" + VALUE_SIGNATURE_MODE_TEXTUAL + "> [optional]"); writer.println(" " + VALUE_SIGNATURE_MODE_BINARY + " ... signs the complete binary document" + (Constants.DEFAULT_SIGNATURE_TYPE.equals(VALUE_SIGNATURE_MODE_BINARY) ? " (default)" : "")); @@ -1056,7 +1031,9 @@ public abstract class Main writer.print(" " + PARAMETER_SIGNATURE_TYPE + " <"); SignatureTypes sig_types = SignatureTypes.getInstance(); SettingsReader settings = SettingsReader.getInstance(); - Set types_array = sig_types.getSignatureTypes(); + // show only signature profiles that can be used for signature +// Set types_array = sig_types.getSignatureTypes(); + Set types_array = sig_types.getSignatureTypesForSignature(); Iterator it = types_array.iterator(); while (it.hasNext()) { @@ -1117,7 +1094,7 @@ public abstract class Main /** * Checks the value for correctness. - * + * * @param mode * The parameter's value. * @return Returns true, if the value is correct, false otherwise. @@ -1129,7 +1106,7 @@ public abstract class Main /** * Checks the value for correctness. - * + * * @param signature_mode * The parameter's value. * @return Returns true, if the value is correct, false otherwise. @@ -1143,7 +1120,7 @@ public abstract class Main /** * Checks the value for correctness. - * + * * @param connector * The parameter's value. * @return Returns true, if the value is correct, false otherwise. @@ -1157,7 +1134,7 @@ public abstract class Main /** * Checks the value for correctness (meaning if it exists) - * + * * @param signature_type * The parameter's value. * @return Returns true, if the value is correct, false otherwise. @@ -1166,10 +1143,10 @@ public abstract class Main { return SignatureTypes.getInstance().getSignatureTypes().contains(signature_type); } - + /** * Translates the commandline argument to a PDF-AS-ID. - * + * * @param signature_mode * The signator mode commandline argument. * @return Returns the corresponding PDFASID. @@ -1197,7 +1174,7 @@ public abstract class Main /** * Formats the verification results. - * + * * @param results * The List of SignatureResponse verification results. * @param writer @@ -1223,9 +1200,9 @@ public abstract class Main /** * Formats the verification results for debugging. Returns 0 if no error * occurs or the sum of all error-codes. - * + * * @param results - * + * * @param writer * The output sink to write the formatted text to. * @throws SettingNotFoundException @@ -1259,7 +1236,7 @@ public abstract class Main String public_property = (String) it.next(); writer.println(" Eigenschaft: " + public_property); } - + writer.println(" Zertifikat-Check:"); writer.println(" " + result.getCertificateCheck().getCode() + " - " + result.getCertificateCheck().getMessage()); writer.println(" Signatur-Check:"); -- cgit v1.2.3