<commit_before>/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

package org.apache.airavata.registry.api.util;

import java.io.File;
import java.net.URL;
import java.util.Properties;

import org.apache.airavata.common.utils.AiravataUtils;
import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.registry.api.exception.RegistrySettingsException;
import org.apache.airavata.registry.api.exception.RegistrySettingsLoadException;
import org.apache.airavata.registry.api.exception.UnspecifiedRegistrySettingsException;

public class RegistrySettings {
    private static final String REPOSITORY_PROPERTIES = "registry.properties";
    private static final String SERVER_REPOSITORY_PROPERTIES = ServerSettings.REPOSITORY_PROPERTIES;
    private static final String CLIENT_REPOSITORY_PROPERTIES = "airavata-client.properties";
    private static Properties properties = new Properties();
    private static Exception propertyLoadException;
    private static final String REGISTRY_ACCESSOR_CLASS = "class.registry.accessor";
    
    static{
    	String propertyFileName = REPOSITORY_PROPERTIES;
    	if (!((new File(propertyFileName)).exists())) {
    		if (AiravataUtils.isServer()){
        		propertyFileName=SERVER_REPOSITORY_PROPERTIES;
        	}else{
        		propertyFileName=CLIENT_REPOSITORY_PROPERTIES;
        	}
		}
		URL url = RegistrySettings.class.getClassLoader()
				.getResource(propertyFileName);
        try {
            properties.load(url.openStream());
        } catch (Exception e) {
        	propertyLoadException=e;
        }
    }
    
    private static void validateSuccessfulPropertyFileLoad() throws RegistrySettingsException{
    	if (propertyLoadException!=null){
    		throw new RegistrySettingsLoadException(propertyLoadException);
    	}
    }
    
    public static String getSetting(String key) throws RegistrySettingsException{
    	validateSuccessfulPropertyFileLoad();
    	if (properties.containsKey(key)){
    		return properties.getProperty(key);
    	}
    	throw new UnspecifiedRegistrySettingsException(key);
    }<commit_msg>fixing error during startup with tomcat.<commit_after>/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

package org.apache.airavata.registry.api.util;

import java.io.File;
import java.net.URL;
import java.util.Properties;

import org.apache.airavata.common.utils.AiravataUtils;
import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.registry.api.exception.RegistrySettingsException;
import org.apache.airavata.registry.api.exception.RegistrySettingsLoadException;
import org.apache.airavata.registry.api.exception.UnspecifiedRegistrySettingsException;

public class RegistrySettings {
    private static final String REPOSITORY_PROPERTIES = "registry.properties";
    private static final String SERVER_REPOSITORY_PROPERTIES = ServerSettings.REPOSITORY_PROPERTIES;
    private static final String CLIENT_REPOSITORY_PROPERTIES = "airavata-client.properties";
    private static Properties properties = new Properties();
    private static Exception propertyLoadException;
    private static final String REGISTRY_ACCESSOR_CLASS = "class.registry.accessor";
    
    static{
    	String propertyFileName = REPOSITORY_PROPERTIES;
    	if (RegistrySettings.class.getClassLoader()
				.getResource(propertyFileName) == null) {
    		if (AiravataUtils.isServer()){
        		propertyFileName=SERVER_REPOSITORY_PROPERTIES;
        	}else{
        		propertyFileName=CLIENT_REPOSITORY_PROPERTIES;
        	}
		}
		URL url = RegistrySettings.class.getClassLoader()
				.getResource(propertyFileName);
        try {
            properties.load(url.openStream());
        } catch (Exception e) {
        	propertyLoadException=e;
        }
    }
    
    private static void validateSuccessfulPropertyFileLoad() throws RegistrySettingsException{
    	if (propertyLoadException!=null){
    		throw new RegistrySettingsLoadException(propertyLoadException);
    	}
    }
    
    public static String getSetting(String key) throws RegistrySettingsException{
    	validateSuccessfulPropertyFileLoad();
    	if (properties.containsKey(key)){
    		return properties.getProperty(key);
    	}
    	throw new UnspecifiedRegistrySettingsException(key);
    }
{'fraction_non_alphanumeric': 0.07454702329594479, 'fraction_numerical': 0.0013805004314063848, 'mean_word_length': 4.062008733624454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1896724', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1528, 'n_words': 438}