From 6025b6016517c6d898d8957d1d7e03ba71431912 Mon Sep 17 00:00:00 2001 From: tknall Date: Fri, 1 Dec 2006 12:20:24 +0000 Subject: Initial import of release 2.2. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@4 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../wag/egov/egiz/sig/SignatureSeparator.java | 139 +++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureSeparator.java (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureSeparator.java') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureSeparator.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureSeparator.java new file mode 100644 index 0000000..3a210fa --- /dev/null +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureSeparator.java @@ -0,0 +1,139 @@ +/* + * + * 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: SignatureSeparator.java,v 1.4 2006/10/31 08:18:56 wprinz Exp $ + */ +package at.knowcenter.wag.egov.egiz.sig; + +import java.util.List; +import java.util.Stack; + +import at.knowcenter.wag.egov.egiz.exceptions.SignatureException; +import at.knowcenter.wag.egov.egiz.exceptions.SignatureTypesException; + +/** + * This class separates all signature blocks in a raw text. + */ +public class SignatureSeparator { + /** + * The signature block stack. On top of the stack is the first signature block that can be + * extracted. First means nearest to the document text. + */ + private Stack signatureBlocks_ = null; + /** + * A list of signature type definitions. + */ + private List signatureTypes_ = null; + /** + * Indicator that shows that a raw text is signated + */ + private boolean hasSignatureBlock_ = false; + + /** + * The empty constructor. It loads all signature type infos to extract the signature block from + * the raw text. + * + * @throws SignatureTypesException + */ + public SignatureSeparator() throws SignatureTypesException { + SignatureTypes sig_types = SignatureTypes.getInstance(); + signatureTypes_ = sig_types.getSignatureTypeDefinitions(); + } + + /** + * This method takes a raw text as input and trys to separate all signature blocks. It returns + * true if a signature block is found. + * + * @param rawText + * @return true if a signature block is found false otherwise + */ + public boolean separateBlock(String rawText) { + signatureBlocks_ = new Stack(); + hasSignatureBlock_ = separateBlock(rawText, rawText.length()); + return hasSignatureBlock_; + } + + /** + * This method calls itself rekursively while signature blocks can be extracted. If a signature + * block is found (search from the bottom of the raw text) the raw text would be reduced by the + * length of the found signature block text. + * + * @param rawText the text to be separated + * @param endIndex the index to cut the tail from the raw text + * @return true if a signature block is found false otherwise + */ + private boolean separateBlock(String rawText, int endIndex) { + boolean found = false; + boolean can_separate = true; + while (can_separate) { + SignatureBlock sig_block = new SignatureBlock(signatureTypes_); + String raw_text = rawText.substring(0, endIndex); + can_separate = sig_block.separateBlockFromRawText(raw_text, true); + if (can_separate) { + signatureBlocks_.push(sig_block); + endIndex = sig_block.getStartIndex(); + found = true; + } + } + return found; + } + + /** + * This method returns the start index of the first signature block. It is used to separate the + * real document text from the signature block texts. + * + * @return the start index of the first signature block + */ + public int getStartIndex() { + int start_index = -1; + if (signatureBlocks_ != null && signatureBlocks_.size() > 0) { + SignatureBlock sig_block = (SignatureBlock) signatureBlocks_.peek(); + return sig_block.getStartIndex(); + } + return start_index; + } + + /** + * @return the first found signature object in the given raw text or null if the raw text does not + * contain any signature objects + */ + public SignatureObject getFirstSignatureObject() { + if (signatureBlocks_ != null && signatureBlocks_.size() > 0) { + SignatureBlock sig_block = (SignatureBlock) signatureBlocks_.peek(); + try { + return sig_block.getSignatureObject(); + } catch (SignatureException e) { + return null; + } + } + return null; + } + + /** + * @return all separated signature blocks as stack, first is on top + */ + public Stack getSignatureBlocks() { + return signatureBlocks_; + } + + /** + * @return true if a signature block is found false otherwise + */ + public boolean hasSignatureBlock() { + return hasSignatureBlock_; + } +} \ No newline at end of file -- cgit v1.2.3