@DefaultKey(value="config") public class SkinConfigTool extends org.apache.velocity.tools.generic.SafeConfig implements ISkinConfig
The tool is configured to access Maven site configuration of a skin inside <custom> element of site
descriptor. It supports global properties (defined at skin level) and per-page properties (defined in
<page><mypage> element). The per-page properties override the global ones.
A sample configuration would be like that:
<custom>
<reflowSkin>
<prop1>value1</prop1>
<prop2>
<prop21>value2</prop21>
</prop2>
<pages>
<mypage project="myproject">
<prop1>override value1</prop1>
</mypage>
</pages>
</reflowSkin>
</custom>
To get the value of prop1, one would simply use $config.prop1. This would return "override value1".
Then $config.prop2 would return "value2" - the global value.
The tool allows querying the value easily, falling back from page to global configuration to null, if none is
available. It also provides convenience accessors for common values.
Note
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_KEY |
static String |
SKIN_KEY
By default use Reflow skin configuration tag.
|
| Constructor and Description |
|---|
SkinConfigTool() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
configure(org.apache.velocity.tools.generic.ValueParser values) |
<T> T |
eval(String vtl,
Class<T> requiredClass)
Evaluate a velocity expression in the current context.
|
org.codehaus.plexus.util.xml.Xpp3Dom |
get(String property)
Default accessor for config properties.
|
<T> T |
getAttributeValue(String property,
String attribute,
Class<T> targetType,
T defaultValue)
Gets the attribute value of the given
attribute of property. |
<T> T |
getAttributeValue(org.codehaus.plexus.util.xml.Xpp3Dom element,
String attribute,
Class<T> targetType,
T defaultValue)
Get the value contained in specific attribute of
element parameter. |
Date |
getBuildOutputTimestamp()
Gets the reproduce build timestamp whether property 'project.build.outputTimestamp' is fill in.
|
List<String> |
getChildren(org.codehaus.plexus.util.xml.Xpp3Dom parentNode)
Gets the list of all children name for the
parentNode. |
Context<?> |
getContext() |
<T> T |
getContextValue(String key,
Class<T> type)
Gets the associated value to
key stored in Velocity context. |
String |
getCurrentFileLocation() |
String |
getCurrentFileName()
See Doxia Sitetools - Site
Renderer for more information.
|
String |
getFileId() |
org.codehaus.plexus.util.xml.Xpp3Dom |
getGlobalProperties() |
String |
getKey() |
String |
getNamespace() |
org.codehaus.plexus.util.xml.Xpp3Dom |
getPageProperties() |
org.apache.maven.project.MavenProject |
getProject() |
String |
getProjectId() |
String |
getProjectLocation() |
<T> T |
getPropertyValue(String property,
Class<T> targetType,
T defaultValue)
Gets the text value of the given
property. |
String |
getResourcePath() |
org.apache.maven.doxia.site.SiteModel |
getSiteModel() |
<T> T |
getToolbox(String toolName,
Class<T> toolType)
Gets the associated tool to
name stored in toolbox of Velocity context. |
org.apache.velocity.tools.ToolContext |
getVelocityContext() |
boolean |
is(String property)
A convenience method to check if the value of the
property is "true". |
boolean |
isActiveLink(String href)
Gets the indicating if the link is active.
|
boolean |
isExternalLink(String url) |
boolean |
isValue(String property,
String value)
A convenience method to check if the
property is set to a specific value. |
boolean |
not(String property)
A convenience method to check if the value of the
property is "false". |
String |
relativeLink(String href) |
void |
setContextValue(String key,
Object value)
Sets the value in Velocity context associated to
key. |
protected void |
setKey(String key)
Sets the key under which this tool has been configured.
|
static String |
slugFilename(String fileName)
Converts a filename to pageId format.
|
String |
value(String property)
Retrieves the text value of the given
property, e.g. as in <myprop>value</myprop>. |
public static final String DEFAULT_KEY
public static final String SKIN_KEY
protected void configure(org.apache.velocity.tools.generic.ValueParser values)
configure in class org.apache.velocity.tools.generic.SafeConfigSafeConfig.configure(ValueParser)protected void setKey(String key)
key - the key of configpublic String getKey()
@Nullable public <T> T getContextValue(@Nonnull String key, @Nonnull Class<T> type)
key stored in Velocity context.getContextValue in interface ISkinConfigT - the type of expected value.key - the key name of associated value in Velocity context.type - the the type of expected value.key stored in Velocity context.public void setContextValue(@Nonnull String key, @Nullable Object value)
key.setContextValue in interface ISkinConfigkey - the key name of associated value in Velocity context.value - the new value@Nullable public <T> T getToolbox(@Nonnull String toolName, @Nonnull Class<T> toolType)
name stored in toolbox of Velocity context.getToolbox in interface ISkinConfigT - the type of expected tool.toolName - the name of tool associated in Velocity context.toolType - the expected class of tool.name stored in toolbox of Velocity context.@Nullable public org.codehaus.plexus.util.xml.Xpp3Dom get(@Nonnull String property)
$config.get("myproperty"), one can utilise
Velocity fallback onto the default getter and use $config.myproperty.get in interface ISkinConfigproperty - the property of interestnull otherwise@Nullable public String value(@Nonnull String property)
property, e.g. as in <myprop>value</myprop>.property - the property of interestnull otherwise.get(String)@Nullable public <T> T getPropertyValue(@Nonnull String property, @Nonnull Class<T> targetType, @Nullable T defaultValue)
property.getPropertyValue in interface ISkinConfigT - the type of returned object.property - the property to usetargetType - the returned target type use to convert value.defaultValue - the default value used if property doesn't exist.property.public List<String> getChildren(org.codehaus.plexus.util.xml.Xpp3Dom parentNode)
parentNode.parentNode - the parent node to use (can be null.String representing the name of all children, which may be empty but never
null.@Nullable public <T> T getAttributeValue(@Nonnull String property, @Nonnull String attribute, @Nonnull Class<T> targetType, @Nullable T defaultValue)
attribute of property.getAttributeValue in interface ISkinConfigT - the type of returned object.property - the property to useattribute - the attribute to use.targetType - the returned target type use to convert value.defaultValue - the default value used if property doesn't exist.property.@Nullable public <T> T getAttributeValue(@Nonnull org.codehaus.plexus.util.xml.Xpp3Dom element, @Nonnull String attribute, @Nonnull Class<T> targetType, @Nullable T defaultValue)
element parameter.getAttributeValue in interface ISkinConfigT - the type of returned value.element - the xml element.attribute - the attribute name.targetType - the class of converted returned value.defaultValue - the value to return if attribute is empty or null.element parameter if exists, otherwise
returns the default value.public boolean is(String property)
property is "true".property - the property of interesttrue if the configuration value is set either in page or globally, and is equal to
"true".get(String)public boolean not(String property)
property is "false". Useful for properties that
are enabled by default - checks if the property is set to "false" explicitly.not in interface ISkinConfigproperty - the property of interesttrue if the configuration value is set either in page or globally, and is equal to
"false". Note that this will return false if property is not set at all.ISkinConfig.get(String)public boolean isValue(String property, String value)
property is set to a specific value.property - the property of interestvalue - the property value to checktrue if the configuration value is set either in page or globally, and is equal to value.get(String)@Nullable public String getProjectId()
getProjectId in interface ISkinConfigString representing the projectId.@Nullable public String getFileId()
getFileId in interface ISkinConfigString representing the fileId.@Nonnull public Context<?> getContext()
getContext in interface ISkinConfigpublic org.apache.velocity.tools.ToolContext getVelocityContext()
@Nonnull public org.apache.maven.project.MavenProject getProject()
getProject in interface ISkinConfig@Nonnull public org.apache.maven.doxia.site.SiteModel getSiteModel()
getSiteModel in interface ISkinConfig@Nonnull public org.codehaus.plexus.util.xml.Xpp3Dom getPageProperties()
getPageProperties in interface ISkinConfigXpp3Dom.@Nonnull public org.codehaus.plexus.util.xml.Xpp3Dom getGlobalProperties()
getGlobalProperties in interface ISkinConfigXpp3Dom.@Nonnull public String getNamespace()
getNamespace in interface ISkinConfigString representing the namespace.@Nonnull public String getProjectLocation()
@Nonnull public String getCurrentFileName()
See Doxia Sitetools - Site Renderer for more information.
String representing the name of current file of the (HTML) document being rendered,
relative to the site root.@Nonnull public String getCurrentFileLocation()
String representing the location path of current rendered file.@Nullable public <T> T eval(@Nullable String vtl, @Nonnull Class<T> requiredClass)
eval in interface ISkinConfigT - Tthe type of expected returned value.vtl - The velocity expression to evaluaterequiredClass - the class of returned value.public String relativeLink(String href)
relativeLink in interface ISkinConfighref - link to relative.public boolean isExternalLink(String url)
url - a url.true whether the link is a external link to the site.public boolean isActiveLink(@Nullable String href)
isActiveLink in interface ISkinConfighref - the link to check.true the link is active, otherwise false.@Nullable public static String slugFilename(@Nullable String fileName)
fileName - the filename to convertString representing the pageId of filename.@Nonnull public String getResourcePath()
getResourcePath in interface ISkinConfigString representing the relative path to root site.@Nullable public Date getBuildOutputTimestamp() throws ParseException
Date representing the reproduce build timestamp whether property
'project.build.outputTimestamp' is fill in.ParseExceptionCopyright © 2012–2023 Friederich Christophe. All rights reserved.