Top Description Inners Fields Constructors Methods
org.apache.commons.text.lookup

public final Class StringLookupFactory

extends Object
Class Inheritance
Imports
java.net.InetAddress, java.nio.charset.StandardCharsets, java.nio.file.Path, java.util.Base64, .Collections, .HashMap, .Locale, .Map, .Properties, java.util.function.BiFunction, .Function, .Supplier, javax.xml.parsers.DocumentBuilderFactory, javax.xml.xpath.XPathFactory, org.apache.commons.text.StringSubstitutor

Create instances of string lookups or access singleton string lookups implemented in this package.

The "classic" look up is mapStringLookup(Map).

The methods for variable interpolation (A.K.A. variable substitution) are:

Unless explicitly requested otherwise, a set of default lookups are included for convenience with these variable interpolation methods. These defaults are listed in the table below. However, the exact lookups included can be configured through the use of the org.apache.commons.text.lookup.StringLookupFactory.defaultStringLookups system property. If present, this system property will be parsed as a comma-separated list of lookup names, with the names being those defined by the DefaultStringLookup enum. For example, setting this system property to "BASE64_ENCODER,ENVIRONMENT" will only include the BASE64_ENCODER and ENVIRONMENT lookups. Setting the property to the empty string will cause no defaults to be configured. Note that not all lookups defined here and in DefaultStringLookup are included by default. Specifically, lookups that can execute code (e.g., SCRIPT) and those that can result in contact with remote servers (e.g., URL and DNS) are not included by default. The current set of default lookups can be accessed directly with addDefaultStringLookups(Map).

Default String Lookups
Key Interface Factory Method Since
base64Decoder StringLookup base64DecoderStringLookup() 1.6
base64Encoder StringLookup base64EncoderStringLookup() 1.6
const StringLookup constantStringLookup() 1.5
date StringLookup dateStringLookup() 1.5
env StringLookup environmentVariableStringLookup() 1.3
file StringLookup fileStringLookup(Path...) 1.5
java StringLookup javaPlatformStringLookup() 1.5
localhost StringLookup localHostStringLookup() 1.3
loobackAddress StringLookup loopbackAddressStringLookup() 1.13.0
properties StringLookup propertiesStringLookup(Path...) 1.5
resourceBundle StringLookup resourceBundleStringLookup() 1.6
sys StringLookup systemPropertyStringLookup() 1.3
urlDecoder StringLookup urlDecoderStringLookup() 1.5
urlEncoder StringLookup urlEncoderStringLookup() 1.5
xml StringLookup xmlStringLookup(Map, Path...) 1.5
xmlDecoder StringLookup xmlDecoderStringLookup() 1.11.0
xmlEncoder StringLookup xmlEncoderStringLookup() 1.11.0
Additional String Lookups (not included by default)
Key Interface Factory Method Since
dns StringLookup dnsStringLookup() 1.8
url StringLookup urlStringLookup() 1.5
script StringLookup scriptStringLookup() 1.5

This class also provides functional lookups used as building blocks for other lookups.

Functional String Lookups
Interface Factory Method Since
BiStringLookup biFunctionStringLookup(BiFunction) 1.9
StringLookup functionStringLookup(Function) 1.9
Since
1.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_STRING_LOOKUPS_PROPERTY

Name of the system property used to determine the string lookups added by the addDefaultStringLookups(Map) method.

private final Path[]
fences

Fences.

public static final StringLookupFactory
INSTANCE

Defines the singleton for this class.

pack-priv static final FunctionStringLookup<String>
INSTANCE_BASE64_DECODER

Decodes Base64 Strings.

pack-priv static final FunctionStringLookup<String>
INSTANCE_BASE64_ENCODER

Encodes Base64 Strings.

pack-priv static final FunctionStringLookup<String>
INSTANCE_ENVIRONMENT_VARIABLES

Looks up keys from environment variables.

pack-priv static final FunctionStringLookup<String>
INSTANCE_NULL

Defines the FunctionStringLookup singleton that always returns null.

pack-priv static final FunctionStringLookup<String>
INSTANCE_SYSTEM_PROPERTIES

Defines the FunctionStringLookup singleton for looking up system properties.

public static final String
KEY_BASE64_DECODER

Default lookup key for interpolation base64Decoder.

public static final String
KEY_BASE64_ENCODER

Default lookup key for interpolation base64Encoder.

public static final String
KEY_CONST

Default lookup key for interpolation const.

public static final String
KEY_DATE

Default lookup key for interpolation date.

public static final String
KEY_DNS

Default lookup key for interpolation dns.

public static final String
KEY_ENV

Default lookup key for interpolation env.

public static final String
KEY_FILE

