From 3a062705af6afa7937174ee46eb84146c4742ae2 Mon Sep 17 00:00:00 2001 From: tknall Date: Mon, 24 Jan 2011 20:30:53 +0000 Subject: - new reference configuration - maven2 repository updated git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@727 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../java/at/knowcenter/wag/egov/egiz/PdfAS.java | 148 ++++++++++----------- 1 file changed, 74 insertions(+), 74 deletions(-) (limited to 'src/main/java/at') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java index dca71ba..c23abc7 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java @@ -1,18 +1,18 @@ /** * Copyright (c) 2006 by Know-Center, Graz, Austria - * + * * This software is the confidential and proprietary information of Know-Center, * Graz, Austria. You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with Know-Center. - * + * * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. - * + * * $Id: PdfAS.java,v 1.5 2006/10/31 08:04:50 wprinz Exp $ */ package at.knowcenter.wag.egov.egiz; @@ -95,20 +95,20 @@ import com.lowagie.text.pdf.PdfReader; /** * This class contains the major methods used by both, the commandline and the * webapp, to perform signation and verification. - * + * * @author wprinz * @author mruhmer */ public abstract class PdfAS { //23.11.2010 changed by exthex - added method: verifyExtendedSignatureHolders(List extended_signature_info, String connectorType, boolean returnHashInputData, Date verificationTime) - + /** * The current version of the pdf-as library. This version string is logged on every invocation * of the api or the web application. */ - public static final String PDFAS_VERSION = "3.2-SNAPSHOT (20101203)"; - + public static final String PDFAS_VERSION = "3.2-SNAPSHOT (20110121)"; + /** * The key of the strict mode setting. */ @@ -128,7 +128,7 @@ public abstract class PdfAS * The Mime Type of a PDF document. */ public static final String PDF_MIME_TYPE = "application/pdf"; - + public static final String CORRECT_DOCUMENT_IF_NECESSARY_KEY = "correct_document_if_necessary"; /** @@ -138,7 +138,7 @@ public abstract class PdfAS /** * Tells, if strict PDF checking the PDF version is enabled. - * + * * @return Returns true, if incoming PDFs should be checked strictly. */ public static boolean isStrictPdfChecking() @@ -161,11 +161,11 @@ public abstract class PdfAS /** * Checks the version of the given PDF to be 1.4 or lower. - * + * *

* This scans the first 1000 bytes of the PDF for the pdf Header. *

- * + * * @param pdfDataSource * The PDF. * @return Returns true, if the given PDF is strict 1.4, false otherwise. @@ -198,17 +198,17 @@ public abstract class PdfAS /** * Applies strict version mode on the PDF and throws an exception, if the pdf * is not 1.4. - * + * *

* Furthermore (independently of strict mode) the PDF is checked for * parsability. *

- * + * * @param pdfDataSource * The pdf to be checked against strict mode. * @throws PDFDocumentException - * @throws SettingsException - * @throws CorrectorException + * @throws SettingsException + * @throws CorrectorException */ public static PdfDataSource applyStrictMode(PdfDataSource pdfDataSource) throws PDFDocumentException, SettingsException, CorrectorException { @@ -227,7 +227,7 @@ public abstract class PdfAS catch (Exception e) { log.debug("Error while parsing Document.", e); - + boolean tryToCorrect = SettingsReader.getInstance().getSetting(CORRECT_DOCUMENT_IF_NECESSARY_KEY, "false").equals("true"); if (!tryToCorrect) { @@ -237,13 +237,13 @@ public abstract class PdfAS Corrector cor = CorrectorFactory.createCorrector(); PdfDataSource correctedDS = cor.correctDocument(pdfDataSource); log.info("Correction finished."); - + return correctedDS; } - + return pdfDataSource; } - + public static at.gv.egiz.pdfas.api.io.DataSource applyStrictMode (at.gv.egiz.pdfas.api.io.DataSource dataSource) throws PDFDocumentException, SettingsException, CorrectorException { if (dataSource.getMimeType().equals("application/pdf")) @@ -315,7 +315,7 @@ public abstract class PdfAS /** * Extracts all signature blocks from the given raw text using textual mode. - * + * * @param raw_text * The raw text. * @return Returns a List of all SignatureHolders extracted from the text. @@ -351,7 +351,7 @@ public abstract class PdfAS /** * Extracts the last signature holder from the given text. - * + * * @param raw_text * @param old_style * @return Returns the found singature holder, or null, if none could be @@ -444,7 +444,7 @@ public abstract class PdfAS /** * Tries to find a block of the given type in the text. - * + * * @param text * The text. * @param sig_type_def @@ -488,7 +488,7 @@ public abstract class PdfAS { // try without /n found_index = text.lastIndexOf(caption); - + // fix #331 here ?? } log.debug("found key:" + caption + " at index:" + found_index); @@ -532,7 +532,7 @@ public abstract class PdfAS * Sorts the FoundKeys List descendingly according to the start indices of the * found keys (the first found key in the list will have the highest start * index, the second one the second highest and so forth). - * + * * @param found_keys * The List of FoundKey objects to be sorted. */ @@ -555,7 +555,7 @@ public abstract class PdfAS * Sorts the FoundKeys List ascendingly according to the start indices of the * found keys (the first found key in the list will have the lowest start * index, the second one the second lowest and so forth). - * + * * @param found_keys * The List of FoundKey objects to be sorted. */ @@ -576,12 +576,12 @@ public abstract class PdfAS /** * Checks that the found keys are in correct order regarding SIG_ID as * optional key. - * + * *

* If the SIG_ID key is misplaced, it will be removed from the found keys * list. *

- * + * * @param found_keys * The found keys ordered descendingly to their start position * @param profile_keys @@ -635,7 +635,7 @@ public abstract class PdfAS /** * Sorts out early blocks and leaves only those at the bottom of the text. - * + * * @param found_blocks * The found blocks. * @return Returns a list of the last blocks. @@ -673,7 +673,7 @@ public abstract class PdfAS /** * Sorts out large blocks. - * + * * @param found_blocks * The found blocks. * @return Returns a list of the smallest blocks. @@ -712,7 +712,7 @@ public abstract class PdfAS /** * Checks the list of blocks for semantic equality. - * + * * @param found_blocks * The list of found blocks. * @return Returns true if all blocks are semantically equal. @@ -758,7 +758,7 @@ public abstract class PdfAS /** * Checks the found keys for the required keys regarding the old style. - * + * * @param found_keys * The found keys. * @param old_style @@ -824,8 +824,8 @@ public abstract class PdfAS /** * Verify a list of signatures - * - * @param extended_signature_info a list of {@link ExtendedSignatureInformation} to be verified + * + * @param extended_signature_info a list of {@link ExtendedSignatureInformation} to be verified * @param connectorType the connector to use for verification * @param returnHashInputData * @param verificationTime @@ -857,7 +857,7 @@ public abstract class PdfAS /** * Verifies a SignatureHolder using the given connector. - * + * * @param signature_holder * The SignatureHolder to be verified. * @param connector @@ -869,8 +869,8 @@ public abstract class PdfAS * F.e. * @throws SignatureException * F.e. - * @throws ConnectorException - * @throws ConnectorFactoryException + * @throws ConnectorException + * @throws ConnectorFactoryException */ public static SignatureResponse verify(SignatureHolder signature_holder, String connectorType, boolean returnHashInputData, Date verificationTime, XMLDsigData dsig) throws NormalizeException, PDFDocumentException, SignatureException, ConnectorException, ConnectorFactoryException { @@ -907,7 +907,7 @@ public abstract class PdfAS String profile = so_to_be_verified.getSignatureTypeDefinition().getType(); // Connector c = ConnectorChooser.chooseCommandlineConnectorForVerify(connector, so_to_be_verified.getKZ(), so.id, profile); String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForVerify(connectorType, so_to_be_verified.getKZ(), so.id, profile); - + ConnectorParameters cp = new ConnectorParameters(); cp.setProfileId(profile); cp.setReturnHashInputData(returnHashInputData); @@ -919,7 +919,7 @@ public abstract class PdfAS private static SignatureResponse executeVerify(XMLDsigData dsig, SignSignatureObject so, SignatureData sd, Connector c) throws ConnectorException { - SignatureResponse res = null; + SignatureResponse res = null; try { return c.doVerify(sd, so, dsig); } catch (ConnectorException e) { @@ -929,10 +929,10 @@ public abstract class PdfAS } else { throw e; } - } + } return res; } - + public static SignatureResponse verifyWeb(SignatureHolder signature_holder, String connector, String loc_ref) throws NormalizeException, PDFDocumentException, SignatureException, ConnectorException { // String text_to_be_verified = signature_holder.getSignedText(); @@ -972,7 +972,7 @@ public abstract class PdfAS return executeVerify(null, so, sd, c); } - + public static SignatureData convertSignatureHolderToSignatureData(SignatureHolder signature_holder) { SignatureData sd = null; @@ -992,7 +992,7 @@ public abstract class PdfAS /** * Signs the given text with the provided connector using the given signature * type. - * + * * @param data_to_sign * The data to be signed. * @param signature_type @@ -1004,7 +1004,7 @@ public abstract class PdfAS * F.e. * @throws PDFDocumentException * F.e. - * @throws ConnectorException + * @throws ConnectorException */ public static SignSignatureObject sign(final SignatureData data_to_sign, final Connector connector, final TimeStamper timeStamper) throws SignatureException, PDFDocumentException, ConnectorException { @@ -1020,20 +1020,20 @@ public abstract class PdfAS // } SignSignatureObject signed_signature_object = connector.doSign(data_to_sign); - + // call timestamper if available - if (timeStamper != null) { + if (timeStamper != null) { log.debug("execute timestamping with stamper: " + timeStamper.getClass()); - signed_signature_object.sigTimeStamp = timeStamper.applyTimeStamp(signed_signature_object.getSignatureValue()); + signed_signature_object.sigTimeStamp = timeStamper.applyTimeStamp(signed_signature_object.getSignatureValue()); } - + return signed_signature_object; } /** * Helper method that creates a SignatureObject and initializes it with the * given type. - * + * * @param signature_type * The type. * @return Returns the created SignatureObject. @@ -1072,16 +1072,16 @@ public abstract class PdfAS // // Connector c = ConnectorChooser.chooseCommandlineConnectorForSign(connector, signature_type); // //// SignSignatureObject sso = sign(si.getSignatureData(), c); -//// +//// //// si.setSignSignatureObject(sso); //// //// signator.finishSign(si, dataSink); -// +// // String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForSign(connectorType); // // signCommandline(pdfDataSource, dataSink, signatorId, connectorId, profile, pos); // } - + public static SignatorInformation signCommandline(PdfDataSource pdfDataSource, DataSink dataSink, PdfASID signatorId, String connectorId, final String profile, final String signatureKeyIdentifier, TablePos pos, TimeStamper timeStamper, Properties overrideProps) throws PresentableException { try { @@ -1099,11 +1099,11 @@ public abstract class PdfAS SignatorInformation si = signator.prepareSign(pdfDataSource, profile, pos, timeStamper); SignSignatureObject sso = sign(si.getSignatureData(), c, timeStamper); - + si.setSignSignatureObject(sso); signator.finishSign(si, dataSink); - + return si; } finally { OverridePropertyHolder.removeProperties(); @@ -1117,7 +1117,7 @@ public abstract class PdfAS /** * Extracts and normalizes the text from the pdf. - * + * * @param pdf * The PDF document. * @return Returns the text String. @@ -1136,34 +1136,34 @@ public abstract class PdfAS /** - * + * * @param pdfDs * @return List of {@link NonTextObjectInfo} */ public static List extractNonTextualObjects(PdfDataSource pdfDs) { return ObjectExtractor.extractNonTextInfo(pdfDs); } - + /** * @deprecated * Use version with explicit encoding {@link PdfAS#extractNormalizedTextTextual(PdfDataSource, String)}. - * This one uses cp1252. - * + * This one uses cp1252. + * * @param pdfDataSource * @return * @throws PresentableException */ public static String extractNormalizedTextTextual(PdfDataSource pdfDataSource) throws PresentableException { return extractNormalizedTextTextual(pdfDataSource, "cp1252"); - + } - + public static String extractNormalizedTextTextual(PdfDataSource pdfDataSource, String encoding) throws PresentableException { String raw_document_text = TextualSignature.extractTextTextual(pdfDataSource, encoding); String document_text = normalizeText(raw_document_text); - return document_text; + return document_text; } /** @deprecated @@ -1173,7 +1173,7 @@ public abstract class PdfAS ByteArrayPdfDataSourceImpl pdfDataSource = new ByteArrayPdfDataSourceImpl(pdf, length); String raw_document_text = TextualSignature.extractTextTextual(pdfDataSource, "cp1252"); String document_text = normalizeText(raw_document_text); - return document_text; + return document_text; } // public static String extractNormalizedTextTextual(InputStream pdfInputStream, int length) throws PresentableException @@ -1181,11 +1181,11 @@ public abstract class PdfAS // DelimitedInputStream dis = new DelimitedInputStream(pdfInputStream, length); // String raw_document_text = TextualSignature.extractTextTextual(dis); // String document_text = normalizeText(raw_document_text); -// return document_text; +// return document_text; // } // /** // * Extracts and normalizes the text from the pdf. -// * +// * // * @param pdf // * The PDF document. // * @param length @@ -1209,7 +1209,7 @@ public abstract class PdfAS /** * Normalizes the given text. - * + * * @param text * The text to be normalized. * @return Returns the normalized text. @@ -1227,7 +1227,7 @@ public abstract class PdfAS /** * Creates the iText PDFPTable from a given SignatureObject. - * + * * @param signature_object * The SignatureObject. * @return Returns the created PDFPTable. @@ -1248,7 +1248,7 @@ public abstract class PdfAS /** * Evalutates absolute positioning and prepares the PositioningInstruction for * placing the table. - * + * * @param pos * The absolute positioning parameter. If null it is sought in the * profile definition. @@ -1287,7 +1287,7 @@ public abstract class PdfAS /** * Sets the width of the table according to the layout of the document and * calculates the y position where the PDFPTable should be placed. - * + * * @param pdf * The PDF document. * @param pdf_table @@ -1335,7 +1335,7 @@ public abstract class PdfAS float page_width = psize.getWidth(); float page_height = psize.getHeight(); - + // now we can calculate x-position float pre_pos_x = SIGNATURE_BORDER / 2; if (!pos.isXauto()) @@ -1426,7 +1426,7 @@ public abstract class PdfAS // /** // * Sets the width of the table according to the layout of the document and // * calculates the y position where the PDFPTable should be placed. -// * +// * // * @deprecated // * @param pdf // * The PDF document. @@ -1471,12 +1471,12 @@ public abstract class PdfAS // /** // * Sets the width of the table according to the layout of the document and // * calculates the y position where the PDFPTable should be placed. -// * +// * // *

// * This algorithm tries to position the table between the end of the text and // * the footer line. // *

-// * +// * // * @deprecated // * @param pdf // * The PDF document. @@ -1525,7 +1525,7 @@ public abstract class PdfAS * This is a convenience function for wrapping the Reader's exceptions into * PDFDocumentException. *

- * + * * @param pdf * The PDF document. * @return Returns the created PdfReader. @@ -1551,7 +1551,7 @@ public abstract class PdfAS /** * Parses the TablePos object from a given String with the appropriate format. - * + * * @param pos_string * The pos string. e.g. x:40.0;y:auto;w:auto;p:1;f:300.0 * @return Returns the parsed TablePos object. -- cgit v1.2.3