diff --git a/maven-central-settings.xml b/.github/maven-central-settings.xml similarity index 100% rename from maven-central-settings.xml rename to .github/maven-central-settings.xml diff --git a/.github/workflows/java11-publish.yml b/.github/workflows/java11-publish.yml index d9719567..fb8ba515 100644 --- a/.github/workflows/java11-publish.yml +++ b/.github/workflows/java11-publish.yml @@ -16,14 +16,15 @@ jobs: with: java-version: '11' distribution: 'temurin' + cache: 'maven' server-id: ossrh - - name: Import GPG Key - uses: crazy-max/ghaction-import-gpg@v6 - with: - gpg_private_key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }} + server-username: OSSRH_USERNAME + server-password: OSSRH_TOKEN + gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE - name: Publish package - run: mvn -B -Pmaven-central -Dgpg.passphrase=${{secrets.MAVEN_GPG_PASSPHRASE}} -s maven-central-settings.xml deploy + run: mvn -B -Pmaven-central deploy env: - MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} diff --git a/.github/workflows/java8-publish.yml b/.github/workflows/java8-publish.yml index fb9c897e..8a9f94af 100644 --- a/.github/workflows/java8-publish.yml +++ b/.github/workflows/java8-publish.yml @@ -16,14 +16,15 @@ jobs: with: java-version: '8' distribution: 'temurin' + cache: 'maven' server-id: ossrh - - name: Import GPG Key - uses: crazy-max/ghaction-import-gpg@v6 - with: - gpg_private_key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }} + server-username: OSSRH_USERNAME + server-password: OSSRH_TOKEN + gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE - name: Publish package - run: mvn -f pom_jre8.xml -B -Pmaven-central -Dgpg.passphrase=${{secrets.MAVEN_GPG_PASSPHRASE}} -s maven-central-settings.xml deploy + run: mvn -f pom_jre8.xml -B -Pmaven-central deploy env: - MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} diff --git a/README.md b/README.md index f9ce2ba3..28b4a2d3 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,26 @@ > [!IMPORTANT] > **This Open-Source Project Needs Your Support** > -> This library has been provided as a free, open-source resource, benefiting countless users without requiring anything in return. Yet, maintaining it takes significant time, effort, and resources—something often overlooked by those who use it freely. +> This library is offered as a free, open-source resource, benefiting countless users without requiring anything in return. However, maintaining it takes significant time, effort, and resources—something that is often overlooked by those who use it freely. > -> There is a noticeable gap between usage and contributions. This highlights a challenging reality for open-source: heavy reliance on the work of developers and maintainers without adequate support in return. Open-source projects like this depend on the contributions of their users to remain sustainable. +> There is a noticeable gap between usage and contributions, highlighting a challenging reality for open-source projects: heavy reliance on the work of developers and maintainers without adequate support in return. Open-source projects like this depend on the contributions of their users to remain sustainable. > -> **Open-source is not free labor. If your company profits from this library but refuses to contribute back, you’re not supporting the ecosystem—you’re exploiting it**. +> **Open-source is not free labor. If your company profits from this library but refuses to contribute back, you are not supporting the ecosystem—you are exploiting it.** > -> This library has been sustained through countless hours of work and resources, provided in good faith to the community. If your business depends on it but doesn’t give back, consider whether you deserve the benefits you’re taking. Support the work, or step aside for those who value collaboration and fairness. +> This library has been sustained through countless hours of work and resources, provided in good faith to the community. If your business depends on it but doesn't give back, consider whether you truly deserve the benefits you're taking. Support the work, or step aside for those who value collaboration and fairness. > ->Don’t let open-source be taken for granted. Support the work that supports you. +> Don’t let open-source be taken for granted. Support the work that supports you. # Titanium JSON-LD 1.1 Processor & API -An implementation of the [JSON-LD 1.1](https://www.w3.org/TR/json-ld/) (JSON-based Serialization for Linked Data) specification in Java utilizing [Jakarta JSON Processing](https://github.com/eclipse-ee4j/jsonp). +An implementation of the [JSON-LD 1.1](https://www.w3.org/TR/json-ld/) (JSON-based Serialization for Linked Data) specification in Java, utilizing [Jakarta JSON Processing](https://github.com/eclipse-ee4j/jsonp). ### Goals -- conformance to the specification -- secure, stable, fast, A+ code (covered by **~1800 tests**) -- minimal external dependencies - - only `jakarta.json-api` is required -- simple to use +- Full conformance to the specification +- Secure, stable, fast, high-quality code (covered by **~1800 tests**) +- Minimal external dependencies + - Only `jakarta.json-api` is required +- Easy to use ### Status @@ -34,12 +34,11 @@ An implementation of the [JSON-LD 1.1](https://www.w3.org/TR/json-ld/) (JSON-bas ### Extensions -- [LD-CLI](https://github.com/filip26/ld-cli) is a native command line utility for Ubuntu, Mac, Windows -- [JSON-LD-star](https://json-ld.github.io/json-ld-star) expansion and compaction built-in support (experimental) +- [LD-CLI](https://github.com/filip26/ld-cli): A native command line utility for Ubuntu, Mac, and Windows +- [JSON-LD-star](https://json-ld.github.io/json-ld-star): Expansion and compaction built-in support (experimental) - [Universal RDF Dataset Normalization Algorithm - URDNA2015](https://github.com/simon-greatrix/rdf-urdna) -- [Iridium CBOR-LD](https://github.com/filip26/iridium-cbor-ld) a CBOR-based Processor for Linked Data -- [LEXREX](https://lexrex.web.app/) semantic vocabularies visual builder and manager - +- [Iridium CBOR-LD](https://github.com/filip26/iridium-cbor-ld): A CBOR-based Processor for Linked Data +- [LEXREX](https://lexrex.web.app/): Semantic vocabularies visual builder and manager ## Table of Contents - [Conformance](#conformance) @@ -52,13 +51,13 @@ An implementation of the [JSON-LD 1.1](https://www.w3.org/TR/json-ld/) (JSON-bas ## Conformance - | Feature | Tests | Pass | Status | Notes | - | --- | ---: | ---: | ---: | --- | -| [Expansion](https://www.w3.org/TR/json-ld/#expanded-document-form) | 373 | 373 | 100% | | +| Feature | Tests | Pass | Status | Notes | +| --- | ---: | ---: | ---: | --- | +| [Expansion](https://www.w3.org/TR/json-ld/#expanded-document-form) | 373 | 373 | 100% | | | [Compaction](https://www.w3.org/TR/json-ld/#compacted-document-form) | 243 | 243 | 100% | | | [Flattening](https://www.w3.org/TR/json-ld/#flattened-document-form) | 55 | 55 | 100% | | | [JSON-LD to RDF](https://www.w3.org/TR/json-ld/#relationship-to-rdf) | 453 | 451 | 99.5% | | -| [RDF to JSON-LD](https://www.w3.org/TR/json-ld/#relationship-to-rdf) | 51 | 51 | 100% | | +| [RDF to JSON-LD](https://www.w3.org/TR/json-ld/#relationship-to-rdf) | 51 | 51 | 100% | | | [Framing](https://www.w3.org/TR/json-ld11-framing/#framing) | 89 | 88 | 98.8% | | | [Remote Document and Context Retrieval](https://www.w3.org/TR/json-ld11-api/#remote-document-and-context-retrieval) | 18 | 17 | 94.4% | | @@ -66,12 +65,11 @@ See [EARL results from the JSON-LD 1.1 Test Suite](https://w3c.github.io/json-ld ## Examples -Titanium provides high-level [JsonLd](https://javadoc.io/doc/com.apicatalog/titanium-json-ld/latest/com/apicatalog/jsonld/JsonLd.html) API to interact with the processor. +Titanium provides a high-level [JsonLd](https://javadoc.io/doc/com.apicatalog/titanium-json-ld/latest/com/apicatalog/jsonld/JsonLd.html) API to interact with the processor. ### Transformations ```javascript - // Expansion JsonLd.expand("https://w3c.github.io/json-ld-api/tests/expand/0001-in.jsonld") .ordered() @@ -97,51 +95,54 @@ JsonLd.fromRdf("https://example/document.nq").options(options).get(); // Framing JsonLd.frame("https://example/document.jsonld", "https://example/frame.jsonld").get(); - ``` ### Local JSON Document ```javascript +// Create a JSON document from InputStream or Reader Document document = JsonDocument.of(InputStream) or JsonDocument.of(Reader) ... +// Expand the document JsonLd.expand(document).get(); +// Compact the document with a context document JsonLd.compact(document, contextDocument).get(); ... ``` -### Processing Timeout [experimental] -A processor gets terminated eventually after a specified time. Please note -the duration does not cover `DocumentLoader` processing time. -You have to set-up a read timeout separately. +### Processing Timeout [Experimental] +The processor will be terminated after a specified duration. +Please note that the duration does not include the time taken by `DocumentLoader` for processing. +You must set up a separate read timeout for document loading. ```javascript -// since 1.4.0 +// Available since 1.4.0 JsonLd.expand(...).timeout(duration)...get(); ``` ### HTTP Document Loader Timeout -Configure and set a custom HTTP document loader instance. +You can configure a custom HTTP document loader instance with a set read timeout. ```javascript -// since 1.4.0 - set read timeout -static DocumentLoader LOADER = HttpLoader.defaultInstance().timeount(Duration.ofSeconds(30)); +// Available since 1.4.0 - Set read timeout for HTTP document loader +static DocumentLoader LOADER = HttpLoader.defaultInstance().timeout(Duration.ofSeconds(30)); ... JsonLd.expand(...).loader(LOADER).get(); ``` -### Document caching -Configure LRU-based cache for loading documents. -The argument determines size of the LRU-cache. +### Document Caching +Configure an LRU-based cache for loading documents. The `capacity` argument specifies the size of the LRU cache. + ```javascript -// since 1.4.0 +// Available since 1.4.0 - Load documents with an LRU-based cache JsonLd.toRdf("https://example/document.jsonld").loader(new LRUDocumentCache(loader, capacity)).get(); ``` -You can share an instance of `LRUDocumentCache` among multiple calls to reuse cached documents. +You can reuse an instance of `LRUDocumentCache` across multiple calls to benefit from cached documents. + ```javascript -// since 1.4.0 +// Available since 1.4.0 - Reuse LRU cache across multiple document loads DocumentLoader cachedLoader = new LRUDocumentCache(loader, capacity); JsonLd.toRdf("https://example/document.jsonld").loader(cachedLoader).get(); @@ -150,10 +151,10 @@ JsonLd.toRdf("https://example/another-document.jsonld").loader(cachedLoader).get ### Undefined Terms Processing Policy -Set processing policy on undefined terms. `Ignore` by default. +Set a processing policy for undefined terms. The default policy is `Ignore`. ```javascript -// since 1.4.1 +// Available since 1.4.1 - Define processing policy for undefined terms JsonLd.expand(...).undefinedTermsPolicy(Fail|Warn|Ignore).get(); ``` @@ -161,27 +162,25 @@ JsonLd.expand(...).undefinedTermsPolicy(Fail|Warn|Ignore).get(); ### Titanium -#### Maven -Java 11+ +#### Maven (Java 11+) ```xml com.apicatalog titanium-json-ld - 1.4.1 + 1.5.0 ``` -#### Gradle -Java 8+, Android API Level >=24 +#### Gradle (Java 8+, Android API Level >= 24) ```gradle -implementation("com.apicatalog:titanium-json-ld-jre8:1.4.1") +implementation("com.apicatalog:titanium-json-ld-jre8:1.5.0") ``` ### JSON-P Provider -Add JSON-P provider, if it is not on the classpath already. +Ensure that the JSON-P provider is added to the classpath if it is not already present. #### Maven @@ -208,23 +207,22 @@ implementation("org.glassfish:jakarta.json:2.0.1") All PR's welcome! -- develop - - implement a new feature - - fix an existing issue - - improve an existing implementation -- test - - report a bug - - implement a test case -- document - - write javadoc - - write a tutorial - - proofread an existing documentation -- promote - - star, share, the project - - write an article -- sponsor - - your requests get top priority - - you will get a badge +- Develop + - Implement a new feature + - Fix an existing issue + - Improve an existing implementation +- Test + - Report a bug + - Implement a new test case +- Document + - Write Javadoc comments + - Write a tutorial or guide + - Proofread existing documentation for clarity and accuracy +- Promote + - Star, share, the project + - Write an article or blog post about the project +- Sponsor + - Sponsorship gives your requests top priority ### Building diff --git a/pom.xml b/pom.xml index e5b577a5..f1468022 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.apicatalog titanium - 1.5.0-SNAPSHOT + 1.5.0 pom_parent.xml titanium-json-ld diff --git a/pom_jre8.xml b/pom_jre8.xml index 73402153..8e63ab4f 100644 --- a/pom_jre8.xml +++ b/pom_jre8.xml @@ -6,7 +6,7 @@ com.apicatalog titanium - 1.5.0-SNAPSHOT + 1.5.0 pom_parent.xml titanium-json-ld-jre8 diff --git a/pom_parent.xml b/pom_parent.xml index ca938554..bf0cd88b 100644 --- a/pom_parent.xml +++ b/pom_parent.xml @@ -6,7 +6,7 @@ 4.0.0 com.apicatalog titanium - 1.5.0-SNAPSHOT + 1.5.0 pom Titanium JSON-LD 1.1 @@ -215,6 +215,9 @@ sign + + bc + diff --git a/src/main/java/com/apicatalog/jsonld/JsonLdOptions.java b/src/main/java/com/apicatalog/jsonld/JsonLdOptions.java index a4d66d97..3c780522 100644 --- a/src/main/java/com/apicatalog/jsonld/JsonLdOptions.java +++ b/src/main/java/com/apicatalog/jsonld/JsonLdOptions.java @@ -25,8 +25,8 @@ import com.apicatalog.jsonld.json.JsonProvider; import com.apicatalog.jsonld.loader.DocumentLoader; import com.apicatalog.jsonld.loader.SchemeRouter; - import com.apicatalog.jsonld.uri.UriValidationPolicy; + import jakarta.json.JsonObject; import jakarta.json.JsonValue; @@ -512,14 +512,28 @@ public UriValidationPolicy getUriValidation() { * Enabled by default. *

