Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor tweaks #295

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.apicatalog</groupId>
<artifactId>titanium</artifactId>
<version>1.3.4-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<relativePath>pom_parent.xml</relativePath>
</parent>
<artifactId>titanium-json-ld</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom_jre8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.apicatalog</groupId>
<artifactId>titanium</artifactId>
<version>1.3.4-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<relativePath>pom_parent.xml</relativePath>
</parent>
<artifactId>titanium-json-ld-jre8</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom_parent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.apicatalog</groupId>
<artifactId>titanium</artifactId>
<version>1.3.4-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Titanium JSON-LD 1.1</name>
Expand Down
308 changes: 147 additions & 161 deletions src/main/java/com/apicatalog/jsonld/compaction/Compaction.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,10 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
// its value MUST be boolean true or false, set propagate to that value.
if (JsonUtils.isObject(localContext)) {

final JsonObject localContextObject = localContext.asJsonObject();
final JsonValue propagateValue = localContext.asJsonObject()
.get(Keywords.PROPAGATE);

if (localContextObject.containsKey(Keywords.PROPAGATE)) {

final JsonValue propagateValue = localContextObject.get(Keywords.PROPAGATE);
if (propagateValue != null) {

if (JsonUtils.isNotBoolean(propagateValue)) {
throw new JsonLdError(JsonLdErrorCode.INVALID_KEYWORD_PROPAGATE_VALUE);
Expand Down Expand Up @@ -171,7 +170,7 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
// 5.2. if context is a string,
if (JsonUtils.isString(itemContext)) {

fetch(((JsonString)itemContext).getString(), baseUrl);
fetch(((JsonString) itemContext).getString(), baseUrl);

// 5.2.7
continue;
Expand All @@ -186,10 +185,10 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
// 5.4. Otherwise, context is a context definition
JsonObject contextDefinition = itemContext.asJsonObject();

// 5.5. If context has an @version
if (contextDefinition.containsKey(Keywords.VERSION)) {
final JsonValue version = contextDefinition.get(Keywords.VERSION);

final JsonValue version = contextDefinition.get(Keywords.VERSION);
// 5.5. If context has an @version
if (version != null) {

String versionString = null;

Expand Down Expand Up @@ -250,10 +249,10 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
}

importedStructure = importedDocument
.getJsonContent()
.orElseThrow(() -> new JsonLdError(JsonLdErrorCode.INVALID_KEYWORD_IMPORT_VALUE));
.getJsonContent()
.orElseThrow(() -> new JsonLdError(JsonLdErrorCode.INVALID_KEYWORD_IMPORT_VALUE));

// 5.6.5
// 5.6.5
} catch (JsonLdError e) {
throw new JsonLdError(JsonLdErrorCode.INVALID_KEYWORD_IMPORT_VALUE, e);
}
Expand All @@ -263,27 +262,27 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
throw new JsonLdError(JsonLdErrorCode.INVALID_REMOTE_CONTEXT);
}

JsonObject importedContext = importedStructure.asJsonObject();
final JsonValue importedContext = importedStructure.asJsonObject().get(Keywords.CONTEXT);

if (!importedContext.containsKey(Keywords.CONTEXT)
|| JsonUtils.isNotObject(importedContext.get(Keywords.CONTEXT))) {
if (importedContext == null
|| JsonUtils.isNotObject(importedContext)) {
throw new JsonLdError(JsonLdErrorCode.INVALID_REMOTE_CONTEXT);
}

importedContext = importedContext.getJsonObject(Keywords.CONTEXT);
final JsonObject importedContextObject = importedContext.asJsonObject();

// 5.6.7
if (importedContext.containsKey(Keywords.IMPORT)) {
if (importedContextObject.containsKey(Keywords.IMPORT)) {
throw new JsonLdError(JsonLdErrorCode.INVALID_CONTEXT_ENTRY);
}

// 5.6.8
contextDefinition = JsonUtils.merge(importedContext, contextDefinition);
contextDefinition = JsonUtils.merge(importedContextObject, contextDefinition);
}

// 5.7. If context has an @base entry and remote contexts is empty,
// i.e., the currently being processed context is not a remote context:
if (contextDefinition.containsKey(Keywords.BASE) /*&& remoteContexts.isEmpty()*/) {
if (contextDefinition.containsKey(Keywords.BASE) /* && remoteContexts.isEmpty() */) {
// 5.7.1
JsonValue value = contextDefinition.get(Keywords.BASE);

Expand All @@ -303,18 +302,18 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
if (valueUri.isAbsolute()) {
result.setBaseUri(valueUri);

// 5.7.4
// 5.7.4
} else if (result.getBaseUri() != null) {
result.setBaseUri(UriResolver.resolveAsUri(result.getBaseUri(), valueUri));

} else {
LOGGER.log(Level.FINE,
"5.7.4: valueString={0}, localContext={1}, baseUrl={2}",
new Object[] {valueString, localContext, baseUrl});
"5.7.4: valueString={0}, localContext={1}, baseUrl={2}",
new Object[] { valueString, localContext, baseUrl });

throw new JsonLdError(JsonLdErrorCode.INVALID_BASE_IRI,
"A relative base IRI cannot be resolved [@base = " + valueString +
"]. Please use JsonLdOptions.setBase() method to set an absolute IRI.");
"]. Please use JsonLdOptions.setBase() method to set an absolute IRI.");
}

} else if (StringUtils.isNotBlank(valueString)) {
Expand All @@ -338,19 +337,18 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
if (JsonUtils.isNull(value)) {
result.setVocabularyMapping(null);

// 5.8.3
// 5.8.3
} else if (JsonUtils.isString(value)) {

final String valueString = ((JsonString) value).getString();

if (StringUtils.isBlank(valueString) || BlankNode.hasPrefix(valueString) || UriUtils.isURI(valueString)) {

final String vocabularyMapping =
result
.uriExpansion()
.vocab(true)
.documentRelative(true)
.expand(valueString);
final String vocabularyMapping = result
.uriExpansion()
.vocab(true)
.documentRelative(true)
.expand(valueString);

if (BlankNode.hasPrefix(valueString) || UriUtils.isURI(vocabularyMapping)) {
result.setVocabularyMapping(vocabularyMapping);
Expand Down Expand Up @@ -378,10 +376,10 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
if (JsonUtils.isNull(value)) {
result.setDefaultLanguage(null);

// 5.9.3
// 5.9.3
} else if (JsonUtils.isString(value)) {

result.setDefaultLanguage(((JsonString)value).getString());
result.setDefaultLanguage(((JsonString) value).getString());

if (!LanguageTag.isWellFormed(result.getDefaultLanguage())) {
LOGGER.log(Level.WARNING, "Language tag [{0}] is not well formed.", result.getDefaultLanguage());
Expand All @@ -407,7 +405,7 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
if (JsonUtils.isNull(value)) {
result.setDefaultBaseDirection(DirectionType.NULL);

// 5.10.4.
// 5.10.4.
} else if (JsonUtils.isString(value)) {

final String direction = ((JsonString) value).getString();
Expand Down Expand Up @@ -439,11 +437,10 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
}
}

final TermDefinitionBuilder termBuilder =
result
.newTerm(contextDefinition, new HashMap<>())
.baseUrl(baseUrl)
.overrideProtectedFlag(overrideProtected);
final TermDefinitionBuilder termBuilder = result
.newTerm(contextDefinition, new HashMap<>())
.baseUrl(baseUrl)
.overrideProtectedFlag(overrideProtected);

// 5.13
for (final String key : contextDefinition.keySet()) {
Expand All @@ -452,9 +449,9 @@ public ActiveContext create(final JsonValue localContext, final URI baseUrl) thr
Keywords.PROPAGATE, Keywords.PROTECTED, Keywords.VERSION, Keywords.VOCAB)) {

termBuilder
.protectedFlag(JsonUtils.isTrue(contextDefinition.get(Keywords.PROTECTED)))
.remoteContexts(new ArrayList<>(remoteContexts))
.create(key);
.protectedFlag(JsonUtils.isTrue(contextDefinition.get(Keywords.PROTECTED)))
.remoteContexts(new ArrayList<>(remoteContexts))
.create(key);
}
}
}
Expand Down Expand Up @@ -534,7 +531,7 @@ private void fetch(final String context, final URI baseUrl) throws JsonLdError {

remoteImport = activeContext.getOptions().getDocumentLoader().loadDocument(contextUri, loaderOptions);

// 5.2.5.1.
// 5.2.5.1.
} catch (JsonLdError e) {
throw new JsonLdError(JsonLdErrorCode.LOADING_REMOTE_CONTEXT_FAILED, e);
}
Expand All @@ -545,7 +542,7 @@ private void fetch(final String context, final URI baseUrl) throws JsonLdError {
}

final JsonStructure importedStructure = remoteImport.getJsonContent()
.orElseThrow(() -> new JsonLdError(JsonLdErrorCode.INVALID_REMOTE_CONTEXT, "Imported context is null."));
.orElseThrow(() -> new JsonLdError(JsonLdErrorCode.INVALID_REMOTE_CONTEXT, "Imported context is null."));

// 5.2.5.2.
if (JsonUtils.isNotObject(importedStructure)) {
Expand Down Expand Up @@ -575,10 +572,10 @@ private void fetch(final String context, final URI baseUrl) throws JsonLdError {
// 5.2.6
try {
result = result
.newContext()
.remoteContexts(new ArrayList<>(remoteContexts))
.validateScopedContext(validateScopedContext)
.create(importedContext, remoteImport.getDocumentUrl());
.newContext()
.remoteContexts(new ArrayList<>(remoteContexts))
.validateScopedContext(validateScopedContext)
.create(importedContext, remoteImport.getDocumentUrl());

if (result.getOptions() != null && result.getOptions().getContextCache() != null && !validateScopedContext) {
result.getOptions().getContextCache().put(contextKey, importedContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public boolean contains(final String variable, final String container, final Str

public boolean contains(final String variable, final String container, final String type, final String key) {
return contains(variable)
&& context.get(variable).containsKey(container)
&& context.get(variable).get(container).containsKey(type)
&& context.get(variable).get(container).get(type).containsKey(key);
&& context.get(variable).containsKey(container)
&& context.get(variable).get(container).containsKey(type)
&& context.get(variable).get(container).get(type).containsKey(key);
}

public InverseContext setIfAbsent(final String variable, final String container, final String type, final String key, final String value) {
Expand Down
Loading
Loading