MatchingContext matchingContext = new MatchingContext(pathContainer, true); matchingContext.setMatchAllowExtraPath(); boolean matches = this.head.matches(0, matchingContext); if (!matches) { PathRemainingMatchInfo info; if (matchingContext.remainingPathIndex == pathContainer.elements().size()) { info = new PathRemainingMatchInfo(EMPTY_PATH, matchingContext.getPathMatchResult()); matchingContext.getPathMatchResult());
return (matchingContext.isMatchOptionalTrailingSeparator() && (pathIndex + 1) == matchingContext.pathLength && matchingContext.isSeparator(pathIndex));
String candidateCapture = matchingContext.pathElementValue(pathIndex); if (candidateCapture.length() == 0) { return false; if (!match && matchingContext.isMatchOptionalTrailingSeparator()) { matchingContext.isSeparator(pathIndex); matchingContext.set(this.variableName, candidateCapture, ((PathSegment)matchingContext.pathElements.get(pathIndex-1)).parameters());
return (matchingContext.isMatchOptionalTrailingSeparator() && (pathIndex + 1) == matchingContext.pathLength && matchingContext.isSeparator(pathIndex));
return (matchingContext.isMatchOptionalTrailingSeparator() && (pathIndex + 1) == matchingContext.pathLength && matchingContext.isSeparator(pathIndex));
return (matchingContext.isMatchOptionalTrailingSeparator() && (pathIndex + 1) == matchingContext.pathLength && matchingContext.isSeparator(pathIndex));
return (matchingContext.isMatchOptionalTrailingSeparator() && // if optional slash is on... segmentData != null && segmentData.length() > 0 && // and there is at least one character to match the *... (pathIndex + 1) == matchingContext.pathLength && // and the next path element is the end of the candidate... matchingContext.isSeparator(pathIndex)); // and the final element is a separator
return (matchingContext.isMatchOptionalTrailingSeparator() && (pathIndex + 1) == matchingContext.pathLength && matchingContext.isSeparator(pathIndex));
@Override public boolean matches(int pathIndex, MatchingContext matchingContext) { String textToMatch = matchingContext.pathElementValue(pathIndex); Matcher matcher = this.pattern.matcher(textToMatch); boolean matches = matcher.matches(); if (!matches && matchingContext.isMatchOptionalTrailingSeparator()) { matches = (this.variableNames.isEmpty() || textToMatch.length() > 0) && (pathIndex + 2) >= matchingContext.pathLength && matchingContext.isSeparator(pathIndex + 1); String name = this.variableNames.get(i - 1); String value = matcher.group(i); matchingContext.set(name, value, (i == this.variableNames.size())? ((PathSegment)matchingContext.pathElements.get(pathIndex)).parameters():
String candidateCapture = matchingContext.pathElementValue(pathIndex); if (candidateCapture.length() == 0) { return false; if (!match && matchingContext.isMatchOptionalTrailingSeparator()) { matchingContext.isSeparator(pathIndex); matchingContext.set(this.variableName, candidateCapture, ((PathSegment)matchingContext.pathElements.get(pathIndex-1)).parameters());
return (matchingContext.isMatchOptionalTrailingSeparator() && // if optional slash is on... segmentData != null && segmentData.length() > 0 && // and there is at least one character to match the *... (pathIndex + 1) == matchingContext.pathLength && // and the next path element is the end of the candidate... matchingContext.isSeparator(pathIndex)); // and the final element is a separator
@Override public boolean matches(int pathIndex, MatchingContext matchingContext) { String textToMatch = matchingContext.pathElementValue(pathIndex); Matcher matcher = this.pattern.matcher(textToMatch); boolean matches = matcher.matches(); if (!matches && matchingContext.isMatchOptionalTrailingSeparator()) { matches = (this.variableNames.isEmpty() || textToMatch.length() > 0) && (pathIndex + 2) >= matchingContext.pathLength && matchingContext.isSeparator(pathIndex + 1); String name = this.variableNames.get(i - 1); String value = matcher.group(i); matchingContext.set(name, value, (i == this.variableNames.size())? ((PathSegment)matchingContext.pathElements.get(pathIndex)).parameters():
String candidateCapture = matchingContext.pathElementValue(pathIndex); if (candidateCapture.length() == 0) { return false; if (!match && matchingContext.isMatchOptionalTrailingSeparator()) { matchingContext.isSeparator(pathIndex); matchingContext.set(this.variableName, candidateCapture, ((PathSegment)matchingContext.pathElements.get(pathIndex-1)).parameters());
MatchingContext matchingContext = new MatchingContext(pathContainer, true); matchingContext.setMatchAllowExtraPath(); boolean matches = this.head.matches(0, matchingContext); if (!matches) {
if (pathIndex < matchingContext.pathLength && !matchingContext.isSeparator(pathIndex)) { return false; matchingContext.set(variableName, pathToString(pathIndex, matchingContext.pathElements), parametersCollector == null?NO_PARAMETERS:parametersCollector);
MatchingContext matchingContext = new MatchingContext(pathContainer, true); matchingContext.setMatchAllowExtraPath(); boolean matches = this.head.matches(0, matchingContext); if (!matches) { PathRemainingMatchInfo info; if (matchingContext.remainingPathIndex == pathContainer.elements().size()) { info = new PathRemainingMatchInfo(EMPTY_PATH, matchingContext.getPathMatchResult()); matchingContext.getPathMatchResult());
if (pathIndex < matchingContext.pathLength && !matchingContext.isSeparator(pathIndex)) { return false; matchingContext.set(this.variableName, pathToString(pathIndex, matchingContext.pathElements), parametersCollector == null?NO_PARAMETERS:parametersCollector);
/** * Match this pattern to the given URI path and return extracted URI template * variables as well as path parameters (matrix variables). * @param pathContainer the candidate path to attempt to match against * @return info object with the extracted variables, or {@code null} for no match */ @Nullable public PathMatchInfo matchAndExtract(PathContainer pathContainer) { if (this.head == null) { return hasLength(pathContainer) && !(this.matchOptionalTrailingSeparator && pathContainerIsJustSeparator(pathContainer)) ? null : PathMatchInfo.EMPTY; } else if (!hasLength(pathContainer)) { if (this.head instanceof WildcardTheRestPathElement || this.head instanceof CaptureTheRestPathElement) { pathContainer = EMPTY_PATH; // Will allow CaptureTheRest to bind the variable to empty } else { return null; } } MatchingContext matchingContext = new MatchingContext(pathContainer, true); return this.head.matches(0, matchingContext) ? matchingContext.getPathMatchResult() : null; }
/** * Matching a separator is easy, basically the character at candidateIndex * must be the separator. */ @Override public boolean matches(int pathIndex, MatchingContext matchingContext) { if (pathIndex < matchingContext.pathLength && matchingContext.isSeparator(pathIndex)) { if (isNoMorePattern()) { if (matchingContext.determineRemainingPath) { matchingContext.remainingPathIndex = pathIndex + 1; return true; } else { return (pathIndex + 1 == matchingContext.pathLength); } } else { pathIndex++; return (this.next != null && this.next.matches(pathIndex, matchingContext)); } } return false; }
/** * Match this pattern to the given URI path and return extracted URI template * variables as well as path parameters (matrix variables). * @param pathContainer the candidate path to attempt to match against * @return info object with the extracted variables, or {@code null} for no match */ @Nullable public PathMatchInfo matchAndExtract(PathContainer pathContainer) { if (this.head == null) { return hasLength(pathContainer) && !(this.matchOptionalTrailingSeparator && pathContainerIsJustSeparator(pathContainer)) ? null : PathMatchInfo.EMPTY; } else if (!hasLength(pathContainer)) { if (this.head instanceof WildcardTheRestPathElement || this.head instanceof CaptureTheRestPathElement) { pathContainer = EMPTY_PATH; // Will allow CaptureTheRest to bind the variable to empty } else { return null; } } MatchingContext matchingContext = new MatchingContext(pathContainer, true); return this.head.matches(0, matchingContext) ? matchingContext.getPathMatchResult() : null; }