You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2014/06/06 10:48:01 UTC
[1/7] git commit: add JSON output format for LDQuery CLI tool
Repository: marmotta
Updated Branches:
refs/heads/develop fa98d109d -> 32a3b58e9
add JSON output format for LDQuery CLI tool
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/4807b593
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/4807b593
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/4807b593
Branch: refs/heads/develop
Commit: 4807b5931bdfd0b858d7b517db79769863c267fb
Parents: fa98d10
Author: Chris Beer <ca...@stanford.edu>
Authored: Wed Jun 4 15:00:46 2014 -0700
Committer: Chris Beer <ca...@stanford.edu>
Committed: Wed Jun 4 15:06:52 2014 -0700
----------------------------------------------------------------------
libraries/ldpath/ldpath-ldquery-cli/pom.xml | 5 +++
.../apache/marmotta/ldpath/ldquery/LDQuery.java | 46 +++++++++++++++-----
2 files changed, 39 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4807b593/libraries/ldpath/ldpath-ldquery-cli/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-ldquery-cli/pom.xml b/libraries/ldpath/ldpath-ldquery-cli/pom.xml
index a81d56a..ced4597 100644
--- a/libraries/ldpath/ldpath-ldquery-cli/pom.xml
+++ b/libraries/ldpath/ldpath-ldquery-cli/pom.xml
@@ -300,6 +300,11 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.jr</groupId>
+ <artifactId>jackson-jr-objects</artifactId>
+ <version>2.3.3</version>
+ </dependency>
<!-- Testing -->
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4807b593/libraries/ldpath/ldpath-ldquery-cli/src/main/java/org/apache/marmotta/ldpath/ldquery/LDQuery.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-ldquery-cli/src/main/java/org/apache/marmotta/ldpath/ldquery/LDQuery.java b/libraries/ldpath/ldpath-ldquery-cli/src/main/java/org/apache/marmotta/ldpath/ldquery/LDQuery.java
index 71a9226..4db6b39 100644
--- a/libraries/ldpath/ldpath-ldquery-cli/src/main/java/org/apache/marmotta/ldpath/ldquery/LDQuery.java
+++ b/libraries/ldpath/ldpath-ldquery-cli/src/main/java/org/apache/marmotta/ldpath/ldquery/LDQuery.java
@@ -18,8 +18,10 @@
package org.apache.marmotta.ldpath.ldquery;
import ch.qos.logback.classic.Level;
+import com.fasterxml.jackson.jr.ob.JSON;
import org.apache.commons.cli.*;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.output.ProxyOutputStream;
import org.apache.marmotta.ldpath.LDPath;
import org.apache.marmotta.ldpath.backend.linkeddata.LDCacheBackend;
import org.apache.marmotta.ldpath.exception.LDPathParseException;
@@ -101,20 +103,38 @@ public class LDQuery {
Map<String,Collection<?>> result = ldpath.programQuery(context,new FileReader(file));
- for(String field : result.keySet()) {
- StringBuilder line = new StringBuilder();
- line.append(field);
- line.append(" = ");
- line.append("{");
- for (Iterator<?> it = result.get(field).iterator(); it.hasNext();) {
- line.append(it.next().toString());
- if(it.hasNext()) {
- line.append(", ");
- }
+ if (cmd.hasOption("format")) {
+ final String format = cmd.getOptionValue("format");
+ if (format.equals("json")) {
+ // Jackson.jr closes the output stream.
+ final ProxyOutputStream proxyOutputStream = new ProxyOutputStream(System.out) {
+ @Override
+ public void close() throws IOException {
+ flush();
+ }
+ };
+ JSON.std.write(result, proxyOutputStream);
+ System.out.println("");
+ } else {
+ System.err.println("Unknown format: " + format);
+ System.exit(1);
}
- line.append("}");
- System.out.println(line);
+ } else {
+ for (String field : result.keySet()) {
+ StringBuilder line = new StringBuilder();
+ line.append(field);
+ line.append(" = ");
+ line.append("{");
+ for (Iterator<?> it = result.get(field).iterator(); it.hasNext(); ) {
+ line.append(it.next().toString());
+ if (it.hasNext()) {
+ line.append(", ");
+ }
+ }
+ line.append("}");
+ System.out.println(line);
+ }
}
}
}
@@ -167,6 +187,8 @@ public class LDQuery {
Option store = OptionBuilder.withArgName("dir").hasArg().withDescription("cache the retrieved data in this directory").create("store");
result.addOption(store);
+ Option format = OptionBuilder.withArgName("format").hasArg().withDescription("output format").create("format");
+ result.addOption(format);
return result;
}
[5/7] git commit: MARMOTTA-507: Merge in pull request from cbeer on
github * cbeer/ldpath-json-functions: Add fn:jsonpath to evaluate a JSONPath
expression on a value
Posted by ja...@apache.org.
MARMOTTA-507: Merge in pull request from cbeer on github
* cbeer/ldpath-json-functions:
Add fn:jsonpath to evaluate a JSONPath expression on a value
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/d515c159
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/d515c159
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/d515c159
Branch: refs/heads/develop
Commit: d515c1594f39ce44daf28cb5741360095eff7f57
Parents: 1f795af ac78208
Author: Jakob Frank <ja...@apache.org>
Authored: Fri Jun 6 10:34:37 2014 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Fri Jun 6 10:34:37 2014 +0200
----------------------------------------------------------------------
libraries/ldpath/ldpath-core-bundle/pom.xml | 10 +-
libraries/ldpath/ldpath-functions-json/pom.xml | 107 +++++++++++++++++++
.../model/functions/json/JsonPathFunction.java | 84 +++++++++++++++
...rmotta.ldpath.api.functions.SelectorFunction | 1 +
.../functions/json/JsonPathFunctionTest.java | 61 +++++++++++
.../src/test/resources/logback.xml | 27 +++++
.../ldpath/model/functions/json/data.n3 | 31 ++++++
libraries/ldpath/ldpath-ldquery-cli/pom.xml | 4 +
.../ldpath/ldpath-template-linkeddata/pom.xml | 4 +
libraries/ldpath/pom.xml | 1 +
parent/pom.xml | 10 ++
11 files changed, 339 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d515c159/libraries/ldpath/ldpath-ldquery-cli/pom.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d515c159/parent/pom.xml
----------------------------------------------------------------------
[7/7] git commit: Credit where credit is due: adding contributors to
the reactor pom.
Posted by ja...@apache.org.
Credit where credit is due: adding contributors to the reactor pom.
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/32a3b58e
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/32a3b58e
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/32a3b58e
Branch: refs/heads/develop
Commit: 32a3b58e9313781e736db4489776a18b622987e5
Parents: 1ee80bd
Author: Jakob Frank <ja...@apache.org>
Authored: Fri Jun 6 10:43:35 2014 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Fri Jun 6 10:43:35 2014 +0200
----------------------------------------------------------------------
pom.xml | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/32a3b58e/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index e8c54f6..3031160 100644
--- a/pom.xml
+++ b/pom.xml
@@ -109,6 +109,22 @@
</developer>
</developers>
+ <contributors>
+ <contributor>
+ <name>Oliver Janner</name>
+ <organization>Salzburg Research</organization>
+ </contributor>
+ <contributor>
+ <name>Viktor Gal</name>
+ <url>http://github.com/vigsterkr</url>
+ <organization>Gravity R&D</organization>
+ </contributor>
+ <contributor>
+ <name>Chris Beer</name>
+ <url>http://cbeer.info/</url>
+ </contributor>
+ </contributors>
+
<organization>
<name>The Apache Software Foundation</name>
<url>http://www.apache.org</url>
[4/7] git commit: MARMOTTA-501: moved dependency declaration for
jackson-jr to parent-pom
Posted by ja...@apache.org.
MARMOTTA-501: moved dependency declaration for jackson-jr to parent-pom
License: AL2
Checked N&L for ldpath-ldquery-cli: jackson dependency already covered.
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/1f795af5
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/1f795af5
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/1f795af5
Branch: refs/heads/develop
Commit: 1f795af5af9c5bbead161de211daf1896a219ccb
Parents: 91ea134
Author: Jakob Frank <ja...@apache.org>
Authored: Fri Jun 6 10:32:47 2014 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Fri Jun 6 10:32:47 2014 +0200
----------------------------------------------------------------------
libraries/ldpath/ldpath-ldquery-cli/pom.xml | 1 -
parent/pom.xml | 6 ++++++
2 files changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1f795af5/libraries/ldpath/ldpath-ldquery-cli/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-ldquery-cli/pom.xml b/libraries/ldpath/ldpath-ldquery-cli/pom.xml
index ced4597..07d1396 100644
--- a/libraries/ldpath/ldpath-ldquery-cli/pom.xml
+++ b/libraries/ldpath/ldpath-ldquery-cli/pom.xml
@@ -303,7 +303,6 @@
<dependency>
<groupId>com.fasterxml.jackson.jr</groupId>
<artifactId>jackson-jr-objects</artifactId>
- <version>2.3.3</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1f795af5/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 2096480..3a85611 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -862,6 +862,12 @@
<version>${jackson.version}</version>
</dependency>
<dependency>
+ <groupId>com.fasterxml.jackson.jr</groupId>
+ <artifactId>jackson-jr-objects</artifactId>
+ <!-- FIXME: align jackson versions! -->
+ <version>2.3.3</version>
+ </dependency>
+ <dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
[6/7] git commit: MARMOTTA-507: removed duplicate dependency
declaration for json-path
Posted by ja...@apache.org.
MARMOTTA-507: removed duplicate dependency declaration for json-path
License AL2
Updated N&L for ldpath-ldquery-cli as the binary release packages the dependency
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/1ee80bd7
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/1ee80bd7
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/1ee80bd7
Branch: refs/heads/develop
Commit: 1ee80bd7e43a663b2661e1e515d25d6ad2de6ea3
Parents: d515c15
Author: Jakob Frank <ja...@apache.org>
Authored: Fri Jun 6 10:36:25 2014 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Fri Jun 6 10:40:20 2014 +0200
----------------------------------------------------------------------
libraries/ldpath/ldpath-ldquery-cli/src/main/doc/LICENSE.txt | 1 +
parent/pom.xml | 7 +------
2 files changed, 2 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1ee80bd7/libraries/ldpath/ldpath-ldquery-cli/src/main/doc/LICENSE.txt
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-ldquery-cli/src/main/doc/LICENSE.txt b/libraries/ldpath/ldpath-ldquery-cli/src/main/doc/LICENSE.txt
index e103479..ab03ea5 100644
--- a/libraries/ldpath/ldpath-ldquery-cli/src/main/doc/LICENSE.txt
+++ b/libraries/ldpath/ldpath-ldquery-cli/src/main/doc/LICENSE.txt
@@ -210,6 +210,7 @@ The Apache License, Version 2.0, also applies to the following subcomponents:
* Infinispan, http://infinispan.org
* JBoss Marshalling, https://github.com/jboss-remoting/jboss-marshalling/
* JGroups, http://www.jgroups.org
+ * JsonPath, https://github.com/jayway/JsonPath
Apache Marmotta subcomponents:
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1ee80bd7/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 47392a0..7126d01 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1498,7 +1498,7 @@
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
- <version>0.8.1</version>
+ <version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.directory.api</groupId>
@@ -1674,11 +1674,6 @@
<artifactId>jsoup</artifactId>
<version>1.7.2</version>
</dependency>
- <dependency>
- <groupId>com.jayway.jsonpath</groupId>
- <artifactId>json-path</artifactId>
- <version>0.9.1</version>
- </dependency>
<dependency>
<groupId>junit</groupId>
[3/7] git commit: MARMOTTA-501: Merge in pull request from cbeer in
github * cbeer/ldpath-json: add JSON output format for LDQuery CLI tool
Posted by ja...@apache.org.
MARMOTTA-501: Merge in pull request from cbeer in github
* cbeer/ldpath-json:
add JSON output format for LDQuery CLI tool
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/91ea134a
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/91ea134a
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/91ea134a
Branch: refs/heads/develop
Commit: 91ea134a9af84b4962b10dec4315f292e00b5620
Parents: fa98d10 4807b59
Author: Jakob Frank <ja...@apache.org>
Authored: Fri Jun 6 10:30:03 2014 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Fri Jun 6 10:30:03 2014 +0200
----------------------------------------------------------------------
libraries/ldpath/ldpath-ldquery-cli/pom.xml | 5 +++
.../apache/marmotta/ldpath/ldquery/LDQuery.java | 46 +++++++++++++++-----
2 files changed, 39 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
[2/7] git commit: Add fn:jsonpath to evaluate a JSONPath expression
on a value
Posted by ja...@apache.org.
Add fn:jsonpath to evaluate a JSONPath expression on a value
JSONPath: https://github.com/jayway/JsonPath
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/ac782081
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/ac782081
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/ac782081
Branch: refs/heads/develop
Commit: ac782081f8c5733b91a76d0d79895f07678e2b8d
Parents: fa98d10
Author: Chris Beer <ca...@stanford.edu>
Authored: Wed Jun 4 13:46:32 2014 -0700
Committer: Chris Beer <ca...@stanford.edu>
Committed: Thu Jun 5 07:35:43 2014 -0700
----------------------------------------------------------------------
libraries/ldpath/ldpath-core-bundle/pom.xml | 10 +-
libraries/ldpath/ldpath-functions-json/pom.xml | 107 +++++++++++++++++++
.../model/functions/json/JsonPathFunction.java | 84 +++++++++++++++
...rmotta.ldpath.api.functions.SelectorFunction | 1 +
.../functions/json/JsonPathFunctionTest.java | 61 +++++++++++
.../src/test/resources/logback.xml | 27 +++++
.../ldpath/model/functions/json/data.n3 | 31 ++++++
libraries/ldpath/ldpath-ldquery-cli/pom.xml | 4 +
.../ldpath/ldpath-template-linkeddata/pom.xml | 4 +
libraries/ldpath/pom.xml | 1 +
parent/pom.xml | 10 ++
11 files changed, 339 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/ac782081/libraries/ldpath/ldpath-core-bundle/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-core-bundle/pom.xml b/libraries/ldpath/ldpath-core-bundle/pom.xml
index fdf351f..893f1cd 100644
--- a/libraries/ldpath/ldpath-core-bundle/pom.xml
+++ b/libraries/ldpath/ldpath-core-bundle/pom.xml
@@ -75,6 +75,11 @@
<artifactId>ldpath-functions-xml</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>ldpath-functions-json</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
@@ -94,6 +99,7 @@
NOTES:
* jdom2 is required for using the ldpath-functions-xml
* jsoup is required for using the ldpath-functions-html
+ * jsonpath is required for using the ldpath-functions-json
-->
<Import-Package>
org.slf4j.*;version="[1.6,2)",
@@ -101,6 +107,7 @@
ch.qos.logback.classic;resolution:=optional,
org.jdom2.*;resolution:=optional,
org.jsoup.*;resolution:=optional,
+ com.jayway.jsonpath.*;resolution:=optional,
*
</Import-Package>
<_exportcontents>
@@ -114,7 +121,8 @@
ldpath-core,
ldpath-functions-collections, ldpath-functions-date,
ldpath-functions-html, ldpath-functions-math,
- ldpath-functions-text, ldpath-functions-xml
+ ldpath-functions-text, ldpath-functions-xml,
+ ldpath-functions-json
</Embed-Dependency>
</instructions>
</configuration>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/ac782081/libraries/ldpath/ldpath-functions-json/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-json/pom.xml b/libraries/ldpath/ldpath-functions-json/pom.xml
new file mode 100644
index 0000000..3c6ae66
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-json/pom.xml
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>marmotta-parent</artifactId>
+ <version>3.3.0-SNAPSHOT</version>
+ <relativePath>../../../parent</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <name>LDPath Functions: JSON</name>
+ <artifactId>ldpath-functions-json</artifactId>
+ <packaging>jar</packaging>
+
+ <description>LDPath Functions for JSON content.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>ldpath-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>ldpath-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.jayway.jsonpath</groupId>
+ <artifactId>json-path</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>ldpath-core</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>ldpath-backend-sesame</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-repository-sail</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-sail-memory</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-rio-n3</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin> <!-- generate JRebel Configuration -->
+ <groupId>org.zeroturnaround</groupId>
+ <artifactId>jrebel-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-rebel-xml</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <relativePath>../../../</relativePath>
+ <rootPath>$${rebel.root}</rootPath>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <!-- No License-Header in META-INF/services -->
+ <exclude>src/main/resources/META-INF/services/*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/ac782081/libraries/ldpath/ldpath-functions-json/src/main/java/org/apache/marmotta/ldpath/model/functions/json/JsonPathFunction.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-json/src/main/java/org/apache/marmotta/ldpath/model/functions/json/JsonPathFunction.java b/libraries/ldpath/ldpath-functions-json/src/main/java/org/apache/marmotta/ldpath/model/functions/json/JsonPathFunction.java
new file mode 100644
index 0000000..4e80ec8
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-json/src/main/java/org/apache/marmotta/ldpath/model/functions/json/JsonPathFunction.java
@@ -0,0 +1,84 @@
+package org.apache.marmotta.ldpath.model.functions.json;
+
+import com.jayway.jsonpath.JsonPath;
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+import org.apache.marmotta.ldpath.api.functions.SelectorFunction;
+import org.apache.marmotta.ldpath.model.transformers.StringTransformer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+public class JsonPathFunction<Node> extends SelectorFunction<Node> {
+
+ private static final Logger log = LoggerFactory.getLogger(JsonPathFunction.class);
+ private final StringTransformer<Node> transformer = new StringTransformer<Node>();
+
+ @Override
+ protected String getLocalName() {
+ return "jsonpath";
+ }
+
+ @Override
+ public Collection<Node> apply(RDFBackend<Node> rdfBackend, Node context, @SuppressWarnings("unchecked") Collection<Node>... args) throws IllegalArgumentException {
+
+ Set<String> jsonpaths = new HashSet<String>();
+ for (Node jsonpath : args[0]) {
+ try {
+ jsonpaths.add(transformer.transform(rdfBackend,jsonpath, null));
+ } catch (IllegalArgumentException iae) {
+ throw new IllegalArgumentException("First argument must not contain anything else than String-Literals!");
+ }
+ }
+
+ Iterator<Node> it;
+ if(args.length < 2){
+ log.debug("Use context {} to execute jsonpaths {}",context,jsonpaths);
+ it = Collections.singleton(context).iterator();
+ } else {
+ log.debug("execute jsonpaths {} on parsed parameters",jsonpaths);
+ it = org.apache.marmotta.ldpath.util.Collections.iterator(1,args);
+ }
+
+ List<Node> result = new ArrayList<Node>();
+ while (it.hasNext()) {
+ Node n = it.next();
+ try {
+ for (String r : doFilter(transformer.transform(rdfBackend,n, null), jsonpaths)) {
+ result.add(rdfBackend.createLiteral(r));
+ }
+ } catch (IOException e) {
+ // This should never happen, since validation is turned off.
+ }
+ }
+
+ return result;
+ }
+
+ private List<String> doFilter(String in, Set<String> jsonpaths) throws IOException {
+ List<String> result = new ArrayList<String>();
+
+ for (String jsonpath : jsonpaths) {
+ result.add(String.valueOf(JsonPath.read(in, jsonpath)));
+ }
+
+ return result;
+ }
+
+ @Override
+ public String getSignature() {
+ return "fn:json(json: String [, nodes: JsonPathList]) : LiteralList";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Evaluate a JSONPath expression on either the value of the context node or the values of the nodes passed as arguments.";
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/ac782081/libraries/ldpath/ldpath-functions-json/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-json/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction b/libraries/ldpath/ldpath-functions-json/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction
new file mode 100644
index 0000000..64c8f37
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-json/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.SelectorFunction
@@ -0,0 +1 @@
+org.apache.marmotta.ldpath.model.functions.json.JsonPathFunction
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/ac782081/libraries/ldpath/ldpath-functions-json/src/test/java/org/apache/marmotta/ldpath/model/functions/json/JsonPathFunctionTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-json/src/test/java/org/apache/marmotta/ldpath/model/functions/json/JsonPathFunctionTest.java b/libraries/ldpath/ldpath-functions-json/src/test/java/org/apache/marmotta/ldpath/model/functions/json/JsonPathFunctionTest.java
new file mode 100644
index 0000000..923e944
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-json/src/test/java/org/apache/marmotta/ldpath/model/functions/json/JsonPathFunctionTest.java
@@ -0,0 +1,61 @@
+package org.apache.marmotta.ldpath.model.functions.json;
+
+import com.google.common.collect.Lists;
+import org.apache.marmotta.ldpath.model.fields.FieldMapping;
+import org.apache.marmotta.ldpath.parser.LdPathParser;
+import org.apache.marmotta.ldpath.parser.ParseException;
+import org.apache.marmotta.ldpath.test.AbstractTestBase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFParseException;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+
+@RunWith(Parameterized.class)
+public class JsonPathFunctionTest extends AbstractTestBase {
+
+ @Parameterized.Parameters(name = "{1}")
+ public static List<String[]> data() {
+ ArrayList<String[]> data = new ArrayList<String[]>();
+ data.add(new String[] { "$.string", "stringValue" });
+ data.add(new String[] { "$.int", "0" });
+ data.add(new String[] { "$..child[0]", "a" });
+ data.add(new String[] { "$.array", "[{\"child\":\"a\"},{\"child\":\"b\"}]" });
+ data.add(new String[] { "$..child", "[\"a\",\"b\"]" });
+ return data;
+ }
+
+ @Parameterized.Parameter
+ public String path;
+ @Parameterized.Parameter(1)
+ public String answer;
+
+ @Before
+ public void loadData() throws RepositoryException, RDFParseException, IOException {
+ super.loadData("data.n3", RDFFormat.N3);
+ }
+
+ @Test
+ public void testJsonPathFunction() throws ParseException {
+
+ final URI ctx = repository.getValueFactory().createURI(NSS.get("ex") + "Quiz");
+
+ final LdPathParser<Value> parser = createParserFromString("fn:jsonpath(\"" + path + "\", <http://www.w3.org/2011/content#chars>) :: xsd:string");
+ final FieldMapping<Object, Value> rule = parser.parseRule(NSS);
+ final Collection<Object> values = rule.getValues(backend, ctx);
+
+ Assert.assertEquals(1, values.size());
+ Assert.assertEquals(answer, values.iterator().next());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/ac782081/libraries/ldpath/ldpath-functions-json/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-json/src/test/resources/logback.xml b/libraries/ldpath/ldpath-functions-json/src/test/resources/logback.xml
new file mode 100644
index 0000000..1bfecff
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-json/src/test/resources/logback.xml
@@ -0,0 +1,27 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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.
+ -->
+
+<configuration>
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %highlight(%level) %cyan(%logger{15}) - %m%n</pattern>
+ </encoder>
+ </appender>
+ <root level="${root-level:-INFO}">
+ <appender-ref ref="CONSOLE"/>
+ </root>
+</configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/ac782081/libraries/ldpath/ldpath-functions-json/src/test/resources/org/apache/marmotta/ldpath/model/functions/json/data.n3
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-json/src/test/resources/org/apache/marmotta/ldpath/model/functions/json/data.n3 b/libraries/ldpath/ldpath-functions-json/src/test/resources/org/apache/marmotta/ldpath/model/functions/json/data.n3
new file mode 100644
index 0000000..bfeec91
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-json/src/test/resources/org/apache/marmotta/ldpath/model/functions/json/data.n3
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+@prefix ex: <http://www.example.com/> .
+@prefix cnt: <http://www.w3.org/2011/content#> .
+
+ex:Quiz a ex:Test, cnt:ContentAsText;
+ cnt:chars """
+ {
+ "string": "stringValue",
+ "int": 0,
+ "array": [
+ { "child": "a" },
+ { "child": "b" }
+ ]
+ }
+ """ .
http://git-wip-us.apache.org/repos/asf/marmotta/blob/ac782081/libraries/ldpath/ldpath-ldquery-cli/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-ldquery-cli/pom.xml b/libraries/ldpath/ldpath-ldquery-cli/pom.xml
index a81d56a..63358d7 100644
--- a/libraries/ldpath/ldpath-ldquery-cli/pom.xml
+++ b/libraries/ldpath/ldpath-ldquery-cli/pom.xml
@@ -176,6 +176,10 @@
<artifactId>ldpath-functions-xml</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>ldpath-functions-json</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.marmotta</groupId>
<artifactId>ldpath-functions-math</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/ac782081/libraries/ldpath/ldpath-template-linkeddata/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-template-linkeddata/pom.xml b/libraries/ldpath/ldpath-template-linkeddata/pom.xml
index bef5b39..1e8845f 100644
--- a/libraries/ldpath/ldpath-template-linkeddata/pom.xml
+++ b/libraries/ldpath/ldpath-template-linkeddata/pom.xml
@@ -118,6 +118,10 @@
</dependency>
<dependency>
<groupId>org.apache.marmotta</groupId>
+ <artifactId>ldpath-functions-json</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
<artifactId>ldpath-functions-math</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/ac782081/libraries/ldpath/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/pom.xml b/libraries/ldpath/pom.xml
index cb6a5c1..0e6b4a6 100644
--- a/libraries/ldpath/pom.xml
+++ b/libraries/ldpath/pom.xml
@@ -100,6 +100,7 @@
<module>ldpath-functions-text</module>
<module>ldpath-functions-math</module>
<module>ldpath-functions-date</module>
+ <module>ldpath-functions-json</module>
<!--
<module>ldpath-backend-sparql</module>
-->
http://git-wip-us.apache.org/repos/asf/marmotta/blob/ac782081/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 2096480..b5196eb 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1639,6 +1639,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>ldpath-functions-json</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.marmotta</groupId>
<artifactId>ldpath-functions-math</artifactId>
<version>${project.version}</version>
@@ -1663,6 +1668,11 @@
<artifactId>jsoup</artifactId>
<version>1.7.2</version>
</dependency>
+ <dependency>
+ <groupId>com.jayway.jsonpath</groupId>
+ <artifactId>json-path</artifactId>
+ <version>0.9.1</version>
+ </dependency>
<dependency>
<groupId>junit</groupId>