com.sun.rave.web.ui.util
Class VariableResolver

java.lang.Object
  extended by com.sun.rave.web.ui.util.VariableResolver

public class VariableResolver
extends java.lang.Object

VariableResolver is used to parse expressions of the format.

$<type$gt;{<key>}

<type> refers to a registerd VariableResolver.DataSource, custom VariableResolver.DataSources can be registered via: setDataSource(String key, VariableResolver.DataSource dataSource). However, there are many built-in VariableResolver.DataSource types that are pre-registered.

Below are the pre-registered types:


Nested Class Summary
static class VariableResolver.AttributeDataSource
           This VariableResolver.DataSource provides access to HttpRequest attributes.
static class VariableResolver.BooleanDataSource
           This VariableResolver.DataSource converts the given key to a Boolean.
static class VariableResolver.BrowserDataSource
           This VariableResolver.DataSource uses the given key to check various properties of the browser that submitted the request.
static class VariableResolver.ConstantDataSource
           This VariableResolver.DataSource allows access to constants in java classes.
static interface VariableResolver.DataSource
           This interface defines a String substitution data source.
static class VariableResolver.EscapeDataSource
           This VariableResolver.DataSource simply returns the key that it is given.
static class VariableResolver.HasFacetDataSource
           This VariableResolver.DataSource tests if the given facet exists on the UIComponent.
static class VariableResolver.HasPropertyDataSource
           This VariableResolver.DataSource tests if the given property exists on the UIComponent.
static class VariableResolver.IntDataSource
           This VariableResolver.DataSource converts the given key to an Integer.
static class VariableResolver.MethodBindingDataSource
           This VariableResolver.DataSource creates a MethodBinding from the supplied key.
static class VariableResolver.PropertyDataSource
           This VariableResolver.DataSource provides access to UIComponent Properties.
static class VariableResolver.RequestParameterDataSource
           This VariableResolver.DataSource provides access to HttpRequest Parameters.
static class VariableResolver.ResourceBundleDataSource
           This VariableResolver.DataSource allows access to resource bundle keys.
static class VariableResolver.SessionDataSource
           This VariableResolver.DataSource provides access to HttpSession attributes.
static class VariableResolver.StyleDataSource
           This VariableResolver.DataSource retrieves style classes from the current Theme.
static class VariableResolver.ThemeDataSource
           This VariableResolver.DataSource retrieves Theme messages from the Theme.
static class VariableResolver.ThemeJavaScriptDataSource
           This VariableResolver.DataSource retrieves the path to a JavaScript file from the Theme.
static class VariableResolver.ThisDataSource
           This class provides an implementation for the syntax $this{xyz} where xyz can be any of the following.
 
Field Summary
static java.lang.String ATTRIBUTE
           Defines "attribute" in $attribute{...}.
static java.lang.String BOOLEAN
           Defines "boolean" in $boolean{...}.
static java.lang.String BROWSER
           Defines "browser" in $browser{...}.
static java.lang.String CONSTANT
           Defines "constant" in $constant{...}.
static java.lang.String ESCAPE
           Defines "escape" in $escape{...}.
static java.lang.String HAS_FACET
           Defines "hasFacet" in $hasFacet{...}.
static java.lang.String HAS_PROPERTY
           Defines "hasProperty" in $hasProperty{...}.
static java.lang.String INT
           Defines "int" in $int{...}.
static java.lang.String METHOD_BINDING
           Defines "methodBinding" in $methodBinding{...}.
static java.lang.String PROPERTY
           Defines "property" in $property{...}.
static java.lang.String REQUEST_PARAMETER
           Defines "requestParameter" in $requestParameter{...}.
static java.lang.String RESOURCE
           Defines "resource" in $resource{...}.
static java.lang.String SESSION
           Defines "session" in $session{...}.
static java.lang.String STYLE
           Defines "style" in $style{...}.
static java.lang.String SUB_END
          The ')' character marks the end of the data content for a String substitution.
static java.lang.String SUB_START
          The '$' character marks the beginning of a substituion in a String.
static java.lang.String SUB_TYPE_DELIM
          The '(' character marks the beginning of the data content of a String substitution.
