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 --- .../knowcenter/wag/egov/egiz/commandline/Main.java | 116 ++++++++------------- 1 file changed, 42 insertions(+), 74 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java') diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java index 1b66f53..0468160 100644 --- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java @@ -73,7 +73,7 @@ import at.knowcenter.wag.egov.egiz.sig.SignatureTypes; /** * The main program entry point of the commandline tool. - * + * * @author wprinz */ public abstract class Main @@ -156,18 +156,18 @@ public abstract class Main /** * Main program entry point. - * + * * @param args * The commandline arguments. * @throws IOException - * + * * @deprecated use {@link at.gv.egiz.pdfas.commandline.Main} instead */ public static void main(String[] args) throws IOException { System.out.println("\nWarning: The entry point at.knowcenter.wag.egov.egiz.commandline.Main is deprecated. Use at.gv.egiz.pdfas.commandline.Main instead.\n"); at.gv.egiz.pdfas.commandline.Main.main(args); } - + /* public static void main(String[] args) throws IOException { @@ -413,7 +413,7 @@ public abstract class Main catch (PresentableException e) { printPresentableException(e); - + if (output != null) { logger_.debug("Deleting output file on error."); @@ -451,10 +451,10 @@ public abstract class Main // } PrintWriter messageOutput = new PrintWriter(System.out); - - + + if (mode.equals(VALUE_MODE_SIGN)) - { + { carryOutSign(input, connector, signature_mode, signature_type, pos_string, user_name, user_password, output, messageOutput); } else @@ -468,22 +468,12 @@ public abstract class Main PrintWriter messageOutput) throws PresentableException { messageOutput.println("Signing..."); - - // for performance measurement - long startTime = 0; - long fileSize = 0; - if (logger_.isInfoEnabled()) { - startTime = System.currentTimeMillis(); - } PdfDataSource pdfDataSource; try { File file = new File(input); pdfDataSource = new FileBasedPdfDataSourceImpl(file, (int)file.length()); - if (logger_.isDebugEnabled()) - fileSize = file.length(); - } catch (IOException e) { @@ -495,7 +485,7 @@ public abstract class Main try { outputFile = new File(output); - + dataSink = new FileBasedDataSink(outputFile); } catch (IOException e) @@ -523,39 +513,23 @@ 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."); } public static void carryOutVerify(String input, String connector, int verify_which, PrintWriter messageOutput) throws PresentableException { messageOutput.println("Verifying..."); - - // 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")) { try { - FileInputStream fis = new FileInputStream(file); + FileInputStream fis = new FileInputStream(file); byte[] input_bytes = new byte[(int) file.length()]; fis.read(input_bytes); fis.close(); @@ -582,24 +556,16 @@ 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 @@ -664,14 +630,14 @@ public abstract class Main // } } // logger_.debug("Finally used sign algorithm = " + signatorId); - + String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForSign(connector); PdfAS.signCommandline(pdfDataSource, dataSink, signatorId, connectorId, signature_type, null, pos, null, null); // PdfAS.sign(algorithm, pdfDataSource, dataSink, signature_type, connector, pos); } - + public static List processVerify(DataSourceHolder dataSource, String connector, int verify_which) throws PresentableException { VerificationFilterParameters parameters = SettingsHelper.readVerificationFilterParametersFromSettings(); @@ -698,7 +664,7 @@ public abstract class Main holders_to_verify = new ArrayList(); holders_to_verify.add(holder); } - + List results = PdfAS.verifySignatureHolders(holders_to_verify, connector, false, null); return results; @@ -749,7 +715,7 @@ public abstract class Main /** * Prints that the provided option was unrecognized. - * + * * @param option * The unrecognized option. * @throws PresentableException @@ -763,7 +729,7 @@ public abstract class Main /** * Prints that the provided value was unrecognized. - * + * * @param parameter * The parameter, which is missing a value. * @throws PresentableException @@ -777,7 +743,7 @@ public abstract class Main /** * Prints that the provided value was unrecognized. - * + * * @param value * The unrecognized value. * @throws PresentableException @@ -791,7 +757,7 @@ public abstract class Main /** * Prints that the provided additional commandline argument was unrecognized. - * + * * @param argument * The unrecognized argument. * @throws PresentableException @@ -805,7 +771,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 @@ -820,7 +786,7 @@ public abstract class Main /** * Prints that something is missing. - * + * * @param missing_term * A descriptive message of the missing thing. * @throws PresentableException @@ -834,7 +800,7 @@ public abstract class Main /** * Prints out the ErrorCodeException in a descriptive form. - * + * * @param ece * The ErrorCodeException to be printed. */ @@ -868,7 +834,7 @@ public abstract class Main /** * Prints the usage text. - * + * * @param writer * The writer to print the text to. * @throws PresentableException @@ -920,7 +886,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()) { @@ -973,7 +941,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. @@ -985,7 +953,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. @@ -998,7 +966,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. @@ -1012,7 +980,7 @@ public abstract class Main /** * Checks the value for correctness. - * + * * @param signature_type * The parameter's value. * @return Returns true, if the value is correct, false otherwise. @@ -1020,8 +988,8 @@ public abstract class Main protected static boolean checkSignatureType(String signature_type) throws SignatureTypesException { return SignatureTypes.getInstance().getSignatureTypes().contains(signature_type); - - // exthex: uuuaaaahhhhh WHY??? wprinz again?, dont do that. Use List.contains(o), please + + // exthex: uuuaaaahhhhh WHY??? wprinz again?, dont do that. Use List.contains(o), please // take a java course and read: http://www.amazon.de/Java-f%C3%BCr-Dummies-Barry-Burd/dp/382662999X // List types_array = sig_types.getSignatureTypes(); // Iterator it = types_array.iterator(); @@ -1038,7 +1006,7 @@ public abstract class Main /** * Translates the commandline argument to a PDF-AS-ID. - * + * * @param signature_mode * The signator mode commandline argument. * @return Returns the corresponding PDFASID. @@ -1066,7 +1034,7 @@ public abstract class Main /** * Formats the verification results. - * + * * @param results * The List of SignatureResponse verification results. * @param writer @@ -1088,12 +1056,12 @@ 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 @@ -1106,16 +1074,16 @@ public abstract class Main while (it.hasNext()) { SignatureResponse result = (SignatureResponse) it.next(); - + toreturn += Integer.valueOf(result.getSignatureCheckCode()).intValue(); } return toreturn; } - + /** * Formats the SignatureResponse. - * + * * @param result * The SignatureResponse to be printed. * @param writer -- cgit v1.2.3