Class UriPattern

java.lang.Object
org.exoplatform.services.rest.uri.UriPattern

public class UriPattern extends Object
Version:
$Id: $
Author:
Andrey Parfonov
  • Field Details

    • URIPATTERN_COMPARATOR

      public static final Comparator<UriPattern> URIPATTERN_COMPARATOR
      Sort the templates according to the string comparison of the template regular expressions.

      JSR-311 specification: "Sort the set of matching resource classes using the number of characters in the regular expression not resulting from template variables as the primary key and the number of matching groups as a secondary key"

  • Constructor Details

    • UriPattern

      public UriPattern(String template)
      Constructs UriPattern.
      Parameters:
      template - the source template
      See Also:
      • Path
  • Method Details

    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getPattern

      public Pattern getPattern()
      Get the regex pattern.
      Returns:
      the regex pattern
    • getTemplate

      public String getTemplate()
      Get the URI template as a String.
      Returns:
      the URI template
    • getRegex

      public String getRegex()
      Get the regular expression.
      Returns:
      the regular expression
    • getNumberOfLiteralCharacters

      public int getNumberOfLiteralCharacters()
      Get the number of literal characters in the template.
      Returns:
      number of literal characters in the template
    • getParameterNames

      public List<String> getParameterNames()
      Returns:
      list of names
    • match

      public boolean match(String uri, List<String> parameters)
      Check is URI string match to pattern. If it is then fill given list by parameter value. Before coping value list is cleared. List will be 1 greater then number of keys. It can be used for check is resource is matching to requested. If resource is match the last element in list must be '/' or null.
      Parameters:
      uri - the URI string
      parameters - target list
      Returns:
      true if URI string is match to pattern, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • createUriWithValues

      public static String createUriWithValues(String schema, String userInfo, String host, int port, String path, String query, String fragment, Map<String,? extends Object> values, boolean encode)
      Create URI from URI part. Each URI part can contains templates.
      Parameters:
      schema - the schema URI part
      userInfo - the user info URI part
      host - the host name URI part
      port - the port number URI part
      path - the path URI part
      query - the query string URI part
      fragment - the fragment URI part
      values - the values which must be used instead templates parameters
      encode - if true then encode value before add it in URI, otherwise value must be validate to legal characters
      Returns:
      the URI string
    • createUriWithValues

      public static String createUriWithValues(String schema, String userInfo, String host, int port, String path, String query, String fragment, Object[] values, boolean encode)
      Create URI from URI part. Each URI part can contains templates.
      Parameters:
      schema - the schema URI part
      userInfo - the user info URI part
      host - the host name URI part
      port - the port number URI part
      path - the path URI part
      query - the query string URI part
      fragment - the fragment URI part
      values - the values which must be used instead templates parameters
      encode - if true then encode value before add it in URI, otherwise value must be validate to legal characters
      Returns:
      the URI string