/** * 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 template the template. * @throws PatternSyntaxException if the specified * regular expression could not be generated * @throws IllegalArgumentException if the template is null or * an empty string. */ public UriTemplate(String template) throws PatternSyntaxException, IllegalArgumentException { this(new UriTemplateParser(template)); }
/** * 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()); }
/** * 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()); }
template = new UriTemplateParser(template).getNormalizedTemplate(); final Matcher m = TEMPLATE_NAMES_PATTERN.matcher(template); int v = offset;
private void parseName(final CharacterIterator ci) { char c = consumeWhiteSpace(ci); nameRegexString = parseRegex(ci); break; } else if (c == '}') { break; } else if (c == ' ') { c = consumeWhiteSpace(ci); nameRegexString = parseRegex(ci); break; } else if (c == '}') {
private void processLiteralCharacters() { if (literalCharactersBuffer.length() > 0) { literalCharacters += literalCharactersBuffer.length(); String s = encodeLiteralCharacters(literalCharactersBuffer.toString()); normalizedTemplate.append(s); // Escape if reserved regex character for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (RESERVED_REGEX_CHARACTERS.contains(c)) { regex.append("\\"); } regex.append(c); } literalCharactersBuffer.setLength(0); } }
template = new UriTemplateParser(template).getNormalizedTemplate(); final Matcher m = TEMPLATE_NAMES_PATTERN.matcher(template); int v = offset;
private void parseName(final CharacterIterator ci) { char c = consumeWhiteSpace(ci); nameRegexString = parseRegex(ci); break; } else if (c == '}') { break; } else if (c == ' ') { c = consumeWhiteSpace(ci); nameRegexString = parseRegex(ci); break; } else if (c == '}') {
private void processLiteralCharacters() { if (literalCharactersBuffer.length() > 0) { literalCharacters += literalCharactersBuffer.length(); String s = encodeLiteralCharacters(literalCharactersBuffer.toString()); normalizedTemplate.append(s); // Escape if reserved regex character for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (RESERVED_REGEX_CHARACTERS.contains(c)) { regex.append("\\"); } regex.append(c); } literalCharactersBuffer.setLength(0); } }
/** * 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()); }
/** * 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 template the template. * @throws PatternSyntaxException if the specified * regular expression could not be generated * @throws IllegalArgumentException if the template is null or * an empty string. */ public UriTemplate(String template) throws PatternSyntaxException, IllegalArgumentException { this(new UriTemplateParser(template)); }