at.knowcenter.wag.egov.egiz
Class PdfAS

java.lang.Object
  extended byat.knowcenter.wag.egov.egiz.PdfAS

public abstract class PdfAS
extends Object

This class contains the major methods used by both, the commandline and the webapp, to perform signation and verification.

Author:
wprinz, mruhmer

Field Summary
static String CORRECT_DOCUMENT_IF_NECESSARY_KEY
           
static String PDF_MIME_TYPE
          The Mime Type of a PDF document.
static String PDFAS_VERSION
          The current version of the pdf-as library.
static float SIGNATURE_BORDER
          The left/right border.
static float SIGNATURE_MARGIN
          The top/bottom border.
static String STRICT_MODE_KEY
          The key of the strict mode setting.
 
Constructor Summary
PdfAS()
           
 
Method Summary
static PositioningInstruction adjustSignatureTableandCalculatePosition(PdfDataSource pdfDataSource, com.lowagie.text.pdf.PdfPTable pdf_table, TablePos pos)
          Sets the width of the table according to the layout of the document and calculates the y position where the PDFPTable should be placed.
static DataSource applyStrictMode(DataSource dataSource)
           
static PdfDataSource applyStrictMode(PdfDataSource pdfDataSource)
          Applies strict version mode on the PDF and throws an exception, if the pdf is not 1.4.
static boolean checkForSemanticEquality(List found_blocks)
          Checks the list of blocks for semantic equality.
static boolean checkFoundRequiredKeys(List found_keys, boolean old_style)
          Checks the found keys for the required keys regarding the old style.
static boolean checkThatOrderIsCorrectAndCorrectFoundKeys(List found_keys, List profile_keys, boolean old_style)
          Checks that the found keys are in correct order regarding SIG_ID as optional key.
static boolean containsFoundKey(List found_keys, String key)
           
static SignatureData convertSignatureHolderToSignatureData(SignatureHolder signature_holder)
           
static com.lowagie.text.pdf.PdfPTable createPdfPTableFromSignatureObject(SignatureObject signature_object)
          Creates the iText PDFPTable from a given SignatureObject.
static SignatureObject createSignatureObjectFromType(String signature_type)
          Helper method that creates a SignatureObject and initializes it with the given type.
static PositioningInstruction determineTablePositioning(TablePos pos, String signature_type, PdfDataSource pdfDataSource, com.lowagie.text.pdf.PdfPTable pdf_table)
          Evalutates absolute positioning and prepares the PositioningInstruction for placing the table.
static List extractNonTextualObjects(PdfDataSource pdfDs)
           
static String extractNormalizedTextTextual(byte[] pdf, int length)
          Deprecated.  
static String extractNormalizedTextTextual(PdfDataSource pdfDataSource)
          Deprecated. Use version with explicit encoding extractNormalizedTextTextual(PdfDataSource, String). This one uses cp1252.
static String extractNormalizedTextTextual(PdfDataSource pdfDataSource, String encoding)
           
static List extractSignatureHoldersTextual(String raw_text, boolean old_style)
          Extracts all signature blocks from the given raw text using textual mode.
static TextualSignatureHolder extractSignatureHolderTextual(String raw_text, boolean old_style)
          Extracts the last signature holder from the given text.
static List findBlockInText(String text, SignatureTypeDefinition sig_type_def, boolean old_style)
          Tries to find a block of the given type in the text.
static int getIndexOfFoundKey(List found_keys, String key)
           
static boolean isPdf14(PdfDataSource pdfDataSource)
          Checks the version of the given PDF to be 1.4 or lower.
static boolean isStrictPdfChecking()
          Tells, if strict PDF checking the PDF version is enabled.
static String normalizeText(String text)
          Normalizes the given text.
static TablePos parsePositionFromPosString(String pos_string)
          Parses the TablePos object from a given String with the appropriate format.
static com.lowagie.text.pdf.PdfReader readInPdfDocument(PdfDataSource pdfDataSource)
          Creates an iText Reader that parses the document.
static SignSignatureObject sign(SignatureData data_to_sign, Connector connector, TimeStamper timeStamper)
          Signs the given text with the provided connector using the given signature type.
static SignatorInformation signCommandline(PdfDataSource pdfDataSource, DataSink dataSink, PdfASID signatorId, String connectorId, String profile, String signatureKeyIdentifier, TablePos pos, TimeStamper timeStamper)
           
static SignatorInformation signCommandline(PdfDataSource pdfDataSource, DataSink dataSink, PdfASID signatorId, String connectorId, String profile, TablePos pos)
           
static void sortFoundKeysAscendingly(List found_keys)
          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).
static void sortFoundKeysDescendingly(List found_keys)
          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).
static List sortOutEarlyBlocks(List found_blocks)
          Sorts out early blocks and leaves only those at the bottom of the text.
static List sortOutLargeBlocks(List found_blocks)
          Sorts out large blocks.
static SignatureResponse verify(SignatureHolder signature_holder, String connectorType, boolean returnHashInputData, Date verificationTime)
          Verifies a SignatureHolder using the given connector.
static List verifySignatureHolders(List signature_holders, String connectorType, boolean returnHashInputData, Date verificationTime)
           
static List verifySignatureHoldersWeb(List signature_holders, VerifySessionInformation si, String loc_ref)
           
static SignatureResponse verifyWeb(SignatureHolder signature_holder, String connector, String loc_ref)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PDFAS_VERSION

public static final String PDFAS_VERSION
The current version of the pdf-as library. This version string is logged on every invocation of the api or the web application.

See Also:
Constant Field Values

STRICT_MODE_KEY

public static final String STRICT_MODE_KEY
The key of the strict mode setting.

See Also:
Constant Field Values

SIGNATURE_BORDER

public static final float SIGNATURE_BORDER
The left/right border.

See Also:
Constant Field Values

SIGNATURE_MARGIN

public static final float SIGNATURE_MARGIN
The top/bottom border.

See Also:
Constant Field Values

PDF_MIME_TYPE

public static final String PDF_MIME_TYPE
The Mime Type of a PDF document.

See Also:
Constant Field Values

CORRECT_DOCUMENT_IF_NECESSARY_KEY

public static final String CORRECT_DOCUMENT_IF_NECESSARY_KEY
See Also:
Constant Field Values
Constructor Detail

PdfAS

public PdfAS()
Method Detail

isStrictPdfChecking

public static boolean isStrictPdfChecking()
Tells, if strict PDF checking the PDF version is enabled.

Returns:
Returns true, if incoming PDFs should be checked strictly.

isPdf14

public static boolean isPdf14(PdfDataSource pdfDataSource)
                       throws PDFDocumentException
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.

Parameters:
pdfDataSource - The PDF.
Returns:
Returns true, if the given PDF is strict 1.4, false otherwise.
Throws:
PDFDocumentException - Forwarded exception.

applyStrictMode

public static PdfDataSource applyStrictMode(PdfDataSource pdfDataSource)
                                     throws PDFDocumentException,
                                            SettingsException,
                                            CorrectorException
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.

Parameters:
pdfDataSource - The pdf to be checked against strict mode.
Throws:
PDFDocumentException
SettingsException
CorrectorException

applyStrictMode

public static DataSource applyStrictMode(DataSource dataSource)
                                  throws PDFDocumentException,
                                         SettingsException,
                                         CorrectorException
Throws:
PDFDocumentException
SettingsException
CorrectorException

extractSignatureHoldersTextual

public static List extractSignatureHoldersTextual(String raw_text,
                                                  boolean old_style)
                                           throws PDFDocumentException,
                                                  SignatureException,
                                                  SignatureTypesException,
                                                  NormalizeException
Extracts all signature blocks from the given raw text using textual mode.

Parameters:
raw_text - The raw text.
Returns:
Returns a List of all SignatureHolders extracted from the text.
Throws:
PDFDocumentException - F.e.
SignatureException - F.e.
SignatureTypesException
NormalizeException

extractSignatureHolderTextual

public static TextualSignatureHolder extractSignatureHolderTextual(String raw_text,
                                                                   boolean old_style)
                                                            throws SignatureException,
                                                                   SignatureTypesException,
                                                                   NormalizeException
Extracts the last signature holder from the given text.

Parameters:
raw_text -
old_style -
Returns:
Returns the found singature holder, or null, if none could be found.
Throws:
SignatureException
SignatureTypesException
NormalizeException

findBlockInText

public static List findBlockInText(String text,
                                   SignatureTypeDefinition sig_type_def,
                                   boolean old_style)
Tries to find a block of the given type in the text.

Parameters:
text - The text.
sig_type_def - The type of the block.
old_style - Tells, if the block is old style (SIG_KZ will be ignored), or if it is a new block.
Returns:
Returns a List of the found keys of the block, or null, if the block could not be found.

sortFoundKeysDescendingly

public static void sortFoundKeysDescendingly(List found_keys)
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).

Parameters:
found_keys - The List of FoundKey objects to be sorted.

