/** * Copyright 2006 by Know-Center, Graz, Austria * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a * joint initiative of the Federal Chancellery Austria and Graz University of * Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. * * $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. * @deprecated This process of separating signature blocks is obsolete - use AbsoluteTextSignature etc. instead. */ 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_; } }