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

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

The 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.util.Properties;
import java.io.IOException;
import java.io.InputStream;

/**
 * AdaptrexProperties provides configuration details for the current webapp or global 
 * configurations for all webapps.  Webapp specific configuration should be placed
 * at /WEB-INF/adaptrex.properties.
 */
public class AdaptrexProperties {
	
	public static final String ADAPTREX_VERSION				= "com.adaptrex.core.version";

	public static final String EXT_FOLDER					= "com.adaptrex.extjs.folder";	
	public static final String EXT_THEME					= "com.adaptrex.extjs.theme";
	
	public static final String SENCHATOUCH					= "com.adaptrex.senchatouch";
	public static final String SENCHATOUCH_FOLDER			= "com.adaptrex.senchatouch.folder";
	public static final String SENCHATOUCH_THEME			= "com.adaptrex.senchatouch.theme";

	public static final String PERSISTENCE_ORM				= "com.adaptrex.persistence.orm";
	public static final String PERSISTENCE_DEFAULTFACTORY	= "com.adaptrex.persistence.defaultfactory";
	
	public static final String REST_PATH					= "com.adaptrex.rest.path";
	
	public static final String ENVIRONMENT					= "com.adaptrex.env";
	public static final String DEBUG						= "com.adaptrex.debug";
	public static final String WEBLIB_PATH					= "com.adaptrex.weblib.path";
	
	
	private Properties properties = null;
	
	public AdaptrexProperties() throws Exception {
		properties = new Properties();
		
		/*
		 * First read the webapp properties
		 */
		ClassLoader loader = Thread.currentThread().getContextClassLoader();
		InputStream stream = loader.getResourceAsStream("adaptrex.properties");
		if (stream == null) {
			throw new Exception("Could not find adaptrex.properties");
		}
		try {
			properties.load(stream);
			stream.close();
		} catch (IOException e) {
			throw new Exception("Could not find adaptrex.properties");
		}
		
		/*
		 * Overwrite/add JVM properties
		 */
		properties.putAll(System.getProperties());
		
		/*
		 * Get framework properties
		 */
		stream = loader.getResourceAsStream("META-INF/adaptrex.framework.properties");		
		if (stream == null) {
			throw new Exception("Could not find adaptrex.properties");
		}
		try {
			properties.load(stream);
			stream.close();
		} catch (IOException e) {
			throw new Exception("Could not find adaptrex.properties");
		}
	}
	
	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