at.knowcenter.wag.egov.egiz
Class PdfAS

java.lang.Object
  extended by at.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

Field Summary
static String PDF_MIME_TYPE
          The Mime Type of a PDF document.
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 adjustTableAndCalculatePosition(byte[] pdf, PdfPTable pdf_table)
          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 PositioningInstruction adjustTableAndCalculatePositionRegardingFooter(byte[] pdf, PdfPTable pdf_table, float footer_line)
          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 void applyStrictMode(byte[] pdf)
          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 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, byte[] pdf, PdfPTable pdf_table)
          Evalutates absolute positioning and prepares the PositioningInstruction for placing the table.
static String extractNormalizedTextTextual(byte[] pdf)
          Extracts and normalizes the text from the pdf.
static String extractNormalizedTextTextual(byte[] pdf, int length)
          Extracts and normalizes the text from the pdf.
static List extractSignatureHoldersTextual(String raw_text, boolean old_style)
          Extracts all signature blocks from the given raw text using textual mode.
static SignatureHolder 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(byte[] pdf)
          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 PdfReader readInPdfDocument(byte[] pdf)
          Creates an iText Reader that parses the document.
static SignResult sign(PdfASID algorithm, byte[] pdf, String signature_type, String connector, String user_name, String user_password, TablePos pos)
          Signs the document using the given algorithm.
static SignatureObject sign(String text_to_sign, String signature_type, String connector, String user_name, String user_password)
          Signs the given text with the provided connector using the given signature type.
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 connector)
          Verifies a SignatureHolder using the given connector.
static List verifyPdf(byte[] pdf, String connector)
          Verifies the given PDF document.
static List verifySignatureHolders(List signature_holders, String connector)
          Verifies the List of SignatureHolders using the given connector.
static List verifyText(String text, String connector)
          Verifies the given text that is supposed to be extracted from a PDF document using text extraction mechanisms.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
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(byte[] pdf)
                       throws PDFDocumentException
Checks the version of the given PDF to be 1.4 or lower.

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

applyStrictMode

public static void applyStrictMode(byte[] pdf)
                            throws PDFDocumentException
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:
pdf - The pdf to be checked against strict mode.
Throws:
PDFDocumentException

verifyPdf

public static List verifyPdf(byte[] pdf,
                             String connector)
                      throws PresentableException
Verifies the given PDF document.

Parameters:
pdf - The PDF document.
connector - The connector.
Returns:
Returns the List of results.
Throws:
PresentableException - Forwarded exception.

verifyText

public static List verifyText(String text,
                              String connector)
                       throws PresentableException
Verifies the given text that is supposed to be extracted from a PDF document using text extraction mechanisms.

Parameters:
text - The text to be verified.
connector - The connecor.
Returns:
Returns the List of results.
Throws:
PresentableException - Forwarded exception.

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 SignatureHolder 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 connector)
                                   throws PDFDocumentException,
                                          NormalizeException,
                                          SignatureException
Verifies the List of SignatureHolders using the given connector.

Parameters:
signature_holders - The List of SignatureHolder objects to be verified.
connector - The connector.
Returns:
Returns the List of SignatureResponse objects.
Throws:
PDFDocumentException - F.e.
NormalizeException - F.e.
SignatureException - F.e.

verify

public static SignatureResponse verify(SignatureHolder signature_holder,
                                       String connector)
                                throws NormalizeException,
                                       PDFDocumentException,
                                       SignatureException
Verifies a SignatureHolder using the given connector.

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

sign

public static SignatureObject sign(String text_to_sign,
                                   String signature_type,
                                   String connector,
                                   String user_name,
                                   String user_password)
                            throws SignatureException,
                                   PDFDocumentException
Signs the given text with the provided connector using the given signature type.

Parameters:
text_to_sign - The text String to be signed.
signature_type - The type of the signature.
connector - The connector.
user_name - The user name.
user_password - The user password.
Returns:
Returns the corresponding SignatureObject.
Throws:
SignatureException - F.e.
PDFDocumentException - F.e.

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.

sign

public static SignResult sign(PdfASID algorithm,
                              byte[] pdf,
                              String signature_type,
                              String connector,
                              String user_name,
                              String user_password,
                              TablePos pos)
                       throws PresentableException
Signs the document using the given algorithm.

Parameters:
algorithm - The Signator algorithm to be used.
pdf - The PDF.
signature_type - The signature type.
connector - The connector.
user_name - The user name.
user_password - The password.
pos - The absolute position. If null, the position is either taken from the profile or computed automatically.
Returns:
Returns the SignResult.
Throws:
PresentableException - F.e.

extractNormalizedTextTextual

public static String extractNormalizedTextTextual(byte[] pdf)
                                           throws PresentableException
Extracts and normalizes the text from the pdf.

Parameters:
pdf - The PDF document.
Returns:
Returns the text String.
Throws:
PresentableException - F.e.

extractNormalizedTextTextual

public static String extractNormalizedTextTextual(byte[] pdf,
                                                  int length)
                                           throws PresentableException
Extracts and normalizes the text from the pdf.

Parameters:
pdf - The PDF document.
length - The length of the PDF document. The decument is considered to be that long even if the byte array is longer.
Returns:
Returns the text String.
Throws:
PresentableException - F.e.

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 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,
                                                               byte[] 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 - The pdf.
pdf_table - The pdf table to be written.
Returns:
Returns the PositioningInformation.
Throws:
PDFDocumentException - F.e.
SettingsException - F.e.

adjustTableAndCalculatePosition

public static PositioningInstruction adjustTableAndCalculatePosition(byte[] pdf,
                                                                     PdfPTable pdf_table)
                                                              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 - The PDF document.
pdf_table - The PDFPTable to be placed.
Returns:
Returns the position where the PDFPTable should be placed.
Throws:
PDFDocumentException - F.e.

adjustTableAndCalculatePositionRegardingFooter

public static PositioningInstruction adjustTableAndCalculatePositionRegardingFooter(byte[] pdf,
                                                                                    PdfPTable pdf_table,
                                                                                    float footer_line)
                                                                             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.

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

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

readInPdfDocument

public static PdfReader readInPdfDocument(byte[] pdf)
                                   throws PDFDocumentException
Creates an iText Reader that parses the document.

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

Parameters:
pdf - The PDF document.
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. 1;40.0;600.0;300.0
Returns:
Returns the parsed TablePos object.
Throws:
PDFDocumentException - Thrown, if the String doesn't have the proper format.


Copyright © 2006-2007 EGIZ - E-Government Innovationszentrum. All Rights Reserved.