<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.venky.swf.routing;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.logging.Logger;

import com.venky.cache.Cache;
import com.venky.core.log.SWFLogger;
import com.venky.core.string.StringUtil;
import com.venky.core.util.ObjectUtil;
import com.venky.core.util.PackageUtil;

/**
 *
 * @author venky
 */
public class Config {
	private Config(){
        properties = new Properties();

        Enumeration<URL> propertyFileUrls;
		try {
			propertyFileUrls = getClass().getClassLoader().getResources("config/swf.properties");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		
		
	    resourceBaseurls = new ArrayList<URL>();
	    while(propertyFileUrls.hasMoreElements()){
	    	URL url = propertyFileUrls.nextElement();
			try {
				Properties one = new Properties();
				one.load((InputStream)url.getContent());
				for (Object key : one.keySet()){
					String nValue = one.getProperty((String)key);
					String oValue = properties.getProperty((String)key);
					if (oValue == null){
						properties.put(key, nValue);
					}else {
						properties.put(key, oValue+","+nValue);
					}
				}
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			
            try {
                url = new URL(url.toString().substring(0,url.toString().length()-"config/swf.properties".length()));
            } catch (MalformedURLException ex) {
                throw new RuntimeException(ex);
            }
            resourceBaseurls.add(url);
	    }
	    properties.putAll(System.getProperties());
	    properties.putAll(System.getenv());
    }
    private Properties properties;
    private static Config _instance ;
    
    public static Config instance(){
        if (_instance != null){
            return _instance;
        }
        synchronized (Config.class){
            if (_instance == null) {
                _instance = new Config();
            }
        }
        return _instance;
    }
	public static void reset(){
		synchronized (Config.class) {
			_instance =null;
		}
	}	

	public String getHostName(){
    	return getProperty("swf.host","localhost");
	}
	public int getPortNumber(){
		String port =  getProperty("swf.port",getProperty("PORT","8080"));
		return Integer.valueOf(port);
	}
	
	public String getServerBaseUrl(){
		StringBuilder url = new StringBuilder().append("http://").append(getHostName());

		if (ObjectUtil.isVoid(getPortNumber()) || "80".equals(getPortNumber())){
			url.append(":").append(getPortNumber());
		}

		return url.toString();
	}
	public String getClientId(String opendIdProvider){
		return getProperty("swf."+opendIdProvider +".client.id");
	}
	public String getClientSecret(String opendIdProvider){
		return getProperty("swf."+opendIdProvider +".client.secret");
	}
	
    private List<URL> resourceBaseurls = null;
    public List<URL> getResourceBaseUrls(){
    	return resourceBaseurls;
    }
    
    public String getProperty(String name){
    	return getProperty(name,null); 
    }
    public String getProperty(String name,String defaultValue){
    	return properties.getProperty(name, defaultValue);<commit_msg>Server url allowed to be default<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.venky.swf.routing;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.logging.Logger;

import com.venky.cache.Cache;
import com.venky.core.log.SWFLogger;
import com.venky.core.string.StringUtil;
import com.venky.core.util.ObjectUtil;
import com.venky.core.util.PackageUtil;

/**
 *
 * @author venky
 */
public class Config {
	private Config(){
        properties = new Properties();

        Enumeration<URL> propertyFileUrls;
		try {
			propertyFileUrls = getClass().getClassLoader().getResources("config/swf.properties");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		
		
	    resourceBaseurls = new ArrayList<URL>();
	    while(propertyFileUrls.hasMoreElements()){
	    	URL url = propertyFileUrls.nextElement();
			try {
				Properties one = new Properties();
				one.load((InputStream)url.getContent());
				for (Object key : one.keySet()){
					String nValue = one.getProperty((String)key);
					String oValue = properties.getProperty((String)key);
					if (oValue == null){
						properties.put(key, nValue);
					}else {
						properties.put(key, oValue+","+nValue);
					}
				}
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			
            try {
                url = new URL(url.toString().substring(0,url.toString().length()-"config/swf.properties".length()));
            } catch (MalformedURLException ex) {
                throw new RuntimeException(ex);
            }
            resourceBaseurls.add(url);
	    }
	    properties.putAll(System.getProperties());
	    properties.putAll(System.getenv());
    }
    private Properties properties;
    private static Config _instance ;
    
    public static Config instance(){
        if (_instance != null){
            return _instance;
        }
        synchronized (Config.class){
            if (_instance == null) {
                _instance = new Config();
            }
        }
        return _instance;
    }
	public static void reset(){
		synchronized (Config.class) {
			_instance =null;
		}
	}	

	public String getHostName(){
    	return getProperty("swf.host","localhost");
	}
	public int getPortNumber(){
		String port =  getProperty("swf.port",getProperty("PORT","8080"));
		return Integer.valueOf(port);
	}
	
	public String getServerBaseUrl(){
		StringBuilder url = new StringBuilder().append("http://").append(getHostName());

		if (!ObjectUtil.isVoid(getPortNumber()) && !ObjectUtil.equals("80",getPortNumber())){
			url.append(":").append(getPortNumber());
		}

		return url.toString();
	}
	public String getClientId(String opendIdProvider){
		return getProperty("swf."+opendIdProvider +".client.id");
	}
	public String getClientSecret(String opendIdProvider){
		return getProperty("swf."+opendIdProvider +".client.secret");
	}
	
    private List<URL> resourceBaseurls = null;
    public List<URL> getResourceBaseUrls(){
    	return resourceBaseurls;
    }
    
    public String getProperty(String name){
    	return getProperty(name,null); 
    }
    public String getProperty(String name,String defaultValue){
    	return properties.getProperty(name, defaultValue);
{'fraction_non_alphanumeric': 0.12729039422543031, 'fraction_numerical': 0.001943364797334814, 'mean_word_length': 3.3299278846153846, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5996572', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2100, 'n_words': 454}