Package org.apache.wiki.variables
Class DefaultVariableManager
- java.lang.Object
-
- org.apache.wiki.variables.DefaultVariableManager
-
- All Implemented Interfaces:
VariableManager
public class DefaultVariableManager extends java.lang.Object implements VariableManager
Manages variables. Variables are case-insensitive. A list of all available variables is on a Wiki page called "WikiVariables".- Since:
- 1.9.20.
-
-
Field Summary
-
Fields inherited from interface org.apache.wiki.variables.VariableManager
VAR_ERROR, VAR_MSG, VAR_RUNFILTERS
-
-
Constructor Summary
Constructors Constructor Description DefaultVariableManager(java.util.Properties props)
Creates a VariableManager object using the property list given.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
expandVariables(Context context, java.lang.String source)
This method does in-place expansion of any variables.java.lang.String
getValue(Context context, java.lang.String varName)
Returns a value of the named variable.java.lang.String
getValue(Context context, java.lang.String varName, java.lang.String defValue)
Returns the value of a named variable.java.lang.String
getVariable(Context context, java.lang.String name)
Shortcut to getValue().java.lang.String
parseAndGetValue(Context context, java.lang.String link)
Parses the link and finds a value.
-
-
-
Constructor Detail
-
DefaultVariableManager
public DefaultVariableManager(java.util.Properties props)
Creates a VariableManager object using the property list given.- Parameters:
props
- The properties.
-
-
Method Detail
-
parseAndGetValue
public java.lang.String parseAndGetValue(Context context, java.lang.String link) throws java.lang.IllegalArgumentException, NoSuchVariableException
Parses the link and finds a value. This is essentially used onceLinkParsingOperations#isVariableLink(String)
has found that the link text actually contains a variable. For example, you could pass in "{$username}" and get back "JanneJalkanen".- Specified by:
parseAndGetValue
in interfaceVariableManager
- Parameters:
context
- The WikiContextlink
- The link text containing the variable name.- Returns:
- The variable value.
- Throws:
java.lang.IllegalArgumentException
- If the format is not valid (does not start with "{$", is zero length, etc.)NoSuchVariableException
- If a variable is not known.
-
expandVariables
public java.lang.String expandVariables(Context context, java.lang.String source)
This method does in-place expansion of any variables. However, the expansion is not done twice, that is, a variable containing text $variable will not be expanded.The variables should be in the same format ({$variablename} as in the web pages.
- Specified by:
expandVariables
in interfaceVariableManager
- Parameters:
context
- The WikiContext of the current page.source
- The source string.- Returns:
- The source string with variables expanded.
-
getValue
public java.lang.String getValue(Context context, java.lang.String varName, java.lang.String defValue)
Returns the value of a named variable. SeeVariableManager.getValue(Context, String)
. The only difference is that this method does not throw an exception, but it returns the given default value instead.- Specified by:
getValue
in interfaceVariableManager
- Parameters:
context
- WikiContextvarName
- The name of the variabledefValue
- A default value.- Returns:
- The variable value, or if not found, the default value.
-
getVariable
public java.lang.String getVariable(Context context, java.lang.String name)
Shortcut to getValue(). However, this method does not throw a NoSuchVariableException, but returns null in case the variable does not exist.- Specified by:
getVariable
in interfaceVariableManager
- Parameters:
context
- WikiContext to look the variable inname
- Name of the variable to look for- Returns:
- Variable value, or null, if there is no such variable.
-
getValue
public java.lang.String getValue(Context context, java.lang.String varName) throws java.lang.IllegalArgumentException, NoSuchVariableException
Returns a value of the named variable. The resolving order is- Known "constant" name, such as "pagename", etc. This is so that pages could not override certain constants.
- WikiContext local variable. This allows a programmer to set a parameter which cannot be overridden by user.
- HTTP Session
- HTTP Request parameters
- WikiPage variable. As set by the user with the SET directive.
- jspwiki.properties
- Specified by:
getValue
in interfaceVariableManager
- Parameters:
context
- The WikiContextvarName
- Name of the variable.- Returns:
- The variable value.
- Throws:
java.lang.IllegalArgumentException
- If the name is somehow broken.NoSuchVariableException
- If a variable is not known.
-
-