|
|
@ -57,13 +57,12 @@ public class PathCompiler { |
|
|
|
RootPathToken root = null; |
|
|
|
RootPathToken root = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char[] chars = path.toCharArray(); |
|
|
|
|
|
|
|
int i = 0; |
|
|
|
int i = 0; |
|
|
|
int positions; |
|
|
|
int positions; |
|
|
|
String fragment = ""; |
|
|
|
String fragment = ""; |
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
do { |
|
|
|
char current = chars[i]; |
|
|
|
char current = path.charAt(i); |
|
|
|
|
|
|
|
|
|
|
|
switch (current) { |
|
|
|
switch (current) { |
|
|
|
case SPACE: |
|
|
|
case SPACE: |
|
|
@ -73,27 +72,27 @@ public class PathCompiler { |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BRACKET_OPEN: |
|
|
|
case BRACKET_OPEN: |
|
|
|
positions = fastForwardUntilClosed(chars, i); |
|
|
|
positions = fastForwardUntilClosed(path, i); |
|
|
|
fragment = new String(chars, i, positions); |
|
|
|
fragment = path.substring(i, i+positions); |
|
|
|
i += positions; |
|
|
|
i += positions; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case PERIOD: |
|
|
|
case PERIOD: |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
if (chars[i] == PERIOD) { |
|
|
|
if (path.charAt(i) == PERIOD) { |
|
|
|
//This is a deep scan
|
|
|
|
//This is a deep scan
|
|
|
|
fragment = ".."; |
|
|
|
fragment = ".."; |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
positions = fastForward(chars, i); |
|
|
|
positions = fastForward(path, i); |
|
|
|
if (positions == 0) { |
|
|
|
if (positions == 0) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
} else if (positions == 1 && chars[i] == '*') { |
|
|
|
} else if (positions == 1 && path.charAt(i) == '*') { |
|
|
|
fragment = new String("[*]"); |
|
|
|
fragment = new String("[*]"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
assertValidFieldChars(chars, i, positions); |
|
|
|
assertValidFieldChars(path, i, positions); |
|
|
|
|
|
|
|
|
|
|
|
fragment = PROPERTY_OPEN + new String(chars, i, positions) + PROPERTY_CLOSE; |
|
|
|
fragment = PROPERTY_OPEN + path.substring(i, i+positions) + PROPERTY_CLOSE; |
|
|
|
} |
|
|
|
} |
|
|
|
i += positions; |
|
|
|
i += positions; |
|
|
|
} |
|
|
|
} |
|
|
@ -103,9 +102,9 @@ public class PathCompiler { |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
positions = fastForward(chars, i); |
|
|
|
positions = fastForward(path, i); |
|
|
|
|
|
|
|
|
|
|
|
fragment = PROPERTY_OPEN + new String(chars, i, positions) + PROPERTY_CLOSE; |
|
|
|
fragment = PROPERTY_OPEN + path.substring(i, i+positions) + PROPERTY_CLOSE; |
|
|
|
i += positions; |
|
|
|
i += positions; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -115,7 +114,7 @@ public class PathCompiler { |
|
|
|
root.append(PathComponentAnalyzer.analyze(fragment, filterList)); |
|
|
|
root.append(PathComponentAnalyzer.analyze(fragment, filterList)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} while (i < chars.length); |
|
|
|
} while (i < path.length()); |
|
|
|
|
|
|
|
|
|
|
|
Path pa = new CompiledPath(root); |
|
|
|
Path pa = new CompiledPath(root); |
|
|
|
|
|
|
|
|
|
|
@ -124,10 +123,10 @@ public class PathCompiler { |
|
|
|
return pa; |
|
|
|
return pa; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void assertValidFieldChars(char[] chars, int start, int positions) { |
|
|
|
private static void assertValidFieldChars(String s, int start, int positions) { |
|
|
|
int i = start; |
|
|
|
int i = start; |
|
|
|
while (i < start + positions) { |
|
|
|
while (i < start + positions) { |
|
|
|
char c = chars[i]; |
|
|
|
char c = s.charAt(i); |
|
|
|
|
|
|
|
|
|
|
|
if (!Character.isLetterOrDigit(c) && c != '-' && c != '_' && c != '$' && c != '@') { |
|
|
|
if (!Character.isLetterOrDigit(c) && c != '-' && c != '_' && c != '$' && c != '@') { |
|
|
|
throw new InvalidPathException("Invalid field name! Use bracket notation if your filed names does not match pattern: ([a-zA-Z@][a-zA-Z0-9@\\$_\\-]*)$"); |
|
|
|
throw new InvalidPathException("Invalid field name! Use bracket notation if your filed names does not match pattern: ([a-zA-Z@][a-zA-Z0-9@\\$_\\-]*)$"); |
|
|
@ -136,10 +135,10 @@ public class PathCompiler { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static int fastForward(char[] chars, int index) { |
|
|
|
private static int fastForward(String s, int index) { |
|
|
|
int skipCount = 0; |
|
|
|
int skipCount = 0; |
|
|
|
while (index < chars.length) { |
|
|
|
while (index < s.length()) { |
|
|
|
char current = chars[index]; |
|
|
|
char current = s.charAt(index); |
|
|
|
if (current == PERIOD || current == BRACKET_OPEN || current == SPACE) { |
|
|
|
if (current == PERIOD || current == BRACKET_OPEN || current == SPACE) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -149,7 +148,7 @@ public class PathCompiler { |
|
|
|
return skipCount; |
|
|
|
return skipCount; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static int fastForwardUntilClosed(char[] chars, int index) { |
|
|
|
private static int fastForwardUntilClosed(String s, int index) { |
|
|
|
int skipCount = 0; |
|
|
|
int skipCount = 0; |
|
|
|
int nestedBrackets = 0; |
|
|
|
int nestedBrackets = 0; |
|
|
|
|
|
|
|
|
|
|
@ -157,8 +156,8 @@ public class PathCompiler { |
|
|
|
index++; |
|
|
|
index++; |
|
|
|
skipCount++; |
|
|
|
skipCount++; |
|
|
|
|
|
|
|
|
|
|
|
while (index < chars.length) { |
|
|
|
while (index < s.length()) { |
|
|
|
char current = chars[index]; |
|
|
|
char current = s.charAt(index); |
|
|
|
|
|
|
|
|
|
|
|
index++; |
|
|
|
index++; |
|
|
|
skipCount++; |
|
|
|
skipCount++; |
|
|
@ -185,7 +184,6 @@ public class PathCompiler { |
|
|
|
static class PathComponentAnalyzer { |
|
|
|
static class PathComponentAnalyzer { |
|
|
|
|
|
|
|
|
|
|
|
private static final Pattern FILTER_PATTERN = Pattern.compile("^\\[\\s*\\?\\s*[,\\s*\\?]*?\\s*]$"); //[?] or [?, ?, ...]
|
|
|
|
private static final Pattern FILTER_PATTERN = Pattern.compile("^\\[\\s*\\?\\s*[,\\s*\\?]*?\\s*]$"); //[?] or [?, ?, ...]
|
|
|
|
private char[] chars; |
|
|
|
|
|
|
|
private int i; |
|
|
|
private int i; |
|
|
|
private char current; |
|
|
|
private char current; |
|
|
|
|
|
|
|
|
|
|
@ -218,10 +216,9 @@ public class PathCompiler { |
|
|
|
return new PredicatePathToken(filters); |
|
|
|
return new PredicatePathToken(filters); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.chars = pathFragment.toCharArray(); |
|
|
|
|
|
|
|
this.i = 0; |
|
|
|
this.i = 0; |
|
|
|
do { |
|
|
|
do { |
|
|
|
current = chars[i]; |
|
|
|
current = pathFragment.charAt(i); |
|
|
|
|
|
|
|
|
|
|
|
switch (current) { |
|
|
|
switch (current) { |
|
|
|
case '?': |
|
|
|
case '?': |
|
|
@ -237,7 +234,7 @@ public class PathCompiler { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} while (i < chars.length); |
|
|
|
} while (i < pathFragment.length()); |
|
|
|
|
|
|
|
|
|
|
|
throw new InvalidPathException("Could not analyze path component: " + pathFragment); |
|
|
|
throw new InvalidPathException("Could not analyze path component: " + pathFragment); |
|
|
|
} |
|
|
|
} |
|
|
@ -259,7 +256,7 @@ public class PathCompiler { |
|
|
|
boolean functionBracketClosed = false; |
|
|
|
boolean functionBracketClosed = false; |
|
|
|
boolean propertyOpen = false; |
|
|
|
boolean propertyOpen = false; |
|
|
|
|
|
|
|
|
|
|
|
current = chars[++i]; //skip the '?'
|
|
|
|
current = pathFragment.charAt(++i); //skip the '?'
|
|
|
|
|
|
|
|
|
|
|
|
while (current != ']' || bracketCount != 0) { |
|
|
|
while (current != ']' || bracketCount != 0) { |
|
|
|
|
|
|
|
|
|
|
@ -303,7 +300,7 @@ public class PathCompiler { |
|
|
|
|
|
|
|
|
|
|
|
} else if (bracketCount == 0 && isLogicOperatorChar(current)) { |
|
|
|
} else if (bracketCount == 0 && isLogicOperatorChar(current)) { |
|
|
|
|
|
|
|
|
|
|
|
if (isLogicOperatorChar(chars[i + 1])) { |
|
|
|
if (isLogicOperatorChar(pathFragment.charAt(i + 1))) { |
|
|
|
++i; |
|
|
|
++i; |
|
|
|
} |
|
|
|
} |
|
|
|
criteria.add(createCriteria(pathBuffer, operatorBuffer, valueBuffer)); |
|
|
|
criteria.add(createCriteria(pathBuffer, operatorBuffer, valueBuffer)); |
|
|
@ -320,7 +317,7 @@ public class PathCompiler { |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!functionBracketOpened || !functionBracketClosed) { |
|
|
|
if (!functionBracketOpened || !functionBracketClosed) { |
|
|
@ -381,7 +378,7 @@ public class PathCompiler { |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
} |
|
|
|
} |
|
|
|
return new PropertyPathToken(properties); |
|
|
|
return new PropertyPathToken(properties); |
|
|
|
} |
|
|
|
} |
|
|
@ -406,15 +403,15 @@ public class PathCompiler { |
|
|
|
|
|
|
|
|
|
|
|
if (contextSize) { |
|
|
|
if (contextSize) { |
|
|
|
|
|
|
|
|
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
while (current != '-') { |
|
|
|
while (current != '-') { |
|
|
|
if (current == ' ' || current == '(' || current == ')') { |
|
|
|
if (current == ' ' || current == '(' || current == ')') { |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
buffer.append(current); |
|
|
|
buffer.append(current); |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
} |
|
|
|
} |
|
|
|
String function = buffer.toString(); |
|
|
|
String function = buffer.toString(); |
|
|
|
buffer = new StringBuilder(); |
|
|
|
buffer = new StringBuilder(); |
|
|
@ -423,11 +420,11 @@ public class PathCompiler { |
|
|
|
} |
|
|
|
} |
|
|
|
while (current != ')') { |
|
|
|
while (current != ')') { |
|
|
|
if (current == ' ') { |
|
|
|
if (current == ' ') { |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
buffer.append(current); |
|
|
|
buffer.append(current); |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -442,12 +439,12 @@ public class PathCompiler { |
|
|
|
if (buffer.length() == 0) { |
|
|
|
if (buffer.length() == 0) { |
|
|
|
//this is a tail slice [:12]
|
|
|
|
//this is a tail slice [:12]
|
|
|
|
sliceTo = true; |
|
|
|
sliceTo = true; |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
while (Character.isDigit(current) || current == ' ' || current == '-') { |
|
|
|
while (Character.isDigit(current) || current == ' ' || current == '-') { |
|
|
|
if (current != ' ') { |
|
|
|
if (current != ' ') { |
|
|
|
buffer.append(current); |
|
|
|
buffer.append(current); |
|
|
|
} |
|
|
|
} |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
} |
|
|
|
} |
|
|
|
numbers.add(Integer.parseInt(buffer.toString())); |
|
|
|
numbers.add(Integer.parseInt(buffer.toString())); |
|
|
|
buffer = new StringBuilder(); |
|
|
|
buffer = new StringBuilder(); |
|
|
@ -455,14 +452,14 @@ public class PathCompiler { |
|
|
|
//we now this starts with [12:???
|
|
|
|
//we now this starts with [12:???
|
|
|
|
numbers.add(Integer.parseInt(buffer.toString())); |
|
|
|
numbers.add(Integer.parseInt(buffer.toString())); |
|
|
|
buffer = new StringBuilder(); |
|
|
|
buffer = new StringBuilder(); |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
|
|
|
|
|
|
|
|
//this is a tail slice [:12]
|
|
|
|
//this is a tail slice [:12]
|
|
|
|
while (Character.isDigit(current) || current == ' ' || current == '-') { |
|
|
|
while (Character.isDigit(current) || current == ' ' || current == '-') { |
|
|
|
if (current != ' ') { |
|
|
|
if (current != ' ') { |
|
|
|
buffer.append(current); |
|
|
|
buffer.append(current); |
|
|
|
} |
|
|
|
} |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (buffer.length() == 0) { |
|
|
|
if (buffer.length() == 0) { |
|
|
@ -486,7 +483,7 @@ public class PathCompiler { |
|
|
|
if (current == ']') { |
|
|
|
if (current == ']') { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
current = chars[++i]; |
|
|
|
current = pathFragment.charAt(++i); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (buffer.length() > 0) { |
|
|
|
if (buffer.length() > 0) { |
|
|
|