public class VariableManager
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
VAR_ERROR |
static java.lang.String |
VAR_MSG |
Constructor and Description |
---|
VariableManager(java.util.Properties props)
Creates a VariableManager object using the property list given.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
expandVariables(WikiContext context,
java.lang.String source)
This method does in-place expansion of any variables.
|
java.lang.String |
getValue(WikiContext context,
java.lang.String varName)
Returns a value of the named variable.
|
java.lang.String |
getValue(WikiContext context,
java.lang.String varName,
java.lang.String defValue)
Returns the value of a named variable.
|
static boolean |
isVariableLink(java.lang.String link)
Returns true if the link is really command to insert
a variable.
|
java.lang.String |
parseAndGetValue(WikiContext context,
java.lang.String link)
Parses the link and finds a value.
|
public static final java.lang.String VAR_ERROR
public static final java.lang.String VAR_MSG
public VariableManager(java.util.Properties props)
props
- The properties.public static boolean isVariableLink(java.lang.String link)
Currently we just check if the link starts with "{$".
link
- The link textpublic java.lang.String parseAndGetValue(WikiContext context, java.lang.String link) throws java.lang.IllegalArgumentException, NoSuchVariableException
isVariableLink(String)
has found that the link text
actually contains a variable. For example, you could pass in
"{$username}" and get back "JanneJalkanen".context
- The WikiContextlink
- The link text containing the variable name.java.lang.IllegalArgumentException
- If the format is not valid (does not
start with "{$", is zero length, etc.)NoSuchVariableException
- If a variable is not known.public java.lang.String expandVariables(WikiContext context, java.lang.String source)
The variables should be in the same format ({$variablename} as in the web pages.
context
- The WikiContext of the current page.source
- The source string.public java.lang.String getValue(WikiContext context, java.lang.String varName, java.lang.String defValue)
getValue(WikiContext, String)
.
The only difference is that this method does not throw an exception, but it
returns the given default value instead.context
- WikiContextvarName
- The name of the variabledefValue
- A default value.public java.lang.String getValue(WikiContext context, java.lang.String varName) throws java.lang.IllegalArgumentException, NoSuchVariableException
context
- The WikiContextvarName
- Name of the variable.java.lang.IllegalArgumentException
- If the name is somehow broken.NoSuchVariableException
- If a variable is not known.stSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.