Polishing
This commit is contained in:
parent
0f36569d75
commit
b1c7f7d127
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -83,17 +83,17 @@ class CaptureTheRestPathElement extends PathElement {
|
|||
}
|
||||
|
||||
private String pathToString(int fromSegment, List<Element> pathElements) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = fromSegment, max = pathElements.size(); i < max; i++) {
|
||||
Element element = pathElements.get(i);
|
||||
if (element instanceof PathSegment) {
|
||||
buf.append(((PathSegment)element).valueToMatch());
|
||||
sb.append(((PathSegment)element).valueToMatch());
|
||||
}
|
||||
else {
|
||||
buf.append(element.value());
|
||||
sb.append(element.value());
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,6 +101,11 @@ class CaptureTheRestPathElement extends PathElement {
|
|||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
return ("/{*" + this.variableName + "}").toCharArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWildcardCount() {
|
||||
return 0;
|
||||
|
@ -117,8 +122,4 @@ class CaptureTheRestPathElement extends PathElement {
|
|||
return "CaptureTheRest(/{*" + this.variableName + "})";
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
return ("/{*"+this.variableName+"}").toCharArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class CaptureVariablePathElement extends PathElement {
|
|||
private final String variableName;
|
||||
|
||||
@Nullable
|
||||
private Pattern constraintPattern;
|
||||
private final Pattern constraintPattern;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -55,6 +55,7 @@ class CaptureVariablePathElement extends PathElement {
|
|||
if (colon == -1) {
|
||||
// no constraint
|
||||
this.variableName = new String(captureDescriptor, 1, captureDescriptor.length - 2);
|
||||
this.constraintPattern = null;
|
||||
}
|
||||
else {
|
||||
this.variableName = new String(captureDescriptor, 1, colon - 1);
|
||||
|
@ -134,6 +135,18 @@ class CaptureVariablePathElement extends PathElement {
|
|||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('{');
|
||||
sb.append(this.variableName);
|
||||
if (this.constraintPattern != null) {
|
||||
sb.append(':').append(this.constraintPattern.pattern());
|
||||
}
|
||||
sb.append('}');
|
||||
return sb.toString().toCharArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWildcardCount() {
|
||||
return 0;
|
||||
|
@ -156,16 +169,4 @@ class CaptureVariablePathElement extends PathElement {
|
|||
(this.constraintPattern != null ? ":" + this.constraintPattern.pattern() : "") + "})";
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append('{');
|
||||
b.append(this.variableName);
|
||||
if (this.constraintPattern != null) {
|
||||
b.append(':').append(this.constraintPattern.pattern());
|
||||
}
|
||||
b.append('}');
|
||||
return b.toString().toCharArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -26,14 +26,15 @@ import org.springframework.web.util.pattern.PathPattern.MatchingContext;
|
|||
* literal path elements 'foo', 'bar' and 'goo'.
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 5.0
|
||||
*/
|
||||
class LiteralPathElement extends PathElement {
|
||||
|
||||
private char[] text;
|
||||
private final char[] text;
|
||||
|
||||
private int len;
|
||||
private final int len;
|
||||
|
||||
private boolean caseSensitive;
|
||||
private final boolean caseSensitive;
|
||||
|
||||
|
||||
public LiteralPathElement(int pos, char[] literalText, boolean caseSensitive, char separator) {
|
||||
|
|
|
@ -336,18 +336,18 @@ public class PathPattern implements Comparable<PathPattern> {
|
|||
PathContainer resultPath = null;
|
||||
if (multipleAdjacentSeparators) {
|
||||
// Need to rebuild the path without the duplicate adjacent separators
|
||||
StringBuilder buf = new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int i = startIndex;
|
||||
while (i < endIndex) {
|
||||
Element e = pathElements.get(i++);
|
||||
buf.append(e.value());
|
||||
sb.append(e.value());
|
||||
if (e instanceof Separator) {
|
||||
while (i < endIndex && (pathElements.get(i) instanceof Separator)) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
resultPath = PathContainer.parsePath(buf.toString(), this.pathOptions);
|
||||
resultPath = PathContainer.parsePath(sb.toString(), this.pathOptions);
|
||||
}
|
||||
else if (startIndex >= endIndex) {
|
||||
resultPath = PathContainer.parsePath("");
|
||||
|
@ -491,13 +491,13 @@ public class PathPattern implements Comparable<PathPattern> {
|
|||
* @return the string form of the pattern
|
||||
*/
|
||||
String computePatternString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
PathElement pe = this.head;
|
||||
while (pe != null) {
|
||||
buf.append(pe.getChars());
|
||||
sb.append(pe.getChars());
|
||||
pe = pe.next;
|
||||
}
|
||||
return buf.toString();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -66,14 +66,14 @@ public class PatternParseException extends IllegalArgumentException {
|
|||
* with a pointer to the error position, as well as the error message.
|
||||
*/
|
||||
public String toDetailedString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(this.pattern).append('\n');
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(this.pattern).append('\n');
|
||||
for (int i = 0; i < this.position; i++) {
|
||||
buf.append(' ');
|
||||
sb.append(' ');
|
||||
}
|
||||
buf.append("^\n");
|
||||
buf.append(getMessage());
|
||||
return buf.toString();
|
||||
sb.append("^\n");
|
||||
sb.append(getMessage());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
|
|
|
@ -136,20 +136,19 @@ class RegexPathElement extends PathElement {
|
|||
if (matches) {
|
||||
if (isNoMorePattern()) {
|
||||
if (matchingContext.determineRemainingPath &&
|
||||
(this.variableNames.isEmpty() || textToMatch.length() > 0)) {
|
||||
(this.variableNames.isEmpty() || textToMatch.length() > 0)) {
|
||||
matchingContext.remainingPathIndex = pathIndex + 1;
|
||||
matches = true;
|
||||
}
|
||||
else {
|
||||
// No more pattern, is there more data?
|
||||
// If pattern is capturing variables there must be some actual data to bind to them
|
||||
matches = (pathIndex + 1) >= matchingContext.pathLength
|
||||
&& (this.variableNames.isEmpty() || textToMatch.length() > 0);
|
||||
matches = (pathIndex + 1 >= matchingContext.pathLength) &&
|
||||
(this.variableNames.isEmpty() || textToMatch.length() > 0);
|
||||
if (!matches && matchingContext.isMatchOptionalTrailingSeparator()) {
|
||||
matches = (this.variableNames.isEmpty()
|
||||
|| textToMatch.length() > 0)
|
||||
&& (pathIndex + 2) >= matchingContext.pathLength
|
||||
&& matchingContext.isSeparator(pathIndex + 1);
|
||||
matches = (this.variableNames.isEmpty() || textToMatch.length() > 0) &&
|
||||
(pathIndex + 2 >= matchingContext.pathLength) &&
|
||||
matchingContext.isSeparator(pathIndex + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,11 +159,11 @@ class RegexPathElement extends PathElement {
|
|||
|
||||
if (matches && matchingContext.extractingVariables) {
|
||||
// Process captures
|
||||
if (this.variableNames.size() != matcher.groupCount()) { // SPR-8455
|
||||
throw new IllegalArgumentException("The number of capturing groups in the pattern segment "
|
||||
+ this.pattern + " does not match the number of URI template variables it defines, "
|
||||
+ "which can occur if capturing groups are used in a URI template regex. "
|
||||
+ "Use non-capturing groups instead.");
|
||||
if (this.variableNames.size() != matcher.groupCount()) { // SPR-8455
|
||||
throw new IllegalArgumentException("The number of capturing groups in the pattern segment " +
|
||||
this.pattern + " does not match the number of URI template variables it defines, " +
|
||||
"which can occur if capturing groups are used in a URI template regex. " +
|
||||
"Use non-capturing groups instead.");
|
||||
}
|
||||
for (int i = 1; i <= matcher.groupCount(); i++) {
|
||||
String name = this.variableNames.get(i - 1);
|
||||
|
@ -187,6 +186,11 @@ class RegexPathElement extends PathElement {
|
|||
return (this.regex.length - varsLength - this.variableNames.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
return this.regex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCaptureCount() {
|
||||
return this.variableNames.size();
|
||||
|
@ -208,8 +212,4 @@ class RegexPathElement extends PathElement {
|
|||
return "Regex(" + String.valueOf(this.regex) + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
return this.regex;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -62,14 +62,15 @@ class SeparatorPathElement extends PathElement {
|
|||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Separator(" + this.separator + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
return new char[] {this.separator};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Separator(" + this.separator + ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -124,15 +124,15 @@ class SingleCharWildcardedPathElement extends PathElement {
|
|||
return this.len;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SingleCharWildcarded(" + String.valueOf(this.text) + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -86,6 +86,11 @@ class WildcardPathElement extends PathElement {
|
|||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
return new char[] {'*'};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWildcardCount() {
|
||||
return 1;
|
||||
|
@ -102,8 +107,4 @@ class WildcardPathElement extends PathElement {
|
|||
return "Wildcard(*)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
return new char[] {'*'};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -47,6 +47,11 @@ class WildcardTheRestPathElement extends PathElement {
|
|||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
return (this.separator + "**").toCharArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWildcardCount() {
|
||||
return 1;
|
||||
|
@ -58,8 +63,4 @@ class WildcardTheRestPathElement extends PathElement {
|
|||
return "WildcardTheRest(" + this.separator + "**)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
return (this.separator+"**").toCharArray();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue