package com.eactive.eai.transformer;

public class SystemKeys {
	public static final String TRANSFROMER_BYTESMESSAGE_CHARSET = "transformer.bytesmessage.charset";
	public static final String TRANSFROMER_BYTESMESSAGE_CHARSET_DEFAULT        = "euc-kr";
	
	public static final String TRANSFROMER_STRING_TRIMEND        = "transformer.string.trimend";
	public static final String TRANSFROMER_VALIDATION            = "transformer.validation";
	public static final String TRANSFROMER_DECIMALPOINT_ADD      = "transformer.decimalpoint.add";
	public static final String TRANSFROMER_SCIENTIFIC_NORMALIZE    = "transformer.scientific.normalize";
	
	public static final String TRANSFROMER_LAYOUT_CACHE_INIT_ONSTARTUP = "transformer.layout.cache.init.onstartup";
	public static final String TRANSFROMER_LAYOUT_CACHE_SIZE     = "transformer.layout.cache.size";
	public static final String TRANSFROMER_LAYOUT_CACHE_IDLE_SEC = "transformer.layout.cache.idle.sec";
	public static final String TRANSFROMER_LAYOUT_PERMCACHE_SIZE     = "transformer.layout.permcache.size";
	
	public static final String TRANSFROMER_PARSER_CACHE_SIZE     = "transformer.parser.cache.size";
	
	public static final String LAYOUT_CACHE_SIZE_DEFAULT        = "400";
	public static final String LAYOUT_PERMCACHE_SIZE_DEFAULT    = "200";
	public static final String LAYOUT_CACHE_IDLE_DEFAULT        = "3600";  // 1시간
    public static final String TRANSFROMER_PARSER_CACHE_DEFAULT = "10000";
    
    public static final String TRANSFROMER_XML_CACHE_SIZE     = "transformer.xml.cache.size";
	public static final String TRANSFROMER_XML_CACHE_IDLE_SEC = "transformer.xml.cache.idle.sec";
	public static final String XML_CACHE_SIZE_DEFAULT        = "4000";
	public static final String XML_CACHE_IDLE_DEFAULT        = "3600";  // 1시간
    
	private static String bytesMessageCharset = TRANSFROMER_BYTESMESSAGE_CHARSET_DEFAULT;
	
	private static boolean stringTrimEnd = true;
	private static boolean validationEnabled = true;
	private static boolean addDecimalpoint = false;
	private static boolean scientificNormalize = true;
	
	private static boolean layoutCacheOnStartup = false;
	
	static {
		reload();
	}
	
	private SystemKeys() {
		
	}
	public static void reload() {
		// BytesMessage에 대한 cahrset
		bytesMessageCharset = System.getProperty(TRANSFROMER_BYTESMESSAGE_CHARSET, TRANSFROMER_BYTESMESSAGE_CHARSET_DEFAULT);
		
		String sBoolean = System.getProperty(TRANSFROMER_STRING_TRIMEND, "true");
		try {
			stringTrimEnd = Boolean.valueOf(sBoolean);
		} catch (Exception ex) {
			stringTrimEnd = true;
		}

		sBoolean = System.getProperty(TRANSFROMER_VALIDATION, "true");
		try {
			validationEnabled = Boolean.valueOf(sBoolean);
		} catch (Exception ex) {
			validationEnabled = true;
		}

		sBoolean = System.getProperty(TRANSFROMER_DECIMALPOINT_ADD, "false");
		try {
			addDecimalpoint = Boolean.valueOf(sBoolean);
		} catch (Exception ex) {
			addDecimalpoint = false;
		}

		sBoolean = System.getProperty(TRANSFROMER_SCIENTIFIC_NORMALIZE, "false");
		try {
			scientificNormalize = Boolean.valueOf(sBoolean);
		} catch (Exception ex) {
			scientificNormalize = false;
		}

		sBoolean = System.getProperty(TRANSFROMER_LAYOUT_CACHE_INIT_ONSTARTUP, "false");
		try {
			layoutCacheOnStartup = Boolean.valueOf(sBoolean);
		} catch (Exception ex) {
			layoutCacheOnStartup = false;
		}
	}
	
	public static String getBytesMessageCharset() {
		return bytesMessageCharset;
	}

	public static void setBytesMessageCharset(String bytesMessageCharset) {
		SystemKeys.bytesMessageCharset = bytesMessageCharset;
	}

	public static boolean isStringTrimEnd() {
		return stringTrimEnd;
	}

	public static boolean isValidationEnabled() {
		return validationEnabled;
	}

	public static boolean isAddDecimalPointEnabled() {
		return addDecimalpoint;
	}

	public static boolean isScientificNormalizeEnabled() {
		return scientificNormalize;
	}

	public static boolean isLayoutCacheOnStartup() {
		return layoutCacheOnStartup;
	}	
}
