Skip to content

Commit 0f439dc

Browse files
committed
Handle @version context entries
1 parent f2e1b25 commit 0f439dc

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

core/src/main/java/com/github/jsonldjava/core/Context.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ else if (context instanceof String) {
215215
// 3.3
216216
throw new JsonLdError(Error.INVALID_LOCAL_CONTEXT, context);
217217
}
218+
// 5.5 in 1.1 (https://w3c.github.io/json-ld-api/#context-processing-algorithm)
219+
if (((Map<String, Object>) context).containsKey(JsonLdConsts.VERSION)) {
220+
final Object version = ((Map<String, Object>) context).get(JsonLdConsts.VERSION);
221+
// 5.5.1
222+
if(!version.equals(Double.valueOf(1.1))) {
223+
throw new JsonLdError(Error.INVALID_VERSION_VALUE, context);
224+
}
225+
// 5.5.2
226+
if(options.getProcessingMode().equals(JsonLdOptions.JSON_LD_1_0)) {
227+
throw new JsonLdError(Error.PROCESSING_MODE_CONFLICT, context);
228+
}
229+
}
218230
checkEmptyKey((Map<String, Object>) context);
219231
// 3.4
220232
if (!parsingARemoteContext
@@ -277,7 +289,7 @@ else if (context instanceof String) {
277289
final Map<String, Boolean> defined = new LinkedHashMap<String, Boolean>();
278290
for (final String key : ((Map<String, Object>) context).keySet()) {
279291
if (JsonLdConsts.BASE.equals(key) || JsonLdConsts.VOCAB.equals(key)
280-
|| JsonLdConsts.LANGUAGE.equals(key)) {
292+
|| JsonLdConsts.LANGUAGE.equals(key) || JsonLdConsts.VERSION.equals(key)) {
281293
continue;
282294
}
283295
result.createTermDefinition((Map<String, Object>) context, key, defined);

core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public final class JsonLdConsts {
5858
public static final String VOCAB = "@vocab";
5959
public static final String BASE = "@base";
6060
public static final String REQUIRE_ALL = "@requireAll";
61+
public static final String VERSION = "@version";
6162

6263
public enum Embed {
6364
ALWAYS, NEVER, LAST, LINK;

core/src/main/java/com/github/jsonldjava/core/JsonLdError.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ public enum Error {
102102

103103
INVALID_EMBED_VALUE("invalid @embed value"),
104104

105+
INVALID_VERSION_VALUE("invalid @version value"),
106+
107+
PROCESSING_MODE_CONFLICT("processing mode conflict"),
108+
105109
// non spec related errors
106110
SYNTAX_ERROR("syntax error"),
107111

core/src/main/java/com/github/jsonldjava/core/JsonLdOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public JsonLdOptions copy() {
8686
/**
8787
* http://www.w3.org/TR/json-ld-api/#widl-JsonLdOptions-processingMode
8888
*/
89-
private String processingMode = JSON_LD_1_0;
89+
private String processingMode = JSON_LD_1_1;
9090
/**
9191
* http://www.w3.org/TR/json-ld-api/#widl-JsonLdOptions-documentLoader
9292
*/

0 commit comments

Comments
 (0)