Class Variable

java.lang.Object
org.restlet.routing.Variable

public final class Variable extends Object
Variable descriptor for reference templates.
Author:
Jerome Louvel
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Matches all characters.
    static final int
    Matches all alphabetical characters.
    static final int
    Matches all alphabetical and digital characters.
    static final int
    Matches any TEXT excluding "(" and ")".
    static final int
    Matches any TEXT inside a comment excluding ";".
    static final int
    Matches all digital characters.
    static final int
    Matches any CHAR except CTLs or separators.
    static final int
    Matches all URI characters.
    static final int
    Matches URI fragment characters.
    static final int
    Matches URI path characters (not the query or the fragment parts).
    static final int
    Matches URI query characters.
    static final int
    Matches URI query parameter characters (name or value).
    static final int
    Matches URI scheme characters.
    static final int
    Matches URI segment characters.
    static final int
    Matches unreserved URI characters.
    static final int
    Matches all alphabetical and digital characters plus the underscore.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    Variable(int type)
    Constructor.
    Variable(int type, String defaultValue, boolean required, boolean fixed)
    Constructor.
    Variable(int type, String defaultValue, boolean required, boolean fixed, boolean decodingOnParse, boolean encodingOnFormat)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    encode(String value)
    According to the type of the variable, encodes the value given in parameters.
    Returns the default value to use if the key couldn't be found in the model.
    int
    Returns the type of variable.
    boolean
    Indicates if the parsed value must be decoded.
    boolean
    Indicates if the formatted value must be encoded.
    boolean
    Returns true if the value is fixed, in which case the "defaultValue" property is always used.
    boolean
    Returns true if the variable is required or optional.
    void
    setDecodingOnParse(boolean decodingOnParse)
    Indicates if the parsed value must be decoded.
    void
    setDefaultValue(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 fixed
    void
    setRequired(boolean required)
    Indicates if the variable is required or optional.
    void
    setType(int type)
    Sets the type of variable.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TYPE_ALL

      public static final int TYPE_ALL
      Matches all characters.
      See Also:
    • TYPE_ALPHA

      public static final int TYPE_ALPHA
      Matches all alphabetical characters.
      See Also:
    • TYPE_ALPHA_DIGIT

      public static final int TYPE_ALPHA_DIGIT
      Matches all alphabetical and digital characters.
      See Also:
    • TYPE_COMMENT

      public static final int TYPE_COMMENT
      Matches any TEXT excluding "(" and ")".
      See Also:
    • TYPE_COMMENT_ATTRIBUTE

      public static final int TYPE_COMMENT_ATTRIBUTE
      Matches any TEXT inside a comment excluding ";".
      See Also:
    • TYPE_DIGIT

      public static final int TYPE_DIGIT
      Matches all digital characters.
      See Also:
    • TYPE_TOKEN

      public static final int TYPE_TOKEN
      Matches any CHAR except CTLs or separators.
      See Also:
    • TYPE_URI_ALL

      public static final int TYPE_URI_ALL
      Matches all URI characters.
      See Also:
    • TYPE_URI_FRAGMENT

      public static final int TYPE_URI_FRAGMENT
      Matches URI fragment characters.
      See Also:
    • TYPE_URI_PATH

      public static final int TYPE_URI_PATH
      Matches URI path characters (not the query or the fragment parts).
      See Also:
    • TYPE_URI_QUERY

      public static final int TYPE_URI_QUERY
      Matches URI query characters.
      See Also:
    • TYPE_URI_QUERY_PARAM

      public static final int TYPE_URI_QUERY_PARAM
      Matches URI query parameter characters (name or value).
      See Also:
    • TYPE_URI_SCHEME

      public static final int TYPE_URI_SCHEME
      Matches URI scheme characters.
      See Also:
    • TYPE_URI_SEGMENT

      public static final int TYPE_URI_SEGMENT
      Matches URI segment characters.
      See Also:
    • TYPE_URI_UNRESERVED

      public static final int TYPE_URI_UNRESERVED
      Matches unreserved URI characters.
      See Also:
    • TYPE_WORD

      public static final int TYPE_WORD
      Matches all alphabetical and digital characters plus the underscore.
      See Also:
  • Constructor Details

    • 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, 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, 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 Details

    • encode

      public String encode(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 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(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.