sortFoundKeysAscendingly

public static void sortFoundKeysAscendingly(List found_keys)
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).

Parameters:
found_keys - The List of FoundKey objects to be sorted.

checkThatOrderIsCorrectAndCorrectFoundKeys

public static boolean checkThatOrderIsCorrectAndCorrectFoundKeys(List found_keys,
                                                                 List profile_keys,
                                                                 boolean old_style)
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.

Parameters:
found_keys - The found keys ordered descendingly to their start position
profile_keys - The profile keys.
old_style - Tells, if SIG_KZ should be ignored, or not.
Returns:
Returns true, if the keys are correct.

sortOutEarlyBlocks

public static List sortOutEarlyBlocks(List found_blocks)
Sorts out early blocks and leaves only those at the bottom of the text.

Parameters:
found_blocks - The found blocks.
Returns:
Returns a list of the last blocks.

sortOutLargeBlocks

public static List sortOutLargeBlocks(List found_blocks)
Sorts out large blocks.

Parameters:
found_blocks - The found blocks.
Returns:
Returns a list of the smallest blocks.

checkForSemanticEquality

public static boolean checkForSemanticEquality(List found_blocks)
Checks the list of blocks for semantic equality.

Parameters:
found_blocks - The list of found blocks.
Returns:
Returns true if all blocks are semantically equal.

getIndexOfFoundKey

public static int getIndexOfFoundKey(List found_keys,
                                     String key)

containsFoundKey

public static boolean containsFoundKey(List found_keys,
                                       String key)

checkFoundRequiredKeys

public static boolean checkFoundRequiredKeys(List found_keys,
                                             boolean old_style)
Checks the found keys for the required keys regarding the old style.

Parameters:
found_keys - The found keys.
old_style - Flag that tells, if KZ is not required.
Returns:
Returns true, if all required keys were found.

verifySignatureHolders

public static List verifySignatureHolders(List signature_holders,
                                          String connectorType,
                                          boolean returnHashInputData,
                                          Date verificationTime)
                                   throws PDFDocumentException,
                                          NormalizeException,
                                          SignatureException,
                                          ConnectorException,
                                          ConnectorFactoryException
Throws:
PDFDocumentException
NormalizeException
SignatureException
ConnectorException
ConnectorFactoryException

verifySignatureHoldersWeb

public static List verifySignatureHoldersWeb(List signature_holders,
                                             VerifySessionInformation si,
                                             String loc_ref)
                                      throws PDFDocumentException,
                                             NormalizeException,
                                             SignatureException,
                                             ConnectorException
Throws:
PDFDocumentException
NormalizeException
SignatureException
ConnectorException

verify

public static SignatureResponse verify(SignatureHolder signature_holder,
                                       String connectorType,
                                       boolean returnHashInputData,
                                       Date verificationTime)
                                throws NormalizeException,
                                       PDFDocumentException,
                                       SignatureException,
                                       ConnectorException,
                                       ConnectorFactoryException
Verifies a SignatureHolder using the given connector.

Parameters:
signature_holder - The SignatureHolder to be verified.
Returns:
Returns the SignatureResponse object.
Throws:
NormalizeException - F.e.
PDFDocumentException - F.e.
SignatureException - F.e.
ConnectorException
ConnectorFactoryException

verifyWeb

public static SignatureResponse verifyWeb(SignatureHolder signature_holder,
                                          String connector,
                                          String loc_ref)
                                   throws NormalizeException,
                                          PDFDocumentException,
                                          SignatureException,
                                          ConnectorException
Throws:
NormalizeException
PDFDocumentException
SignatureException
ConnectorException

convertSignatureHolderToSignatureData

public static SignatureData convertSignatureHolderToSignatureData(SignatureHolder signature_holder)

sign

public static SignSignatureObject sign(SignatureData data_to_sign,
                                       Connector connector,
                                       TimeStamper timeStamper)
                                throws SignatureException,
                                       PDFDocumentException,
                                       ConnectorException
Signs the given text with the provided connector using the given signature type.

Parameters:
data_to_sign - The data to be signed.
connector - The connector.
Returns:
Returns the corresponding SignatureObject.
Throws:
SignatureException - F.e.
PDFDocumentException - F.e.
ConnectorException

createSignatureObjectFromType

public static SignatureObject createSignatureObjectFromType(String signature_type)
                                                     throws SignatureException,
                                                            SignatureTypesException
Helper method that creates a SignatureObject and initializes it with the given type.

