Search in sources :

Example 1 with CharacterIndex

use of com.jayway.jsonpath.internal.CharacterIndex in project JsonPath by json-path.

the class PathCompiler method compile.

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;
    }
}
Also used : Path(com.jayway.jsonpath.internal.Path) LinkedList(java.util.LinkedList) InvalidPathException(com.jayway.jsonpath.InvalidPathException) InvalidPathException(com.jayway.jsonpath.InvalidPathException) CharacterIndex(com.jayway.jsonpath.internal.CharacterIndex) Predicate(com.jayway.jsonpath.Predicate)

Example 2 with CharacterIndex

use of com.jayway.jsonpath.internal.CharacterIndex in project JsonPath by jayway.

the class PathCompiler method compile.

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));
        return new PathCompiler(ci, filterStack).compile();
    } catch (Exception e) {
        InvalidPathException ipe;
        if (e instanceof InvalidPathException) {
            ipe = (InvalidPathException) e;
        } else {
            ipe = new InvalidPathException(e);
        }
        throw ipe;
    }
}
Also used : LinkedList(java.util.LinkedList) InvalidPathException(com.jayway.jsonpath.InvalidPathException) InvalidPathException(com.jayway.jsonpath.InvalidPathException) CharacterIndex(com.jayway.jsonpath.internal.CharacterIndex) Predicate(com.jayway.jsonpath.Predicate)

Aggregations

InvalidPathException (com.jayway.jsonpath.InvalidPathException)2 Predicate (com.jayway.jsonpath.Predicate)2 CharacterIndex (com.jayway.jsonpath.internal.CharacterIndex)2 LinkedList (java.util.LinkedList)2 Path (com.jayway.jsonpath.internal.Path)1