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 - 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 values
      anchor - anchor structure element providing anchor-namespace variable values
      topStruct - top structure element providing record-namespace variable values
      structElement - current structure element providing struct-namespace variable values
      page - current physical page providing page-namespace variable values
    • VariableReplacer

      public VariableReplacer(Map<String,Map<String,List<String>>> replacementsMap)
      Specifically replace the variables defined in the given replacement map.
      Parameters:
      replacementsMap - namespace-keyed map of variable name to replacement value lists
    • VariableReplacer

      public VariableReplacer(Configuration configuration)
      Only replace configuration variables.
      Parameters:
      configuration - application configuration providing config-namespace variable values
    • VariableReplacer

      public VariableReplacer(StructElementStub struct)
      Take variable values from global configuration and the given struct element.
      Parameters:
      struct - structure element providing variable values for replacement
  • 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 - string containing variable placeholders to replace
      Returns:
      A list of strings
    • replaceFirst

      public String replaceFirst(String template)
      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

      public String replaceAll(String template, String separator)
      Concatenate all returned strings of replace(String), separated by the given separator.
      Parameters:
      template - string containing variable placeholders to replace
      separator - string to place between each replaced result
      Returns:
      The concatenated strings with replaced variables
    • addReplacement

      public void addReplacement(String s, String value)
      Adds a custom replacement variable.
      Parameters:
      s - variable placeholder name to register for replacement
      value - replacement value to use for the given variable
    • 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 - 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 new IMetadataValue object 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