Parameters:
signature_type - The type.
Returns:
Returns the created SignatureObject.
Throws:
SignatureException - f.e.
SignatureTypesException - f.e.

signCommandline

public static SignatorInformation signCommandline(PdfDataSource pdfDataSource,
                                                  DataSink dataSink,
                                                  PdfASID signatorId,
                                                  String connectorId,
                                                  String profile,
                                                  String signatureKeyIdentifier,
                                                  TablePos pos,
                                                  TimeStamper timeStamper)
                                           throws PresentableException
Throws:
PresentableException

signCommandline

public static SignatorInformation signCommandline(PdfDataSource pdfDataSource,
                                                  DataSink dataSink,
                                                  PdfASID signatorId,
                                                  String connectorId,
                                                  String profile,
                                                  TablePos pos)
                                           throws PresentableException
Throws:
PresentableException

extractNonTextualObjects

public static List extractNonTextualObjects(PdfDataSource pdfDs)
Parameters:
pdfDs -
Returns:
List of NonTextObjectInfo

extractNormalizedTextTextual

public static String extractNormalizedTextTextual(PdfDataSource pdfDataSource)
                                           throws PresentableException
Deprecated. Use version with explicit encoding extractNormalizedTextTextual(PdfDataSource, String). This one uses cp1252.

Parameters:
pdfDataSource -
Returns:
Throws:
PresentableException

extractNormalizedTextTextual

public static String extractNormalizedTextTextual(PdfDataSource pdfDataSource,
                                                  String encoding)
                                           throws PresentableException
Throws:
PresentableException

extractNormalizedTextTextual

public static String extractNormalizedTextTextual(byte[] pdf,
                                                  int length)
                                           throws PresentableException
Deprecated.  

Throws:
PresentableException

normalizeText

public static String normalizeText(String text)
                            throws NormalizeException
Normalizes the given text.

Parameters:
text - The text to be normalized.
Returns:
Returns the normalized text.
Throws:
NormalizeException - F.e.

createPdfPTableFromSignatureObject

public static com.lowagie.text.pdf.PdfPTable createPdfPTableFromSignatureObject(SignatureObject signature_object)
                                                                         throws PDFDocumentException,
                                                                                SignatureException
Creates the iText PDFPTable from a given SignatureObject.

Parameters:
signature_object - The SignatureObject.
Returns:
Returns the created PDFPTable.
Throws:
PDFDocumentException - F.e.
SignatureException - F.e.

determineTablePositioning

public static PositioningInstruction determineTablePositioning(TablePos pos,
                                                               String signature_type,
                                                               PdfDataSource pdfDataSource,
                                                               com.lowagie.text.pdf.PdfPTable pdf_table)
                                                        throws PDFDocumentException,
                                                               SettingsException
Evalutates absolute positioning and prepares the PositioningInstruction for placing the table.

Parameters:
pos - The absolute positioning parameter. If null it is sought in the profile definition.
signature_type - The profile definition of the table to be written.
pdf_table - The pdf table to be written.
Returns:
Returns the PositioningInformation.
Throws:
PDFDocumentException - F.e.
SettingsException - F.e.

adjustSignatureTableandCalculatePosition

public static PositioningInstruction adjustSignatureTableandCalculatePosition(PdfDataSource pdfDataSource,
                                                                              com.lowagie.text.pdf.PdfPTable pdf_table,
                                                                              TablePos pos)
                                                                       throws PDFDocumentException
Sets the width of the table according to the layout of the document and calculates the y position where the PDFPTable should be placed.

Parameters:
pdf_table - The PDFPTable to be placed.
Returns:
Returns the position where the PDFPTable should be placed.
Throws:
PDFDocumentException - F.e.

readInPdfDocument

public static com.lowagie.text.pdf.PdfReader readInPdfDocument(PdfDataSource pdfDataSource)
                                                        throws PDFDocumentException
Creates an iText Reader that parses the document.

This is a convenience function for wrapping the Reader's exceptions into PDFDocumentException.

Returns:
Returns the created PdfReader.
Throws:
PDFDocumentException - F.e.

parsePositionFromPosString

public static TablePos parsePositionFromPosString(String pos_string)
                                           throws PDFDocumentException
Parses the TablePos object from a given String with the appropriate format.

Parameters:
pos_string - The pos string. e.g. x:40.0;y:auto;w:auto;p:1;f:300.0
Returns:
Returns the parsed TablePos object.
Throws:
PDFDocumentException - Thrown, if the String doesn't have the proper format.


Copyright © 2006-2010. All Rights Reserved.