package org.springframework.web.util.pattern;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.PathContainer.Element;
import org.springframework.http.server.PathContainer.PathSegment;
import org.springframework.web.util.pattern.PathPattern.MatchingContext;
class LiteralPathElement extends PathElement {
private char[] text;
private int len;
private boolean caseSensitive;
public LiteralPathElement(int pos, char[] literalText, boolean caseSensitive, char separator) {
super(pos, separator);
this.len = literalText.length;
this.caseSensitive = caseSensitive;
if (caseSensitive) {
this.text = literalText;
}
else {
this.text = new char[literalText.length];
for (int i = 0; i < this.len; i++) {
this.text[i] = Character.toLowerCase(literalText[i]);
}
}
}
@Override
public boolean matches(int pathIndex, MatchingContext matchingContext) {
if (pathIndex >= matchingContext.pathLength) {
return false;
}
Element element = matchingContext.pathElements.get(pathIndex);
if (!(element instanceof PathContainer.PathSegment)) {
return false;
}
String value = ((PathSegment)element).valueToMatch();
if (value.length() != this.len) {
return false;
}
if (this.caseSensitive) {
for (int i = 0; i < this.len; i++) {
if (value.charAt(i) != this.text[i]) {
return false;
}
}
}
else {
for (int i = 0; i < this.len; i++) {
if (Character.toLowerCase(value.charAt(i)) != this.text[i]) {
return false;
}
}
}
pathIndex++;
if (isNoMorePattern()) {
if (matchingContext.determineRemainingPath) {
matchingContext.remainingPathIndex = pathIndex;
return true;
}
else {
if (pathIndex == matchingContext.pathLength) {
return true;
}
else {
return (matchingContext.isMatchOptionalTrailingSeparator() &&
(pathIndex + 1) == matchingContext.pathLength &&
matchingContext.isSeparator(pathIndex));
}
}
}
else {
return (this.next != null && this.next.matches(pathIndex, matchingContext));
}
}
@Override
public int getNormalizedLength() {
return this.len;
}
@Override
public char[] getChars() {
return this.text;
}
@Override
public String toString() {
return "Literal(" + String.valueOf(this.text) + ")";
}
}