Package ninja.utils
Interface NinjaProperties
-
- All Known Implementing Classes:
NinjaPropertiesImpl
public interface NinjaProperties
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONF_FILE_LOCATION_BY_CONVENTION
The default configuration.static String
NINJA_EXTERNAL_CONF
Often you may want to use a separate configuration file.static String
NINJA_EXTERNAL_RELOAD
The System property used to enable hot-reloading of the external configuration file at runtime.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description String
get(String key)
Get a String property or null if it is not there...Properties
getAllCurrentNinjaProperties()
Boolean
getBoolean(String key)
Boolean
getBooleanOrDie(String key)
The "die" method forces this key to be set.Boolean
getBooleanWithDefault(String key, Boolean defaultValue)
Get a Boolean property or a default value when property cannot be found in any configuration file.String
getContextPath()
Returns context under which the application is currently running.Integer
getInteger(String key)
Get a property as Integer of null if not there / or property no integerInteger
getIntegerOrDie(String key)
The "die" method forces this key to be set.Integer
getIntegerWithDefault(String key, Integer defaultValue)
Get a Integer property or a default value when property cannot be found in any configuration file.String
getOrDie(String key)
The "die" method forces this key to be set.String[]
getStringArray(String key)
eg.String
getWithDefault(String key, String defaultValue)
Get a String property or a default value when property cannot be found in any configuration file.boolean
isDev()
Whether we are in dev modeboolean
isProd()
Whether we are in prod modeboolean
isTest()
Whether we are in test modevoid
setContextPath(String contextPath)
-
-
-
Field Detail
-
NINJA_EXTERNAL_CONF
static final String NINJA_EXTERNAL_CONF
Often you may want to use a separate configuration file. You can define the file to use in addition to your default config at conf/application.conf by setting NINJA_EXTERNAL_CONF as JVM system property. You must make sure that the specified file is on the classpath of the application. Eg servlet containers usually have a special directory that gets included into the classpath. That makes using different configurations for different environments quite simple. We don't use file IO to get the file because we would most likely run into security issues easily.- See Also:
- Constant Field Values
-
NINJA_EXTERNAL_RELOAD
static final String NINJA_EXTERNAL_RELOAD
The System property used to enable hot-reloading of the external configuration file at runtime.- See Also:
- Constant Field Values
-
CONF_FILE_LOCATION_BY_CONVENTION
static final String CONF_FILE_LOCATION_BY_CONVENTION
The default configuration. Make sure that file exists. Otherwise the application won't start up.- See Also:
- Constant Field Values
-
-
Method Detail
-
get
String get(String key)
Get a String property or null if it is not there...- Parameters:
key
-- Returns:
- the property of null if not there
-
getWithDefault
String getWithDefault(String key, String defaultValue)
Get a String property or a default value when property cannot be found in any configuration file.- Parameters:
key
- the key used in the configuration file.defaultValue
- Default value returned, when value cannot be found in configuration.- Returns:
- the value of the key or the default value.
-
getInteger
Integer getInteger(String key)
Get a property as Integer of null if not there / or property no integer- Parameters:
key
-- Returns:
- the property or null if not there or property no integer
-
getIntegerWithDefault
Integer getIntegerWithDefault(String key, Integer defaultValue)
Get a Integer property or a default value when property cannot be found in any configuration file.- Parameters:
key
- the key used in the configuration file.defaultValue
- Default value returned, when value cannot be found in configuration.- Returns:
- the value of the key or the default value.
-
getBoolean
Boolean getBoolean(String key)
- Parameters:
key
-- Returns:
- the property or null if not there or property no boolean
-
getBooleanWithDefault
Boolean getBooleanWithDefault(String key, Boolean defaultValue)
Get a Boolean property or a default value when property cannot be found in any configuration file.- Parameters:
key
- the key used in the configuration file.defaultValue
- Default value returned, when value cannot be found in configuration.- Returns:
- the value of the key or the default value.
-
getBooleanOrDie
Boolean getBooleanOrDie(String key)
The "die" method forces this key to be set. Otherwise a runtime exception will be thrown.- Parameters:
key
-- Returns:
- the boolean or a RuntimeException will be thrown.
-
getIntegerOrDie
Integer getIntegerOrDie(String key)
The "die" method forces this key to be set. Otherwise a runtime exception will be thrown.- Parameters:
key
-- Returns:
- the Integer or a RuntimeException will be thrown.
-
getOrDie
String getOrDie(String key)
The "die" method forces this key to be set. Otherwise a runtime exception will be thrown.- Parameters:
key
-- Returns:
- the String or a RuntimeException will be thrown.
-
getStringArray
String[] getStringArray(String key)
eg. key=myval1,myval2 Delimiter is a comma "," as outlined in the example above.- Returns:
- an array containing the values of that key or null if not found.
-
isDev
boolean isDev()
Whether we are in dev mode- Returns:
- True if we are in dev mode
-
isTest
boolean isTest()
Whether we are in test mode- Returns:
- True if we are in test mode
-
isProd
boolean isProd()
Whether we are in prod mode- Returns:
- True if we are in prod mode
-
getContextPath
String getContextPath()
Returns context under which the application is currently running. For instance on Java application servers it is common to use something like http://www.myserver.com/myapplication/index.html - where myapplication would be set by the application server. We need the context to generate for instance correct reversed routes.- Returns:
- The context or "" if empty.
-
setContextPath
void setContextPath(String contextPath)
-
getAllCurrentNinjaProperties
Properties getAllCurrentNinjaProperties()
- Returns:
- All properties that are currently loaded from internal and external files
-
-