Class URITemplate


  • public final class URITemplate
    extends Object
    • Constructor Detail

      • URITemplate

        public URITemplate​(String theTemplate)
    • Method Detail

      • getLiteralChars

        public String getLiteralChars()
      • getValue

        public String getValue()
      • getPatternValue

        public String getPatternValue()
      • getVariables

        public List<String> getVariables()
        List of all variables in order of appearance in template.
        Returns:
        unmodifiable list of variable names w/o patterns, e.g. for "/foo/{v1:\\d}/{v2}" returned list is ["v1","v2"].
      • getCustomVariables

        public List<String> getCustomVariables()
        List of variables with patterns (regexps). List is subset of elements from getVariables().
        Returns:
        unmodifiable list of variables names w/o patterns.
      • match

        public boolean match​(String uri,
                             javax.ws.rs.core.MultivaluedMap<String,​String> templateVariableToValue)
      • substitute

        public String substitute​(List<String> values)
                          throws IllegalArgumentException
        Substitutes template variables with listed values. List of values is counterpart for list of variables. When list of value is shorter than variables substitution is partial. When variable has pattern, value must fit to pattern, otherwise IllegalArgumentException is thrown.

        Example1: for template "/{a}/{b}/{a}" getVariables() returns "[a, b, a]"; providing here list of value "[foo, bar, baz]" results with "/foo/bar/baz".

        Example2: for template "/{a}/{b}/{a}" providing list of values "[foo]" results with "/foo/{b}/{a}".

        Parameters:
        values - values for variables
        Returns:
        template with bound variables.
        Throws:
        IllegalArgumentException - when values is null, any value does not match pattern etc.
      • substitute

        public String substitute​(Map<String,​? extends Object> valuesMap,
                                 Set<String> encodePathSlashVars,
                                 boolean allowUnresolved)
                          throws IllegalArgumentException
        Substitutes template variables with mapped values. Variables are mapped to values; if not all variables are bound result will still contain variables. Note that all variables with the same name are replaced by one value.

        Example: for template "/{a}/{b}/{a}" getVariables() returns "[a, b, a]"; providing here mapping "[a: foo, b: bar]" results with "/foo/bar/foo" (full substitution) and for mapping "[b: baz]" result is "{a}/baz/{a}" (partial substitution).

        Parameters:
        valuesMap - map variables to their values; on each value Object.toString() is called.
        Returns:
        template with bound variables.
        Throws:
        IllegalArgumentException
      • encodeLiteralCharacters

        public String encodeLiteralCharacters​(boolean isQuery)
        Encoded literal characters surrounding template variables, ex. "a {id} b" will be encoded to "a%20{id}%20b"
        Returns:
        encoded value
      • createTemplate

        public static URITemplate createTemplate​(javax.ws.rs.Path path)
      • createExactTemplate

        public static URITemplate createExactTemplate​(String pathValue)