Package org.restlet.routing
Class Variable
- java.lang.Object
-
- org.restlet.routing.Variable
-
public final class Variable extends java.lang.Object
Variable descriptor for reference templates.- Author:
- Jerome Louvel
- See Also:
Template
-
-
Field Summary
Fields Modifier and Type Field Description static int
TYPE_ALL
Matches all characters.static int
TYPE_ALPHA
Matches all alphabetical characters.static int
TYPE_ALPHA_DIGIT
Matches all alphabetical and digital characters.static int
TYPE_COMMENT
Matches any TEXT excluding "(" and ")".static int
TYPE_COMMENT_ATTRIBUTE
Matches any TEXT inside a comment excluding ";".static int
TYPE_DIGIT
Matches all digital characters.static int
TYPE_TOKEN
Matches any CHAR except CTLs or separators.static int
TYPE_URI_ALL
Matches all URI characters.static int
TYPE_URI_FRAGMENT
Matches URI fragment characters.static int
TYPE_URI_PATH
Matches URI path characters (not the query or the fragment parts).static int
TYPE_URI_QUERY
Matches URI query characters.static int
TYPE_URI_QUERY_PARAM
Matches URI query parameter characters (name or value).static int
TYPE_URI_SCHEME
Matches URI scheme characters.static int
TYPE_URI_SEGMENT
Matches URI segment characters.static int
TYPE_URI_UNRESERVED
Matches unreserved URI characters.static int
TYPE_WORD
Matches all alphabetical and digital characters plus the underscore.
-
Constructor Summary
Constructors Constructor Description Variable()
Default constructor.Variable(int type)
Constructor.Variable(int type, java.lang.String defaultValue, boolean required, boolean fixed)
Constructor.Variable(int type, java.lang.String defaultValue, boolean required, boolean fixed, boolean decodingOnParse, boolean encodingOnFormat)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
encode(java.lang.String value)
According to the type of the variable, encodes the value given in parameters.java.lang.String
getDefaultValue()
Returns the default value to use if the key couldn't be found in the model.int
getType()
Returns the type of variable.boolean
isDecodingOnParse()
Indicates if the parsed value must be decoded.boolean
isEncodingOnFormat()
Indicates if the formatted value must be encoded.boolean
isFixed()
Returns true if the value is fixed, in which case the "defaultValue" property is always used.boolean
isRequired()
Returns true if the variable is required or optional.void
setDecodingOnParse(boolean decodingOnParse)
Indicates if the parsed value must be decoded.void
setDefaultValue(java.lang.String defaultValue)
Sets the default value to use if the key couldn't be found in the model.void
setEncodingOnFormat(boolean encodingOnFormat)
Indicates if the formatted value must be encoded.void
setFixed(boolean fixed)
Indicates if the value is fixedvoid
setRequired(boolean required)
Indicates if the variable is required or optional.void
setType(int type)
Sets the type of variable.
-
-
-
Field Detail
-
TYPE_ALL
public static final int TYPE_ALL
Matches all characters.- See Also:
- Constant Field Values
-
TYPE_ALPHA
public static final int TYPE_ALPHA
Matches all alphabetical characters.- See Also:
- Constant Field Values
-
TYPE_ALPHA_DIGIT
public static final int TYPE_ALPHA_DIGIT
Matches all alphabetical and digital characters.- See Also:
- Constant Field Values
-
TYPE_COMMENT
public static final int TYPE_COMMENT
Matches any TEXT excluding "(" and ")".- See Also:
- Constant Field Values
-
TYPE_COMMENT_ATTRIBUTE
public static final int TYPE_COMMENT_ATTRIBUTE
Matches any TEXT inside a comment excluding ";".- See Also:
- Constant Field Values
-
TYPE_DIGIT
public static final int TYPE_DIGIT
Matches all digital characters.- See Also:
- Constant Field Values
-
TYPE_TOKEN
public static final int TYPE_TOKEN
Matches any CHAR except CTLs or separators.- See Also:
- Constant Field Values
-
TYPE_URI_ALL
public static final int TYPE_URI_ALL
Matches all URI characters.- See Also:
- Constant Field Values
-
TYPE_URI_FRAGMENT
public static final int TYPE_URI_FRAGMENT
Matches URI fragment characters.- See Also:
- Constant Field Values
-
TYPE_URI_PATH
public static final int TYPE_URI_PATH
Matches URI path characters (not the query or the fragment parts).- See Also:
- Constant Field Values
-
TYPE_URI_QUERY
public static final int TYPE_URI_QUERY
Matches URI query characters.- See Also:
- Constant Field Values
-
TYPE_URI_QUERY_PARAM
public static final int TYPE_URI_QUERY_PARAM
Matches URI query parameter characters (name or value).- See Also:
- Constant Field Values
-
TYPE_URI_SCHEME
public static final int TYPE_URI_SCHEME
Matches URI scheme characters.- See Also:
- Constant Field Values
-
TYPE_URI_SEGMENT
public static final int TYPE_URI_SEGMENT
Matches URI segment characters.- See Also:
- Constant Field Values
-
TYPE_URI_UNRESERVED
public static final int TYPE_URI_UNRESERVED
Matches unreserved URI characters.- See Also:
- Constant Field Values
-
TYPE_WORD
public static final int TYPE_WORD
Matches all alphabetical and digital characters plus the underscore.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Variable
public Variable()
Default constructor. Type is TYPE_ALL, default value is "", required is true and fixed is false.
-
Variable
public Variable(int type)
Constructor. Default value is "", required is true and fixed is false.- Parameters:
type
- The type of variable. See TYPE_* constants.
-
Variable
public Variable(int type, java.lang.String defaultValue, boolean required, boolean fixed)
Constructor.- Parameters:
type
- The type of variable. See TYPE_* constants.defaultValue
- The default value to use if the key couldn't be found in the model.required
- Indicates if the variable is required or optional.fixed
- Indicates if the value is fixed, in which case the "defaultValue" property is always used.
-
Variable
public Variable(int type, java.lang.String defaultValue, boolean required, boolean fixed, boolean decodingOnParse, boolean encodingOnFormat)
Constructor.- Parameters:
type
- The type of variable. See TYPE_* constants.defaultValue
- The default value to use if the key couldn't be found in the model.required
- Indicates if the variable is required or optional.fixed
- Indicates if the value is fixed, in which case the "defaultValue" property is always used.decodingOnParse
- Indicates if the parsed value must be decoded.encodingOnFormat
- Indicates if the formatted value must be encoded.
-
-
Method Detail
-
encode
public java.lang.String encode(java.lang.String value)
According to the type of the variable, encodes the value given in parameters.- Parameters:
value
- The value to encode.- Returns:
- The encoded value, according to the variable type.
-
getDefaultValue
public java.lang.String getDefaultValue()
Returns the default value to use if the key couldn't be found in the model.- Returns:
- The default value to use if the key couldn't be found in the model.
-
getType
public int getType()
Returns the type of variable. See TYPE_* constants.- Returns:
- The type of variable. See TYPE_* constants.
-
isDecodingOnParse
public boolean isDecodingOnParse()
Indicates if the parsed value must be decoded.- Returns:
- True if the parsed value must be decoded, false otherwise.
-
isEncodingOnFormat
public boolean isEncodingOnFormat()
Indicates if the formatted value must be encoded.- Returns:
- True if the formatted value must be encoded, false otherwise.
-
isFixed
public boolean isFixed()
Returns true if the value is fixed, in which case the "defaultValue" property is always used.- Returns:
- True if the value is fixed, in which case the "defaultValue" property is always used.
-
isRequired
public boolean isRequired()
Returns true if the variable is required or optional.- Returns:
- True if the variable is required or optional.
-
setDecodingOnParse
public void setDecodingOnParse(boolean decodingOnParse)
Indicates if the parsed value must be decoded.- Parameters:
decodingOnParse
- True if the parsed value must be decoded, false otherwise.
-
setDefaultValue
public void setDefaultValue(java.lang.String defaultValue)
Sets the default value to use if the key couldn't be found in the model.- Parameters:
defaultValue
- The default value to use if the key couldn't be found in the model.
-
setEncodingOnFormat
public void setEncodingOnFormat(boolean encodingOnFormat)
Indicates if the formatted value must be encoded.- Parameters:
encodingOnFormat
- True if the formatted value must be encoded, false otherwise.
-
setFixed
public void setFixed(boolean fixed)
Indicates if the value is fixed- Parameters:
fixed
- True if the value is fixed
-
setRequired
public void setRequired(boolean required)
Indicates if the variable is required or optional.- Parameters:
required
- True if the variable is required or optional.
-
setType
public void setType(int type)
Sets the type of variable. See TYPE_* constants.- Parameters:
type
- The type of variable.
-
-