diff --git a/.gitignore b/.gitignore
index b429e1ac..aeafccd3 100755
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ target/
.idea
*~
pom.xml.versionsBackup
+dependency-reduced-pom.xml
diff --git a/.travis.yml b/.travis.yml
index 36aa3a3e..a311838b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,10 +1,15 @@
language: java
jdk:
- - oraclejdk7
- - oraclejdk8
+ - openjdk8
+ - openjdk11
notifications:
- email:
- - ansell.peter@gmail.com
- - tristan.king@gmail.com
+ email: false
after_success:
- mvn clean test jacoco:report coveralls:report
+arch:
+ - amd64
+ - ppc64le
+
+cache:
+ directories:
+ - $HOME/.m2
diff --git a/LICENCE b/LICENCE
index e03ca9bb..2b584c5e 100644
--- a/LICENCE
+++ b/LICENCE
@@ -1,4 +1,5 @@
Copyright (c) 2012, Deutsche Forschungszentrum für Künstliche Intelligenz GmbH
+Copyright (c) 2012-2017, JSONLD-Java contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -21,4 +22,4 @@ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
index 9e028ea8..f1102e69 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,9 @@
+**JSONLD-Java is looking for a maintainer**
+
JSONLD-JAVA
===========
-This is a Java implementation of the [JSON-LD specification](http://www.w3.org/TR/json-ld/) and the [JSON-LD-API specification](http://www.w3.org/TR/json-ld-api/).
+This is a Java implementation of the [JSON-LD 1.0 specification](https://www.w3.org/TR/2014/REC-json-ld-20140116/) and the [JSON-LD-API 1.0 specification](https://www.w3.org/TR/2014/REC-json-ld-api-20140116/).
[](https://travis-ci.org/jsonld-java/jsonld-java) [](https://coveralls.io/r/jsonld-java/jsonld-java?branch=master)
@@ -14,11 +16,12 @@ From Maven
com.github.jsonld-javajsonld-java
- 0.8.2
+ 0.13.5
Code example
------------
+
```java
// Open a valid json(-ld) input file
InputStream inputStream = new FileInputStream("input.json");
@@ -36,11 +39,11 @@ Object compact = JsonLdProcessor.compact(jsonObject, context, options);
// Print out the result (or don't, it's your call!)
System.out.println(JsonUtils.toPrettyString(compact));
```
+
Processor options
-----------------
-The Options specified by the [JSON-LD API Specification](http://json-ld.org/spec/latest/json-ld-api/#jsonldoptions) are accessible via the `com.github.jsonldjava.core.JsonLdOptions` class, and each `JsonLdProcessor.*` function has an optional input to take an instance of this class.
-
+The Options specified by the [JSON-LD API Specification](https://json-ld.org/spec/latest/json-ld-api/#the-jsonldoptions-type) are accessible via the `com.github.jsonldjava.core.JsonLdOptions` class, and each `JsonLdProcessor.*` function has an optional input to take an instance of this class.
Controlling network traffic
---------------------------
@@ -57,8 +60,7 @@ The default HTTP Client is wrapped with a
[CachingHttpClient](https://hc.apache.org/httpcomponents-client-ga/httpclient-cache/apidocs/org/apache/http/impl/client/cache/CachingHttpClient.html) to provide a
small memory-based cache (1000 objects, max 128 kB each) of regularly accessed contexts.
-
-### Loading contexts from classpath/JAR
+### Loading contexts from classpath
Your application might be parsing JSONLD documents which always use the same
external `@context` IRIs. Although the default HTTP cache (see above) will
@@ -107,8 +109,10 @@ automatically injected together with the current `Date`, meaning that the
resource loaded from the JAR will effectively never expire (the real HTTP
server will never be consulted by the Apache HTTP client):
- Date: Wed, 19 Mar 2014 13:25:08 GMT
- Cache-Control: max-age=2147483647
+```
+Date: Wed, 19 Mar 2014 13:25:08 GMT
+Cache-Control: max-age=2147483647
+```
The mechanism for loading `jarcache.json` relies on
[Thread.currentThread().getContextClassLoader()](http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#getContextClassLoader%28%29)
@@ -116,26 +120,55 @@ to locate resources from the classpath - if you are running on a command line,
within a framework (e.g. OSGi) or Servlet container (e.g. Tomcat) this should
normally be set correctly. If not, try:
- ClassLoader oldContextCL = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
- JsonLdProcessor.expand(input); // or any other JsonLd operation
- } finally {
- // Restore, in case the current thread was doing something else
- // with the context classloader before calling our method
- Thread.currentThread().setContextClassLoader(oldContextCL);
- }
+```java
+ClassLoader oldContextCL = Thread.currentThread().getContextClassLoader();
+try {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ JsonLdProcessor.expand(input); // or any other JsonLd operation
+} finally {
+ // Restore, in case the current thread was doing something else
+ // with the context classloader before calling our method
+ Thread.currentThread().setContextClassLoader(oldContextCL);
+}
+```
To disable all remote document fetching, when using the default DocumentLoader, set the
following Java System Property to "true" using:
- System.setProperty("com.github.jsonldjava.disallowRemoteContextLoading", "true");
+```java
+System.setProperty("com.github.jsonldjava.disallowRemoteContextLoading", "true");
+```
You can also use the constant provided in DocumentLoader for the same purpose:
- System.setProperty(DocumentLoader.DISALLOW_REMOTE_CONTEXT_LOADING, "true");
+```java
+System.setProperty(DocumentLoader.DISALLOW_REMOTE_CONTEXT_LOADING, "true");
+```
+
+Note that if you override DocumentLoader you should also support this setting for consistency and security.
-Note that if you override DocumentLoader you should also support this setting for consistency.
+### Loading contexts from a string
+
+Your application might be parsing JSONLD documents which reference external `@context` IRIs
+that are not available as file URIs on the classpath. In this case, the `jarcache.json`
+approach will not work. Instead you can inject the literal context file strings through
+the `JsonLdOptions` object, as follows:
+
+```java
+// Inject a context document into the options as a literal string
+DocumentLoader dl = new DocumentLoader();
+JsonLdOptions options = new JsonLdOptions();
+// ... the contents of "contexts/example.jsonld"
+String jsonContext = "{ \"@context\": { ... } }";
+dl.addInjectedDoc("http://www.example.com/context", jsonContext);
+options.setDocumentLoader(dl);
+
+InputStream inputStream = new FileInputStream("input.json");
+Object jsonObject = JsonUtils.fromInputStream(inputStream);
+Map context = new HashMap();
+Object compact = JsonLdProcessor.compact(jsonObject, context, options);
+System.out.println(JsonUtils.toPrettyString(compact));
+```
### Customizing the Apache HttpClient
@@ -149,40 +182,40 @@ and passed as an argument to `JsonLdProcessor` arguments.
Example of inserting a credential provider (e.g. to load a `@context` protected
by HTTP Basic Auth):
-
- Object input = JsonUtils.fromInputStream(..);
- DocumentLoader documentLoader = new DocumentLoader();
-
- CredentialsProvider credsProvider = new BasicCredentialsProvider();
- credsProvider.setCredentials(
- new AuthScope("localhost", 443),
- new UsernamePasswordCredentials("username", "password"));
+
+```java
+Object input = JsonUtils.fromInputStream(..);
+DocumentLoader documentLoader = new DocumentLoader();
- CacheConfig cacheConfig = CacheConfig.custom().setMaxCacheEntries(1000)
- .setMaxObjectSize(1024 * 128).build();
-
- CloseableHttpClient httpClient = CachingHttpClientBuilder
- .create()
- // allow caching
- .setCacheConfig(cacheConfig)
- // Wrap the local JarCacheStorage around a BasicHttpCacheStorage
- .setHttpCacheStorage(
- new JarCacheStorage(null, cacheConfig, new BasicHttpCacheStorage(
- cacheConfig)))....
+CredentialsProvider credsProvider = new BasicCredentialsProvider();
+credsProvider.setCredentials(
+ new AuthScope("localhost", 443),
+ new UsernamePasswordCredentials("username", "password"));
+
+CacheConfig cacheConfig = CacheConfig.custom().setMaxCacheEntries(1000)
+ .setMaxObjectSize(1024 * 128).build();
+
+CloseableHttpClient httpClient = CachingHttpClientBuilder
+ .create()
+ // allow caching
+ .setCacheConfig(cacheConfig)
+ // Wrap the local JarCacheStorage around a BasicHttpCacheStorage
+ .setHttpCacheStorage(
+ new JarCacheStorage(null, cacheConfig, new BasicHttpCacheStorage(
+ cacheConfig)))....
- // Add in the credentials provider
- .setDefaultCredentialsProvider(credsProvider);
-
+ // Add in the credentials provider
+ .setDefaultCredentialsProvider(credsProvider);
+ // When you are finished setting the properties, call build
+ .build();
- // When you are finished setting the properties, call build
- .build();
-
- documentLoader.setHttpClient(httpClient);
+documentLoader.setHttpClient(httpClient);
- JsonLdOptions options = new JsonLdOptions();
- options.setDocumentLoader(documentLoader);
- // .. and any other options
- Object rdf = JsonLdProcessor.toRDF(input, options);
+JsonLdOptions options = new JsonLdOptions();
+options.setDocumentLoader(documentLoader);
+// .. and any other options
+Object rdf = JsonLdProcessor.toRDF(input, options);
+```
PLAYGROUND
----------
@@ -191,14 +224,18 @@ The [jsonld-java-tools](https://github.com/jsonld-java/jsonld-java-tools) reposi
### Initial clone and setup
- git clone git@github.com:jsonld-java/jsonld-java-tools.git
- chmod +x ./jsonldplayground
+```bash
+git clone git@github.com:jsonld-java/jsonld-java-tools.git
+chmod +x ./jsonldplayground
+```
### Usage
run the following to get usage details:
- ./jsonldplayground --help
+```bash
+./jsonldplayground --help
+```
For Developers
--------------
@@ -207,14 +244,17 @@ For Developers
`jsonld-java` uses maven to compile. From the base `jsonld-java` module run `mvn clean install` to install the jar into your local maven repository.
-
### Running tests
- mvn test
+```bash
+mvn test
+```
or
- mvn test -pl core
+```bash
+mvn test -pl core
+```
to run only core package tests
@@ -243,7 +283,9 @@ https://github.com/jsonld-java/jsonld-java/tree/master/core/reports
Implementation Reports conforming to the [JSON-LD Implementation Report](http://json-ld.org/test-suite/reports/#instructions-for-submitting-implementation-reports) document can be regenerated using the following command:
- mvn test -pl core -Dtest=JsonLdProcessorTest -Dreport.format=
+```bash
+mvn test -pl core -Dtest=JsonLdProcessorTest -Dreport.format=
+```
Current possible values for `` include JSON-LD (`application/ld+json` or `jsonld`), NQuads (`text/plain`, `nquads`, `ntriples`, `nq` or `nt`) and Turtle (`text/turtle`, `turtle` or `ttl`). `*` can be used to generate reports in all available formats.
@@ -255,7 +297,7 @@ This is the base package for JSONLD-Java. Integration with other Java packages a
Existing integrations
---------------------
-* [OpenRDF Sesame](https://bitbucket.org/openrdf/sesame)
+* [Eclipse RDF4J](https://github.com/eclipse/rdf4j)
* [Apache Jena](https://github.com/apache/jena/)
* [RDF2GO](https://github.com/jsonld-java/jsonld-java-rdf2go)
* [Apache Clerezza](https://github.com/jsonld-java/jsonld-java-clerezza)
@@ -274,54 +316,57 @@ Create maven module
Here is the basic outline for what your module's pom.xml should look like
-
-
-
- jsonld-java-integration
- com.github.jsonld-java-parent
- 0.8.1-SNAPSHOT
-
- 4.0.0
- jsonld-java-{your module}
- JSONLD Java :: {your module name}
- JSON-LD Java integration module for {RDF Library your module integrates}
- jar
-
-
-
- {YOU}
- {YOUR EMAIL ADDRESS}
-
-
-
-
-
- ${project.groupId}
- jsonld-java
- ${project.version}
- jar
- compile
-
-
- ${project.groupId}
- jsonld-java
- ${project.version}
- test-jar
- test
-
-
- junit
- junit
- test
-
-
- org.slf4j
- slf4j-jdk14
- test
-
-
-
+```xml
+
+
+
+ com.github.jsonld-java
+ jsonld-java-parent
+ 0.13.5
+
+ 4.0.0
+ jsonld-java-{your module}
+ 0.13.5-SNAPSHOT
+ JSONLD Java :: {your module name}
+ JSON-LD Java integration module for {RDF Library your module integrates}
+ jar
+
+
+
+ {YOU}
+ {YOUR EMAIL ADDRESS}
+
+
+
+
+
+ ${project.groupId}
+ jsonld-java
+ ${project.version}
+ jar
+ compile
+
+
+ ${project.groupId}
+ jsonld-java
+ ${project.version}
+ test-jar
+ test
+
+
+ junit
+ junit
+ test
+
+
+ org.slf4j
+ slf4j-jdk14
+ test
+
+
+
+```
Make sure you edit the following:
* `project/artifactId` : set this to `jsonld-java-{module id}`, where `{module id}` usually represents the RDF library you're integrating (e.g. `jsonld-java-jena`)
@@ -356,12 +401,16 @@ There are two ways to use your `RDFParser` implementation.
Register your parser with the `JSONLD` class and set `options.format` when you call `fromRDF`
- JSONLD.registerRDFParser("format/identifier", new YourRDFParser());
- Object jsonld = JSONLD.fromRDF(yourInput, new Options("") {{ format = "format/identifier" }});
+```java
+JSONLD.registerRDFParser("format/identifier", new YourRDFParser());
+Object jsonld = JSONLD.fromRDF(yourInput, new Options("") {{ format = "format/identifier" }});
+```
or pass an instance of your `RDFParser` into the `fromRDF` function
- Object jsonld = JSONLD.fromRDF(yourInput, new YourRDFParser());
+```java
+Object jsonld = JSONLD.fromRDF(yourInput, new YourRDFParser());
+```
### JSONLDTripleCallback
@@ -370,7 +419,9 @@ RDF model from JSON-LD - being called for each triple (technically quad).
Pass an instance of your `TripleCallback` to `JSONLD.toRDF`
- Object yourOutput = JSONLD.toRDF(jsonld, new YourTripleCallback());
+```java
+Object yourOutput = JSONLD.toRDF(jsonld, new YourTripleCallback());
+```
Integrate with your framework
-----------------------------
@@ -398,6 +449,134 @@ Alternatively, we can also host your repository in the jsonld-java organisation
CHANGELOG
=========
+### 2023-11-06
+* Release 0.13.6
+* Bump Jackson-databind version to latest for security update
+
+### 2023-11-03
+* Release 0.13.5
+* Bump Jackson and Guava versions to latest for security updates
+
+### 2021-12-13
+* Release 0.13.4
+* Switch test logging from log4j to logback (Patch by @ansell)
+* Improve Travis CI build Performance (Patch by @YunLemon)
+
+### 2021-03-06
+* Release 0.13.3
+* Fix @type when subject and object are the same (Reported by @barthanssens, Patch by @umbreak)
+* Ignore @base if remote context is not relative (Reported by @whikloj, Patch by @dr0i)
+* Fix throwing recursive context inclusion (Patch by @umbreak)
+
+### 2020-09-24
+* Release 0.13.2
+* Fix Guava dependency shading (Reported by @ggrasso)
+* Fix @context issues when using a remote context (Patch by @umbreak)
+* Deprecate Context.serialize (Patch by @umbreak)
+
+### 2020-09-09
+* Release 0.13.1
+* Fix java.net.URI resolution (Reported by @ebremer and @afs, Patch by @dr0i)
+* Shade Guava failureaccess module (Patch by @peacekeeper)
+* Don't minimize Guava class shading (Patch by @elahrvivaz)
+* Follow link headers to @context files (Patch by @dr0i and @fsteeg)
+
+### 2019-11-28
+* Release 0.13.0
+* Bump Jackson versions to latest for security updates (Patch by @afs)
+* Do not canonicalise XSD Decimal typed values (Patch by @jhg023)
+* Bump dependency and plugin versions
+
+### 2019-08-03
+* Release 0.12.5
+* Bump Jackson versions to latest for security updates (Patches by @afs)
+* IRI resolution fixes (Patch by @fsteeg)
+
+### 2019-04-20
+* Release 0.12.4
+* Bump Jackson version to 2.9.8
+* Add a regression test for a past framing bug
+* Throw error on empty key
+* Add regression tests for workarounds to Text/URL dual definitions
+* Persist JsonLdOptions through normalize/toRDF
+
+### 2018-11-24
+* Release 0.12.3
+* Fix NaN/Inf/-Inf raw value types on conversion to RDF
+* Added fix for wrong rdf:type to @type conversion (Path by @umbreak)
+* Open up Context.getTypeMapping and Context.getLanguageMapping for reuse
+
+### 2018-11-03
+* W3c json ld syntax 34 allow container set on aliased type (Patch by @dr0i)
+* Release 0.12.2
+
+### 2018-09-05
+* handle omit graph flag (Patch by @eroux)
+* Release 0.12.1
+* Make pruneBlankNodeIdentifiers false by default in 1.0 mode and always true in 1.1 mode (Patch by @eroux)
+* Fix issue with blank node identifier pruning when @id is aliased (Patch by @eroux)
+* Allow wildcard {} for @id in framing (Patch by @eroux)
+
+### 2018-07-07
+* Fix tests setup for schema.org with HttpURLConnection that break because of the inability of HttpURLConnection to redirect from HTTP to HTTPS
+
+### 2018-04-08
+* Release 0.12.0
+* Encapsulate RemoteDocument and make it immutable
+
+### 2018-04-03
+* Fix performance issue caused by not caching schema.org and others that use ``Cache-Control: private`` (Patch by @HansBrende)
+* Cache classpath scans for jarcache.json to fix a similar performance issue
+* Add internal shaded dependency on Google Guava to use maintained soft and weak reference maps rather than adhoc versions
+* Make JsonLdError a RuntimeException to improve its use in closures
+* Bump minor version to 0.12 to reflect the API incompatibility caused by JsonLdError and protected field change and hiding in JarCacheStorage
+
+### 2018-01-25
+* Fix resource leak in JsonUtils.fromURL on unsuccessful requests (Patch by @plaplaige)
+
+### 2017-11-15
+* Ignore UTF BOM (Patch by @christopher-johnson)
+
+### 2017-08-26
+* Release 0.11.1
+* Fix @embed:@always support (Patch by @dr0i)
+
+### 2017-08-24
+* Release 0.11.0
+
+### 2017-08-22
+* Add implicit "flag only" subframe to fix incomplete list recursion (Patch by @christopher-johnson)
+* Support pruneBlankNodeIdentifiers framing option in 1.1 mode (Patch by @fsteeg and @eroux)
+* Support new @embed values (Patch by @eroux)
+
+### 2017-07-11
+* Add injection of contexts directly into DocumentLoader (Patch by @ryankenney)
+* Fix N-Quads content type (Patch by @NicolasRouquette)
+* Add JsonUtils.fromJsonParser (Patch by @dschulten)
+
+### 2017-02-16
+* Make literals compare consistently (Patch by @stain)
+* Release 0.10.0
+
+### 2017-01-09
+* Propagate causes for JsonLdError instances where they were caused by other Exceptions
+* Remove schema.org hack as it appears to work again now...
+* Remove deprecated and unused APIs
+* Bump version to 0.10.0-SNAPSHOT per the removed/changed APIs
+
+### 2016-12-23
+* Release 0.9.0
+* Fixes schema.org support that is broken with Apache HTTP Client but works with java.net.URL
+
+### 2016-05-20
+* Fix reported NPE in JsonLdApi.removeDependents
+
+### 2016-05-18
+* Release 0.8.3
+* Fix @base in remote contexts corrupting the local context
+
+### 2016-04-23
+* Support @default inside of sets for framing
### 2016-02-29
* Fix ConcurrentModificationException in the implementation of the Framing API
diff --git a/core/pom.xml b/core/pom.xml
index e317d19e..f14fb287 100755
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -4,7 +4,7 @@
jsonld-java-parentcom.github.jsonld-java
- 0.8.3-SNAPSHOT
+ 0.13.64.0.0jsonld-java
@@ -43,14 +43,18 @@
commons-iocommons-io
+
+ com.google.guava
+ guava
+ junitjunittest
- org.slf4j
- slf4j-log4j12
+ ch.qos.logback
+ logback-classictest
@@ -61,6 +65,52 @@
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+
+
+
+ com.google.guava:guava
+ com.google.guava:failureaccess
+
+
+
+
+ com.google.common
+ com.github.jsonldjava.shaded.com.google.common
+
+
+ com.google.thirdparty
+ com.github.jsonldjava.shaded.com.google.thirdparty
+
+
+
+
+ com.google.guava:guava
+
+ META-INF/maven/**
+
+
+
+ com.google.guava:failureaccess
+
+ META-INF/maven/**
+
+
+
+
+
+
+ package
+
+ shade
+
+
+
+ org.codehaus.mojoanimal-sniffer-maven-plugin
@@ -72,6 +122,7 @@
+ !com.google.common.*,
org.slf4j.*; version="[1.0.0,2)",
*
diff --git a/core/src/main/java/com/github/jsonldjava/core/Context.java b/core/src/main/java/com/github/jsonldjava/core/Context.java
index 572c385e..4e563d78 100644
--- a/core/src/main/java/com/github/jsonldjava/core/Context.java
+++ b/core/src/main/java/com/github/jsonldjava/core/Context.java
@@ -9,6 +9,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
import com.github.jsonldjava.core.JsonLdError.Error;
import com.github.jsonldjava.utils.JsonLdUrl;
@@ -23,6 +24,9 @@
*/
public class Context extends LinkedHashMap {
+ private static final long serialVersionUID = 2894534897574805571L;
+
+ private static final Pattern URL_PATTERN = Pattern.compile("^https?://.*$", Pattern.CASE_INSENSITIVE);
private JsonLdOptions options;
private Map termDefinitions;
public Map inverse = null;
@@ -38,11 +42,13 @@ public Context(JsonLdOptions opts) {
public Context(Map map, JsonLdOptions opts) {
super(map);
+ checkEmptyKey(map);
init(opts);
}
public Context(Map map) {
super(map);
+ checkEmptyKey(map);
init(new JsonLdOptions());
}
@@ -55,7 +61,7 @@ public Context(Object context, JsonLdOptions opts) {
private void init(JsonLdOptions options) {
this.options = options;
if (options.getBase() != null) {
- this.put("@base", options.getBase());
+ this.put(JsonLdConsts.BASE, options.getBase());
}
this.termDefinitions = newMap();
}
@@ -75,7 +81,8 @@ public Object compactValue(String activeProperty, Map value) {
// 1)
int numberMembers = value.size();
// 2)
- if (value.containsKey("@index") && "@index".equals(this.getContainer(activeProperty))) {
+ if (value.containsKey(JsonLdConsts.INDEX)
+ && JsonLdConsts.INDEX.equals(this.getContainer(activeProperty))) {
numberMembers--;
}
// 3)
@@ -85,36 +92,38 @@ public Object compactValue(String activeProperty, Map value) {
// 4)
final String typeMapping = getTypeMapping(activeProperty);
final String languageMapping = getLanguageMapping(activeProperty);
- if (value.containsKey("@id")) {
+ if (value.containsKey(JsonLdConsts.ID)) {
// 4.1)
- if (numberMembers == 1 && "@id".equals(typeMapping)) {
- return compactIri((String) value.get("@id"));
+ if (numberMembers == 1 && JsonLdConsts.ID.equals(typeMapping)) {
+ return compactIri((String) value.get(JsonLdConsts.ID));
}
// 4.2)
- if (numberMembers == 1 && "@vocab".equals(typeMapping)) {
- return compactIri((String) value.get("@id"), true);
+ if (numberMembers == 1 && JsonLdConsts.VOCAB.equals(typeMapping)) {
+ return compactIri((String) value.get(JsonLdConsts.ID), true);
}
// 4.3)
return value;
}
- final Object valueValue = value.get("@value");
+ final Object valueValue = value.get(JsonLdConsts.VALUE);
// 5)
- if (value.containsKey("@type") && Obj.equals(value.get("@type"), typeMapping)) {
+ if (value.containsKey(JsonLdConsts.TYPE)
+ && Obj.equals(value.get(JsonLdConsts.TYPE), typeMapping)) {
return valueValue;
}
// 6)
- if (value.containsKey("@language")) {
+ if (value.containsKey(JsonLdConsts.LANGUAGE)) {
// TODO: SPEC: doesn't specify to check default language as well
- if (Obj.equals(value.get("@language"), languageMapping)
- || Obj.equals(value.get("@language"), this.get("@language"))) {
+ if (Obj.equals(value.get(JsonLdConsts.LANGUAGE), languageMapping) || Obj
+ .equals(value.get(JsonLdConsts.LANGUAGE), this.get(JsonLdConsts.LANGUAGE))) {
return valueValue;
}
}
// 7)
- if (numberMembers == 1
- && (!(valueValue instanceof String) || !this.containsKey("@language") || (termDefinitions
- .containsKey(activeProperty)
- && getTermDefinition(activeProperty).containsKey("@language") && languageMapping == null))) {
+ if (numberMembers == 1 && (!(valueValue instanceof String)
+ || !this.containsKey(JsonLdConsts.LANGUAGE)
+ || (termDefinitions.containsKey(activeProperty)
+ && getTermDefinition(activeProperty).containsKey(JsonLdConsts.LANGUAGE)
+ && languageMapping == null))) {
return valueValue;
}
// 8)
@@ -138,6 +147,28 @@ public Context parse(Object localContext, List remoteContexts) throws Js
if (remoteContexts == null) {
remoteContexts = new ArrayList();
}
+ return parse(localContext, remoteContexts, false);
+ }
+
+ /**
+ * Helper method used to work around logic errors related to the recursive
+ * nature of the JSONLD-API Context Processing Algorithm.
+ *
+ * @param localContext
+ * The Local Context object.
+ * @param remoteContexts
+ * The list of Strings denoting the remote Context URLs.
+ * @param parsingARemoteContext
+ * True if localContext represents a remote context that has been
+ * parsed and sent into this method and false otherwise. This
+ * must be set to know whether to propagate the @code{@base} key
+ * from the context to the result.
+ * @return The parsed and merged Context.
+ * @throws JsonLdError
+ * If there is an error parsing the contexts.
+ */
+ private Context parse(Object localContext, final List remoteContexts,
+ boolean parsingARemoteContext) throws JsonLdError {
// 1. Initialize result to the result of cloning active context.
Context result = this.clone(); // TODO: clone?
// 2)
@@ -147,7 +178,7 @@ public Context parse(Object localContext, List remoteContexts) throws Js
((List