/** * Create a path pattern and post fix with a right hand path pattern. * * @param template the path template. * @param rhpp the right hand path pattern postfix. */ public JerseyPathPattern(JerseyPathTemplate template, RightHandPath rhpp) { super(postfixWithCapturingGroup(template.getJerseyPattern().getRegex(), rhpp), addIndexForRightHandPathCapturingGroup(template.getJerseyPattern().getGroupIndexes())); this.template = template; }
/** * Create a URI path template and encode (percent escape) any characters of * the template that are not valid URI characters. Paths that don't start with * a slash ({@code '/'}) will be automatically prefixed with one. * * @param path the URI path template. */ public JerseyPathTemplate(final String path) { super(new JerseyPathTemplateParser(JerseyPathTemplate.prefixWithSlash(path))); }
@Override public String getPath() { return template.getTemplate(); }
/** * Return a new path pattern with a same path template but * a {@link RightHandPath#capturingZeroSegments closed} right hand path. * * @param pattern an (open) path pattern to convert to a closed pattern. * @return closed path pattern for the same path template. */ public static JerseyPathPattern asClosed(JerseyPathPattern pattern) { return new JerseyPathPattern(pattern.getTemplate().getTemplate(), RightHandPath.capturingZeroSegments); } //
/** * Create the URI pattern from a URI template parser. * * @param templateParser the URI template parser. * @return the URI pattern. */ private static JerseyPatternWithGroups initUriPattern(JerseyUriTemplateParser templateParser) { return new JerseyPatternWithGroups(templateParser.getPattern(), templateParser.getGroupIndexes()); }
/** * Create a path pattern and post fix with * {@link RightHandPath#capturingZeroOrMoreSegments}. * * @param template the path template. * * @see #PathPattern(String, JerseyPathPattern.RightHandPath) */ public JerseyPathPattern(String template) { this(new JerseyPathTemplate(template)); }
@Override public boolean match(String path, Map<String, String> params) { return match((CharSequence)path,params); }
/** * Hashcode is calculated from String of the regular expression * generated from the template. * * @return the hash code. */ @Override public final int hashCode() { return pattern.hashCode(); }
/** * Construct a new pattern. * * @param regex the regular expression. If the expression is null or an * empty string then the pattern will only match a null or empty * string. * @param groupIndexes the array of group indexes to capturing groups. * @throws java.util.regex.PatternSyntaxException if the * regular expression could not be compiled */ public JerseyPatternWithGroups(final String regex, final int[] groupIndexes) throws PatternSyntaxException { this(compile(regex), groupIndexes); }
public final boolean match(CharSequence uri) throws IllegalArgumentException { return pattern.matches(uri); }
/** * Create a URI by substituting any template variables * for corresponding template values. * <p> * A URI template varibale without a value will be substituted by the * empty string. * * @param values the array of template values. The values will be * substituted in order of occurence of unique template variables. * @return the URI. */ public final String createURI(String... values) { return createURI(values, 0, values.length); }
private static String postfixWithCapturingGroup(String regex) { return postfixWithCapturingGroup(regex, RightHandPath.capturingZeroOrMoreSegments); }
@Override public boolean hasVariables() { return getNumberOfTemplateVariables() > 0; }
/** * Equality is calculated from the String of the regular expression * generated from the templates. * * @param o the reference object with which to compare. * @return true if equals, otherwise false. */ @Override public final boolean equals(Object o) { if (o instanceof JerseyUriTemplate) { JerseyUriTemplate that = (JerseyUriTemplate) o; return this.pattern.equals(that.pattern); } else { return false; } } }
@Override public int end(final int group) { if (group != 0) { throw new IndexOutOfBoundsException(); } return end(); }
/** * Create a path pattern and post fix with * {@link RightHandPath#capturingZeroOrMoreSegments}. * * @param template the path template * * @see #PathPattern(JerseyPathTemplate, JerseyPathPattern.RightHandPath) */ public JerseyPathPattern(JerseyPathTemplate template) { super(postfixWithCapturingGroup(template.getJerseyPattern().getRegex()), addIndexForRightHandPathCapturingGroup(template.getJerseyPattern().getGroupIndexes())); this.template = template; }
/** * Create a path pattern and post fix with a right hand path pattern. * * @param template the path template. * @param rhpp the right hand path pattern postfix. */ public JerseyPathPattern(String template, RightHandPath rhpp) { this(new JerseyPathTemplate(template), rhpp); }
@Override public boolean matches(String path) { return match((CharSequence)path); } }
@Override public PathTemplate createPathTemplate(String path) { return new JerseyPathTemplate(path); }