/**
* Copyright (C) 2010-2011 J.W.Marsden
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package jsonij.json;
import java.io.IOException;
import java.io.Reader;
import jsonij.json.jpath.Component;
import jsonij.json.jpath.JPathImp;
import jsonij.json.jpath.JPathParser;
import jsonij.parser.ParserException;
/**
* JPath implementation. Inspired by XPath and <a href="http://goessner.net/articles/JsonPath/">JsonPath</a>.
*
* @author J.W.Marsden
*/
public class JPath<C extends Component> extends JPathImp<C> {
public JPath() {
}
public static JPath<Component> parse(String path) throws IOException, ParserException {
JPathParser parser = new JPathParser();
JPath<Component> jPath = parser.parse(path);
return jPath;
}
public static Value evaluate(java.lang.String document, java.lang.String jPath) throws ParserException, IOException {
JSON jsonDocument = JSON.parse(document);
JPath jPathInstance = JPath.parse(jPath);
return jPathInstance.evaluate(jsonDocument);
}
public static Value evaluate(Reader documentReader, java.lang.String jPath) throws ParserException, IOException {
JSON jsonDocument = JSON.parse(documentReader);
JPath jPathInstance = JPath.parse(jPath);
return jPathInstance.evaluate(jsonDocument);
}
public static Value evaluate(JSON jsonDocument, java.lang.String jPath) throws ParserException, IOException {
JPath jPathInstance = JPath.parse(jPath);
return jPathInstance.evaluate(jsonDocument);
}
public static Value evaluate(Value value, java.lang.String jPath) throws ParserException, IOException {
JPath jPathInstance = JPath.parse(jPath);
return jPathInstance.evaluate(value);
}
}