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 classNinjaPropertiesImpl.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 voidbindProperties(com.google.inject.Binder binder)static NinjaPropertiesImpl.Builderbuilder()Stringget(String key)Get a String property or null if it is not there...PropertiesgetAllCurrentNinjaProperties()BooleangetBoolean(String key)BooleangetBooleanOrDie(String key)The "die" method forces this key to be set.BooleangetBooleanWithDefault(String key, Boolean defaultValue)Get a Boolean property or a default value when property cannot be found in any configuration file.StringgetContextPath()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.IntegergetInteger(String key)Get a property as Integer of null if not there / or property no integerIntegergetIntegerOrDie(String key)The "die" method forces this key to be set.IntegergetIntegerWithDefault(String key, Integer defaultValue)Get a Integer property or a default value when property cannot be found in any configuration file.StringgetOrDie(String key)The "die" method forces this key to be set.String[]getStringArray(String key)eg.StringgetWithDefault(String key, String defaultValue)Get a String property or a default value when property cannot be found in any configuration file.booleanisDev()Whether we are in dev modebooleanisProd()Whether we are in prod modebooleanisTest()Whether we are in test modevoidsetContextPath(String contextPath)voidsetProperty(String key, String value)
-
-
-
Method Detail
-
builder
public static NinjaPropertiesImpl.Builder builder()
-
get
public String get(String key)
Description copied from interface:NinjaPropertiesGet a String property or null if it is not there...- Specified by:
getin interfaceNinjaProperties- Returns:
- the property of null if not there
-
getOrDie
public String getOrDie(String key)
Description copied from interface:NinjaPropertiesThe "die" method forces this key to be set. Otherwise a runtime exception will be thrown.- Specified by:
getOrDiein interfaceNinjaProperties- Returns:
- the String or a RuntimeException will be thrown.
-
getInteger
public Integer getInteger(String key)
Description copied from interface:NinjaPropertiesGet a property as Integer of null if not there / or property no integer- Specified by:
getIntegerin interfaceNinjaProperties- Returns:
- the property or null if not there or property no integer
-
getIntegerOrDie
public Integer getIntegerOrDie(String key)
Description copied from interface:NinjaPropertiesThe "die" method forces this key to be set. Otherwise a runtime exception will be thrown.- Specified by:
getIntegerOrDiein interfaceNinjaProperties- Returns:
- the Integer or a RuntimeException will be thrown.
-
getBooleanOrDie
public Boolean getBooleanOrDie(String key)
Description copied from interface:NinjaPropertiesThe "die" method forces this key to be set. Otherwise a runtime exception will be thrown.- Specified by:
getBooleanOrDiein interfaceNinjaProperties- Returns:
- the boolean or a RuntimeException will be thrown.
-
getBoolean
public Boolean getBoolean(String key)
- Specified by:
getBooleanin 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:NinjaPropertiesWhether we are in prod mode- Specified by:
isProdin interfaceNinjaProperties- Returns:
- True if we are in prod mode
-
isDev
public boolean isDev()
Description copied from interface:NinjaPropertiesWhether we are in dev mode- Specified by:
isDevin interfaceNinjaProperties- Returns:
- True if we are in dev mode
-
isTest
public boolean isTest()
Description copied from interface:NinjaPropertiesWhether we are in test mode- Specified by:
isTestin 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:
getContextPathin interfaceNinjaProperties- Returns:
- the context-path with a leading "/" or "" if running on root
-
setContextPath
public void setContextPath(String contextPath)
- Specified by:
setContextPathin interfaceNinjaProperties
-
getAllCurrentNinjaProperties
public Properties getAllCurrentNinjaProperties()
- Specified by:
getAllCurrentNinjaPropertiesin interfaceNinjaProperties- Returns:
- All properties that are currently loaded from internal and external files
-
getStringArray
public String[] getStringArray(String key)
Description copied from interface:NinjaPropertieseg. key=myval1,myval2 Delimiter is a comma "," as outlined in the example above.- Specified by:
getStringArrayin 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:NinjaPropertiesGet a String property or a default value when property cannot be found in any configuration file.- Specified by:
getWithDefaultin 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:NinjaPropertiesGet a Integer property or a default value when property cannot be found in any configuration file.- Specified by:
getIntegerWithDefaultin 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:NinjaPropertiesGet a Boolean property or a default value when property cannot be found in any configuration file.- Specified by:
getBooleanWithDefaultin 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.
-
-