org.apache.wiki
Class VariableManager

java.lang.Object
  extended by org.apache.wiki.VariableManager

public class VariableManager
extends Object

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
static String VAR_ERROR
           
static String VAR_MSG
           
 
Constructor Summary
VariableManager(Properties props)
          Creates a VariableManager object using the property list given.
 
Method Summary
 String expandVariables(WikiContext context, String source)
          This method does in-place expansion of any variables.
 String getValue(WikiContext context, String varName)
          Returns a value of the named variable.
 String getValue(WikiContext context, String varName, String defValue)
          Returns the value of a named variable.
static boolean isVariableLink(String link)
          Returns true if the link is really command to insert a variable.
 String parseAndGetValue(WikiContext context, String link)
          Parses the link and finds a value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VAR_ERROR

public static final String VAR_ERROR
See Also:
Constant Field Values

VAR_MSG

public static final String VAR_MSG
See Also:
Constant Field Values
Constructor Detail

VariableManager

public VariableManager(Properties props)
Creates a VariableManager object using the property list given.

Parameters:
props - The properties.
Method Detail

isVariableLink

public static boolean isVariableLink(String link)
Returns true if the link is really command to insert a variable.

Currently we just check if the link starts with "{$".

Parameters:
link - The link text
Returns:
true, if this represents a variable link.

parseAndGetValue

public String parseAndGetValue(WikiContext context,
                               String link)
                        throws IllegalArgumentException,
                               NoSuchVariableException
Parses the link and finds a value. This is essentially used once isVariableLink(String) has found that the link text actually contains a variable. For example, you could pass in "{$username}" and get back "JanneJalkanen".

Parameters:
context - The WikiContext
link - The link text containing the variable name.
Returns:
The variable value.
Throws:
IllegalArgumentException - If the format is not valid (does not start with "{$", is zero length, etc.)
NoSuchVariableException - If a variable is not known.

expandVariables

public String expandVariables(WikiContext context,
                              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.

Parameters:
context - The WikiContext of the current page.
source - The source string.
Returns:
The source string with variables expanded.

getValue

public String getValue(WikiContext context,
                       String varName,
                       String defValue)
Returns the value of a named variable. See getValue(WikiContext, String). The only difference is that this method does not throw an exception, but it returns the given default value instead.

Parameters:
context - WikiContext
varName - The name of the variable
defValue - A default value.
Returns:
The variable value, or if not found, the default value.

getValue

public String getValue(WikiContext context,
                       String varName)
                throws IllegalArgumentException,
                       NoSuchVariableException
Returns a value of the named variable. The resolving order is
  1. Known "constant" name, such as "pagename", etc. This is so that pages could not override certain constants.
  2. WikiContext local variable. This allows a programmer to set a parameter which cannot be overridden by user.
  3. HTTP Session
  4. HTTP Request parameters
  5. WikiPage variable. As set by the user with the SET directive.
  6. jspwiki.properties
Use this method only whenever you really need to have a parameter that can be overridden by anyone using the wiki.

Parameters:
context - The WikiContext
varName - Name of the variable.
Returns:
The variable value.
Throws:
IllegalArgumentException - If the name is somehow broken.
NoSuchVariableException - If a variable is not known.


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.