/* * 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: SignatureTypes.java,v 1.5 2006/10/31 08:18:56 wprinz Exp $ */ package at.knowcenter.wag.egov.egiz.sig; import java.awt.Color; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Vector; import org.apache.log4j.Logger; import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger; import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; import at.knowcenter.wag.egov.egiz.exceptions.SignatureException; import at.knowcenter.wag.egov.egiz.exceptions.SignatureTypesException; import at.knowcenter.wag.egov.egiz.table.Style; import at.knowcenter.wag.exactparser.ByteArrayUtils; public class SignatureTypes { /** * The settings key prefix for signature definitions. "sig_obj." */ public static final String SIG_OBJ = "sig_obj."; /** * The settings key prefix for signature object types */ public static final String TYPES = SIG_OBJ + "types"; /** * The settings key prefix for the default signature object type */ public static final String DEFAULT_TYPE = SIG_OBJ + "type.default"; /** * The settings key postfix for the type description */ public static final String SIG_DESCR = "description"; /** * The state value activating an signature definition */ private static final String STATE_ON = "on"; // /** // * The state value de activating an signature definition // */ // private static final String STATE_OFF = "off"; /** * The settings key prefix for the signature table object definition */ public static final String TABLE = "table."; /** * The settings key sub prefix getting the main table definition */ public static final String MAIN_TABLE = "main"; /** * The settings value refering to a table */ public final static String TYPE_TABLE = "TABLE"; /** * The settings value refering to an image */ public final static String TYPE_IMAGE = "i"; /** * The settings value refering to a text caption */ public final static String TYPE_CAPTION = "c"; /** * The settings value refering to a text value */ public final static String TYPE_VALUE = "v"; /** * The settings key sub prefix getting the width of columns for a table * definition */ public final static String COLS_WITH = "ColsWidth"; /** * The settings key sub prefix getting the style definition */ public final static String STYLE = "Style"; /** * The default style definition for images. */ private Style defaultImageStyle_ = new Style(); /** * The default style definition for captions. */ private Style defaultCaptionStyle_ = new Style(); /** * The default style definition for values. */ private Style defaultValueStyle_ = new Style(); /** * Standard key get/set the singature name */ public static final String SIG_NAME = "SIG_NAME"; /** * Standard key get/set the signature date */ public static final String SIG_DATE = "SIG_DATE"; /** * Standard key get/set the signator issuer */ public static final String SIG_ISSUER = "SIG_ISSUER"; /** * Standard key get/set the siganture value */ public static final String SIG_VALUE = "SIG_VALUE"; /** * Standard key get/set the normalisation method used */ public static final String SIG_NORM = "SIG_NORM"; /** * Standard key get/set the signation id's used by BKU signated documents */ public static final String SIG_ID = "SIG_ID"; /** * The EGIZ Algorithm "Kennzeichnung". */ public static final String SIG_KZ = "SIG_KZ"; /** * Standard key get/set the reference to the signature label (image mark) */ public static final String SIG_LABEL = "SIG_LABEL"; /** * Standard key get/set the serial number of the signature */ public static final String SIG_NUMBER = "SIG_NUMBER"; // public static final String SIG_TYPE = "SIG_TYPE"; /** * Standard key get/set the signature meta informations */ public static final String SIG_META = "SIG_META"; /** * The logger definition. */ private static final Logger logger_ = ConfigLogger.getLogger(SignatureTypes.class); // /** // * The normalizer reference // */ // private Normalizer normalizer_ = null; /** * The settings reader reference */ private SettingsReader settings_ = null; // /** // * The reference to the settings property tree // */ // private PropertyTree pTree_ = null; // /** // * The current signature type used reading and analysing the property tree // */ // private String sigType_ = null; // /** // * List of all keys used in the current signature definition // */ // private ArrayList sigKeys_ = null; /** * Array of required signature keys */ // public static String[] REQUIRED_SIG_KEYS = new String[]{SIG_NAME, SIG_DATE, // SIG_ISSUER, SIG_VALUE, SIG_NUMBER, SIG_ID}; public static String[] REQUIRED_SIG_KEYS = new String[] { SIG_DATE, SIG_ISSUER, SIG_VALUE, SIG_NUMBER, SIG_ID }; /** * Tells, if the given key is a required key. *

* Note that the SIG_KZ is a required key. *

* @param key The key to be tested if it is a required key. * @return Returns true, if the key is required, false otherwise. */ public static boolean isRequiredKey (String key) { if (key.equals(SIG_KZ)) { return true; } for (int i = 0; i < REQUIRED_SIG_KEYS.length; i++) { if (key.equals(REQUIRED_SIG_KEYS[i])) { return true; } } return false; } public static String[] ALL_SIG_KEYS = new String[] { SIG_NAME, SIG_DATE, SIG_ISSUER, SIG_VALUE, SIG_NORM, SIG_ID, SIG_LABEL, SIG_NUMBER, SIG_META }; public static byte [][] ALL_SIG_BREV = new byte[][] { { 'n', 'a', 'm' }, { 'd', 'a', 't' }, { 'i', 's', 's' }, { 'v', 'a', 'l' }, { 'n', 'o', 'r' }, { 's', 'i', 'd' }, { 'l', 'a', 'b' }, { 's', 'n', 'r' }, { 'm', 'e', 't' } }; // /** // * Sorted representation of keys defined in rows // */ // private ArrayList sortedSigKeys_ = new ArrayList(); // /** // * Reference from signature key to there corresponding value // */ // private Hashtable sigEntries_ = new Hashtable(8); /** * A list of all configured signature type definitions */ private List signatureTypeDefinitions_ = new Vector(); /** * A type-name to type-definition map */ private Map typeDefMap_ = new HashMap(); // /** // * A map of required keys used to reconstruct a signature block // */ // private static HashMap requiredSigKeys_ = new HashMap(); /** * A plain list of signature type names */ ArrayList typeList_ = new ArrayList(4); /** * Used as singleton to read the singnature type definitions only one times of * a session */ private static SignatureTypes instance_ = null; /** * This is the private constructor method to provide a singleton instance of * this class. It inits a normalizer, the settings reader, read the default * styles and load the configured signature types. * * @throws SignatureTypesException * @see SettingsReader */ private SignatureTypes() throws SignatureTypesException { try { loadSettings(); } catch (SettingsException e) { throw new SignatureTypesException(e); } setDefaultStyles(); loadSignatureTypes(); } /** * This static method returns the stored instance of this class. If the * singleton does not exist, this method creates a new singleton and gives * this instance back to the caller. * * @return the stored instance of this class * @throws SignatureTypesException */ public static SignatureTypes getInstance() throws SignatureTypesException { if (instance_ == null) { instance_ = new SignatureTypes(); } return instance_; } /** * This method load the signature definitions * * @throws SettingsException * * @throws SettingsException * ErrorCode:101 */ private void loadSettings() throws SettingsException { if (settings_ == null) { settings_ = SettingsReader.getInstance(); } // pTree_ = settings_.getPTree(); } /** * This method set the default styles for images, captions and values. */ private void setDefaultStyles() { defaultImageStyle_.setPadding(3); defaultImageStyle_.setHAlign(Style.CENTER); defaultImageStyle_.setVAlign(Style.MIDDLE); defaultImageStyle_.setBgColor(new Color(255, 255, 255)); defaultCaptionStyle_.setHAlign(Style.CENTER); defaultCaptionStyle_.setVAlign(Style.MIDDLE); defaultValueStyle_.setVAlign(Style.MIDDLE); } /** * This method load the configured signature types. It stores the definition * representations only if the type is set to ON. It stores the type * definition object, the definition map and the simple type name list. */ private void loadSignatureTypes() { if (settings_ != null) { ArrayList types = settings_.getKeys(TYPES); for (int type_idx = 0; type_idx < types.size(); type_idx++) { String type = (String) types.get(type_idx); if (STATE_ON.equals(settings_.getSetting(TYPES + "." + type, null))) { SignatureTypeDefinition sig_type_def; try { sig_type_def = new SignatureTypeDefinition(settings_, type); signatureTypeDefinitions_.add(sig_type_def); typeDefMap_.put(type, sig_type_def); typeList_.add(type); } catch (SignatureException e) { if (logger_.isDebugEnabled()) { logger_.debug(e.getMessage()); } e.printStackTrace(); } } } } } /** * @return a arrayList (String) of signature types */ public ArrayList getSignatureTypes() { return typeList_; } /** * @return a list of signature type definitions */ public List getSignatureTypeDefinitions() { return signatureTypeDefinitions_; } /** * This method returns the corresponding signature type definition to a given * type key * * @param type * the key to get the signature type definition * @return the stored signature type definition */ public SignatureTypeDefinition getSignatureTypeDefinition(String type) { return (SignatureTypeDefinition) typeDefMap_.get(type); } public static String convertBrevToType (final byte [] brev) { for (int i = 0; i < ALL_SIG_BREV.length; i++) { if (ByteArrayUtils.compareByteArrays(ALL_SIG_BREV[i], 0, brev)) { return ALL_SIG_KEYS[i]; } } return null; } public static byte [] convertTypeToBrev (final String type) { for (int i = 0; i < ALL_SIG_KEYS.length; i++) { if (ALL_SIG_KEYS.equals(type)) { return ALL_SIG_BREV[i]; } } return null; } /** * The standard toString method. Used for testing only. * * @return the string representation of the class */ public String toString() { String strg = ""; for (int i = 0; i < signatureTypeDefinitions_.size(); i++) { SignatureTypeDefinition std = (SignatureTypeDefinition) signatureTypeDefinitions_.get(i); strg += "----------TYPE:" + std.getType() + "----------\n"; strg += std.toString(); } return strg; } }