new UriPattern("/([^/]+)"), r)); new UriPattern(".*"), new TerminatingRule()));
/** * Public constructor. * @param template The template */ public PathPattern(final UriTemplate template) { super( PathPattern.postfixWithCapturingGroup(template.getPattern().getRegex()), PathPattern.indexCapturingGroup(template.getPattern().getGroupIndexes()) ); this.template = template; }
public Iterator<R> match(CharSequence path, UriMatchResultContext resultContext) { if (resultContext.isTracingEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("match path \"").append(path).append("\" -> "); boolean first = true; for (PatternRulePair<R> prp : rules) { if (!first) sb.append(", "); sb.append("\"").append(prp.p.toString()).append("\""); first = false; } resultContext.trace(sb.toString()); } for (PatternRulePair<R> prp : rules) { // Match each template final MatchResult mr = prp.p.match(path); if (mr != null) { resultContext.setMatchResult(mr); return new SingleEntryIterator<R>(prp.r); } } return new EmptyIterator<R>(); }
@Override public String toString() { if (target.hasValue()) { return "ARC(" + new String(code) + ") --> " + target.getPattern().getRegex(); } else { return "ARC(" + new String(code) + ") --> null"; } }
@Override public final String toString() { return pattern.toString(); }
/** * 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 URI 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 * URI path. * @param groupIndexes the array of group indexes to capturing groups. * @throws java.util.regex.PatternSyntaxException if the * regular expression could not be compiled */ public UriPattern(String regex, int[] groupIndexes) { this(compile(regex), groupIndexes); }
/** * 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 UriTemplate) { UriTemplate that = (UriTemplate)o; return this.pattern.equals(that.pattern); } else { return false; } }
/** * Match a URI against the template. * <p> * If the URI matches against the pattern then the template variable to value * map will be filled with template variables as keys and template values as * values. * <p> * * @param uri the uri to match against the template. * @param groupValues the list to store the values of a pattern's * capturing groups if matching is successful. The values are stored * in the same order as the pattern's capturing groups. * @return true if the URI matches the template, otherwise false. * @throws IllegalArgumentException if the uri or * templateVariableToValue is null. */ public final boolean match(CharSequence uri, List<String> groupValues) throws IllegalArgumentException { if (groupValues == null) throw new IllegalArgumentException(); return pattern.match(uri, groupValues); }
@Override public String toString() { if (target.hasValue()) { return "ARC(" + new String(code) + ") --> " + target.getPattern().getRegex(); } else { return "ARC(" + new String(code) + ") --> null"; } }
@Override public final String toString() { return pattern.toString(); }
/** * 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 URI 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 * URI path. * @param groupIndexes the array of group indexes to capturing groups. * @throws java.util.regex.PatternSyntaxException if the * regular expression could not be compiled */ public UriPattern(String regex, int[] groupIndexes) { this(compile(regex), groupIndexes); }
/** * 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 UriTemplate) { UriTemplate that = (UriTemplate)o; return this.pattern.equals(that.pattern); } else { return false; } }
/** * Public ctor. * @param template The template * @param rightHandSide Right hand side of the template */ public PathPattern(final UriTemplate template, final String rightHandSide) { super( PathPattern.postfixWithCapturingGroup( template.getPattern().getRegex(), rightHandSide ), PathPattern.indexCapturingGroup(template.getPattern().getGroupIndexes()) ); this.template = template; }
public Iterator<R> match(CharSequence path, UriMatchResultContext resultContext) { if (resultContext.isTracingEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("match path \"").append(path).append("\" -> "); boolean first = true; for (PatternRulePair<R> prp : rules) { if (!first) sb.append(", "); sb.append("\"").append(prp.p.toString()).append("\""); first = false; } resultContext.trace(sb.toString()); } for (PatternRulePair<R> prp : rules) { // Match each template final MatchResult mr = prp.p.match(path); if (mr != null) { resultContext.setMatchResult(mr); return new SingleEntryIterator<R>(prp.r); } } return new EmptyIterator<R>(); }
/** * Match a URI against the template. * <p> * If the URI matches against the pattern then the template variable to value * map will be filled with template variables as keys and template values as * values. * <p> * * @param uri the uri to match against the template. * @param groupValues the list to store the values of a pattern's * capturing groups if matching is successful. The values are stored * in the same order as the pattern's capturing groups. * @return true if the URI matches the template, otherwise false. * @throws IllegalArgumentException if the uri or * templateVariableToValue is null. */ public final boolean match(CharSequence uri, List<String> groupValues) throws IllegalArgumentException { if (groupValues == null) throw new IllegalArgumentException(); return pattern.match(uri, groupValues); }
@Override public String toString() { if (target.hasValue()) { return "ARC(" + new String(code) + ") --> " + target.getPattern().getRegex(); } else { return "ARC(" + new String(code) + ") --> null"; } }
/** * 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()); }