/** * Construct a new URI template. * * <p>The template will be parsed to extract template variables. * * <p>A specific regular expression will be generated from the template to match URIs according to * the template and map template variables to template values. * * <p> * * @param templateParser the parser to parse the template. * @throws PatternSyntaxException if the specified regular expression could not be generated * @throws IllegalArgumentException if the template is null or an empty string. */ protected UriTemplate(UriTemplateParser templateParser) throws PatternSyntaxException, IllegalArgumentException { this.template = templateParser.getTemplate(); this.normalizedTemplate = templateParser.getNormalizedTemplate(); this.pattern = createUriPattern(templateParser); this.numOfExplicitRegexes = templateParser.getNumberOfExplicitRegexes(); this.numOfCharacters = templateParser.getNumberOfLiteralCharacters(); this.endsWithSlash = template.charAt(template.length() - 1) == '/'; this.templateVariables = Collections.unmodifiableList(templateParser.getNames()); }
/** * Create the URI pattern from a URI template parser. * * @param templateParser the URI template parser. * @return the URI pattern. */ protected UriPattern createUriPattern(UriTemplateParser templateParser) { return new UriPattern(templateParser.getPattern(), templateParser.getGroupIndexes()); }