Package lt.velykis.maven.skins.reflow
Class SkinConfigTool
- java.lang.Object
-
- org.apache.velocity.tools.generic.SafeConfig
-
- lt.velykis.maven.skins.reflow.SkinConfigTool
-
@DefaultKey("config") public class SkinConfigTool extends org.apache.velocity.tools.generic.SafeConfig
An Apache Velocity tool that simplifies retrieval of custom configuration values for a Maven Site.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
- Since:
- 1.0
- Author:
- Andrius Velykis
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_KEY
static String
SKIN_KEY
By default use Reflow skin configuration tag
-
Constructor Summary
Constructors Constructor Description SkinConfigTool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
configure(org.apache.velocity.tools.generic.ValueParser values)
org.codehaus.plexus.util.xml.Xpp3Dom
get(String property)
Default accessor for config properties.String
getFileId()
String
getKey()
Should return the key under which this tool has been configured.String
getProjectId()
boolean
is(String property)
A convenience method to check if the value of theproperty
is"true"
.boolean
isValue(String property, String value)
A convenience method to check if theproperty
is set to a specific value.boolean
not(String property)
A convenience method to check if the value of theproperty
is"false"
.protected void
setKey(String key)
Sets the key under which this tool has been configured.String
value(String property)
Retrieves the text value of the givenproperty
, e.g.
-
-
-
Field Detail
-
DEFAULT_KEY
public static final String DEFAULT_KEY
- See Also:
- Constant Field Values
-
SKIN_KEY
public static final String SKIN_KEY
By default use Reflow skin configuration tag- See Also:
- Constant Field Values
-
-
Method Detail
-
configure
protected void configure(org.apache.velocity.tools.generic.ValueParser values)
- Overrides:
configure
in classorg.apache.velocity.tools.generic.SafeConfig
- See Also:
SafeConfig.configure(ValueParser)
-
setKey
protected void setKey(String key)
Sets the key under which this tool has been configured.- Since:
- 1.0
-
getKey
public String getKey()
Should return the key under which this tool has been configured. The default is `config`.- Since:
- 1.0
-
get
public org.codehaus.plexus.util.xml.Xpp3Dom get(String property)
Default accessor for config properties. Instead of using$config.get("myproperty")
, one can utilise Velocity fallback onto the default getter and use$config.myproperty
.- Parameters:
property
- the property of interest- Returns:
- configuration node if found in the following sequence:
- In page configuration
- In global configuration
null
otherwise
- Since:
- 1.0
-
value
public String value(String property)
Retrieves the text value of the givenproperty
, e.g. as in<myprop>value</myprop>
.- Parameters:
property
- the property of interest- Returns:
- the configuration value if found in page or globally,
null
otherwise. - Since:
- 1.0
- See Also:
get(String)
-
is
public boolean is(String property)
A convenience method to check if the value of theproperty
is"true"
.- Parameters:
property
- the property of interest- Returns:
true
if the configuration value is set either in page or globally, and is equal to"true"
.- Since:
- 1.0
- See Also:
get(String)
-
not
public boolean not(String property)
A convenience method to check if the value of theproperty
is"false"
. Useful for properties that are enabled by default - checks if the property is set to"false"
explicitly.- Parameters:
property
- the property of interest- Returns:
true
if the configuration value is set either in page or globally, and is equal to"false"
. Note that this will returnfalse
if property is not set at all.- Since:
- 1.0
- See Also:
get(String)
-
isValue
public boolean isValue(String property, String value)
A convenience method to check if theproperty
is set to a specific value.- Parameters:
property
- the property of interestvalue
- the property value to check- Returns:
true
if the configuration value is set either in page or globally, and is equal tovalue
.- Since:
- 1.0
- See Also:
get(String)
-
getProjectId
public String getProjectId()
-
getFileId
public String getFileId()
-
-