* - * @deprecated use JsonLdOptions#setUriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) + * @deprecated since 1.5.0, use + * JsonLdOptions#setUriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) * @param enabled set true to enable validation */ @Deprecated public void setUriValidation(boolean enabled) { - this.uriValidation = UriValidationPolicy.of(enabled); + setUriValidation(enabled ? UriValidationPolicy.Full : UriValidationPolicy.SchemeOnly); } + /** + * Sets the URI validation policy. By default, the policy is set to + * {@code Full}. + * + *

+ * Note: Changing this policy may produce unexpected or non-compliant results, + * depending on the specified validation rules. + *

+ * + * @param uriValidation the desired URI validation policy + * + * @since 1.5.0 + */ public void setUriValidation(UriValidationPolicy uriValidation) { this.uriValidation = uriValidation; } diff --git a/src/main/java/com/apicatalog/jsonld/api/ExpansionApi.java b/src/main/java/com/apicatalog/jsonld/api/ExpansionApi.java index 29b15f3c..8b751ee5 100644 --- a/src/main/java/com/apicatalog/jsonld/api/ExpansionApi.java +++ b/src/main/java/com/apicatalog/jsonld/api/ExpansionApi.java @@ -19,8 +19,8 @@ import com.apicatalog.jsonld.JsonLdError; import com.apicatalog.jsonld.JsonLdOptions; -import com.apicatalog.jsonld.JsonLdVersion; import com.apicatalog.jsonld.JsonLdOptions.ProcessingPolicy; +import com.apicatalog.jsonld.JsonLdVersion; import com.apicatalog.jsonld.document.Document; import com.apicatalog.jsonld.document.JsonDocument; import com.apicatalog.jsonld.loader.DocumentLoader; diff --git a/src/main/java/com/apicatalog/jsonld/context/TermDefinitionBuilder.java b/src/main/java/com/apicatalog/jsonld/context/TermDefinitionBuilder.java index 1f709366..721a834e 100644 --- a/src/main/java/com/apicatalog/jsonld/context/TermDefinitionBuilder.java +++ b/src/main/java/com/apicatalog/jsonld/context/TermDefinitionBuilder.java @@ -34,8 +34,8 @@ import com.apicatalog.jsonld.lang.Keywords; import com.apicatalog.jsonld.lang.LanguageTag; import com.apicatalog.jsonld.uri.UriUtils; - import com.apicatalog.jsonld.uri.UriValidationPolicy; + import jakarta.json.JsonArray; import jakarta.json.JsonObject; import jakarta.json.JsonString; diff --git a/src/main/java/com/apicatalog/jsonld/deseralization/JsonLdToRdf.java b/src/main/java/com/apicatalog/jsonld/deseralization/JsonLdToRdf.java index bbb1102b..5ba19cde 100644 --- a/src/main/java/com/apicatalog/jsonld/deseralization/JsonLdToRdf.java +++ b/src/main/java/com/apicatalog/jsonld/deseralization/JsonLdToRdf.java @@ -204,11 +204,11 @@ public RdfDataset build() throws JsonLdError { } /** - * @deprecated use JsonLdToRdf#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) + * @deprecated since 1.5.0, use JsonLdToRdf#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) */ @Deprecated - public JsonLdToRdf uriValidation(boolean uriValidation) { - return uriValidation(UriValidationPolicy.of(uriValidation)); + public JsonLdToRdf uriValidation(boolean enabled) { + return uriValidation(enabled ? UriValidationPolicy.Full : UriValidationPolicy.SchemeOnly); } public JsonLdToRdf uriValidation(UriValidationPolicy uriValidation) { diff --git a/src/main/java/com/apicatalog/jsonld/deseralization/ListToRdf.java b/src/main/java/com/apicatalog/jsonld/deseralization/ListToRdf.java index 98930b47..aafe654f 100644 --- a/src/main/java/com/apicatalog/jsonld/deseralization/ListToRdf.java +++ b/src/main/java/com/apicatalog/jsonld/deseralization/ListToRdf.java @@ -122,11 +122,11 @@ public RdfValue build() throws JsonLdError { } /** - * @deprecated use ListToRdf#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) + * @deprecated since 1.5.0, use ListToRdf#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) */ @Deprecated - public ListToRdf uriValidation(boolean uriValidation) { - return uriValidation(UriValidationPolicy.of(uriValidation)); + public ListToRdf uriValidation(boolean enabled) { + return uriValidation(enabled ? UriValidationPolicy.Full : UriValidationPolicy.SchemeOnly); } public ListToRdf uriValidation(UriValidationPolicy uriValidation) { diff --git a/src/main/java/com/apicatalog/jsonld/deseralization/ObjectToRdf.java b/src/main/java/com/apicatalog/jsonld/deseralization/ObjectToRdf.java index 75007bf6..22d9c1ed 100644 --- a/src/main/java/com/apicatalog/jsonld/deseralization/ObjectToRdf.java +++ b/src/main/java/com/apicatalog/jsonld/deseralization/ObjectToRdf.java @@ -53,17 +53,20 @@ /** * - * @see Object to RDF Conversion + * @see Object + * to RDF Conversion * */ final class ObjectToRdf { private static final Logger LOGGER = Logger.getLogger(ObjectToRdf.class.getName()); - private static final DecimalFormat xsdNumberFormat = - new DecimalFormat("0.0##############E0", new DecimalFormatSymbols(Locale.ENGLISH)); + private static final DecimalFormat xsdNumberFormat = new DecimalFormat("0.0##############E0", new DecimalFormatSymbols(Locale.ENGLISH)); - static { xsdNumberFormat.setMinimumFractionDigits(1); } + static { + xsdNumberFormat.setMinimumFractionDigits(1); + } // required private JsonObject item; @@ -85,7 +88,7 @@ private ObjectToRdf(JsonObject item, List triples, NodeMap nodeMap) { } public static final ObjectToRdf with(JsonObject item, List triples, NodeMap nodeMap) { - return new ObjectToRdf(item, triples, nodeMap); + return new ObjectToRdf(item, triples, nodeMap); } public ObjectToRdf rdfDirection(RdfDirection rdfDirection) { @@ -104,7 +107,7 @@ public Optional build() throws JsonLdError { return Optional.empty(); } - String idString = ((JsonString)id).getString(); + String idString = ((JsonString) id).getString(); if (BlankNode.isWellFormed(idString)) { return Optional.of(Rdf.createBlankNode(idString)); @@ -119,10 +122,10 @@ public Optional build() throws JsonLdError { // 3. if (ListObject.isListObject(item)) { return Optional.of(ListToRdf - .with(item.get(Keywords.LIST).asJsonArray(), triples, nodeMap) - .rdfDirection(rdfDirection) - .uriValidation(uriValidation) - .build()); + .with(item.get(Keywords.LIST).asJsonArray(), triples, nodeMap) + .rdfDirection(rdfDirection) + .uriValidation(uriValidation) + .build()); } // 4. @@ -134,8 +137,8 @@ public Optional build() throws JsonLdError { // 5. String datatype = item.containsKey(Keywords.TYPE) && JsonUtils.isString(item.get(Keywords.TYPE)) - ? item.getString(Keywords.TYPE) - : null; + ? item.getString(Keywords.TYPE) + : null; // 6. if (datatype != null && !Keywords.JSON.equals(datatype) && !UriUtils.isAbsoluteUri(datatype, uriValidation)) { @@ -146,8 +149,7 @@ public Optional build() throws JsonLdError { // 7. if (item.containsKey(Keywords.LANGUAGE) && (JsonUtils.isNotString(item.get(Keywords.LANGUAGE)) - || !LanguageTag.isWellFormed(item.getString(Keywords.LANGUAGE))) - ) { + || !LanguageTag.isWellFormed(item.getString(Keywords.LANGUAGE)))) { LOGGER.log(Level.WARNING, "Language tag [{0}] is not well formed string and value is skipped.", item.get(Keywords.LANGUAGE)); return Optional.empty(); } @@ -159,7 +161,7 @@ public Optional build() throws JsonLdError { valueString = JsonCanonicalizer.canonicalize(value); datatype = RdfConstants.JSON; - // 9. + // 9. } else if (JsonUtils.isTrue(value)) { valueString = "true"; @@ -176,19 +178,16 @@ public Optional build() throws JsonLdError { datatype = XsdConstants.BOOLEAN; } - - // 10. - 11. + // 10. - 11. } else if (JsonUtils.isNumber(value)) { - JsonNumber number = ((JsonNumber)value); - + JsonNumber number = ((JsonNumber) value); // 11. - if ((!number.isIntegral() && number.doubleValue() % -1 != 0) + if ((!number.isIntegral() && number.doubleValue() % -1 != 0) || XsdConstants.DOUBLE.equals(datatype) || XsdConstants.FLOAT.equals(datatype) - || number.bigDecimalValue().compareTo(BigDecimal.ONE.movePointRight(21)) >= 0 - ) { + || number.bigDecimalValue().compareTo(BigDecimal.ONE.movePointRight(21)) >= 0) { valueString = toXsdDouble(number.bigDecimalValue()); @@ -196,7 +195,7 @@ public Optional build() throws JsonLdError { datatype = XsdConstants.DOUBLE; } - // 10. + // 10. } else { valueString = number.bigIntegerValue().toString(); @@ -207,13 +206,12 @@ public Optional build() throws JsonLdError { } - // 12. + // 12. } else if (datatype == null) { datatype = item.containsKey(Keywords.LANGUAGE) - ? RdfConstants.LANG_STRING - : XsdConstants.STRING - ; + ? RdfConstants.LANG_STRING + : XsdConstants.STRING; } if (valueString == null) { @@ -222,7 +220,7 @@ public Optional build() throws JsonLdError { return Optional.empty(); } - valueString = ((JsonString)value).getString(); + valueString = ((JsonString) value).getString(); } RdfLiteral rdfLiteral = null; @@ -232,18 +230,18 @@ public Optional build() throws JsonLdError { // 13.1. final String language = item.containsKey(Keywords.LANGUAGE) - ? item.getString(Keywords.LANGUAGE).toLowerCase() - : ""; + ? item.getString(Keywords.LANGUAGE).toLowerCase() + : ""; // 13.2. if (RdfDirection.I18N_DATATYPE == rdfDirection) { datatype = "https://www.w3.org/ns/i18n#" - .concat(language) - .concat("_") - .concat(item.getString(Keywords.DIRECTION)); + .concat(language) + .concat("_") + .concat(item.getString(Keywords.DIRECTION)); rdfLiteral = Rdf.createTypedString(valueString, datatype); - // 13.3. + // 13.3. } else if (RdfDirection.COMPOUND_LITERAL == rdfDirection) { final String blankNodeId = nodeMap.createIdentifier(); @@ -253,31 +251,28 @@ public Optional build() throws JsonLdError { // 13.3.2. triples.add(Rdf.createTriple( - subject, - Rdf.createIRI(RdfConstants.VALUE), - Rdf.createString(valueString)) - ); + subject, + Rdf.createIRI(RdfConstants.VALUE), + Rdf.createString(valueString))); // 13.3.3. if (item.containsKey(Keywords.LANGUAGE) && JsonUtils.isString(item.get(Keywords.LANGUAGE))) { triples.add(Rdf.createTriple( - subject, - Rdf.createIRI(RdfConstants.LANGUAGE), - Rdf.createString(item.getString(Keywords.LANGUAGE).toLowerCase())) - ); + subject, + Rdf.createIRI(RdfConstants.LANGUAGE), + Rdf.createString(item.getString(Keywords.LANGUAGE).toLowerCase()))); } // 13.3.4. triples.add(Rdf.createTriple( - subject, - Rdf.createIRI(RdfConstants.DIRECTION), - Rdf.createString(item.getString(Keywords.DIRECTION))) - ); + subject, + Rdf.createIRI(RdfConstants.DIRECTION), + Rdf.createString(item.getString(Keywords.DIRECTION)))); return Optional.of(Rdf.createBlankNode(blankNodeId)); } - // 14. + // 14. } else { if (item.containsKey(Keywords.LANGUAGE) && JsonUtils.isString(item.get(Keywords.LANGUAGE))) { @@ -297,11 +292,12 @@ private static final String toXsdDouble(BigDecimal bigDecimal) { } /** - * @deprecated use Object#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) + * @deprecated since 1.5.0, use + * Object#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) */ @Deprecated - public ObjectToRdf uriValidation(boolean uriValidation) { - return uriValidation(UriValidationPolicy.of(uriValidation)); + public ObjectToRdf uriValidation(boolean enabled) { + return uriValidation(enabled ? UriValidationPolicy.Full : UriValidationPolicy.SchemeOnly); } public ObjectToRdf uriValidation(UriValidationPolicy uriValidation) { diff --git a/src/main/java/com/apicatalog/jsonld/expansion/UriExpansion.java b/src/main/java/com/apicatalog/jsonld/expansion/UriExpansion.java index b844d4ab..da795c68 100644 --- a/src/main/java/com/apicatalog/jsonld/expansion/UriExpansion.java +++ b/src/main/java/com/apicatalog/jsonld/expansion/UriExpansion.java @@ -29,8 +29,8 @@ import com.apicatalog.jsonld.lang.Keywords; import com.apicatalog.jsonld.uri.UriResolver; import com.apicatalog.jsonld.uri.UriUtils; - import com.apicatalog.jsonld.uri.UriValidationPolicy; + import jakarta.json.JsonObject; import jakarta.json.JsonString; import jakarta.json.JsonValue; @@ -127,7 +127,7 @@ public String expand(final String value) throws JsonLdError { final int splitIndex = result.indexOf(':', 1); if (splitIndex != -1) { - // 6.1. Split value into a prefix and suffix + // 6.1. Split value into a prefix and suffix // at the first occurrence of a colon (:). // 6.2. If prefix is underscore (_) or suffix begins with double-forward-slash // (//), return value as it is already an IRI or a blank node identifier. @@ -207,13 +207,13 @@ private String expandResult(final String result) { return result; } - /** - * @deprecated use UriExpansion#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) + * @deprecated since 1.5.0, use + * UriExpansion#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) */ @Deprecated - public UriExpansion uriValidation(boolean uriValidation) { - return uriValidation(UriValidationPolicy.of(uriValidation)); + public UriExpansion uriValidation(boolean enabled) { + return uriValidation(enabled ? UriValidationPolicy.Full : UriValidationPolicy.SchemeOnly); } public UriExpansion uriValidation(UriValidationPolicy uriValidation) { diff --git a/src/main/java/com/apicatalog/jsonld/framing/Frame.java b/src/main/java/com/apicatalog/jsonld/framing/Frame.java index a7cdc710..e4747814 100644 --- a/src/main/java/com/apicatalog/jsonld/framing/Frame.java +++ b/src/main/java/com/apicatalog/jsonld/framing/Frame.java @@ -30,8 +30,8 @@ import com.apicatalog.jsonld.lang.NodeObject; import com.apicatalog.jsonld.lang.ValueObject; import com.apicatalog.jsonld.uri.UriUtils; - import com.apicatalog.jsonld.uri.UriValidationPolicy; + import jakarta.json.JsonArray; import jakarta.json.JsonObject; import jakarta.json.JsonString; diff --git a/src/main/java/com/apicatalog/jsonld/loader/LRUDocumentCache.java b/src/main/java/com/apicatalog/jsonld/loader/LRUDocumentCache.java index 5d2579db..2a37d3c1 100644 --- a/src/main/java/com/apicatalog/jsonld/loader/LRUDocumentCache.java +++ b/src/main/java/com/apicatalog/jsonld/loader/LRUDocumentCache.java @@ -1,12 +1,12 @@ package com.apicatalog.jsonld.loader; +import java.net.URI; +import java.util.Objects; + import com.apicatalog.jsonld.JsonLdError; import com.apicatalog.jsonld.context.cache.LruCache; import com.apicatalog.jsonld.document.Document; -import java.net.URI; -import java.util.Objects; - public class LRUDocumentCache implements DocumentLoader { private final DocumentLoader documentLoader; diff --git a/src/main/java/com/apicatalog/jsonld/processor/ProcessingRuntime.java b/src/main/java/com/apicatalog/jsonld/processor/ProcessingRuntime.java index d41d2515..5c4aac86 100644 --- a/src/main/java/com/apicatalog/jsonld/processor/ProcessingRuntime.java +++ b/src/main/java/com/apicatalog/jsonld/processor/ProcessingRuntime.java @@ -7,8 +7,8 @@ import com.apicatalog.jsonld.context.cache.Cache; import com.apicatalog.jsonld.document.Document; import com.apicatalog.jsonld.loader.DocumentLoader; - import com.apicatalog.jsonld.uri.UriValidationPolicy; + import jakarta.json.JsonValue; /** diff --git a/src/main/java/com/apicatalog/jsonld/serialization/RdfToJsonld.java b/src/main/java/com/apicatalog/jsonld/serialization/RdfToJsonld.java index d4f79ee0..f4be4543 100644 --- a/src/main/java/com/apicatalog/jsonld/serialization/RdfToJsonld.java +++ b/src/main/java/com/apicatalog/jsonld/serialization/RdfToJsonld.java @@ -65,7 +65,6 @@ public final class RdfToJsonld { // runtime private GraphMap graphMap; - private Map> compoundLiteralSubjects; private Map referenceOnce; @@ -179,7 +178,7 @@ public JsonArray build() throws JsonLdError { final JsonValue lang = JsonUtils.flatten(clNode.get(RdfConstants.LANGUAGE), Keywords.VALUE); - if (JsonUtils.isNotString(lang) || !LanguageTag.isWellFormed(((JsonString)lang).getString())) { + if (JsonUtils.isNotString(lang) || !LanguageTag.isWellFormed(((JsonString) lang).getString())) { throw new JsonLdError(JsonLdErrorCode.INVALID_LANGUAGE_TAGGED_STRING); } @@ -192,9 +191,8 @@ public JsonArray build() throws JsonLdError { final JsonValue direction = JsonUtils.flatten(clNode.get(RdfConstants.DIRECTION), Keywords.VALUE); if (JsonUtils.isNotString(direction) - || (!"ltr".equalsIgnoreCase(((JsonString)direction).getString()) - && !"rtl".equalsIgnoreCase(((JsonString)direction).getString())) - ) { + || (!"ltr".equalsIgnoreCase(((JsonString) direction).getString()) + && !"rtl".equalsIgnoreCase(((JsonString) direction).getString()))) { throw new JsonLdError(JsonLdErrorCode.INVALID_BASE_DIRECTION); } @@ -222,7 +220,7 @@ public JsonArray build() throws JsonLdError { final JsonArrayBuilder list = JsonProvider.instance().createArrayBuilder(); final List listNodes = new ArrayList<>(); - String nodeId = ((JsonString)node.get(Keywords.ID)).getString(); + String nodeId = ((JsonString) node.get(Keywords.ID)).getString(); // 6.4.3. while (RdfConstants.REST.equals(usage.property) @@ -232,12 +230,10 @@ public JsonArray build() throws JsonLdError { && node.containsKey(RdfConstants.REST) && node.get(RdfConstants.FIRST).asJsonArray().size() == 1 && node.get(RdfConstants.REST).asJsonArray().size() == 1 - && (node.size() == 3 /* keywords: @id, @first, @last */ + && (node.size() == 3 /* keywords: @id, @first, @last */ || (node.size() == 4 && node.containsKey(Keywords.TYPE) - && node.get(Keywords.TYPE).asJsonArray().size() == 1 - && node.get(Keywords.TYPE).asJsonArray().contains(JsonProvider.instance().createValue(RdfConstants.LIST)) - )) - ) { + && node.get(Keywords.TYPE).asJsonArray().size() == 1 + && node.get(Keywords.TYPE).asJsonArray().contains(JsonProvider.instance().createValue(RdfConstants.LIST))))) { // 6.4.3.1. list.add(0, node.get(RdfConstants.FIRST).asJsonArray().get(0)); // reverse order -> index = 0 see 6.4.5. @@ -261,7 +257,7 @@ public JsonArray build() throws JsonLdError { break; } - nodeId = ((JsonString)node.get(Keywords.ID)).getString(); + nodeId = ((JsonString) node.get(Keywords.ID)).getString(); // 6.4.3.5. if (UriUtils.isAbsoluteUri(nodeId, uriValidation)) { @@ -376,11 +372,10 @@ private void step5(final String graphName, final RdfGraph graph) throws JsonLdEr } // 5.7.6. - final JsonObject value = - RdfToObject - .with(triple.getObject(), rdfDirection, useNativeTypes) - .processingMode(processingMode) - .build(); + final JsonObject value = RdfToObject + .with(triple.getObject(), rdfDirection, useNativeTypes) + .processingMode(processingMode) + .build(); final Optional predicateValue = graphMap.get(graphName, subject, predicate); @@ -393,7 +388,7 @@ private void step5(final String graphName, final RdfGraph graph) throws JsonLdEr graphMap.set(graphName, subject, predicate, JsonProvider.instance().createArrayBuilder(array).add(value).build()); } - // 5.7.8. + // 5.7.8. } else { graphMap.set(graphName, subject, predicate, JsonProvider.instance().createArrayBuilder().add(value).build()); } @@ -409,12 +404,12 @@ private void step5(final String graphName, final RdfGraph graph) throws JsonLdEr graphMap.addUsage(graphName, triple.getObject().getValue(), reference); - // 5.7.10. + // 5.7.10. } else if (referenceOnce.containsKey(triple.getObject().getValue())) { referenceOnce.put(triple.getObject().getValue(), null); - // 5.7.11. + // 5.7.11. } else if (triple.getObject().isBlankNode()) { Reference reference = new Reference(); @@ -436,11 +431,12 @@ protected static class Reference { } /** - * @deprecated use RdfToJsonld#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) + * @deprecated since 1.5.0, use + * RdfToJsonld#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy) */ @Deprecated - public RdfToJsonld uriValidation(boolean uriValidation) { - return uriValidation(UriValidationPolicy.of(uriValidation)); + public RdfToJsonld uriValidation(boolean enabled) { + return uriValidation(enabled ? UriValidationPolicy.Full : UriValidationPolicy.SchemeOnly); } public RdfToJsonld uriValidation(UriValidationPolicy uriValidation) { diff --git a/src/main/java/com/apicatalog/jsonld/serialization/RdfToObject.java b/src/main/java/com/apicatalog/jsonld/serialization/RdfToObject.java index e7461ede..f0404bb1 100644 --- a/src/main/java/com/apicatalog/jsonld/serialization/RdfToObject.java +++ b/src/main/java/com/apicatalog/jsonld/serialization/RdfToObject.java @@ -20,8 +20,8 @@ import com.apicatalog.jsonld.JsonLdError; import com.apicatalog.jsonld.JsonLdErrorCode; import com.apicatalog.jsonld.JsonLdOptions.RdfDirection; -import com.apicatalog.jsonld.json.JsonProvider; import com.apicatalog.jsonld.JsonLdVersion; +import com.apicatalog.jsonld.json.JsonProvider; import com.apicatalog.jsonld.lang.Keywords; import com.apicatalog.rdf.RdfLiteral; import com.apicatalog.rdf.RdfValue; diff --git a/src/main/java/com/apicatalog/jsonld/uri/UriUtils.java b/src/main/java/com/apicatalog/jsonld/uri/UriUtils.java index a15e02f1..6313f698 100644 --- a/src/main/java/com/apicatalog/jsonld/uri/UriUtils.java +++ b/src/main/java/com/apicatalog/jsonld/uri/UriUtils.java @@ -28,12 +28,11 @@ private UriUtils() { public static final boolean isURI(final String value) { return value != null - && StringUtils.isNotBlank(value) - && !Keywords.matchForm(StringUtils.strip(value)) - && create(StringUtils.strip(value)) != null; + && StringUtils.isNotBlank(value) + && !Keywords.matchForm(StringUtils.strip(value)) + && create(StringUtils.strip(value)) != null; } - public static final URI create(final String uri) { if (uri == null) { @@ -80,8 +79,7 @@ public static final boolean isNotURI(final String uri) { return uri == null || StringUtils.isBlank(uri) || Keywords.matchForm(StringUtils.strip(uri)) - || create(StringUtils.strip(uri)) == null - ; + || create(StringUtils.strip(uri)) == null; } /** @@ -94,11 +92,12 @@ public static final boolean isNotURI(final String uri) { */ @Deprecated public static final boolean isNotAbsoluteUri(final String uri) { - return isNotAbsoluteUri(uri, UriValidationPolicy.of(true)); + return isNotAbsoluteUri(uri, UriValidationPolicy.Full); } /** - * Deprecated in favor of {@link UriUtils#isNotAbsoluteUri(String, UriValidationPolicy)} + * Deprecated in favor of + * {@link UriUtils#isNotAbsoluteUri(String, UriValidationPolicy)} * * @deprecated since 1.3.0 * @@ -107,7 +106,7 @@ public static final boolean isNotAbsoluteUri(final String uri) { */ @Deprecated public static final boolean isNotAbsoluteUri(final String uri, final boolean validate) { - return !isAbsoluteUri(uri, UriValidationPolicy.of(validate)); + return !isAbsoluteUri(uri, validate ? UriValidationPolicy.Full : UriValidationPolicy.SchemeOnly); } public static final boolean isNotAbsoluteUri(final String uri, UriValidationPolicy policy) { @@ -115,7 +114,8 @@ public static final boolean isNotAbsoluteUri(final String uri, UriValidationPoli } /** - * Deprecated in favor of {@link UriUtils#isAbsoluteUri(String, UriValidationPolicy)} + * Deprecated in favor of + * {@link UriUtils#isAbsoluteUri(String, UriValidationPolicy)} * * @deprecated since 1.3.0 * @@ -128,7 +128,8 @@ public static final boolean isAbsoluteUri(final String uri) { } /** - * Deprecated in favor of {@link UriUtils#isAbsoluteUri(String, UriValidationPolicy)} + * Deprecated in favor of + * {@link UriUtils#isAbsoluteUri(String, UriValidationPolicy)} * * @deprecated since 1.4.2 * @@ -137,29 +138,29 @@ public static final boolean isAbsoluteUri(final String uri) { */ @Deprecated public static final boolean isAbsoluteUri(final String uri, boolean validate) { - return isAbsoluteUri(uri, UriValidationPolicy.of(validate)); + return isAbsoluteUri(uri, validate ? UriValidationPolicy.Full : UriValidationPolicy.SchemeOnly); } public static final boolean isAbsoluteUri(final String uri, final UriValidationPolicy policy) { switch (policy) { - case None: - return true; - case SchemeOnly: - return startsWithScheme(uri); - case Full: - if (uri == null - || uri.length() < 3 // minimal form s(1):ssp(1) - ) { + case None: + return true; + case SchemeOnly: + return startsWithScheme(uri); + case Full: + if (uri == null + || uri.length() < 3 // minimal form s(1):ssp(1) + ) { + return false; + } else { + try { + return URI.create(uri).isAbsolute(); + } catch (IllegalArgumentException e) { return false; - } else{ - try { - return URI.create(uri).isAbsolute(); - } catch (IllegalArgumentException e) { - return false; - } } - default: - return false; + } + default: + return false; } } @@ -169,17 +170,16 @@ private static final boolean startsWithScheme(final String uri) { if (uri == null || uri.length() < 2 // a scheme must have at least one letter followed by ':' || !Character.isLetter(uri.codePointAt(0)) // a scheme name must start with a letter - ) { + ) { return false; } for (int i = 1; i < uri.length(); i++) { if ( - // a scheme name must start with a letter followed by a letter/digit/+/-/. - Character.isLetterOrDigit(uri.codePointAt(i)) - || uri.charAt(i) == '-' || uri.charAt(i) == '+' || uri.charAt(i) == '.' - ) { + // a scheme name must start with a letter followed by a letter/digit/+/-/. + Character.isLetterOrDigit(uri.codePointAt(i)) + || uri.charAt(i) == '-' || uri.charAt(i) == '+' || uri.charAt(i) == '.') { continue; } diff --git a/src/main/java/com/apicatalog/jsonld/uri/UriValidationPolicy.java b/src/main/java/com/apicatalog/jsonld/uri/UriValidationPolicy.java index abb64f37..7d334ca1 100644 --- a/src/main/java/com/apicatalog/jsonld/uri/UriValidationPolicy.java +++ b/src/main/java/com/apicatalog/jsonld/uri/UriValidationPolicy.java @@ -1,26 +1,28 @@ package com.apicatalog.jsonld.uri; +/** + * Represents different URI validation policies. These policies determine the + * extent to which URIs are validated during processing. + */ public enum UriValidationPolicy { /** - * No validation is performed + * Disables URI validation entirely, accepting all input as-is. This option + * provides maximum flexibility but may lead to non-compliant or invalid URI + * handling. */ None, /** - * The validation only targets the scheme + * Validates only the scheme component of the URI, allowing for more lenient + * processing while still ensuring a recognizable scheme (e.g., "http:", + * "https:"). */ SchemeOnly, /** - * The validation is be fully performed + * Performs full URI validation, ensuring that the URI conforms to all syntax + * and structural requirements defined by relevant standards. */ - Full ; - - /** - * Method allowing to convert the legacy boolean to the matching policy - */ - public static UriValidationPolicy of(boolean value) { - return value ? Full : SchemeOnly ; - } + Full; }