Class ConfigTool

java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.sentrysoftware.maven.skin.ConfigTool

@DefaultKey("configTool") public class ConfigTool extends org.apache.velocity.tools.generic.SafeConfig
An Apache Velocity tool that provides unified configuration management for Maven sites, merging site-wide configuration from site.xml with per-page overrides from Markdown front matter.

Configuration precedence (highest to lowest):

  1. Front matter (converted to <meta> tags in headContent)
  2. Site-wide configuration (<custom> element in site.xml)
  3. Default value provided by the caller

Front matter in Markdown files:


 ---
 interpolation: none
 showToc: false
 tocMaxDepth: 3
 ---
 
is converted by Doxia to <meta> tags:

 <meta name="interpolation" content="none"/>
 <meta name="showToc" content="false"/>
 <meta name="tocMaxDepth" content="3"/>
 
Since:
1.6
Author:
Bertrand Martin
  • Field Summary

    Fields inherited from class org.apache.velocity.tools.generic.SafeConfig

    LOCK_CONFIG_KEY, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of ConfigTool.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    getBooleanValue(Object siteModel, String headContent, String key, boolean defaultValue)
    Get a boolean configuration value with proper string-to-boolean conversion.
    int
    getIntValue(Object siteModel, String headContent, String key, int defaultValue)
    Get an integer configuration value.
    getValue(Object siteModel, String headContent, String key, String defaultValue)
    Get a configuration value with front matter overriding site.xml settings.

    Methods inherited from class org.apache.velocity.tools.generic.SafeConfig

    configure, isConfigLocked, isSafeMode

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConfigTool

      public ConfigTool()
      Creates a new instance of ConfigTool.
  • Method Details

    • getValue

      public String getValue(Object siteModel, String headContent, String key, String defaultValue)
      Get a configuration value with front matter overriding site.xml settings.

      Usage in Velocity:

      
       #set($interpolation = $configTool.getValue($site, $headContent, "interpolation", "maven"))
       
      Parameters:
      siteModel - The site decoration model ($site or $decoration) - can be null
      headContent - The HTML head content string containing meta tags ($headContent) - can be null
      key - The configuration key (e.g., "interpolation", "showToc")
      defaultValue - The default value if not found in either source
      Returns:
      The configuration value (front matter > site.xml > default)
      Since:
      1.6
    • getBooleanValue

      public boolean getBooleanValue(Object siteModel, String headContent, String key, boolean defaultValue)
      Get a boolean configuration value with proper string-to-boolean conversion.

      Recognizes "true", "yes", "1" as true (case-insensitive). Recognizes "false", "no", "0" as false (case-insensitive). Any other value returns the default.

      Usage in Velocity:

      
       #set($showToc = $configTool.getBooleanValue($site, $headContent, "showToc", true))
       
      Parameters:
      siteModel - The site decoration model ($site or $decoration) - can be null
      headContent - The HTML head content string containing meta tags ($headContent) - can be null
      key - The configuration key (e.g., "showToc", "checkImages")
      defaultValue - The default value if not found or invalid
      Returns:
      The boolean configuration value (front matter > site.xml > default)
      Since:
      1.6
    • getIntValue

      public int getIntValue(Object siteModel, String headContent, String key, int defaultValue)
      Get an integer configuration value.

      If the value cannot be parsed as an integer, returns the default value.

      Usage in Velocity:

      
       #set($tocMaxDepth = $configTool.getIntValue($site, $headContent, "tocMaxDepth", 3))
       
      Parameters:
      siteModel - The site decoration model ($site or $decoration) - can be null
      headContent - The HTML head content string containing meta tags ($headContent) - can be null
      key - The configuration key (e.g., "tocMaxDepth", "maxImageWidth")
      defaultValue - The default value if not found or invalid
      Returns:
      The integer configuration value (front matter > site.xml > default)
      Since:
      1.6