PathNode(CharSequence charSequence, boolean existsCheck, boolean shouldExist) { this(PathCompiler.compile(charSequence.toString()), existsCheck, shouldExist); }
if (isWhitespace(c)) { continue; type = ParamType.JSON; else if (isPathContext(c)) { case PATH: LinkedList<Predicate> predicates = new LinkedList<Predicate>(); PathCompiler compiler = new PathCompiler(parameter.toString(), predicates); param = new Parameter(compiler.compile()); break;
private boolean readNextToken(PathTokenAppender appender) { char c = path.currentChar(); switch (c) { case OPEN_SQUARE_BRACKET: return readBracketPropertyToken(appender) || readArrayToken(appender) || readWildCardToken(appender) || readFilterToken(appender) || readPlaceholderToken(appender) || fail("Could not parse token starting at position " + path.position() + ". Expected ?, ', 0-9, * "); case PERIOD: return readDotToken(appender) || fail("Could not parse token starting at position " + path.position()); case WILDCARD: return readWildCardToken(appender) || fail("Could not parse token starting at position " + path.position()); default: return readPropertyOrFunctionToken(appender) || fail("Could not parse token starting at position " + path.position()); } }
private RootPathToken readContextToken() { readWhitespace(); if (!isPathContext(path.currentChar())) { throw new InvalidPathException("Path must start with '$' or '@'"); } RootPathToken pathToken = PathTokenFactory.createRootPathToken(path.currentChar()); if (path.currentIsTail()) { return pathToken; } path.incrementPosition(1); if(path.currentChar() != PERIOD && path.currentChar() != OPEN_SQUARE_BRACKET){ fail("Illegal character at position " + path.position() + " expected '.' or '['"); } PathTokenAppender appender = pathToken.getPathTokenAppender(); readNextToken(appender); return pathToken; }
public static Path compile(String path, final Predicate... filters) { try { CharacterIndex ci = new CharacterIndex(path); ci.trim(); if(!( ci.charAt(0) == DOC_CONTEXT) && !( ci.charAt(0) == EVAL_CONTEXT)){ ci = new CharacterIndex("$." + path); ci.trim(); } if(ci.lastCharIs('.')){ fail("Path must not end with a '.' or '..'"); } LinkedList<Predicate> filterStack = new LinkedList<Predicate>(asList(filters)); Path p = new PathCompiler(ci, filterStack).compile(); return p; } catch (Exception e) { InvalidPathException ipe; if (e instanceof InvalidPathException) { ipe = (InvalidPathException) e; } else { ipe = new InvalidPathException(e); } throw ipe; } }
functionParameters = parseFunctionParameters(functionName); } else { path.setPosition(readPosition + 1); return path.currentIsTail() || readNextToken(appender);
} else if (c == CLOSE_SQUARE_BRACKET && !inProperty) { if (lastSignificantWasComma){ fail("Found empty property at index "+readPosition); char nextSignificantChar = path.nextSignificantChar(readPosition); if (nextSignificantChar != CLOSE_SQUARE_BRACKET && nextSignificantChar != COMMA) { fail("Property must be separated by comma or Property must be terminated close square bracket at index "+readPosition); fail("Found empty property at index "+readPosition); fail("Property has not been closed - missing closing " + potentialStringDelimiter); return path.currentIsTail() || readNextToken(appender);
private void readWhitespace() { while (path.inBounds()) { char c = path.currentChar(); if (!isWhitespace(c)) { break; } path.incrementPosition(1); } }
private Path compile() { RootPathToken root = readContextToken(); return new CompiledPath(root, root.getPathFragment().equals("$")); }
private RootPathToken readContextToken() { readWhitespace(); if (!isPathContext(path.currentChar())) { throw new InvalidPathException("Path must start with '$' or '@'"); } RootPathToken pathToken = PathTokenFactory.createRootPathToken(path.currentChar()); if (path.currentIsTail()) { return pathToken; } path.incrementPosition(1); if(path.currentChar() != PERIOD && path.currentChar() != OPEN_SQUARE_BRACKET){ fail("Illegal character at position " + path.position() + " expected '.' or '["); } PathTokenAppender appender = pathToken.getPathTokenAppender(); readNextToken(appender); return pathToken; }
public static Path compile(String path, final Predicate... filters) { try { CharacterIndex ci = new CharacterIndex(path); ci.trim(); if(!( ci.charAt(0) == DOC_CONTEXT) && !( ci.charAt(0) == EVAL_CONTEXT)){ ci = new CharacterIndex("$." + path); ci.trim(); } if(ci.lastCharIs('.')){ fail("Path must not end with a '.' or '..'"); } LinkedList<Predicate> filterStack = new LinkedList<Predicate>(asList(filters)); Path p = new PathCompiler(ci, filterStack).compile(); return p; } catch (Exception e) { InvalidPathException ipe; if (e instanceof InvalidPathException) { ipe = (InvalidPathException) e; } else { ipe = new InvalidPathException(e); } throw ipe; } }
functionParameters = parseFunctionParameters(functionName); } else { path.setPosition(readPosition + 1); return path.currentIsTail() || readNextToken(appender);
} else if (c == CLOSE_SQUARE_BRACKET && !inProperty) { if (lastSignificantWasComma){ fail("Found empty property at index "+readPosition); char nextSignificantChar = path.nextSignificantChar(readPosition); if (nextSignificantChar != CLOSE_SQUARE_BRACKET && nextSignificantChar != COMMA) { fail("Property must be separated by comma or Property must be terminated close square bracket at index "+readPosition); fail("Found empty property at index "+readPosition); return path.currentIsTail() || readNextToken(appender);
private void readWhitespace() { while (path.inBounds()) { char c = path.currentChar(); if (!isWhitespace(c)) { break; } path.incrementPosition(1); } }
private Path compile() { RootPathToken root = readContextToken(); return new CompiledPath(root, root.getPathFragment().equals("$")); }
private boolean readNextToken(PathTokenAppender appender) { char c = path.currentChar(); switch (c) { case OPEN_SQUARE_BRACKET: return readBracketPropertyToken(appender) || readArrayToken(appender) || readWildCardToken(appender) || readFilterToken(appender) || readPlaceholderToken(appender) || fail("Could not parse token starting at position " + path.position() + ". Expected ?, ', 0-9, * "); case PERIOD: return readDotToken(appender) || fail("Could not parse token starting at position " + path.position()); case WILDCARD: return readWildCardToken(appender) || fail("Could not parse token starting at position " + path.position()); default: return readPropertyOrFunctionToken(appender) || fail("Could not parse token starting at position " + path.position()); } }
private JsonPath(String jsonPath, Predicate[] filters) { notNull(jsonPath, "path can not be null"); this.path = PathCompiler.compile(jsonPath, filters); }
if (isWhitespace(c)) { continue; type = ParamType.JSON; else if (isPathContext(c)) { case PATH: LinkedList<Predicate> predicates = new LinkedList<Predicate>(); PathCompiler compiler = new PathCompiler(parameter.toString(), predicates); param = new Parameter(compiler.compile()); break;
private RootPathToken readContextToken() { readWhitespace(); if (!isPathContext(path.currentChar())) { throw new InvalidPathException("Path must start with '$' or '@'"); } RootPathToken pathToken = PathTokenFactory.createRootPathToken(path.currentChar()); if (path.currentIsTail()) { return pathToken; } path.incrementPosition(1); if(path.currentChar() != PERIOD && path.currentChar() != OPEN_SQUARE_BRACKET){ fail("Illegal character at position " + path.position() + " expected '.' or '["); } PathTokenAppender appender = pathToken.getPathTokenAppender(); readNextToken(appender); return pathToken; }
public static Path compile(String path, final Predicate... filters) { try { CharacterIndex ci = new CharacterIndex(path); ci.trim(); if(!( ci.charAt(0) == DOC_CONTEXT) && !( ci.charAt(0) == EVAL_CONTEXT)){ ci = new CharacterIndex("$." + path); ci.trim(); } if(ci.lastCharIs('.')){ fail("Path must not end with a '.' or '..'"); } LinkedList<Predicate> filterStack = new LinkedList<Predicate>(asList(filters)); Path p = new PathCompiler(ci, filterStack).compile(); return p; } catch (Exception e) { InvalidPathException ipe; if (e instanceof InvalidPathException) { ipe = (InvalidPathException) e; } else { ipe = new InvalidPathException(e); } throw ipe; } }