Class VariableReplacer

java.lang.Object
io.goobi.viewer.model.variables.VariableReplacer
Direct Known Subclasses:
NoopVariableReplacer

public class VariableReplacer extends Object
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 Details

    • VariableReplacer

      public VariableReplacer(ViewManager viewManager) throws IndexUnreachableException
      Take variable values from current struct element and page of the given navigationHelper
      Parameters:
      viewManager -
      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 -
      anchor -
      topStruct -
      structElement -
      page -
    • VariableReplacer

      public VariableReplacer(Map<String,Map<String,List<String>>> replacementsMap)
      Specifically replace the variables defined in the given replacement map
      Parameters:
      replacementsMap -
    • VariableReplacer

      public VariableReplacer(Configuration configuration)
      Only replace configuration variables
      Parameters:
      configuration -
    • VariableReplacer

      public VariableReplacer(StructElementStub struct)
      Take variable values from global configuration and the given struct element
      Parameters:
      struct -
  • Method Details

    • replace

      public List<String> replace(String template)
      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 -
      Returns:
      A list of strings
    • replaceFirst

      public String replaceFirst(String template)
      Return a single string which only uses the first replacement values for each variable if there is more than one
      Parameters:
      template -
      Returns:
      the string with replaced variables
    • replaceAll

      public String replaceAll(String template, String separator)
      Concatenate all returned strings of replace(String), separated by the given separator
      Parameters:
      template -
      separator -
      Returns:
      The concatenated strings with replaced variables
    • addReplacement

      public void addReplacement(String s, String value)
      Add a custom replacement variable
      Parameters:
      s -
      value -
    • replace

      public de.intranda.metadata.multilanguage.Metadata replace(de.intranda.metadata.multilanguage.Metadata metadata)
      return a new Metadata object with the replaced values of the given metadata object as values
      Parameters:
      metadata -
      Returns:
      a new metadata object
    • replace

      public de.intranda.metadata.multilanguage.IMetadataValue replace(de.intranda.metadata.multilanguage.IMetadataValue value)
      return a new IMetadataValue object with the replaced values of the given object as values
      Parameters:
      value -
      Returns:
      a new IMetadata value