Package ninja.utils
Class NinjaPropertiesImpl
- java.lang.Object
-
- ninja.utils.NinjaPropertiesImpl
-
- All Implemented Interfaces:
NinjaProperties
public class NinjaPropertiesImpl extends Object implements NinjaProperties
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NinjaPropertiesImpl.Builder
-
Field Summary
-
Fields inherited from interface ninja.utils.NinjaProperties
CONF_FILE_LOCATION_BY_CONVENTION, NINJA_EXTERNAL_CONF, NINJA_EXTERNAL_RELOAD
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bindProperties(com.google.inject.Binder binder)
static NinjaPropertiesImpl.Builder
builder()
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()
Get the context path on which the application is running That means: - when running on root the context path is empty - when running on context there is NEVER a trailing slash We conform to the following rules: Returns the portion of the request URI that indicates the context of the request.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)
void
setProperty(String key, String value)
-
-
-
Method Detail
-
builder
public static NinjaPropertiesImpl.Builder builder()
-
get
public String get(String key)
Description copied from interface:NinjaProperties
Get a String property or null if it is not there...- Specified by:
get
in interfaceNinjaProperties
- Returns:
- the property of null if not there
-
getOrDie
public String getOrDie(String key)
Description copied from interface:NinjaProperties
The "die" method forces this key to be set. Otherwise a runtime exception will be thrown.- Specified by:
getOrDie
in interfaceNinjaProperties
- Returns:
- the String or a RuntimeException will be thrown.
-
getInteger
public Integer getInteger(String key)
Description copied from interface:NinjaProperties
Get a property as Integer of null if not there / or property no integer- Specified by:
getInteger
in interfaceNinjaProperties
- Returns:
- the property or null if not there or property no integer
-
getIntegerOrDie
public Integer getIntegerOrDie(String key)
Description copied from interface:NinjaProperties
The "die" method forces this key to be set. Otherwise a runtime exception will be thrown.- Specified by:
getIntegerOrDie
in interfaceNinjaProperties
- Returns:
- the Integer or a RuntimeException will be thrown.
-
getBooleanOrDie
public Boolean getBooleanOrDie(String key)
Description copied from interface:NinjaProperties
The "die" method forces this key to be set. Otherwise a runtime exception will be thrown.- Specified by:
getBooleanOrDie
in interfaceNinjaProperties
- Returns:
- the boolean or a RuntimeException will be thrown.
-
getBoolean
public Boolean getBoolean(String key)
- Specified by:
getBoolean
in interfaceNinjaProperties
- Returns:
- the property or null if not there or property no boolean
-
bindProperties
public void bindProperties(com.google.inject.Binder binder)
-
isProd
public boolean isProd()
Description copied from interface:NinjaProperties
Whether we are in prod mode- Specified by:
isProd
in interfaceNinjaProperties
- Returns:
- True if we are in prod mode
-
isDev
public boolean isDev()
Description copied from interface:NinjaProperties
Whether we are in dev mode- Specified by:
isDev
in interfaceNinjaProperties
- Returns:
- True if we are in dev mode
-
isTest
public boolean isTest()
Description copied from interface:NinjaProperties
Whether we are in test mode- Specified by:
isTest
in interfaceNinjaProperties
- Returns:
- True if we are in test mode
-
getContextPath
public String getContextPath()
Get the context path on which the application is running That means: - when running on root the context path is empty - when running on context there is NEVER a trailing slash We conform to the following rules: Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string. As outlined by: http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getContextPath()- Specified by:
getContextPath
in interfaceNinjaProperties
- Returns:
- the context-path with a leading "/" or "" if running on root
-
setContextPath
public void setContextPath(String contextPath)
- Specified by:
setContextPath
in interfaceNinjaProperties
-
getAllCurrentNinjaProperties
public Properties getAllCurrentNinjaProperties()
- Specified by:
getAllCurrentNinjaProperties
in interfaceNinjaProperties
- Returns:
- All properties that are currently loaded from internal and external files
-
getStringArray
public String[] getStringArray(String key)
Description copied from interface:NinjaProperties
eg. key=myval1,myval2 Delimiter is a comma "," as outlined in the example above.- Specified by:
getStringArray
in interfaceNinjaProperties
- Returns:
- an array containing the values of that key or null if not found.
-
getWithDefault
public String getWithDefault(String key, String defaultValue)
Description copied from interface:NinjaProperties
Get a String property or a default value when property cannot be found in any configuration file.- Specified by:
getWithDefault
in interfaceNinjaProperties
- 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.
-
getIntegerWithDefault
public Integer getIntegerWithDefault(String key, Integer defaultValue)
Description copied from interface:NinjaProperties
Get a Integer property or a default value when property cannot be found in any configuration file.- Specified by:
getIntegerWithDefault
in interfaceNinjaProperties
- 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.
-
getBooleanWithDefault
public Boolean getBooleanWithDefault(String key, Boolean defaultValue)
Description copied from interface:NinjaProperties
Get a Boolean property or a default value when property cannot be found in any configuration file.- Specified by:
getBooleanWithDefault
in interfaceNinjaProperties
- 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.
-
-