@@ -120,11 +120,10 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
120
120
// its value MUST be boolean true or false, set propagate to that value.
121
121
if (JsonUtils .isObject (localContext )) {
122
122
123
- final JsonObject localContextObject = localContext .asJsonObject ();
123
+ final JsonValue propagateValue = localContext .asJsonObject ()
124
+ .get (Keywords .PROPAGATE );
124
125
125
- if (localContextObject .containsKey (Keywords .PROPAGATE )) {
126
-
127
- final JsonValue propagateValue = localContextObject .get (Keywords .PROPAGATE );
126
+ if (propagateValue != null ) {
128
127
129
128
if (JsonUtils .isNotBoolean (propagateValue )) {
130
129
throw new JsonLdError (JsonLdErrorCode .INVALID_KEYWORD_PROPAGATE_VALUE );
@@ -171,7 +170,7 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
171
170
// 5.2. if context is a string,
172
171
if (JsonUtils .isString (itemContext )) {
173
172
174
- fetch (((JsonString )itemContext ).getString (), baseUrl );
173
+ fetch (((JsonString ) itemContext ).getString (), baseUrl );
175
174
176
175
// 5.2.7
177
176
continue ;
@@ -186,10 +185,10 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
186
185
// 5.4. Otherwise, context is a context definition
187
186
JsonObject contextDefinition = itemContext .asJsonObject ();
188
187
189
- // 5.5. If context has an @version
190
- if (contextDefinition .containsKey (Keywords .VERSION )) {
188
+ final JsonValue version = contextDefinition .get (Keywords .VERSION );
191
189
192
- final JsonValue version = contextDefinition .get (Keywords .VERSION );
190
+ // 5.5. If context has an @version
191
+ if (version != null ) {
193
192
194
193
String versionString = null ;
195
194
@@ -250,10 +249,10 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
250
249
}
251
250
252
251
importedStructure = importedDocument
253
- .getJsonContent ()
254
- .orElseThrow (() -> new JsonLdError (JsonLdErrorCode .INVALID_KEYWORD_IMPORT_VALUE ));
252
+ .getJsonContent ()
253
+ .orElseThrow (() -> new JsonLdError (JsonLdErrorCode .INVALID_KEYWORD_IMPORT_VALUE ));
255
254
256
- // 5.6.5
255
+ // 5.6.5
257
256
} catch (JsonLdError e ) {
258
257
throw new JsonLdError (JsonLdErrorCode .INVALID_KEYWORD_IMPORT_VALUE , e );
259
258
}
@@ -263,27 +262,27 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
263
262
throw new JsonLdError (JsonLdErrorCode .INVALID_REMOTE_CONTEXT );
264
263
}
265
264
266
- JsonObject importedContext = importedStructure .asJsonObject ();
265
+ final JsonValue importedContext = importedStructure .asJsonObject (). get ( Keywords . CONTEXT );
267
266
268
- if (! importedContext . containsKey ( Keywords . CONTEXT )
269
- || JsonUtils .isNotObject (importedContext . get ( Keywords . CONTEXT ) )) {
267
+ if (importedContext == null
268
+ || JsonUtils .isNotObject (importedContext )) {
270
269
throw new JsonLdError (JsonLdErrorCode .INVALID_REMOTE_CONTEXT );
271
270
}
272
271
273
- importedContext = importedContext .getJsonObject ( Keywords . CONTEXT );
272
+ final JsonObject importedContextObject = importedContext .asJsonObject ( );
274
273
275
274
// 5.6.7
276
- if (importedContext .containsKey (Keywords .IMPORT )) {
275
+ if (importedContextObject .containsKey (Keywords .IMPORT )) {
277
276
throw new JsonLdError (JsonLdErrorCode .INVALID_CONTEXT_ENTRY );
278
277
}
279
278
280
279
// 5.6.8
281
- contextDefinition = JsonUtils .merge (importedContext , contextDefinition );
280
+ contextDefinition = JsonUtils .merge (importedContextObject , contextDefinition );
282
281
}
283
282
284
283
// 5.7. If context has an @base entry and remote contexts is empty,
285
284
// i.e., the currently being processed context is not a remote context:
286
- if (contextDefinition .containsKey (Keywords .BASE ) /*&& remoteContexts.isEmpty()*/ ) {
285
+ if (contextDefinition .containsKey (Keywords .BASE ) /* && remoteContexts.isEmpty() */ ) {
287
286
// 5.7.1
288
287
JsonValue value = contextDefinition .get (Keywords .BASE );
289
288
@@ -303,18 +302,18 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
303
302
if (valueUri .isAbsolute ()) {
304
303
result .setBaseUri (valueUri );
305
304
306
- // 5.7.4
305
+ // 5.7.4
307
306
} else if (result .getBaseUri () != null ) {
308
307
result .setBaseUri (UriResolver .resolveAsUri (result .getBaseUri (), valueUri ));
309
308
310
309
} else {
311
310
LOGGER .log (Level .FINE ,
312
- "5.7.4: valueString={0}, localContext={1}, baseUrl={2}" ,
313
- new Object [] {valueString , localContext , baseUrl });
311
+ "5.7.4: valueString={0}, localContext={1}, baseUrl={2}" ,
312
+ new Object [] { valueString , localContext , baseUrl });
314
313
315
314
throw new JsonLdError (JsonLdErrorCode .INVALID_BASE_IRI ,
316
315
"A relative base IRI cannot be resolved [@base = " + valueString +
317
- "]. Please use JsonLdOptions.setBase() method to set an absolute IRI." );
316
+ "]. Please use JsonLdOptions.setBase() method to set an absolute IRI." );
318
317
}
319
318
320
319
} else if (StringUtils .isNotBlank (valueString )) {
@@ -338,19 +337,18 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
338
337
if (JsonUtils .isNull (value )) {
339
338
result .setVocabularyMapping (null );
340
339
341
- // 5.8.3
340
+ // 5.8.3
342
341
} else if (JsonUtils .isString (value )) {
343
342
344
343
final String valueString = ((JsonString ) value ).getString ();
345
344
346
345
if (StringUtils .isBlank (valueString ) || BlankNode .hasPrefix (valueString ) || UriUtils .isURI (valueString )) {
347
346
348
- final String vocabularyMapping =
349
- result
350
- .uriExpansion ()
351
- .vocab (true )
352
- .documentRelative (true )
353
- .expand (valueString );
347
+ final String vocabularyMapping = result
348
+ .uriExpansion ()
349
+ .vocab (true )
350
+ .documentRelative (true )
351
+ .expand (valueString );
354
352
355
353
if (BlankNode .hasPrefix (valueString ) || UriUtils .isURI (vocabularyMapping )) {
356
354
result .setVocabularyMapping (vocabularyMapping );
@@ -378,10 +376,10 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
378
376
if (JsonUtils .isNull (value )) {
379
377
result .setDefaultLanguage (null );
380
378
381
- // 5.9.3
379
+ // 5.9.3
382
380
} else if (JsonUtils .isString (value )) {
383
381
384
- result .setDefaultLanguage (((JsonString )value ).getString ());
382
+ result .setDefaultLanguage (((JsonString ) value ).getString ());
385
383
386
384
if (!LanguageTag .isWellFormed (result .getDefaultLanguage ())) {
387
385
LOGGER .log (Level .WARNING , "Language tag [{0}] is not well formed." , result .getDefaultLanguage ());
@@ -407,7 +405,7 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
407
405
if (JsonUtils .isNull (value )) {
408
406
result .setDefaultBaseDirection (DirectionType .NULL );
409
407
410
- // 5.10.4.
408
+ // 5.10.4.
411
409
} else if (JsonUtils .isString (value )) {
412
410
413
411
final String direction = ((JsonString ) value ).getString ();
@@ -439,11 +437,10 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
439
437
}
440
438
}
441
439
442
- final TermDefinitionBuilder termBuilder =
443
- result
444
- .newTerm (contextDefinition , new HashMap <>())
445
- .baseUrl (baseUrl )
446
- .overrideProtectedFlag (overrideProtected );
440
+ final TermDefinitionBuilder termBuilder = result
441
+ .newTerm (contextDefinition , new HashMap <>())
442
+ .baseUrl (baseUrl )
443
+ .overrideProtectedFlag (overrideProtected );
447
444
448
445
// 5.13
449
446
for (final String key : contextDefinition .keySet ()) {
@@ -452,9 +449,9 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
452
449
Keywords .PROPAGATE , Keywords .PROTECTED , Keywords .VERSION , Keywords .VOCAB )) {
453
450
454
451
termBuilder
455
- .protectedFlag (JsonUtils .isTrue (contextDefinition .get (Keywords .PROTECTED )))
456
- .remoteContexts (new ArrayList <>(remoteContexts ))
457
- .create (key );
452
+ .protectedFlag (JsonUtils .isTrue (contextDefinition .get (Keywords .PROTECTED )))
453
+ .remoteContexts (new ArrayList <>(remoteContexts ))
454
+ .create (key );
458
455
}
459
456
}
460
457
}
@@ -534,7 +531,7 @@ private void fetch(final String context, final URI baseUrl) throws JsonLdError {
534
531
535
532
remoteImport = activeContext .getOptions ().getDocumentLoader ().loadDocument (contextUri , loaderOptions );
536
533
537
- // 5.2.5.1.
534
+ // 5.2.5.1.
538
535
} catch (JsonLdError e ) {
539
536
throw new JsonLdError (JsonLdErrorCode .LOADING_REMOTE_CONTEXT_FAILED , e );
540
537
}
@@ -545,7 +542,7 @@ private void fetch(final String context, final URI baseUrl) throws JsonLdError {
545
542
}
546
543
547
544
final JsonStructure importedStructure = remoteImport .getJsonContent ()
548
- .orElseThrow (() -> new JsonLdError (JsonLdErrorCode .INVALID_REMOTE_CONTEXT , "Imported context is null." ));
545
+ .orElseThrow (() -> new JsonLdError (JsonLdErrorCode .INVALID_REMOTE_CONTEXT , "Imported context is null." ));
549
546
550
547
// 5.2.5.2.
551
548
if (JsonUtils .isNotObject (importedStructure )) {
@@ -575,10 +572,10 @@ private void fetch(final String context, final URI baseUrl) throws JsonLdError {
575
572
// 5.2.6
576
573
try {
577
574
result = result
578
- .newContext ()
579
- .remoteContexts (new ArrayList <>(remoteContexts ))
580
- .validateScopedContext (validateScopedContext )
581
- .create (importedContext , remoteImport .getDocumentUrl ());
575
+ .newContext ()
576
+ .remoteContexts (new ArrayList <>(remoteContexts ))
577
+ .validateScopedContext (validateScopedContext )
578
+ .create (importedContext , remoteImport .getDocumentUrl ());
582
579
583
580
if (result .getOptions () != null && result .getOptions ().getContextCache () != null && !validateScopedContext ) {
584
581
result .getOptions ().getContextCache ().put (contextKey , importedContext );
0 commit comments