static java.lang.String THEME
           Defines "theme" in $theme{...}.
static java.lang.String THEME_JS
           Defines "themeScript" in $themeScript{...}.
static java.lang.String THIS
           Defines "this" in $this{...}.
 
Constructor Summary
VariableResolver()
           
 
Method Summary
static VariableResolver.DataSource getDataSource(java.lang.String key)
           This method looks up the requested VariableResolver.DataSource by the given key.
static void main(java.lang.String[] args)
          The main function for this class provides some simple test cases.
static java.lang.Object resolveVariables(javax.faces.context.FacesContext ctx, LayoutElement desc, javax.faces.component.UIComponent component, java.lang.Object value)
          This method replaces the ${..} variables with their attribute values.
static java.lang.Object resolveVariables(javax.faces.context.FacesContext ctx, LayoutElement desc, javax.faces.component.UIComponent component, java.lang.String string, java.lang.String startToken, java.lang.String typeDelim, java.lang.String endToken)
           This method will substitute variables into the given String, or return the variable if the substitution is the whole String.
static java.lang.Object resolveVariables(LayoutElement desc, javax.faces.component.UIComponent component, java.lang.Object value)
          This method replaces the ${..} variables with their values.
static void setDataSource(java.lang.String key, VariableResolver.DataSource dataSource)
           This method sets the given VariableResolver.DataSource to be used for $[type]{...} when key matches type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTRIBUTE

public static final java.lang.String ATTRIBUTE

Defines "attribute" in $attribute{...}. This allows you to retrieve an HttpRequest attribute.

See Also:
Constant Field Values

PROPERTY

public static final java.lang.String PROPERTY

Defines "property" in $property{...}. This allows you to retrieve a property from the UIComponent.

See Also:
Constant Field Values

HAS_PROPERTY

public static final java.lang.String HAS_PROPERTY

Defines "hasProperty" in $hasProperty{...}. This allows you to see if a property from the UIComponent exists.

See Also:
Constant Field Values

HAS_FACET

public static final java.lang.String HAS_FACET

Defines "hasFacet" in $hasFacet{...}. This allows you to see if a facet from the UIComponent exists.

See Also:
Constant Field Values

SESSION

public static final java.lang.String SESSION

Defines "session" in $session{...}. This allows you to retrieve an HttpSession attribute.

See Also:
Constant Field Values

STYLE

public static final java.lang.String STYLE

Defines "style" in $style{...}. This allows you to retrieve a style classes from the current Theme.

See Also:
Constant Field Values

THEME

public static final java.lang.String THEME

Defines "theme" in $theme{...}. This allows you to retrieve a Theme message from the current Theme.

See Also:
Constant Field Values

THEME_JS

public static final java.lang.String THEME_JS

Defines "themeScript" in $themeScript{...}. This allows you to retrieve a JavaScript classes from the current Theme.

See Also:
Constant Field Values

REQUEST_PARAMETER

public static final java.lang.String REQUEST_PARAMETER

Defines "requestParameter" in $requestParameter{...}. This allows you to retrieve a HttpRequest parameter (QUERY_STRING parameter).

See Also:
Constant Field Values

THIS

public static final java.lang.String THIS

Defines "this" in $this{...}. This allows you to retrieve a number of different objects related to the relative placement of this expression.

See Also:
VariableResolver.ThisDataSource, Constant Field Values

ESCAPE

public static final java.lang.String ESCAPE

Defines "escape" in $escape{...}. This allows some reserved characters to be escaped in "if" attributes. Such as '=' or '|'.

See Also:
Constant Field Values

BOOLEAN

public static final java.lang.String BOOLEAN

Defines "boolean" in $boolean{...}. This converts the given String to a Boolean.

See Also:
Constant Field Values

BROWSER

public static final java.lang.String BROWSER

Defines "browser" in $browser{...}. This checks properties of the browser that sent the request.

See Also:
Constant Field Values

INT

public static final java.lang.String INT

Defines "int" in $int{...}. This converts the given String to an Integer.

See Also:
Constant Field Values

METHOD_BINDING

public static final java.lang.String METHOD_BINDING

