Package io.goobi.viewer.model.variables
Class VariableReplacer
java.lang.Object
io.goobi.viewer.model.variables.VariableReplacer
- Direct Known Subclasses:
NoopVariableReplacer
Replace variable expression denoted by
{variable-name} in strings. Possible variables are those listed in ReplacerVariables or
any SOLR fields (partially listed in SolrConstants). Values may be taken from configuration and/or solr-derived documents passed in
construction of the VariableReplacer instance.
Variables may have more than one value, typically for multivalued metadata fields, for this reason, in general a list of replaced strings is returned, with one element for each replacement value
-
Constructor Summary
ConstructorsConstructorDescriptionVariableReplacer(Configuration configuration) Only replace configuration variables.VariableReplacer(Configuration config, StructElementStub anchor, StructElementStub topStruct, StructElementStub structElement, PhysicalElement page) Take variable values from the given config and structure elements.VariableReplacer(StructElementStub struct) Take variable values from global configuration and the given struct element.VariableReplacer(ViewManager viewManager) Take variable values from current struct element and page of the given navigationHelper.Specifically replace the variables defined in the given replacement map. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddReplacement(String s, String value) Adds a custom replacement variable.de.intranda.metadata.multilanguage.IMetadataValuereplace(de.intranda.metadata.multilanguage.IMetadataValue value) Return a newIMetadataValueobject with the replaced values of the given object as values.de.intranda.metadata.multilanguage.Metadatareplace(de.intranda.metadata.multilanguage.Metadata metadata) Return a newMetadataobject with the replaced values of the given metadata object as values.Replace variables in the given template string.replaceAll(String template, String separator) Concatenate all returned strings ofreplace(String), separated by the given separator.replaceFirst(String template) Returns a single string which only uses the first replacement values for each variable if there is more than one.
-
Constructor Details
-
VariableReplacer
Take variable values from current struct element and page of the given navigationHelper.- Parameters:
viewManager- view manager providing the current record context- Throws:
IndexUnreachableException
-
VariableReplacer
public VariableReplacer(Configuration config, StructElementStub anchor, StructElementStub topStruct, StructElementStub structElement, PhysicalElement page) Take variable values from the given config and structure elements. Any passed objects may be null, in which case the associated values won't be replaced- Parameters:
config- application configuration providing config-namespace variable valuesanchor- anchor structure element providing anchor-namespace variable valuestopStruct- top structure element providing record-namespace variable valuesstructElement- current structure element providing struct-namespace variable valuespage- current physical page providing page-namespace variable values
-
VariableReplacer
Specifically replace the variables defined in the given replacement map.- Parameters:
replacementsMap- namespace-keyed map of variable name to replacement value lists
-
VariableReplacer
Only replace configuration variables.- Parameters:
configuration- application configuration providing config-namespace variable values
-
VariableReplacer
Take variable values from global configuration and the given struct element.- Parameters:
struct- structure element providing variable values for replacement
-
-
Method Details
-
replace
Replace variables in the given template string. The first element in the returned list will use the first replacement value and so on- Parameters:
template- string containing variable placeholders to replace- Returns:
- A list of strings
-
replaceFirst
Returns a single string which only uses the first replacement values for each variable if there is more than one.- Parameters:
template- string containing variable placeholders to replace- Returns:
- the string with replaced variables
-
replaceAll
Concatenate all returned strings ofreplace(String), separated by the given separator.- Parameters:
template- string containing variable placeholders to replaceseparator- string to place between each replaced result- Returns:
- The concatenated strings with replaced variables
-
addReplacement
Adds a custom replacement variable.- Parameters:
s- variable placeholder name to register for replacementvalue- replacement value to use for the given variable
-
replace
public de.intranda.metadata.multilanguage.Metadata replace(de.intranda.metadata.multilanguage.Metadata metadata) Return a newMetadataobject with the replaced values of the given metadata object as values.- Parameters:
metadata- source metadata object whose value string is used as template- Returns:
- a new metadata object
-
replace
public de.intranda.metadata.multilanguage.IMetadataValue replace(de.intranda.metadata.multilanguage.IMetadataValue value) Return a newIMetadataValueobject with the replaced values of the given object as values.- Parameters:
value- source metadata value whose content strings are used as templates- Returns:
- a new IMetadata value
-