Default lookup key for interpolation file.

public static final String
KEY_JAVA

Default lookup key for interpolation java.

public static final String
KEY_LOCALHOST

Default lookup key for interpolation localhost.

public static final String
KEY_LOOPBACK_ADDRESS

Default lookup key for interpolation loobackAddress.

public static final String
KEY_PROPERTIES

Default lookup key for interpolation properties.

public static final String
KEY_RESOURCE_BUNDLE

Default lookup key for interpolation resourceBundle.

public static final String
KEY_SCRIPT

Default lookup key for interpolation script.

public static final String
KEY_SYS

Default lookup key for interpolation sys.

public static final String
KEY_URL

Default lookup key for interpolation url.

public static final String
KEY_URL_DECODER

Default lookup key for interpolation urlDecoder.

public static final String
KEY_URL_ENCODER

Default lookup key for interpolation urlEncoder.

public static final String
KEY_XML

Default lookup key for interpolation xml.

public static final String
KEY_XML_DECODER

Default lookup key for interpolation xmlDecoder.

public static final String
KEY_XML_ENCODER

Default lookup key for interpolation xmlEncoder.

Constructor Summary

AccessConstructor and Description
private
StringLookupFactory()

Constructs a new instance.

private
StringLookupFactory(final Path[] fences)

Constructs a new instance.

Method Summary

Modifier and TypeMethod and Description
public void
addDefaultStringLookups(final Map<String, StringLookup>
the map of string lookups to edit.
stringLookupMap
)

Adds the default string lookups for this class to stringLookupMap.

public StringLookup

Returns:

The Base64DecoderStringLookup singleton instance.
base64DecoderStringLookup
()

Returns the Base64DecoderStringLookup singleton instance to decode Base64 strings.

public StringLookup

Returns:

The Base64EncoderStringLookup singleton instance.
base64EncoderStringLookup
()

Returns the Base64EncoderStringLookup singleton instance to encode strings to Base64.

public StringLookup

Returns:

The Base64DecoderStringLookup singleton instance.
base64StringLookup
()
Deprecated Use base64DecoderStringLookup().

Returns the Base64DecoderStringLookup singleton instance to decode Base64 strings.

public <
the function return type.
R
,
the function's second parameter type.
U
>
BiStringLookup<U>

Returns:

a new MapStringLookup.
biFunctionStringLookup
(final BiFunction<String, U, R>
the function.
biFunction
)

Returns a new function-based lookup where the request for a lookup is answered by applying the function with a lookup key.

public static StringLookupFactory.Builder

Returns:

a new Builder
builder
()

Constructs a new Builder.

public static void
clear()

Clears any static resources.

public StringLookup

Returns:

The ConstantStringLookup singleton instance.
constantStringLookup
()

Returns the ConstantStringLookup singleton instance to look up the value of a fully-qualified static final value.

public StringLookup

Returns:

The DateStringLookup singleton instance.
dateStringLookup
()

Returns the DateStringLookup singleton instance to format the current date with the format given in the key in a format compatible with java.text.SimpleDateFormat.

public StringLookup

Returns:

the DnsStringLookup singleton instance.
dnsStringLookup
()

Returns the DnsStringLookup singleton instance where the lookup key is one of:

  • name: for the local host name, for example EXAMPLE but also EXAMPLE.apache.org.
  • 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.
public StringLookup

Returns:

The EnvironmentVariableStringLookup singleton instance.
environmentVariableStringLookup
()

Returns the EnvironmentVariableStringLookup singleton instance where the lookup key is an environment variable name.

public StringLookup

Returns:

a file StringLookup instance.
fileStringLookup
()

Returns a file StringLookup instance.

public StringLookup

Returns:

a file StringLookup instance.
fileStringLookup
(final Path...
The fences guarding Path resolution.
fences
)

Returns a fenced file StringLookup instance.

public <
the function return type.
R
>
StringLookup

Returns:

a new MapStringLookup.
functionStringLookup
(final Function<String, R>
the function.
function
)

Returns a new function-based lookup where the request for a lookup is answered by applying the function with a lookup key.

public StringLookup

Returns:

the default InterpolatorStringLookup.
interpolatorStringLookup
()

Returns a InterpolatorStringLookup containing the configured default lookups.

public StringLookup

Returns:

a new InterpolatorStringLookup.
interpolatorStringLookup
(final Map<String, StringLookup>
the map of string lookups.
stringLookupMap
,
final StringLookup
the default string lookup; this lookup is used when a variable cannot be resolved using the lookups in stringLookupMap or the configured default lookups (if enabled)
defaultStringLookup
,
final boolean
whether to use default lookups as described above.
addDefaultLookups
)

Returns a new InterpolatorStringLookup.

public <
the value type the default string lookup's map.
V
>
StringLookup

Returns:

a new InterpolatorStringLookup.
interpolatorStringLookup
(final Map<String, V>
the default map for string lookups.
map
)

Returns a new InterpolatorStringLookup using the given key-value pairs and the configured default lookups to resolve variables.

public StringLookup

Returns:

a new InterpolatorStringLookup.
interpolatorStringLookup
(final StringLookup
the default string lookup.
defaultStringLookup
)

Returns a new InterpolatorStringLookup using the given lookup and the configured default lookups to resolve variables.

public StringLookup

Returns:

The JavaPlatformStringLookup singleton instance.
javaPlatformStringLookup
()

Returns the JavaPlatformStringLookup singleton instance.

public StringLookup

Returns:

The InetAddressStringLookup singleton instance.
localHostStringLookup
()

Returns the InetAddressStringLookup instance where the lookup key for InetAddress#getLocalHost() 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.
public StringLookup

Returns:

The InetAddressStringLookup singleton instance.
loopbackAddressStringLookup
()

Returns the InetAddressStringLookup instance where the lookup key for InetAddress#getLoopbackAddress() 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.
public <
the map value type.
V
>
StringLookup

Returns:

a new MapStringLookup.
mapStringLookup
(final Map<String, V>
the map.
map
)

Returns a new map-based lookup where the request for a lookup is answered with the value for that key.

public StringLookup

Returns:

The NullStringLookup singleton instance.
nullStringLookup
()

Returns the NullStringLookup singleton instance which always returns null.

public StringLookup

Returns:

a Properties StringLookup instance.
propertiesStringLookup
()

Returns a Properties StringLookup instance.

public StringLookup

Returns:

a Properties StringLookup instance.
propertiesStringLookup
(final Path...
The fences guarding Path resolution.
fences
)

Returns a fenced Properties StringLookup instance.

public StringLookup

Returns:

The ResourceBundleStringLookup singleton instance.
resourceBundleStringLookup
()

Returns the ResourceBundleStringLookup singleton instance.

public StringLookup

Returns:

a ResourceBundleStringLookup instance for the given bundle name.
resourceBundleStringLookup
(final String
Only lookup in this bundle.
bundleName
)

Returns a ResourceBundleStringLookup instance for the given bundle name.

public StringLookup

Returns:

The ScriptStringLookup singleton instance.
scriptStringLookup
()

Returns the ScriptStringLookup singleton instance.

public StringLookup

Returns:

The SystemPropertyStringLookup singleton instance.
systemPropertyStringLookup
()

Returns the SystemPropertyStringLookup singleton instance where the lookup key is a system property name.

pack-priv static String

Returns:

string lookup map key
toKey
(final String
string to convert to a string lookup map key
key
)

Gets a string suitable for use as a key in the string lookup map.

pack-priv static <
the class of the map keys
K
,
the class of the map values
V
>
Map<K, V>

Returns:

the given map if the input is non-null or an empty immutable map if the input is null.
toMap
(final Map<K, V>
The map to test
map
)

Returns the given map if the input is non-null or an empty immutable map if the input is null.

public StringLookup

Returns:

The UrlStringLookup singleton instance.
urlDecoderStringLookup
()

Returns the UrlDecoderStringLookup singleton instance.

public StringLookup

Returns:

The UrlStringLookup singleton instance.
urlEncoderStringLookup
()

Returns the UrlDecoderStringLookup singleton instance.

public StringLookup

Returns:

The UrlStringLookup singleton instance.
urlStringLookup
()

Returns the UrlStringLookup singleton instance.

public StringLookup

Returns:

The XmlDecoderStringLookup singleton instance.
xmlDecoderStringLookup
()

Returns the XmlDecoderStringLookup singleton instance.

public StringLookup

Returns:

The XmlEncoderStringLookup singleton instance.
xmlEncoderStringLookup
()

Returns the XmlEncoderStringLookup singleton instance.

public StringLookup

Returns:

An XML StringLookup instance.
xmlStringLookup
()

Returns an XML StringLookup instance.

public StringLookup

Returns:

An XML StringLookup instance.
xmlStringLookup
(final Map<String, Boolean>
DocumentBuilderFactory and XPathFactory features to set.
factoryFeatures
)

Returns an XML StringLookup instance.

public StringLookup

Returns:

An XML StringLookup instance.
xmlStringLookup
(final Map<String, Boolean>
DocumentBuilderFactory and XPathFactory features to set.
factoryFeatures
,
final Path...
The fences guarding Path resolution.
fences
)

Returns a fenced XML StringLookup instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait