Skip to content

Commit

Permalink
GH-5032 Allow system property to override rio settings for JSON-LD an…
Browse files Browse the repository at this point in the history
…d others (#5038)
  • Loading branch information
hmottestad authored Jun 19, 2024
2 parents 7034492 + 842c175 commit 4554510
Show file tree
Hide file tree
Showing 31 changed files with 244 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
package org.eclipse.rdf4j.query.resultio;

import org.eclipse.rdf4j.rio.RioSetting;
import org.eclipse.rdf4j.rio.helpers.BooleanRioSetting;
import org.eclipse.rdf4j.rio.helpers.RioSettingImpl;
import org.eclipse.rdf4j.rio.helpers.StringRioSetting;

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

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

}
12 changes: 12 additions & 0 deletions core/rio/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class BasicParserSettings {
* <p>
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.verify_datatype_values}.
*/
public static final RioSetting<Boolean> VERIFY_DATATYPE_VALUES = new BooleanRioSetting(
public static final BooleanRioSetting VERIFY_DATATYPE_VALUES = new BooleanRioSetting(
"org.eclipse.rdf4j.rio.verify_datatype_values", "Verify recognised datatype values", Boolean.FALSE);

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

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

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

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

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

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

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class BasicWriterSettings {
* <p>
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.pretty_print}.
*/
public static final RioSetting<Boolean> PRETTY_PRINT = new BooleanRioSetting("org.eclipse.rdf4j.rio.pretty_print",
public static final BooleanRioSetting PRETTY_PRINT = new BooleanRioSetting("org.eclipse.rdf4j.rio.pretty_print",
"Pretty print", Boolean.TRUE);

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class BinaryRDFWriterSettings {
* @deprecated Use {@link org.eclipse.rdf4j.rio.binary.BinaryRDFWriterSettings#VERSION} instead.
*/
@Deprecated(since = "4.3.0", forRemoval = true)
public static final RioSetting<Long> VERSION = new LongRioSetting(
public static final LongRioSetting VERSION = new LongRioSetting(
"org.eclipse.rdf4j.rio.binary.format_version", "Binary RDF format", 2L);

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

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

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

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2024 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
package org.eclipse.rdf4j.rio.helpers;

import org.eclipse.rdf4j.rio.RioSetting;

/**
* A {@link RioSetting} with a {@link Integer} value. The given default for the setting can be overridden by means of a
* system property with a name equal to the setting key.
*
* @author Håvard M. Ottestad
*/
public class IntegerRioSetting extends AbstractRioSetting<Integer> {

private static final long serialVersionUID = -5945095126593465950L;

public IntegerRioSetting(String key, String description, Integer defaultValue) {
super(key, description, defaultValue);
}

@Override
public Integer convert(String stringValue) {
try {
return Integer.parseInt(stringValue);
} catch (NumberFormatException e) {
throw new RioConfigurationException("Conversion error for setting: " + getKey(), e);
}
}

}
Loading

0 comments on commit 4554510

Please sign in to comment.