All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adaptrex.core.AdaptrexConfig Maven / Gradle / Ivy

There is a newer version: 1.0-Alpha3
Show newest version
/*
 * Copyright 2012 Adaptrex, LLC
 *
 * Licensed 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 com.adaptrex.core;

import java.io.IOException;
import java.util.Properties;
import java.io.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * AdaptrexConfig provides configuration details for the current webapp or global 
 * configurations for all webapps.  Webapp specific configuration should be placed
 * at /WEB-INF/adaptrex.webapp.config and global configuration should be placed
 * in a file called adaptrex.config in the server classpath.
 */
public class AdaptrexConfig {
	
	public static final String WEBLIB					= "com.adaptrex.weblib.path";
	
	public static final String EXT_PATH					= "com.adaptrex.ext.path";
	public static final String EXT_THEME				= "com.adaptrex.ext.theme";
	public static final String EXT_BUILD				= "com.adaptrex.ext.build";
	public static final String EXT_VERSION				= "com.adaptrex.ext.version";
	public static final String EXT_NAMESPACE			= "com.adaptrex.ext.namespace";
	
	public static final String SENCHATOUCH_VERSION		= "com.adaptrex.senchatouch.version";
	public static final String SENCHATOUCH_PATH			= "com.adaptrex.senchatouch.path";

	public static final String DEBUG					= "com.adaptrex.debug";
	
	public static final String PERSISTENCE_ORM			= "com.adaptrex.persistence.orm";
	public static final String PERSISTENCE_ORM_DEFAULT	= "com.adaptrex.persistence.defaultfactory";
	
	private Properties properties = null;
	
    private Logger log = LoggerFactory.getLogger(AdaptrexConfig.class);

	public AdaptrexConfig() {
		properties = new Properties();
		
		/*
		 * First read the webapp properties
		 */
		ClassLoader loader = Thread.currentThread().getContextClassLoader();
		InputStream stream = loader.getResourceAsStream("adaptrex.properties");
		if (stream != null) {
			try {
				properties.load(stream);
				stream.close();
			} catch (Exception e) {}
		} else {
			log.info("Couldn't find adaptrex.properties");
		}
		
		/*
		 * Override with Java properties
		 */
		properties.putAll(System.getProperties());
	}
	
	public String get(String key) {
		return get(key, null);
	}
	
	public String get(String key, String def) {
		String v = properties.getProperty(key);
		return v != null ? v : def;
	}	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy