Skip to content

Commit f0c4026

Browse files
authored
Merge pull request #438 from filip26/feat/v2-m2
2.0.0-M2
2 parents 5fda452 + d156856 commit f0c4026

627 files changed

Lines changed: 10604 additions & 1228 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
# Titanium JSON-LD 1.1 Processor & API
22

3-
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).
3+
An implementation of the [JSON-LD 1.1](https://www.w3.org/TR/json-ld/) (JSON-based Serialization for Linked Data) specification in Java.
44

5-
### 🎯 Goals
6-
- Full conformance to the specification
7-
- Secure, stable, fast, high-quality code (**~2900 tests**)
8-
- Minimal external dependencies
9-
- Simple and easy-to-use
5+
### ✨ Features
106

11-
### 🚦 Status
7+
- Full conformance with the JSON-LD 1.1 specification
8+
- Secure, stable, high-performance implementation with ~3000 tests
9+
- Minimal external dependencies
10+
- Simple, easy-to-use API
11+
- Extensions (since v2.0):
12+
- JSON-LD-star expansion (experimental)
13+
- Processing policies: undefined terms, time/space constraints
14+
- Generated TypeMap / TermMap (experimental)
15+
- Built-in loaders: HTTPS, file, classpath, scheme router, URI rewriter
16+
- Generalized processing with [tree-io](https://github.com/filip26/tree-io) (Jakarta JSON, Jackson, or anything else)
17+
18+
### 🎯 Status
1219

1320
[![Java 17 CI](https://github.com/filip26/titanium-json-ld/actions/workflows/java17-build.yml/badge.svg)](https://github.com/filip26/titanium-json-ld/actions/workflows/java17-build.yml)
1421
[![CodeQL](https://github.com/filip26/titanium-json-ld/actions/workflows/codeql.yml/badge.svg)](https://github.com/filip26/titanium-json-ld/actions/workflows/codeql.yml)
22+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/c530c6b43b0243c08ce81521c5b4cf6a)](https://app.codacy.com/gh/filip26/titanium-json-ld/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
1523
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/c530c6b43b0243c08ce81521c5b4cf6a)](https://app.codacy.com/gh/filip26/titanium-json-ld/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
1624
[![Javadoc](https://javadoc.io/badge2/com.apicatalog/titanium-json-ld/javadoc.svg)](https://javadoc.io/doc/com.apicatalog/titanium-json-ld)
1725
[![Maven Central](https://img.shields.io/maven-central/v/com.apicatalog/titanium-json-ld.svg?label=Maven%20Central)](https://mvnrepository.com/artifact/com.apicatalog/titanium-json-ld)
@@ -185,7 +193,7 @@ implementation("com.apicatalog:titanium-json-ld-jre8:1.7.0")
185193
186194
### JSON-P Provider
187195

188-
Titanium relies on a **JSON-P (Jakarta JSON Processing)** provider. Ensure that one is available on your classpath.
196+
Titanium v1.x.x relies on a **JSON-P (Jakarta JSON Processing)** provider. Ensure that one is available on your classpath.
189197

190198
#### Maven
191199

pom.xml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.apicatalog</groupId>
7-
<version>2.0.0-M1</version>
7+
<version>2.0.0-M2</version>
88
<artifactId>titanium-json-ld</artifactId>
99
<packaging>jar</packaging>
1010

@@ -51,16 +51,16 @@
5151

5252
<maven.compiler.release>17</maven.compiler.release>
5353

54-
<titanium.rdf.api.version>1.0.0</titanium.rdf.api.version>
55-
<titanium.rdf.nquads.version>1.0.2</titanium.rdf.nquads.version>
56-
54+
<rdf-api.version>1.0.0</rdf-api.version>
5755
<jcs.version>3.0.0-M1</jcs.version>
5856
<tree-io.version>0.11.0</tree-io.version>
59-
<jakarta.json.version>2.0.1</jakarta.json.version>
6057

6158
<!-- test resources -->
6259
<junit.version>6.0.1</junit.version>
63-
<wiremock.version>2.35.2</wiremock.version>
60+
<jakarta.json.version>2.0.1</jakarta.json.version>
61+
<nquads.version>1.0.2</nquads.version>
62+
<rdf-primitives.version>1.0.3</rdf-primitives.version>
63+
<rdfc.version>2.0.0</rdfc.version>
6464

6565
<sonar.projectKey>filip26_titanium-json-ld</sonar.projectKey>
6666
<sonar.organization>apicatalog</sonar.organization>
@@ -81,7 +81,7 @@
8181
<dependency>
8282
<groupId>com.apicatalog</groupId>
8383
<artifactId>titanium-rdf-api</artifactId>
84-
<version>${titanium.rdf.api.version}</version>
84+
<version>${rdf-api.version}</version>
8585
</dependency>
8686
<!-- Tests-->
8787
<dependency>
@@ -99,19 +99,19 @@
9999
<dependency>
100100
<groupId>com.apicatalog</groupId>
101101
<artifactId>titanium-rdf-n-quads</artifactId>
102-
<version>${titanium.rdf.nquads.version}</version>
102+
<version>${nquads.version}</version>
103103
<scope>test</scope>
104104
</dependency>
105105
<dependency>
106106
<groupId>com.apicatalog</groupId>
107107
<artifactId>titanium-rdf-primitives</artifactId>
108-
<version>1.0.3</version>
108+
<version>${rdf-primitives.version}</version>
109109
<scope>test</scope>
110110
</dependency>
111111
<dependency>
112112
<groupId>com.apicatalog</groupId>
113113
<artifactId>titanium-rdfc</artifactId>
114-
<version>2.0.0</version>
114+
<version>${rdfc.version}</version>
115115
<scope>test</scope>
116116
</dependency>
117117
<dependency>
@@ -190,9 +190,6 @@
190190
<artifactId>maven-surefire-plugin</artifactId>
191191
<version>3.5.4</version>
192192
<configuration>
193-
<!-- <excludes>
194-
<exclude>**Test.java</exclude>
195-
</excludes> -->
196193
<includes>
197194
<include>**Suite.java</include>
198195
<include>**Test.java</include>

src/main/java/com/apicatalog/jsonld/JsonLd.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.apicatalog.jsonld.framing.Frame;
2525
import com.apicatalog.jsonld.fromrdf.QuadsToJsonLd;
2626
import com.apicatalog.jsonld.processor.Compactor;
27-
import com.apicatalog.jsonld.processor.Execution;
27+
import com.apicatalog.jsonld.processor.ExecutionEvents;
2828
import com.apicatalog.jsonld.processor.Expander;
2929
import com.apicatalog.jsonld.processor.Flattener;
3030
import com.apicatalog.jsonld.processor.Framer;
@@ -74,7 +74,7 @@ public static final Collection<?> expand(
7474
options.loader(),
7575
options.isExtractAllScripts()),
7676
options,
77-
Execution.of(options).start());
77+
ExecutionEvents.of(options).start());
7878
}
7979

8080
/**
@@ -92,7 +92,7 @@ public static final Collection<?> expand(
9292
return Expander.expand(
9393
document,
9494
options,
95-
Execution.of(options).start());
95+
ExecutionEvents.of(options).start());
9696
}
9797

9898
/**
@@ -127,7 +127,7 @@ public static final Collection<?> expand(
127127
return Expander.expand(
128128
document,
129129
options,
130-
Execution.of(options).start());
130+
ExecutionEvents.of(options).start());
131131
}
132132

133133
/* --- COMPACT -- */
@@ -209,7 +209,7 @@ public static final Collection<?> expand(
209209
document,
210210
context,
211211
options,
212-
Execution.of(options).start());
212+
ExecutionEvents.of(options).start());
213213
}
214214

215215
/**
@@ -227,7 +227,7 @@ public static final Collection<?> expand(
227227
final TreeIO context,
228228
final Options options) throws JsonLdException {
229229

230-
final Execution runtime = Execution.of(options).start();
230+
final ExecutionEvents runtime = ExecutionEvents.of(options).start();
231231

232232
return Compactor.compact(
233233
Compactor.expand(document, options, runtime),
@@ -280,7 +280,7 @@ public static final Object flatten(
280280
options.isExtractAllScripts()),
281281
null,
282282
options,
283-
Execution.of(options).start());
283+
ExecutionEvents.of(options).start());
284284
}
285285

286286
/**
@@ -306,7 +306,7 @@ public static final Object flatten(
306306
? Context.load(context, options.loader()).content()
307307
: null,
308308
options,
309-
Execution.of(options).start());
309+
ExecutionEvents.of(options).start());
310310
}
311311

312312
/**
@@ -326,7 +326,7 @@ public static final Object flatten(
326326
document,
327327
null,
328328
options,
329-
Execution.of(options).start());
329+
ExecutionEvents.of(options).start());
330330
}
331331

332332
/**
@@ -346,7 +346,7 @@ public static final Object flatten(
346346
? context.content()
347347
: null,
348348
options,
349-
Execution.of(options).start());
349+
ExecutionEvents.of(options).start());
350350
}
351351

352352
/**
@@ -452,7 +452,7 @@ public static final Object flatten(
452452
document,
453453
null,
454454
options,
455-
Execution.of(options).start());
455+
ExecutionEvents.of(options).start());
456456
}
457457

458458
/**
@@ -475,7 +475,7 @@ public static final Object flatten(
475475
document,
476476
context,
477477
options,
478-
Execution.of(options).start());
478+
ExecutionEvents.of(options).start());
479479
}
480480

481481
/* --- FRAME -- */
@@ -558,7 +558,7 @@ public static final Object flatten(
558558
document,
559559
frame,
560560
options,
561-
Execution.of(options).start());
561+
ExecutionEvents.of(options).start());
562562
}
563563

564564
/**
@@ -596,7 +596,7 @@ public static final Object flatten(
596596
final TreeIO frame,
597597
final Options options) throws JsonLdException {
598598

599-
final Execution runtime = Execution.of(options).start();
599+
final ExecutionEvents runtime = ExecutionEvents.of(options).start();
600600

601601
final var contextNode = Context.extract(frame);
602602

@@ -655,7 +655,7 @@ public static final void toRdf(
655655
document,
656656
consumer,
657657
options,
658-
Execution.of(options).start());
658+
ExecutionEvents.of(options).start());
659659
}
660660

661661
/**
@@ -677,7 +677,7 @@ public static final void toRdf(
677677
document,
678678
consumer,
679679
options,
680-
Execution.of(options).start());
680+
ExecutionEvents.of(options).start());
681681
}
682682

683683
/**
@@ -698,7 +698,7 @@ public static final void toRdf(
698698
new TreeIO(document, NativeAdapter.instance()),
699699
consumer,
700700
options,
701-
Execution.of(options).start());
701+
ExecutionEvents.of(options).start());
702702
}
703703

704704
/* --- FROM RDF -- */

src/main/java/com/apicatalog/jsonld/JsonLdException.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Objects;
2020
import java.util.Optional;
2121

22+
import com.apicatalog.tree.io.TreeIO;
23+
2224
/**
2325
* Represents a JSON-LD processing error.
2426
*
@@ -30,6 +32,9 @@ public final class JsonLdException extends Exception {
3032
private static final long serialVersionUID = -7548366490116267200L;
3133

3234
private final ErrorCode code;
35+
36+
// a node that caused the exception, if any
37+
//TODO private final TreeIO value;
3338

3439
/**
3540
* Creates a new {@code JsonLdException} with the specified error code.
@@ -420,7 +425,13 @@ public enum ErrorCode {
420425
*/
421426
UNDEFINED_TERM("An undefined term has been found. Set policy to ignore to pass"),
422427

423-
UNSPECIFIED("An unspecified processing error");
428+
INLINE_CONTEXT_IS_NOT_ALLOWED("Inline contexts are not allowed"),
429+
430+
UNSPECIFIED("An unspecified processing error"),
431+
432+
MISSING_DOCUMENT_LOADER("A document loader is not present")
433+
434+
;
424435

425436
private final String description;
426437

src/main/java/com/apicatalog/jsonld/Options.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public enum ProcessingPolicy {
8686
/** Default settings. */
8787
public static final boolean DEFAULT_RDF_STAR = false;
8888
public static final boolean DEFAULT_NUMERIC_ID = false;
89+
public static final boolean DEFAULT_INLINE_CONTEXTS = true;
8990
public static final UriValidationPolicy DEFAULT_URI_VALIDATION = UriValidationPolicy.Full;
9091

9192
/**
@@ -154,9 +155,12 @@ public enum ProcessingPolicy {
154155

155156
// custom
156157

157-
// allow numeric @id
158+
// allows numeric @id
158159
private boolean useNumericId;
159160

161+
// allows inline contexts
162+
private boolean useInlineContexts;
163+
160164
// context cache
161165
// private Cache<String, JsonValue> contextCache;
162166

@@ -198,6 +202,7 @@ private Options() {
198202

199203
// custom
200204
this.useNumericId = DEFAULT_NUMERIC_ID;
205+
this.useInlineContexts = DEFAULT_INLINE_CONTEXTS;
201206
// this.contextCache = new LruCache<>(256);
202207
this.documentCache = null;
203208
this.uriValidation = DEFAULT_URI_VALIDATION;
@@ -232,6 +237,7 @@ private Options(Options options) {
232237

233238
// custom
234239
this.useNumericId = options.useNumericId;
240+
this.useInlineContexts = options.useInlineContexts;
235241
// this.contextCache = options.contextCache;
236242
this.documentCache = options.documentCache;
237243
this.uriValidation = options.uriValidation;
@@ -931,4 +937,13 @@ public Options undefinedTermsPolicy(ProcessingPolicy undefinedTerms) {
931937
this.undefinedTerms = undefinedTerms;
932938
return this;
933939
}
940+
941+
public boolean useInlineContexts() {
942+
return useInlineContexts;
943+
}
944+
945+
public Options useInlineContexts(boolean useInlineContext) {
946+
this.useInlineContexts = useInlineContext;
947+
return this;
948+
}
934949
}

0 commit comments

Comments
 (0)