Package org.sentrysoftware.maven.skin
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):
- Front matter (converted to
<meta>tags in headContent) - Site-wide configuration (
<custom>element in site.xml) - 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 -
Method Summary
Modifier and TypeMethodDescriptionbooleangetBooleanValue(Object siteModel, String headContent, String key, boolean defaultValue) Get a boolean configuration value with proper string-to-boolean conversion.intgetIntValue(Object siteModel, String headContent, String key, int defaultValue) Get an integer configuration value.Get a configuration value with front matter overriding site.xml settings.Methods inherited from class org.apache.velocity.tools.generic.SafeConfig
configure, isConfigLocked, isSafeMode
-
Constructor Details
-
ConfigTool
public ConfigTool()Creates a new instance of ConfigTool.
-
-
Method Details
-
getValue
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 nullheadContent- The HTML head content string containing meta tags ($headContent) - can be nullkey- 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 nullheadContent- The HTML head content string containing meta tags ($headContent) - can be nullkey- 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
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 nullheadContent- The HTML head content string containing meta tags ($headContent) - can be nullkey- 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
-