Class StringLookupFactory
- java.lang.Object
-
- org.apache.commons.text.lookup.StringLookupFactory
-
public final class StringLookupFactory extends Object
Provides access to lookups defined in this package.The default lookups are:
- Since:
- 1.3
-
-
Field Summary
Fields Modifier and Type Field Description static StringLookupFactoryINSTANCEDefines the singleton for this class.static StringKEY_BASE64_DECODERDefault lookup key for interpolation.static StringKEY_BASE64_ENCODERDefault lookup key for interpolation.static StringKEY_CONSTDefault lookup key for interpolation.static StringKEY_DATEDefault lookup key for interpolation.static StringKEY_ENVDefault lookup key for interpolation.static StringKEY_FILEDefault lookup key for interpolation.static StringKEY_JAVADefault lookup key for interpolation.static StringKEY_LOCALHOSTDefault lookup key for interpolation.static StringKEY_PROPERTIESDefault lookup key for interpolation.static StringKEY_RESOURCE_BUNDLEDefault lookup key for interpolation.static StringKEY_SCRIPTDefault lookup key for interpolation.static StringKEY_SYSDefault lookup key for interpolation.static StringKEY_URLDefault lookup key for interpolation.static StringKEY_URL_DECODERDefault lookup key for interpolation.static StringKEY_URL_ENCODERDefault lookup key for interpolation.static StringKEY_XMLDefault lookup key for interpolation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddDefaultStringLookups(Map<String,StringLookup> stringLookupMap)Adds thedefault lookups.StringLookupbase64DecoderStringLookup()Returns the Base64StringLookup singleton instance to format the current date with the format given in the key in a format compatible withSimpleDateFormat.StringLookupbase64EncoderStringLookup()Returns the Base64StringLookup singleton instance to format the current date with the format given in the key in a format compatible withSimpleDateFormat.StringLookupbase64StringLookup()Deprecated.static voidclear()Clears any static resources.StringLookupconstantStringLookup()Returns the ConstantStringLookup singleton instance to get the value of a fully-qualified static final value.StringLookupdateStringLookup()Returns the DateStringLookup singleton instance to format the current date with the format given in the key in a format compatible withSimpleDateFormat.StringLookupenvironmentVariableStringLookup()Returns the EnvironmentVariableStringLookup singleton instance where the lookup key is an environment variable name.StringLookupfileStringLookup()Returns the FileStringLookup singleton instance.StringLookupinterpolatorStringLookup()Returns a new InterpolatorStringLookup using thedefault lookups.StringLookupinterpolatorStringLookup(Map<String,StringLookup> stringLookupMap, StringLookup defaultStringLookup, boolean addDefaultLookups)Returns a new InterpolatorStringLookup using thedefault lookups.<V> StringLookupinterpolatorStringLookup(Map<String,V> map)Returns a new InterpolatorStringLookup using thedefault lookups.StringLookupinterpolatorStringLookup(StringLookup defaultStringLookup)Returns a new InterpolatorStringLookup using thedefault lookups.StringLookupjavaPlatformStringLookup()Returns the JavaPlatformStringLookup singleton instance.StringLookuplocalHostStringLookup()Returns the LocalHostStringLookup singleton instance where the lookup key is one of: name: for the local host name, for exampleEXAMPLE. canonical-name: for the local canonical host name, for exampleEXAMPLE.apache.org. address: for the local host address, for example192.168.56.1.<V> StringLookupmapStringLookup(Map<String,V> map)Returns a new map-based lookup where the request for a lookup is answered with the value for that key.StringLookupnullStringLookup()Returns the NullStringLookup singleton instance which always returns null.StringLookuppropertiesStringLookup()Returns the PropertiesStringLookup singleton instance.StringLookupresourceBundleStringLookup()Returns the ResourceBundleStringLookup singleton instance.StringLookupresourceBundleStringLookup(String bundleName)Returns a ResourceBundleStringLookup instance for the given bundle name.StringLookupscriptStringLookup()Returns the ScriptStringLookup singleton instance.StringLookupsystemPropertyStringLookup()Returns the SystemPropertyStringLookup singleton instance where the lookup key is a system property name.StringLookupurlDecoderStringLookup()Returns the UrlDecoderStringLookup singleton instance.StringLookupurlEncoderStringLookup()Returns the UrlDecoderStringLookup singleton instance.StringLookupurlStringLookup()Returns the UrlStringLookup singleton instance.StringLookupxmlStringLookup()Returns the XmlStringLookup singleton instance.
-
-
-
Field Detail
-
INSTANCE
public static final StringLookupFactory INSTANCE
Defines the singleton for this class.
-
KEY_BASE64_DECODER
public static final String KEY_BASE64_DECODER
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_BASE64_ENCODER
public static final String KEY_BASE64_ENCODER
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_CONST
public static final String KEY_CONST
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_DATE
public static final String KEY_DATE
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_ENV
public static final String KEY_ENV
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_FILE
public static final String KEY_FILE
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_JAVA
public static final String KEY_JAVA
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_LOCALHOST
public static final String KEY_LOCALHOST
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_PROPERTIES
public static final String KEY_PROPERTIES
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_RESOURCE_BUNDLE
public static final String KEY_RESOURCE_BUNDLE
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_SCRIPT
public static final String KEY_SCRIPT
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_SYS
public static final String KEY_SYS
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_URL
public static final String KEY_URL
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_URL_DECODER
public static final String KEY_URL_DECODER
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_URL_ENCODER
public static final String KEY_URL_ENCODER
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
KEY_XML
public static final String KEY_XML
Default lookup key for interpolation.- Since:
- 1.6
- See Also:
- Constant Field Values
-
-
Method Detail
-
clear
public static void clear()
Clears any static resources.- Since:
- 1.5
-
addDefaultStringLookups
public void addDefaultStringLookups(Map<String,StringLookup> stringLookupMap)
Adds thedefault lookups.- Parameters:
stringLookupMap- the map of string lookups.- Since:
- 1.5
-
base64DecoderStringLookup
public StringLookup base64DecoderStringLookup()
Returns the Base64StringLookup singleton instance to format the current date with the format given in the key in a format compatible withSimpleDateFormat.- Returns:
- the DateStringLookup singleton instance.
- Since:
- 1.5
-
base64EncoderStringLookup
public StringLookup base64EncoderStringLookup()
Returns the Base64StringLookup singleton instance to format the current date with the format given in the key in a format compatible withSimpleDateFormat.- Returns:
- the DateStringLookup singleton instance.
- Since:
- 1.6
-
base64StringLookup
@Deprecated public StringLookup base64StringLookup()
Deprecated.Returns the Base64StringLookup singleton instance to format the current date with the format given in the key in a format compatible withSimpleDateFormat.- Returns:
- the DateStringLookup singleton instance.
- Since:
- 1.5
-
constantStringLookup
public StringLookup constantStringLookup()
Returns the ConstantStringLookup singleton instance to get the value of a fully-qualified static final value.- Returns:
- the DateStringLookup singleton instance.
- Since:
- 1.5
-
dateStringLookup
public StringLookup dateStringLookup()
Returns the DateStringLookup singleton instance to format the current date with the format given in the key in a format compatible withSimpleDateFormat.- Returns:
- the DateStringLookup singleton instance.
-
environmentVariableStringLookup
public StringLookup environmentVariableStringLookup()
Returns the EnvironmentVariableStringLookup singleton instance where the lookup key is an environment variable name.- Returns:
- the EnvironmentVariableStringLookup singleton instance.
-
fileStringLookup
public StringLookup fileStringLookup()
Returns the FileStringLookup singleton instance.Looks up the value for the key in the format "CharsetName:Path".
For example: "UTF-8:com/domain/document.properties".
- Returns:
- the FileStringLookup singleton instance.
- Since:
- 1.5
-
interpolatorStringLookup
public StringLookup interpolatorStringLookup()
Returns a new InterpolatorStringLookup using thedefault lookups.- Returns:
- a new InterpolatorStringLookup.
-
interpolatorStringLookup
public StringLookup interpolatorStringLookup(Map<String,StringLookup> stringLookupMap, StringLookup defaultStringLookup, boolean addDefaultLookups)
Returns a new InterpolatorStringLookup using thedefault lookups.If
addDefaultLookupsis true, the following lookups are used in addition to the ones provided instringLookupMap:- Parameters:
stringLookupMap- the map of string lookups.defaultStringLookup- the default string lookup.addDefaultLookups- whether to use lookups as described above.- Returns:
- a new InterpolatorStringLookup.
- Since:
- 1.4
-
interpolatorStringLookup
public <V> StringLookup interpolatorStringLookup(Map<String,V> map)
Returns a new InterpolatorStringLookup using thedefault lookups.- Type Parameters:
V- the value type the default string lookup's map.- Parameters:
map- the default map for string lookups.- Returns:
- a new InterpolatorStringLookup.
-
interpolatorStringLookup
public StringLookup interpolatorStringLookup(StringLookup defaultStringLookup)
Returns a new InterpolatorStringLookup using thedefault lookups.- Parameters:
defaultStringLookup- the default string lookup.- Returns:
- a new InterpolatorStringLookup.
-
javaPlatformStringLookup
public StringLookup javaPlatformStringLookup()
Returns the JavaPlatformStringLookup singleton instance. Looks up keys related to Java: Java version, JRE version, VM version, and so on.The lookup keys with examples are:
- version: "Java version 1.8.0_181"
- runtime: "Java(TM) SE Runtime Environment (build 1.8.0_181-b13) from Oracle Corporation"
- vm: "Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)"
- os: "Windows 10 10.0, architecture: amd64-64"
- hardware: "processors: 4, architecture: amd64-64, instruction sets: amd64"
- locale: "default locale: en_US, platform encoding: iso-8859-1"
- Returns:
- the JavaPlatformStringLookup singleton instance.
-
localHostStringLookup
public StringLookup localHostStringLookup()
Returns the LocalHostStringLookup singleton instance where the lookup key is one of:- name: for the local host name, for example
EXAMPLE. - canonical-name: for the local canonical host name, for example
EXAMPLE.apache.org. - address: for the local host address, for example
192.168.56.1.
- Returns:
- the DateStringLookup singleton instance.
- name: for the local host name, for example
-
mapStringLookup
public <V> StringLookup mapStringLookup(Map<String,V> map)
Returns a new map-based lookup where the request for a lookup is answered with the value for that key.- Type Parameters:
V- the map value type.- Parameters:
map- the map.- Returns:
- a new MapStringLookup.
-
nullStringLookup
public StringLookup nullStringLookup()
Returns the NullStringLookup singleton instance which always returns null.- Returns:
- the NullStringLookup singleton instance.
-
propertiesStringLookup
public StringLookup propertiesStringLookup()
Returns the PropertiesStringLookup singleton instance.Looks up the value for the key in the format "DocumentPath:Key".
For example: "com/domain/document.properties:Key".
- Returns:
- the PropertiesStringLookup singleton instance.
- Since:
- 1.5
-
resourceBundleStringLookup
public StringLookup resourceBundleStringLookup()
Returns the ResourceBundleStringLookup singleton instance.Looks up the value for a given key in the format "BundleName:BundleKey".
For example: "com.domain.messages:MyKey".
- Returns:
- the ResourceBundleStringLookup singleton instance.
-
resourceBundleStringLookup
public StringLookup resourceBundleStringLookup(String bundleName)
Returns a ResourceBundleStringLookup instance for the given bundle name.Looks up the value for a given key in the format "BundleKey".
For example: "MyKey".
- Parameters:
bundleName- Only lookup in this bundle.- Returns:
- a ResourceBundleStringLookup instance for the given bundle name.
- Since:
- 1.5
-
scriptStringLookup
public StringLookup scriptStringLookup()
Returns the ScriptStringLookup singleton instance.Looks up the value for the key in the format "ScriptEngineName:Script".
For example: "javascript:\"HelloWorld\"".
- Returns:
- the ScriptStringLookup singleton instance.
- Since:
- 1.5
-
systemPropertyStringLookup
public StringLookup systemPropertyStringLookup()
Returns the SystemPropertyStringLookup singleton instance where the lookup key is a system property name.- Returns:
- the SystemPropertyStringLookup singleton instance.
-
urlDecoderStringLookup
public StringLookup urlDecoderStringLookup()
Returns the UrlDecoderStringLookup singleton instance.Decodes URL Strings using the UTF-8 encoding.
For example: "Hello%20World%21" becomes "Hello World!".
- Returns:
- the UrlStringLookup singleton instance.
- Since:
- 1.6
-
urlEncoderStringLookup
public StringLookup urlEncoderStringLookup()
Returns the UrlDecoderStringLookup singleton instance.Decodes URL Strings using the UTF-8 encoding.
For example: "Hello World!" becomes "Hello+World%21".
- Returns:
- the UrlStringLookup singleton instance.
- Since:
- 1.6
-
urlStringLookup
public StringLookup urlStringLookup()
Returns the UrlStringLookup singleton instance.Looks up the value for the key in the format "CharsetName:URL".
For example, using the HTTP scheme: "UTF-8:http://www.google.com"
For example, using the file scheme: "UTF-8:file:///C:/somehome/commons/commons-text/src/test/resources/document.properties"
- Returns:
- the UrlStringLookup singleton instance.
- Since:
- 1.5
-
xmlStringLookup
public StringLookup xmlStringLookup()
Returns the XmlStringLookup singleton instance.Looks up the value for the key in the format "DocumentPath:XPath".
For example: "com/domain/document.xml:/path/to/node".
- Returns:
- the XmlStringLookup singleton instance.
- Since:
- 1.5
-
-