Defines "methodBinding" in $methodBinding{...}. This allows MethodBindings in to be created.

See Also:
Constant Field Values

CONSTANT

public static final java.lang.String CONSTANT

Defines "constant" in $constant{...}. This allows constants in java classes to be accessed.

See Also:
Constant Field Values

RESOURCE

public static final java.lang.String RESOURCE

Defines "resource" in $resource{...}. This allows resource to be accessed.

See Also:
Constant Field Values

SUB_START

public static final java.lang.String SUB_START
The '$' character marks the beginning of a substituion in a String.

See Also:
Constant Field Values

SUB_TYPE_DELIM

public static final java.lang.String SUB_TYPE_DELIM
The '(' character marks the beginning of the data content of a String substitution.

See Also:
Constant Field Values

SUB_END

public static final java.lang.String SUB_END
The ')' character marks the end of the data content for a String substitution.

See Also:
Constant Field Values
Constructor Detail

VariableResolver

public VariableResolver()
Method Detail

resolveVariables

public static java.lang.Object resolveVariables(javax.faces.context.FacesContext ctx,
                                                LayoutElement desc,
                                                javax.faces.component.UIComponent component,
                                                java.lang.String string,
                                                java.lang.String startToken,
                                                java.lang.String typeDelim,
                                                java.lang.String endToken)

This method will substitute variables into the given String, or return the variable if the substitution is the whole String. This method looks for the LAST occurance of startToken in the given String. It then searches from that location (if found) to the first occurance of typeDelim. The value inbetween is used as the type of substitution to perform (i.e. request attribute, session, etc.). It next looks for the next occurance of endToken. The value inbetween is used as the key passed to the VariableResolver.DataSource specified by the type. The String value from the VariableResolver.DataSource replaces the portion of the String from the startToken to the endToken. If this is the entire String, the Object is returned instead of the String value. This process is repeated until no more substitutions are * needed.

This algorithm will accomodate nested variables (e.g. "${A{$x}}"). It also allows the replacement value itself to contain variables. Care should be taken to ensure that the replacement String included does not directly or indirectly refer to itself -- this will cause an infinite loop.

There is one special case where the string to be evaluated begins with the startToken and ends with the endToken. In this case, string substitution is NOT performed. Instead the value of the request attribute is returned.

Parameters:
ctx - The FacesContext
desc - The closest LayoutElement to this string
component - The assoicated UIComponent
string - The string to be evaluated.
startToken - Marks the beginning "$"
typeDelim - Marks separation of type/variable "{"
endToken - Marks the end of the variable "}"
Returns:
The new string with substitutions, or the specified request attribute value.

resolveVariables

public static java.lang.Object resolveVariables(LayoutElement desc,
                                                javax.faces.component.UIComponent component,
                                                java.lang.Object value)
This method replaces the ${..} variables with their values. It will only do this for Strings and List's that contain Strings.

Parameters:
desc - The LayoutElement descriptor
component - The UIComponent
value - The value to resolve
Returns:
The result

resolveVariables

public static java.lang.Object resolveVariables(javax.faces.context.FacesContext ctx,
                                                LayoutElement desc,
                                                javax.faces.component.UIComponent component,
                                                java.lang.Object value)
This method replaces the ${..} variables with their attribute values. It will only do this for Strings and List's that contain Strings.

Parameters:
ctx - The FacesContext
desc - The LayoutElement descriptor
component - The UIComponent
value - The value to resolve
Returns:
The result

getDataSource

public static VariableResolver.DataSource getDataSource(java.lang.String key)

This method looks up the requested VariableResolver.DataSource by the given key.

Parameters:
key - The key identifying the desired VariableResolver.DataSource
Returns:
The requested VariableResolver.DataSource

setDataSource

public static void setDataSource(java.lang.String key,
                                 VariableResolver.DataSource dataSource)

This method sets the given VariableResolver.DataSource to be used for $[type]{...} when key matches type.

Parameters:
key - The key identifying the VariableResolver.DataSource
dataSource - The VariableResolver.DataSource

main

public static void main(java.lang.String[] args)
The main function for this class provides some simple test cases.

Parameters:
args - The commandline arguments.