Skip to content

Commit 4554510

Browse files
authored
GH-5032 Allow system property to override rio settings for JSON-LD and others (#5038)
2 parents 7034492 + 842c175 commit 4554510

31 files changed

Lines changed: 244 additions & 99 deletions

File tree

core/queryresultio/api/src/main/java/org/eclipse/rdf4j/query/resultio/BasicQueryWriterSettings.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
package org.eclipse.rdf4j.query.resultio;
1212

1313
import org.eclipse.rdf4j.rio.RioSetting;
14+
import org.eclipse.rdf4j.rio.helpers.BooleanRioSetting;
1415
import org.eclipse.rdf4j.rio.helpers.RioSettingImpl;
16+
import org.eclipse.rdf4j.rio.helpers.StringRioSetting;
1517

1618
/**
1719
* {@link RioSetting} constants to use with {@link QueryResultWriter}s.
@@ -26,7 +28,7 @@ public class BasicQueryWriterSettings {
2628
* <p>
2729
* Defaults to false.
2830
*/
29-
public final static RioSetting<Boolean> ADD_SESAME_QNAME = new RioSettingImpl<>(
31+
public final static BooleanRioSetting ADD_SESAME_QNAME = new BooleanRioSetting(
3032
"org.eclipse.rdf4j.query.resultio.addsesameqname", "Add Sesame QName", false);
3133

3234
/**
@@ -35,7 +37,7 @@ public class BasicQueryWriterSettings {
3537
* <p>
3638
* Defaults to "sesamecallback".
3739
*/
38-
public static final RioSetting<String> JSONP_CALLBACK = new RioSettingImpl<>(
40+
public static final StringRioSetting JSONP_CALLBACK = new StringRioSetting(
3941
"org.eclipse.rdf4j.query.resultio.jsonpcallback", "JSONP callback function", "sesamecallback");
4042

4143
/**

core/repository/http/src/main/java/org/eclipse/rdf4j/repository/http/helpers/HTTPRepositorySettings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import org.eclipse.rdf4j.repository.http.HTTPRepository;
1414
import org.eclipse.rdf4j.rio.RioSetting;
15+
import org.eclipse.rdf4j.rio.helpers.IntegerRioSetting;
1516
import org.eclipse.rdf4j.rio.helpers.RioSettingImpl;
1617
import org.slf4j.Logger;
1718
import org.slf4j.LoggerFactory;
@@ -31,7 +32,7 @@ public class HTTPRepositorySettings {
3132
* By default inner buffers within {@link org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection} keep in memory
3233
* up to 200000 statement before they are flushed to the remote repository.
3334
*/
34-
public static final RioSetting<Integer> MAX_STATEMENT_BUFFER_SIZE = new RioSettingImpl<>(
35+
public static final IntegerRioSetting MAX_STATEMENT_BUFFER_SIZE = new IntegerRioSetting(
3536
"org.eclipse.rdf4j.http.maxstatementbuffersize", "Maximum number of statement buffered in memory", 200000);
3637

3738
}

core/rio/api/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@
8080
</exclusion>
8181
</exclusions>
8282
</dependency>
83+
<dependency>
84+
<groupId>com.fasterxml.jackson.core</groupId>
85+
<artifactId>jackson-annotations</artifactId>
86+
</dependency>
87+
<dependency>
88+
<groupId>com.fasterxml.jackson.core</groupId>
89+
<artifactId>jackson-core</artifactId>
90+
</dependency>
91+
<dependency>
92+
<groupId>com.fasterxml.jackson.core</groupId>
93+
<artifactId>jackson-databind</artifactId>
94+
</dependency>
8395
<dependency>
8496
<groupId>commons-io</groupId>
8597
<artifactId>commons-io</artifactId>

core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/BasicParserSettings.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class BasicParserSettings {
4646
* <p>
4747
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.verify_datatype_values}.
4848
*/
49-
public static final RioSetting<Boolean> VERIFY_DATATYPE_VALUES = new BooleanRioSetting(
49+
public static final BooleanRioSetting VERIFY_DATATYPE_VALUES = new BooleanRioSetting(
5050
"org.eclipse.rdf4j.rio.verify_datatype_values", "Verify recognised datatype values", Boolean.FALSE);
5151

5252
/**
@@ -58,7 +58,7 @@ public class BasicParserSettings {
5858
* <p>
5959
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.fail_on_unknown_datatypes}.
6060
*/
61-
public static final RioSetting<Boolean> FAIL_ON_UNKNOWN_DATATYPES = new BooleanRioSetting(
61+
public static final BooleanRioSetting FAIL_ON_UNKNOWN_DATATYPES = new BooleanRioSetting(
6262
"org.eclipse.rdf4j.rio.fail_on_unknown_datatypes", "Fail on unknown datatypes", Boolean.FALSE);
6363

6464
/**
@@ -70,7 +70,7 @@ public class BasicParserSettings {
7070
* <p>
7171
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.normalize_datatype_values}.
7272
*/
73-
public static final RioSetting<Boolean> NORMALIZE_DATATYPE_VALUES = new BooleanRioSetting(
73+
public static final BooleanRioSetting NORMALIZE_DATATYPE_VALUES = new BooleanRioSetting(
7474
"org.eclipse.rdf4j.rio.normalize_datatype_values", "Normalize recognised datatype values", Boolean.FALSE);
7575

7676
/**
@@ -91,7 +91,7 @@ public class BasicParserSettings {
9191
* <p>
9292
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.fail_on_unknown_languages}.
9393
*/
94-
public static final RioSetting<Boolean> FAIL_ON_UNKNOWN_LANGUAGES = new BooleanRioSetting(
94+
public static final BooleanRioSetting FAIL_ON_UNKNOWN_LANGUAGES = new BooleanRioSetting(
9595
"org.eclipse.rdf4j.rio.fail_on_unknown_languages", "Fail on unknown languages", Boolean.FALSE);
9696

9797
/**
@@ -104,7 +104,7 @@ public class BasicParserSettings {
104104
* <p>
105105
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.verify_language_tags}.
106106
*/
107-
public static final RioSetting<Boolean> VERIFY_LANGUAGE_TAGS = new BooleanRioSetting(
107+
public static final BooleanRioSetting VERIFY_LANGUAGE_TAGS = new BooleanRioSetting(
108108
"org.eclipse.rdf4j.rio.verify_language_tags", "Verify language tags", Boolean.TRUE);
109109

110110
/**
@@ -116,7 +116,7 @@ public class BasicParserSettings {
116116
* <p>
117117
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.normalize_language_tags}.
118118
*/
119-
public static final RioSetting<Boolean> NORMALIZE_LANGUAGE_TAGS = new BooleanRioSetting(
119+
public static final BooleanRioSetting NORMALIZE_LANGUAGE_TAGS = new BooleanRioSetting(
120120
"org.eclipse.rdf4j.rio.normalize_language_tags", "Normalize recognised language tags", Boolean.FALSE);
121121

122122
/**
@@ -134,7 +134,7 @@ public class BasicParserSettings {
134134
* <p>
135135
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.verify_relative_uris}.
136136
*/
137-
public static final RioSetting<Boolean> VERIFY_RELATIVE_URIS = new BooleanRioSetting(
137+
public static final BooleanRioSetting VERIFY_RELATIVE_URIS = new BooleanRioSetting(
138138
"org.eclipse.rdf4j.rio.verify_relative_uris", "Verify relative URIs", Boolean.TRUE);
139139

140140
/**
@@ -145,7 +145,7 @@ public class BasicParserSettings {
145145
* <p>
146146
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.verify_uri_syntax}.
147147
*/
148-
public static final RioSetting<Boolean> VERIFY_URI_SYNTAX = new BooleanRioSetting(
148+
public static final BooleanRioSetting VERIFY_URI_SYNTAX = new BooleanRioSetting(
149149
"org.eclipse.rdf4j.rio.verify_uri_syntax", "Verify URI syntax", Boolean.TRUE);
150150

151151
/**
@@ -156,7 +156,7 @@ public class BasicParserSettings {
156156
* <p>
157157
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.preserve_bnode_ids}.
158158
*/
159-
public static final RioSetting<Boolean> PRESERVE_BNODE_IDS = new BooleanRioSetting(
159+
public static final BooleanRioSetting PRESERVE_BNODE_IDS = new BooleanRioSetting(
160160
"org.eclipse.rdf4j.rio.preserve_bnode_ids", "Preserve blank node identifiers", Boolean.FALSE);
161161

162162
/**
@@ -168,7 +168,7 @@ public class BasicParserSettings {
168168
* <p>
169169
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.skolem_origin}.
170170
*/
171-
public static final RioSetting<String> SKOLEMIZE_ORIGIN = new StringRioSetting(
171+
public static final StringRioSetting SKOLEMIZE_ORIGIN = new StringRioSetting(
172172
"org.eclipse.rdf4j.rio.skolem_origin",
173173
"Replace blank nodes with well known genid IRIs using this scheme and authority", null);
174174

@@ -197,7 +197,7 @@ public class BasicParserSettings {
197197
* <p>
198198
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.large_literals_limit}.
199199
*/
200-
public static final RioSetting<Long> LARGE_LITERALS_LIMIT = new LongRioSetting(
200+
public static final LongRioSetting LARGE_LITERALS_LIMIT = new LongRioSetting(
201201
"org.eclipse.rdf4j.rio.large_literals_limit", "Size limit for large literals", 1048576L);
202202

203203
/**
@@ -227,7 +227,7 @@ public class BasicParserSettings {
227227
* <p>
228228
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.process_encoded_rdf_star}.
229229
*/
230-
public static final RioSetting<Boolean> PROCESS_ENCODED_RDF_STAR = new BooleanRioSetting(
230+
public static final BooleanRioSetting PROCESS_ENCODED_RDF_STAR = new BooleanRioSetting(
231231
"org.eclipse.rdf4j.rio.process_encoded_rdf_star",
232232
"Converts RDF-star triples encoded as RDF-compatible IRIs back to triple values", Boolean.TRUE);
233233

core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/BasicWriterSettings.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class BasicWriterSettings {
2626
* <p>
2727
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.pretty_print}.
2828
*/
29-
public static final RioSetting<Boolean> PRETTY_PRINT = new BooleanRioSetting("org.eclipse.rdf4j.rio.pretty_print",
29+
public static final BooleanRioSetting PRETTY_PRINT = new BooleanRioSetting("org.eclipse.rdf4j.rio.pretty_print",
3030
"Pretty print", Boolean.TRUE);
3131

3232
/**
@@ -42,7 +42,7 @@ public class BasicWriterSettings {
4242
*
4343
* @since 2.3
4444
*/
45-
public static final RioSetting<Boolean> INLINE_BLANK_NODES = new BooleanRioSetting(
45+
public static final BooleanRioSetting INLINE_BLANK_NODES = new BooleanRioSetting(
4646
"org.eclipse.rdf4j.rio.inline_blank_nodes",
4747
"Use blank node property lists, collections, and anonymous nodes instead of blank node labels",
4848
Boolean.FALSE);
@@ -57,7 +57,7 @@ public class BasicWriterSettings {
5757
* <p>
5858
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.rdf10_plain_literals}.
5959
*/
60-
public static final RioSetting<Boolean> XSD_STRING_TO_PLAIN_LITERAL = new BooleanRioSetting(
60+
public static final BooleanRioSetting XSD_STRING_TO_PLAIN_LITERAL = new BooleanRioSetting(
6161
"org.eclipse.rdf4j.rio.rdf10_plain_literals", "RDF-1.0 compatible Plain Literals", Boolean.TRUE);
6262

6363
/**
@@ -78,7 +78,7 @@ public class BasicWriterSettings {
7878
* <p>
7979
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.rdf10_language_literals}.
8080
*/
81-
public static final RioSetting<Boolean> RDF_LANGSTRING_TO_LANG_LITERAL = new BooleanRioSetting(
81+
public static final BooleanRioSetting RDF_LANGSTRING_TO_LANG_LITERAL = new BooleanRioSetting(
8282
"org.eclipse.rdf4j.rio.rdf10_language_literals", "RDF-1.0 compatible Language Literals", Boolean.TRUE);
8383

8484
/**
@@ -88,7 +88,7 @@ public class BasicWriterSettings {
8888
* <p>
8989
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.base_directive}.
9090
*/
91-
public static final RioSetting<Boolean> BASE_DIRECTIVE = new BooleanRioSetting(
91+
public static final BooleanRioSetting BASE_DIRECTIVE = new BooleanRioSetting(
9292
"org.eclipse.rdf4j.rio.base_directive", "Serialize base directive", Boolean.TRUE);
9393

9494
/**
@@ -99,7 +99,7 @@ public class BasicWriterSettings {
9999
* <p>
100100
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.convert_rdf_star}.
101101
*/
102-
public static final RioSetting<Boolean> CONVERT_RDF_STAR_TO_REIFICATION = new BooleanRioSetting(
102+
public static final BooleanRioSetting CONVERT_RDF_STAR_TO_REIFICATION = new BooleanRioSetting(
103103
"org.eclipse.rdf4j.rio.convert_rdf_star", "Convert RDF-star statements to RDF reification", Boolean.FALSE);
104104

105105
/**
@@ -113,7 +113,7 @@ public class BasicWriterSettings {
113113
* <p>
114114
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.encode_rdf_star}.
115115
*/
116-
public static final RioSetting<Boolean> ENCODE_RDF_STAR = new BooleanRioSetting(
116+
public static final BooleanRioSetting ENCODE_RDF_STAR = new BooleanRioSetting(
117117
"org.eclipse.rdf4j.rio.encode_rdf_star",
118118
"Encodes RDF-star triples to special IRIs for compatibility with RDF", Boolean.TRUE);
119119

core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/BinaryRDFWriterSettings.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class BinaryRDFWriterSettings {
3232
* @deprecated Use {@link org.eclipse.rdf4j.rio.binary.BinaryRDFWriterSettings#VERSION} instead.
3333
*/
3434
@Deprecated(since = "4.3.0", forRemoval = true)
35-
public static final RioSetting<Long> VERSION = new LongRioSetting(
35+
public static final LongRioSetting VERSION = new LongRioSetting(
3636
"org.eclipse.rdf4j.rio.binary.format_version", "Binary RDF format", 2L);
3737

3838
/**
@@ -46,7 +46,7 @@ public class BinaryRDFWriterSettings {
4646
* @deprecated Use {@link org.eclipse.rdf4j.rio.binary.BinaryRDFWriterSettings#BUFFER_SIZE} instead.
4747
*/
4848
@Deprecated(since = "4.3.0", forRemoval = true)
49-
public static final RioSetting<Long> BUFFER_SIZE = new LongRioSetting(
49+
public static final LongRioSetting BUFFER_SIZE = new LongRioSetting(
5050
"org.eclipse.rdf4j.rio.binary.buffer_size", "Buffer size", 8192L);
5151

5252
/**
@@ -60,7 +60,7 @@ public class BinaryRDFWriterSettings {
6060
* @deprecated Use {@link org.eclipse.rdf4j.rio.binary.BinaryRDFWriterSettings#CHARSET} instead.
6161
*/
6262
@Deprecated(since = "4.3.0", forRemoval = true)
63-
public static final RioSetting<String> CHARSET = new StringRioSetting(
63+
public static final StringRioSetting CHARSET = new StringRioSetting(
6464
"org.eclipse.rdf4j.rio.binary.charset", "Charset", StandardCharsets.UTF_8.name());
6565

6666
/**
@@ -81,7 +81,7 @@ public class BinaryRDFWriterSettings {
8181
* @deprecated Use {@link org.eclipse.rdf4j.rio.binary.BinaryRDFWriterSettings#RECYCLE_IDS} instead.
8282
*/
8383
@Deprecated(since = "4.3.0", forRemoval = true)
84-
public static final RioSetting<Boolean> RECYCLE_IDS = new BooleanRioSetting(
84+
public static final BooleanRioSetting RECYCLE_IDS = new BooleanRioSetting(
8585
"org.eclipse.rdf4j.rio.binary.recycle_ids", "Charset", true);
8686

8787
/**
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Eclipse RDF4J contributors.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Distribution License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/org/documents/edl-v10.php.
8+
*
9+
* SPDX-License-Identifier: BSD-3-Clause
10+
*******************************************************************************/
11+
package org.eclipse.rdf4j.rio.helpers;
12+
13+
import org.eclipse.rdf4j.rio.RioSetting;
14+
15+
/**
16+
* A {@link RioSetting} with a {@link Integer} value. The given default for the setting can be overridden by means of a
17+
* system property with a name equal to the setting key.
18+
*
19+
* @author Håvard M. Ottestad
20+
*/
21+
public class IntegerRioSetting extends AbstractRioSetting<Integer> {
22+
23+
private static final long serialVersionUID = -5945095126593465950L;
24+
25+
public IntegerRioSetting(String key, String description, Integer defaultValue) {
26+
super(key, description, defaultValue);
27+
}
28+
29+
@Override
30+
public Integer convert(String stringValue) {
31+
try {
32+
return Integer.parseInt(stringValue);
33+
} catch (NumberFormatException e) {
34+
throw new RioConfigurationException("Conversion error for setting: " + getKey(), e);
35+
}
36+
}
37+
38+
}

0 commit comments

Comments
 (0)