Compare commits

...

10 commits

405 changed files with 1816 additions and 4247 deletions

View file

@ -1,8 +0,0 @@
version = 1
[[analyzers]]
name = "java"
enabled = true
[analyzers.meta]
runtime_version = "11"

View file

@ -1,14 +0,0 @@
# xbib Content
image:https://api.travis-ci.org/xbib/content.svg[title="Build status", link="https://travis-ci.org/xbib/content/"]
image:https://img.shields.io/sonar/http/nemo.sonarqube.com/org.xbib%3Acontent/coverage.svg?style=flat-square[title="Coverage", link="https://sonarqube.com/dashboard/index?id=org.xbib%3Acontent"]
image:https://maven-badges.herokuapp.com/maven-central/org.xbib/content/badge.svg[title="Maven Central", link="http://search.maven.org/#search%7Cga%7C1%7Cxbib%20content"]
image:https://img.shields.io/badge/License-Apache%202.0-blue.svg[title="Apache License 2.0", link="https://opensource.org/licenses/Apache-2.0"]
image:https://img.shields.io/twitter/url/https/twitter.com/xbib.svg?style=social&label=Follow%20%40xbib[title="Twitter", link="https://twitter.com/xbib"]
image:https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif[title="PayPal", link="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GVHFQYZ9WZ8HG"]
This is a Java library for processing structured data ("content") in the most popular formats, such as
JSON, SMILE-JSON, YAML, XML, CSV, and also semantic descriptions in RDF (N-Triples, Turtle, RDF/XML).
xbib Content offers stream-based Java builders, parsers, and a settings API oder the formats, so it is very convenienant
to use. The only dependency is https://github.com/fasterxml/jackson[the Java Jackson library].

9
README.md Normal file
View file

@ -0,0 +1,9 @@
# xbib Content
Deperecated, use datastructures instead.
This is a Java library for processing structured data ("content") in the most popular formats, such as
JSON, SMILE-JSON, YAML, XML, CSV, and also semantic descriptions in RDF (N-Triples, Turtle, RDF/XML).
xbib Content offers stream-based Java builders, parsers, and a settings API oder the formats, so it is very convenienant
to use. The only dependency is https://github.com/fasterxml/jackson[the Java Jackson library].

View file

@ -1,27 +1,24 @@
plugins { plugins {
id "de.marcphilipp.nexus-publish" version "0.4.0" id 'maven-publish'
id "io.codearte.nexus-staging" version "0.21.1" id 'signing'
id "org.xbib.gradle.plugin.asciidoctor" version "2.5.2.2" id "io.github.gradle-nexus.publish-plugin" version "2.0.0-rc-1"
id "org.cyclonedx.bom" version "1.7.2" id "org.xbib.gradle.plugin.asciidoctor" version "3.0.0"
id "com.github.spotbugs" version "5.0.3"
id "pmd"
id "checkstyle"
} }
wrapper { wrapper {
gradleVersion = libs.versions.gradle.get() gradleVersion = libs.versions.gradle.get()
distributionType = Wrapper.DistributionType.ALL distributionType = Wrapper.DistributionType.BIN
} }
ext { ext {
user = 'xbib' user = 'joerg'
name = 'content' name = 'content'
description = 'Content processing library for Java' description = 'Content processing library for Java'
inceptionYear = '2016' inceptionYear = '2016'
url = 'https://github.com/' + user + '/' + name url = 'https://xbib.org/' + user + '/' + name
scmUrl = 'https://github.com/' + user + '/' + name scmUrl = 'https://xbib.org/' + user + '/' + name
scmConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git' scmConnection = 'scm:git:git://xbib.org/' + user + '/' + name + '.git'
scmDeveloperConnection = 'scm:git:ssh://git@github.com:' + user + '/' + name + '.git' scmDeveloperConnection = 'scm:git:ssh://forgejo@xbib.org:' + user + '/' + name + '.git'
issueManagementSystem = 'Github' issueManagementSystem = 'Github'
issueManagementUrl = ext.scmUrl + '/issues' issueManagementUrl = ext.scmUrl + '/issues'
licenseName = 'The Apache License, Version 2.0' licenseName = 'The Apache License, Version 2.0'
@ -29,15 +26,10 @@ ext {
} }
subprojects { subprojects {
apply from: rootProject.file('gradle/ide/idea.gradle') apply from: rootProject.file('gradle/repositories/maven.gradle')
apply from: rootProject.file('gradle/compile/java.gradle') apply from: rootProject.file('gradle/compile/java.gradle')
apply from: rootProject.file('gradle/test/junit5.gradle') apply from: rootProject.file('gradle/test/junit5.gradle')
apply from: rootProject.file('gradle/repositories/maven.gradle') apply from: rootProject.file('gradle/publish/maven.gradle')
apply from: rootProject.file('gradle/quality/spotbugs.gradle')
apply from: rootProject.file('gradle/quality/checkstyle.gradle')
apply from: rootProject.file('gradle/quality/pmd.gradle')
apply from: rootProject.file('gradle/publishing/publication.gradle')
} }
apply from: rootProject.file('gradle/publishing/sonatype.gradle') apply from: rootProject.file('gradle/publish/sonatype.gradle')
apply from: rootProject.file('gradle/quality/cyclonedx.gradle') apply from: rootProject.file('gradle/publish/forgejo.gradle')

View file

@ -1,5 +0,0 @@
dependencies {
api project(':settings-datastructures')
testImplementation project(':settings-datastructures-json')
testImplementation project(':settings-datastructures-yaml')
}

View file

@ -1,13 +0,0 @@
import org.xbib.config.ConfigLogger;
import org.xbib.config.NullConfigLogger;
import org.xbib.config.SystemConfigLogger;
import org.xbib.settings.SettingsLoader;
module org.xbib.config {
exports org.xbib.config;
uses ConfigLogger;
uses SettingsLoader;
provides ConfigLogger with NullConfigLogger, SystemConfigLogger;
requires org.xbib.settings.api;
requires transitive org.xbib.settings.datastructures;
}

View file

@ -1,17 +0,0 @@
package org.xbib.config;
@SuppressWarnings("serial")
public class ConfigException extends RuntimeException {
public ConfigException(Exception e) {
super(e);
}
public ConfigException(String message) {
super(message);
}
public ConfigException(String message, Throwable cause) {
super(message, cause);
}
}

View file

@ -1,168 +0,0 @@
package org.xbib.config;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ConfigFinder {
private final FileSystem fileSystem;
private final EnumSet<FileVisitOption> opts;
private final List<Path> result;
private Comparator<Path> comparator;
public ConfigFinder() {
this(FileSystems.getDefault(), EnumSet.of(FileVisitOption.FOLLOW_LINKS));
}
public ConfigFinder(FileSystem fileSystem, EnumSet<FileVisitOption> opts) {
this.fileSystem = fileSystem;
this.opts = opts;
this.result = new ArrayList<>();
}
public ConfigFinder find(String path, String pathPattern) throws IOException {
return find(null, null, fileSystem.getPath(path), pathPattern);
}
public ConfigFinder find(String base, String basePattern, String path, String pathPattern) throws IOException {
return find(base == null || base.isEmpty() ? null : fileSystem.getPath(base), basePattern,
path == null || path.isEmpty() ? null : fileSystem.getPath(path), pathPattern);
}
public ConfigFinder find(Path base, String basePattern, Path path, String pathPattern) throws IOException {
return find(base, basePattern, path, pathPattern, null);
}
/**
* Find the most recent version of a file.
*
* @param base the path of the base directory
* @param basePattern a pattern to match directory entries in the base directory or null to match '*'
* @param path the path of the file if no recent path can be found in the base directory or null
* @param pathPattern the file name pattern to match
* @param modifiedSince time stamp for file or null
* @return this Finder
* @throws IOException if find fails
*/
public ConfigFinder find(Path base,
String basePattern,
Path path,
String pathPattern,
FileTime modifiedSince) throws IOException {
if (base != null && path == null) {
// find input in base
final PathMatcher baseMatcher = base.getFileSystem()
.getPathMatcher("glob:" + (basePattern != null ? basePattern : "*"));
final PathMatcher pathMatcher = base.getFileSystem()
.getPathMatcher("glob:" + (pathPattern != null ? pathPattern : "*"));
List<Path> directories = new ArrayList<>();
List<Path> list = Files.find(base, 1,
(p, a) -> {
if (Files.isDirectory(p) && baseMatcher.matches(p.getFileName())) {
directories.add(p);
return false;
}
return Files.isRegularFile(p) && pathMatcher.matches(p.getFileName());
}, FileVisitOption.FOLLOW_LINKS)
.collect(Collectors.toList());
if (directories.isEmpty()) {
return this;
}
list.sort(LAST_MODIFIED_COMPARATOR.reversed());
result.addAll(list);
path = list.iterator().next();
}
if (path == null) {
return this;
}
final PathMatcher pathMatcher = path.getFileSystem()
.getPathMatcher("glob:" + (pathPattern != null ? pathPattern : "*"));
Files.walkFileTree(path, opts, Integer.MAX_VALUE, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path p, BasicFileAttributes a) {
if ((Files.isRegularFile(p) && pathMatcher.matches(p.getFileName())) &&
(modifiedSince == null || a.lastModifiedTime().toMillis() > modifiedSince.toMillis())) {
result.add(p);
}
return FileVisitResult.CONTINUE;
}
});
return this;
}
public ConfigFinder sortBy(String mode) {
if ("lastmodified".equals(mode)) {
this.comparator = LAST_MODIFIED_COMPARATOR;
} else if ("name".equals(mode)) {
this.comparator = PATH_NAME_COMPARATOR;
}
return this;
}
public ConfigFinder order(String mode) {
if ("desc".equals(mode)) {
this.comparator = Collections.reverseOrder(comparator);
}
return this;
}
public Stream<Path> getPathFiles() {
return getPathFiles(-1);
}
public Stream<Path> getPathFiles(long max) {
if (comparator != null) {
result.sort(comparator);
}
return result.stream().limit(max < 0 ? result.size() : max);
}
public Stream<Path> skipPathFiles(long skip) {
if (comparator != null) {
result.sort(comparator);
}
return result.stream().skip(skip < 0 ? 0 : skip);
}
public Stream<String> getPaths() {
return getPaths(-1);
}
public Stream<String> getPaths(long max) {
if (comparator != null) {
result.sort(comparator);
}
return result.stream()
.map(p -> p.toAbsolutePath().toString())
.limit(max < 0 ? result.size() : max);
}
private static final Comparator<Path> LAST_MODIFIED_COMPARATOR = Comparator.comparing(p -> {
try {
return Files.getLastModifiedTime(p);
} catch (IOException e) {
return null;
}
});
private static final Comparator<Path> PATH_NAME_COMPARATOR = Comparator.comparing(Path::toString);
}

View file

@ -1,311 +0,0 @@
package org.xbib.config;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.stream.Collectors;
import org.xbib.settings.Settings;
import org.xbib.settings.SettingsBuilder;
import org.xbib.settings.SettingsLoader;
import org.xbib.settings.SettingsLoaderService;
/**
* A configuration loader for configuration files.
*/
public class ConfigLoader {
private static final Map<ConfigParams, Settings> map = new HashMap<>();
private ConfigLogger logger;
private ConfigLoader() {
}
private static class Holder {
private static ConfigLogger createConfigLogger() {
ServiceLoader<ConfigLogger> serviceLoader = ServiceLoader.load(ConfigLogger.class);
Optional<ConfigLogger> optionalConfigLogger = serviceLoader.findFirst();
return optionalConfigLogger.orElse(new NullConfigLogger());
}
private static final ConfigLoader configLoader = new ConfigLoader().withLogger(createConfigLogger());
}
public static ConfigLoader getInstance() {
return Holder.configLoader;
}
public ConfigLoader withLogger(ConfigLogger logger) {
this.logger = logger;
return this;
}
public synchronized Settings load(ConfigParams configParams) throws ConfigException {
map.computeIfAbsent(configParams, p -> internalLoad(p)
.replacePropertyPlaceholders()
.build());
return map.get(configParams);
}
private SettingsBuilder internalLoad(ConfigParams params) throws ConfigException {
SettingsBuilder settings = Settings.settingsBuilder();
if (params.withSystemEnvironment) {
settings.loadFromSystemEnvironment();
}
if (params.withSystemProperties) {
settings.loadFromSystemProperties();
}
if (!params.settings.isEmpty()) {
for (Settings s : params.settings) {
settings.put(s);
}
}
if (!params.reader.isEmpty()) {
for (ConfigParams.SuffixedReader reader : params.reader) {
SettingsBuilder readerSettings = createSettingsFromReader(reader.reader, reader.suffix);
if (readerSettings != null) {
settings.put(readerSettings.build());
if (!params.includeAll) {
return overrideFromProperties(params, settings);
}
}
}
}
if (params.args != null) {
SettingsBuilder argsSettings = createSettingsFromArgs(params);
if (argsSettings != null) {
settings.put(argsSettings.build());
if (!params.includeAll) {
return overrideFromProperties(params, settings);
}
}
}
if (params.withStdin) {
SettingsBuilder stdinSettings = createSettingsFromStdin();
if (stdinSettings != null) {
settings.put(stdinSettings.build());
if (!params.includeAll) {
return overrideFromProperties(params, settings);
}
}
}
if (!params.fileLocations.isEmpty()) {
SettingsBuilder fileSettings = createSettingsFromFile(params.fileLocations);
if (fileSettings != null) {
settings.put(fileSettings.build());
if (!params.includeAll) {
return overrideFromProperties(params, settings);
}
}
}
if (!params.fileNamesWithoutSuffix.isEmpty()) {
for (String fileNameWithoutSuffix : params.fileNamesWithoutSuffix) {
SettingsBuilder fileSettings = createSettingsFromFile(createListOfLocations(params, fileNameWithoutSuffix));
if (fileSettings != null) {
settings.put(fileSettings.build());
if (!params.includeAll) {
return overrideFromProperties(params, settings);
}
}
}
for (String fileNameWithoutSuffix : params.fileNamesWithoutSuffix) {
if (params.classLoaders != null) {
for (ClassLoader cl : params.classLoaders) {
if (cl != null) {
SettingsBuilder classpathSettings = createClasspathSettings(params, cl, fileNameWithoutSuffix);
if (classpathSettings != null) {
settings.put(classpathSettings.build());
if (!params.includeAll) {
return overrideFromProperties(params, settings);
}
}
}
}
}
}
}
if (!params.jdbcLookups.isEmpty()) {
for (ConfigParams.JdbcLookup jdbcLookup : params.jdbcLookups) {
try {
settings.fromJdbc(jdbcLookup.connection, jdbcLookup.statement, jdbcLookup.params);
} catch (SQLException sqlException) {
throw new ConfigException(sqlException);
}
}
}
if (params.includeAll) {
return overrideFromProperties(params, settings);
}
if (params.failIfEmpty) {
throw new ConfigException("no config found");
}
return settings;
}
private SettingsBuilder createSettingsFromArgs(ConfigParams params) throws ConfigException {
if (!params.fileNamesWithoutSuffix.isEmpty() && params.args != null) {
for (String fileNameWithoutSuffix : params.fileNamesWithoutSuffix) {
for (String suffix : SettingsLoaderService.getInstance().getSuffixes()) {
for (int i = 0; i < params.args.size() - 1; i++) {
String arg = params.args.get(i);
String s = params.directoryName != null ?
"--" + params.directoryName + "-" + fileNameWithoutSuffix + "." + suffix :
"--" + fileNameWithoutSuffix + "." + suffix;
if (arg.equals(s)) {
return createSettingsFromReader(new StringReader(params.args.get(i + 1)), suffix);
}
}
}
}
}
return null;
}
private SettingsBuilder createSettingsFromStdin() throws ConfigException {
if (System.in != null) {
try {
int numBytesWaiting = System.in.available();
if (numBytesWaiting > 0) {
String suffix = System.getProperty("config.format", "yaml");
return createSettingsFromStream(System.in, "." + suffix);
}
} catch (IOException e) {
throw new ConfigException(e);
}
}
return null;
}
private SettingsBuilder createSettingsFromFile(List<String> settingsFileNames) throws ConfigException {
SettingsBuilder settings = Settings.settingsBuilder();
for (String settingsFileName: settingsFileNames) {
int pos = settingsFileName.lastIndexOf('.');
String suffix = (pos > 0 ? settingsFileName.substring(pos + 1) : "").toLowerCase(Locale.ROOT);
Path path = Paths.get(settingsFileName);
if (logger != null) {
logger.info("trying " + path);
}
if (Files.exists(path)) {
if (logger != null) {
logger.info("found path: " + path);
}
System.setProperty("config.path", path.getParent().toString());
try {
InputStream inputStream = Files.newInputStream(path);
SettingsBuilder fileSettings = createSettingsFromStream(inputStream, suffix);
if (fileSettings != null) {
settings.put(fileSettings.build());
}
} catch (Exception e) {
throw new ConfigException(e);
}
}
}
return settings.isEmpty() ? null : settings;
}
private SettingsBuilder createClasspathSettings(ConfigParams params,
ClassLoader classLoader,
String fileNameWithoutSuffix) throws ConfigException {
SettingsBuilder settings = Settings.settingsBuilder();
for (String suffix : SettingsLoaderService.getInstance().getSuffixes()) {
String path = params.directoryName != null ?
params.directoryName + '-' + fileNameWithoutSuffix + suffix : fileNameWithoutSuffix + suffix;
InputStream inputStream = classLoader.getResourceAsStream(path);
if (inputStream != null) {
if (logger != null) {
logger.info("found resource: " + path);
}
SettingsBuilder streamSettings = createSettingsFromStream(inputStream, suffix);
if (streamSettings != null) {
settings.put(streamSettings.build());
}
}
}
return settings.isEmpty() ? null : settings;
}
private SettingsBuilder createSettingsFromStream(InputStream inputStream,
String suffix) throws ConfigException {
if (inputStream == null) {
if (logger != null) {
logger.error("unable to open input stream");
}
return null;
}
return createSettingsFromReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8), suffix);
}
private SettingsBuilder createSettingsFromReader(Reader reader,
String suffix) throws ConfigException {
if (reader == null) {
if (logger != null) {
logger.error("unable to open reader");
}
return null;
}
SettingsLoader settingsLoader = SettingsLoaderService.getInstance().loaderFromResource(suffix);
if (settingsLoader != null) {
SettingsBuilder settings;
try (BufferedReader bufferedReader = new BufferedReader(reader)) {
String content = bufferedReader.lines().collect(Collectors.joining("\n"));
settings = Settings.settingsBuilder().put(settingsLoader.load(content));
} catch (IOException e) {
throw new ConfigException(e);
}
return settings;
} else {
if (logger != null) {
logger.error("suffix is invalid: " + suffix);
}
}
return null;
}
private SettingsBuilder overrideFromProperties(ConfigParams params, SettingsBuilder settingsBuilder) {
if (params.withSystemPropertiesOverride) {
settingsBuilder.map(e -> {
String key = e.getKey();
String value = System.getProperty(params.directoryName != null ? params.directoryName + '.' + key : key);
return value != null ? Map.entry(key, value) : Map.entry(key, e.getValue());
});
}
return settingsBuilder;
}
private List<String> createListOfLocations(ConfigParams params,
String fileNameWithoutSuffix) {
List<String> list = new ArrayList<>();
for (String suffix : SettingsLoaderService.getInstance().getSuffixes()) {
String xdgConfigHome = System.getenv("XDG_CONFIG_HOME");
if (xdgConfigHome == null) {
xdgConfigHome = System.getProperty("user.home") + "/.config";
}
if (params.directoryName != null) {
list.add(params.directoryName + '-' + fileNameWithoutSuffix + "." + suffix);
list.add(xdgConfigHome + '/' + params.directoryName + '/' + fileNameWithoutSuffix + "." + suffix);
list.add("/etc/" + params.directoryName + '/' + fileNameWithoutSuffix + "." + suffix);
} else {
list.add(fileNameWithoutSuffix + "." + suffix);
list.add(xdgConfigHome + '/' + fileNameWithoutSuffix + "." + suffix);
list.add("/etc/" + fileNameWithoutSuffix + "." + suffix);
}
}
return list;
}
}

View file

@ -1,10 +0,0 @@
package org.xbib.config;
public interface ConfigLogger {
void info(String string);
void warn(String string);
void error(String message);
}

View file

@ -1,192 +0,0 @@
package org.xbib.config;
import java.io.IOException;
import java.io.Reader;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import org.xbib.settings.Settings;
import org.xbib.settings.datastructures.DatastructureSettings;
public class ConfigParams implements Comparable<ConfigParams> {
private static final Comparator<ConfigParams> COMPARATOR =
Comparator.comparing(ConfigParams::toString);
boolean withSystemEnvironment = false;
boolean withSystemProperties = false;
boolean failIfEmpty = false;
boolean includeAll = false;
boolean withStdin = false;
boolean withSystemPropertiesOverride = false;
List<ClassLoader> classLoaders = null;
final List<SuffixedReader> reader = new ArrayList<>();
final List<JdbcLookup> jdbcLookups = new ArrayList<>();
final List<DatastructureSettings> settings = new ArrayList<>();
List<String> args = null;
String directoryName = null;
final List<String> fileNamesWithoutSuffix = new ArrayList<>();
final List<String> fileLocations = new ArrayList<>();
public ConfigParams() {
}
public ConfigParams withSystemEnvironment() {
this.withSystemEnvironment = true;
return this;
}
public ConfigParams withSystemProperties() {
this.withSystemProperties = true;
return this;
}
public ConfigParams withSystemPropertiesOverride() {
this.withSystemPropertiesOverride = true;
return this;
}
public ConfigParams includeAll() {
this.includeAll = true;
return this;
}
public ConfigParams failIfEmpty() {
this.failIfEmpty = true;
return this;
}
public ConfigParams withStdin(boolean withStdin) {
this.withStdin = withStdin;
return this;
}
public ConfigParams withArgs(String[] args) {
this.args = Arrays.asList(args);
return this;
}
public ConfigParams withClassLoaders(ClassLoader... classLoaders) {
this.classLoaders = Arrays.asList(classLoaders);
return this;
}
public ConfigParams withReader(Reader reader, String suffix) {
SuffixedReader suffixedReader = new SuffixedReader();
suffixedReader.reader = reader;
suffixedReader.suffix = suffix;
this.reader.add(suffixedReader);
return this;
}
public ConfigParams withSettings(Settings settings) {
this.settings.add(DatastructureSettings.builder().put(settings.getAsMap()).build());
return this;
}
public ConfigParams withDirectoryName(String directoryName) {
this.directoryName = directoryName;
return this;
}
public ConfigParams withFileNamesWithoutSuffix(String... fileNamesWithoutSuffix) {
this.fileNamesWithoutSuffix.addAll(Arrays.asList(fileNamesWithoutSuffix));
return this;
}
public ConfigParams withLocation(String location) {
this.fileLocations.add(location);
return this;
}
public ConfigParams withPath(String basePath, String basePattern, String path, String pathPattern) throws IOException {
ConfigFinder configFinder = new ConfigFinder();
configFinder.find(basePath, basePattern, path, pathPattern).getPaths().forEach(this::withLocation);
return this;
}
public ConfigParams withJdbc(Connection connection, String statement, String[] params) {
JdbcLookup jdbcLookup = new JdbcLookup();
jdbcLookup.connection = connection;
jdbcLookup.statement = statement;
jdbcLookup.params = params;
jdbcLookups.add(jdbcLookup);
return this;
}
@Override
public int hashCode() {
return toString().hashCode();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ConfigParams that = (ConfigParams) o;
return withSystemEnvironment == that.withSystemEnvironment &&
withSystemProperties == that.withSystemProperties &&
failIfEmpty == that.failIfEmpty &&
includeAll == that.includeAll &&
withStdin == that.withStdin &&
withSystemPropertiesOverride == that.withSystemPropertiesOverride &&
Objects.equals(classLoaders, that.classLoaders) &&
Objects.equals(reader, that.reader) &&
Objects.equals(jdbcLookups, that.jdbcLookups) &&
Objects.equals(settings, that.settings) &&
Objects.equals(args, that.args) &&
Objects.equals(directoryName, that.directoryName) &&
Objects.equals(fileNamesWithoutSuffix, that.fileNamesWithoutSuffix) &&
Objects.equals(fileLocations, that.fileLocations);
}
@Override
public int compareTo(ConfigParams o) {
return COMPARATOR.compare(this, o);
}
@Override
public String toString() {
return "" +
withSystemEnvironment +
withSystemProperties +
withStdin +
classLoaders +
reader +
args +
directoryName +
fileNamesWithoutSuffix +
fileLocations;
}
static class SuffixedReader {
Reader reader;
String suffix;
}
static class JdbcLookup {
Connection connection;
String statement;
String[] params;
}
}

View file

@ -1,19 +0,0 @@
package org.xbib.config;
public class NullConfigLogger implements ConfigLogger {
public NullConfigLogger() {
}
@Override
public void info(String string) {
}
@Override
public void warn(String message) {
}
@Override
public void error(String message) {
}
}

View file

@ -1,22 +0,0 @@
package org.xbib.config;
public class SystemConfigLogger implements ConfigLogger {
public SystemConfigLogger() {
}
@Override
public void info(String string) {
System.err.println("info: " + string);
}
@Override
public void warn(String message) {
System.err.println("warning: " + message);
}
@Override
public void error(String message) {
System.err.println("error: " + message);
}
}

View file

@ -1,4 +0,0 @@
/**
* Classes for configuration setup.
*/
package org.xbib.config;

View file

@ -1,76 +0,0 @@
package org.xbib.config.test;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import org.junit.jupiter.api.Test;
import org.xbib.config.ConfigLoader;
import org.xbib.config.ConfigParams;
import org.xbib.settings.Settings;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ConfigLoaderTest {
@Test
public void configEmptyTest() {
Settings settings = ConfigLoader.getInstance()
.load(new ConfigParams());
assertTrue(settings.isEmpty());
}
@Test
public void configSettingsTest() {
Settings configSettings = Settings.settingsBuilder()
.put("hello", "world")
.build();
Settings settings = ConfigLoader.getInstance()
.load(new ConfigParams().withSettings(configSettings));
assertEquals("world", settings.get("hello"));
}
@Test
public void configArgsTest() {
String[] args = new String[] {
"--config.yaml",
"hello: world"
};
Settings settings = ConfigLoader.getInstance()
.load(new ConfigParams()
.withArgs(args)
.withFileNamesWithoutSuffix("config"));
assertEquals("world", settings.get("hello"));
}
@Test
public void configPropertiesTest() {
Reader reader = new StringReader("a=b");
Settings settings = ConfigLoader.getInstance()
.load(new ConfigParams()
.withReader(reader, "properties"));
assertEquals("b", settings.get("a"));
}
@Test
public void configFileTest() throws IOException {
Settings settings = ConfigLoader.getInstance()
.load(new ConfigParams()
.withPath(null, null, "src/test/resources", "config.*"));
assertEquals("world", settings.get("hello"));
assertEquals("world2", settings.get("hello2"));
}
@Test
public void testSystemPropertiesOverride() throws IOException {
System.setProperty("hello", "override");
Settings settings = ConfigLoader.getInstance()
.load(new ConfigParams()
.withPath(null, null, "src/test/resources", "config.*"));
assertEquals("world", settings.get("hello"));
settings = ConfigLoader.getInstance()
.load(new ConfigParams()
.withSystemPropertiesOverride()
.withPath(null, null, "src/test/resources", "config.*"));
assertEquals("override", settings.get("hello"));
}
}

View file

@ -1,4 +0,0 @@
/**
* Test classes for config.
*/
package org.xbib.config.test;

View file

@ -1,2 +0,0 @@
org.xbib.config.NullConfigLogger
org.xbib.config.SystemConfigLogger

View file

@ -1,3 +0,0 @@
org.xbib.settings.datastructures.PropertiesSettingsLoader
org.xbib.settings.datastructures.json.JsonSettingsLoader
org.xbib.settings.datastructures.yaml.YamlSettingsLoader

View file

@ -1,3 +0,0 @@
{
"hello2": "world2"
}

View file

@ -1 +0,0 @@
hello: world

11
content-csv/build.gradle Normal file
View file

@ -0,0 +1,11 @@
def moduleName = 'org.xbib.content.csv.test'
def patchArgs = ['--patch-module', "$moduleName=" + files(sourceSets.test.resources.srcDirs).asPath ]
tasks.named('compileTestJava') {
options.compilerArgs += patchArgs
}
tasks.named('test') {
jvmArgs += patchArgs
}

View file

@ -0,0 +1,6 @@
module org.xbib.content.csv.test {
requires org.junit.jupiter.api;
requires org.xbib.content.csv;
exports org.xbib.content.csv.test;
opens org.xbib.content.csv.test to org.junit.platform.commons;
}

View file

@ -1,4 +0,0 @@
/**
* Classes for testing CSV content.
*/
package org.xbib.content.csv;

View file

@ -1,6 +1,8 @@
package org.xbib.content.csv; package org.xbib.content.csv.test;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.xbib.content.csv.CSVGenerator;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Arrays; import java.util.Arrays;

View file

@ -1,7 +1,9 @@
package org.xbib.content.csv; package org.xbib.content.csv.test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.xbib.content.csv.CSVParser;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -10,16 +12,13 @@ import java.nio.charset.StandardCharsets;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
/**
*
*/
public class CSVParserTest { public class CSVParserTest {
@Test @Test
public void testCommaSeparated() throws IOException { public void testCommaSeparated() throws IOException {
InputStream in = getClass().getResourceAsStream("test.csv"); InputStream inputStream = getClass().getResourceAsStream("test.csv");
int count = 0; int count = 0;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
CSVParser csvParser = new CSVParser(reader); CSVParser csvParser = new CSVParser(reader);
Iterator<List<String>> it = csvParser.iterator(); Iterator<List<String>> it = csvParser.iterator();
while (it.hasNext()) { while (it.hasNext()) {
@ -32,9 +31,9 @@ public class CSVParserTest {
@Test @Test
public void testLargeFile() throws IOException { public void testLargeFile() throws IOException {
InputStream in = getClass().getResourceAsStream("titleFile.csv"); InputStream inputStream = getClass().getResourceAsStream("titleFile.csv");
int count = 0; int count = 0;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
CSVParser csvParser = new CSVParser(reader); CSVParser csvParser = new CSVParser(reader);
Iterator<List<String>> it = csvParser.iterator(); Iterator<List<String>> it = csvParser.iterator();
while (it.hasNext()) { while (it.hasNext()) {

View file

@ -1,4 +1,4 @@
package org.xbib.content.csv; package org.xbib.content.csv.test;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.BufferedReader; import java.io.BufferedReader;

View file

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%-25c][%t] %m%n"/>
</Console>
</appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</configuration>

View file

@ -1,5 +1,15 @@
dependencies { dependencies {
api project(':content-core') api project(':content-core')
api libs.jackson.databind api libs.jackson.databind
testImplementation libs.mockito.inline testImplementation testLibs.mockito.core
}
def patchArgs = ['--patch-module', "org.xbib.content.json.test=" + sourceSets.test.resources.sourceDirectories.singleFile]
tasks.named('compileTestJava') {
options.compilerArgs += patchArgs
}
tasks.named('test') {
jvmArgs += patchArgs
} }

View file

@ -19,6 +19,7 @@ public class JsonXContentGenerator extends AbstractXContentGenerator {
private final JsonGeneratorDelegate delegate; private final JsonGeneratorDelegate delegate;
@SuppressWarnings("this-escape")
public JsonXContentGenerator(JsonGenerator generator) { public JsonXContentGenerator(JsonGenerator generator) {
this.delegate = new JsonGeneratorDelegate(generator); this.delegate = new JsonGeneratorDelegate(generator);
super.setGenerator(delegate); super.setGenerator(delegate);

View file

@ -53,7 +53,7 @@ public class JsonXContentParser extends AbstractXContentParser {
@Override @Override
public String currentName() throws IOException { public String currentName() throws IOException {
return parser.getCurrentName(); return parser.currentName();
} }
@Override @Override

View file

@ -6,11 +6,9 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.net.URL;
/** /**
* Utility class to load JSON values from various sources as {@link com.fasterxml.jackson.databind.JsonNode}s. * Utility class to load JSON values from various sources as {@link com.fasterxml.jackson.databind.JsonNode}s.
*
* This class uses a {@link JsonNodeReader} to parse JSON inputs. * This class uses a {@link JsonNodeReader} to parse JSON inputs.
* *
* @see JsonNodeReader * @see JsonNodeReader
@ -25,34 +23,28 @@ public final class JsonLoader {
} }
/** /**
* Read a {@link com.fasterxml.jackson.databind.JsonNode} from a resource path. * Read a {@link com.fasterxml.jackson.databind.JsonNode} from an input stream.
*
* This method first tries and loads the resource using {@link
* Class#getResource(String)}; if not found, is tries and uses the context
* classloader and if this is not found, this class's classloader.
*
* This method throws an {@link java.io.IOException} if the resource does not * This method throws an {@link java.io.IOException} if the resource does not
* exist. * exist.
* *
* @param classLoader the class loader * @param inputStream the input stream
* @param resource the path to the resource (must begin
* with a {@code /})
* @return the JSON document at the resource * @return the JSON document at the resource
* @throws IllegalArgumentException resource path does not begin with a * @throws IllegalArgumentException resource path does not begin with a
* {@code /} * {@code /}
* @throws java.io.IOException there was a problem loading the resource, or the JSON * @throws java.io.IOException there was a problem loading the resource, or the JSON
* document is invalid * document is invalid
*/ */
public static JsonNode fromResource(ClassLoader classLoader, final String resource) public static JsonNode fromResource(InputStream inputStream)
throws IOException { throws IOException {
URL url = JsonLoader.class.getResource(resource);
InputStream in = url != null ? url.openStream() : classLoader.getResourceAsStream(resource);
final JsonNode ret; final JsonNode ret;
try { try {
ret = READER.fromInputStream(in); if (inputStream == null) {
throw new IOException("not found");
}
ret = READER.fromInputStream(inputStream);
} finally { } finally {
if (in != null) { if (inputStream != null) {
in.close(); inputStream.close();
} }
} }
return ret; return ret;

View file

@ -1,5 +1,6 @@
package org.xbib.content.json.jackson; package org.xbib.content.json.jackson;
import com.fasterxml.jackson.core.ErrorReportConfiguration;
import com.fasterxml.jackson.core.JsonLocation; import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
@ -35,7 +36,7 @@ public final class JsonNodeReader {
private final ObjectReader reader; private final ObjectReader reader;
public JsonNodeReader(final ObjectMapper mapper) { public JsonNodeReader(final ObjectMapper mapper) {
reader = mapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, true) this.reader = mapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, true)
.readerFor(JsonNode.class); .readerFor(JsonNode.class);
} }
@ -64,13 +65,14 @@ public final class JsonNodeReader {
/** /**
* Read a JSON value from an {@link java.io.InputStream}. * Read a JSON value from an {@link java.io.InputStream}.
* *
* @param in the input stream * @param inputStream the input stream
* @return the value * @return the value
* @throws java.io.IOException malformed input, or problem encountered when reading * @throws java.io.IOException malformed input, or problem encountered when reading
* from the stream * from the stream
*/ */
public JsonNode fromInputStream(final InputStream in) throws IOException { public JsonNode fromInputStream(final InputStream inputStream) throws IOException {
try (JsonParser parser = reader.getFactory().createParser(in); MappingIterator<JsonNode> iterator = reader.readValues(parser)) { try (JsonParser parser = reader.getFactory().createParser(inputStream);
MappingIterator<JsonNode> iterator = reader.readValues(parser)) {
return readNode(iterator); return readNode(iterator);
} }
} }
@ -78,13 +80,14 @@ public final class JsonNodeReader {
/** /**
* Read a JSON value from a {@link java.io.Reader}. * Read a JSON value from a {@link java.io.Reader}.
* *
* @param r the reader * @param reader the reader
* @return the value * @return the value
* @throws java.io.IOException malformed input, or problem encountered when reading * @throws java.io.IOException malformed input, or problem encountered when reading
* from the reader * from the reader
*/ */
public JsonNode fromReader(final Reader r) throws IOException { public JsonNode fromReader(final Reader reader) throws IOException {
try (JsonParser parser = reader.getFactory().createParser(r); MappingIterator<JsonNode> iterator = reader.readValues(parser)) { try (JsonParser parser = this.reader.getFactory().createParser(reader);
MappingIterator<JsonNode> iterator = this.reader.readValues(parser)) {
return readNode(iterator); return readNode(iterator);
} }
} }
@ -97,7 +100,7 @@ public final class JsonNodeReader {
private JsonParseExceptionBuilder(final JsonParser jsonParser, final Object source) { private JsonParseExceptionBuilder(final JsonParser jsonParser, final Object source) {
this.jsonParser = jsonParser; this.jsonParser = jsonParser;
location = new JsonLocation(ContentReference.construct(false, source), 0L, 1, 1); location = new JsonLocation(ContentReference.construct(false, source, ErrorReportConfiguration.defaults()), 0L, 1, 1);
} }
JsonParseExceptionBuilder setLocation(final JsonLocation location) { JsonParseExceptionBuilder setLocation(final JsonLocation location) {

View file

@ -45,8 +45,7 @@ public abstract class TreePointer<T extends TreeNode> implements Iterable<TokenR
* @param missing the representation of a missing node (may be null) * @param missing the representation of a missing node (may be null)
* @param tokenResolvers the list of reference token resolvers * @param tokenResolvers the list of reference token resolvers
*/ */
TreePointer(final T missing, protected TreePointer(final T missing, final List<TokenResolver<T>> tokenResolvers) {
final List<TokenResolver<T>> tokenResolvers) {
this.missing = missing; this.missing = missing;
this.tokenResolvers = new ArrayList<>(tokenResolvers); this.tokenResolvers = new ArrayList<>(tokenResolvers);
} }
@ -58,7 +57,7 @@ public abstract class TreePointer<T extends TreeNode> implements Iterable<TokenR
* *
* @param tokenResolvers the list of token resolvers * @param tokenResolvers the list of token resolvers
*/ */
protected TreePointer(final List<TokenResolver<T>> tokenResolvers) { TreePointer(final List<TokenResolver<T>> tokenResolvers) {
this(null, tokenResolvers); this(null, tokenResolvers);
} }
@ -70,7 +69,7 @@ public abstract class TreePointer<T extends TreeNode> implements Iterable<TokenR
* @throws JsonPointerException input is not a valid JSON Pointer * @throws JsonPointerException input is not a valid JSON Pointer
* @throws NullPointerException input is null * @throws NullPointerException input is null
*/ */
protected static List<ReferenceToken> tokensFromInput(final String input) public static List<ReferenceToken> tokensFromInput(final String input)
throws JsonPointerException { throws JsonPointerException {
String s = input; String s = input;
final List<ReferenceToken> ret = new ArrayList<>(); final List<ReferenceToken> ret = new ArrayList<>();

View file

@ -0,0 +1,17 @@
module org.xbib.content.json.test {
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
requires java.logging;
requires jdk.unsupported; // sun.reflect for objenesis in mockito
requires org.mockito;
requires org.junit.jupiter.api;
requires org.xbib.content.api;
requires org.xbib.content.core;
requires org.xbib.content.json;
exports org.xbib.content.json.test;
exports org.xbib.content.json.test.jackson;
exports org.xbib.content.json.test.pointer;
opens org.xbib.content.json.test to org.junit.platform.commons;
opens org.xbib.content.json.test.jackson to org.junit.platform.commons;
opens org.xbib.content.json.test.pointer to org.junit.platform.commons;
}

View file

@ -1,5 +0,0 @@
/**
* Classes for testing JSON jackson.
*/
package org.xbib.content.json.jackson;

View file

@ -1,4 +0,0 @@
/**
* Classes for testing JSON pointer.
*/
package org.xbib.content.json.pointer;

View file

@ -1,4 +1,4 @@
package org.xbib.content.json; package org.xbib.content.json.test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;

View file

@ -1,8 +1,10 @@
package org.xbib.content.json; package org.xbib.content.json.test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.xbib.content.XContentParser; import org.xbib.content.XContentParser;
import org.xbib.content.json.JsonXContent;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;

View file

@ -1,4 +1,4 @@
package org.xbib.content.json.jackson; package org.xbib.content.json.test.jackson;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@ -8,6 +8,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.xbib.content.json.jackson.JsonNodeReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;

View file

@ -1,4 +1,4 @@
package org.xbib.content.json.jackson; package org.xbib.content.json.test.jackson;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
@ -6,14 +6,14 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.xbib.content.json.jackson.JsonLoader;
import org.xbib.content.json.jackson.JsonNumEquals;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
/**
*
*/
public final class JsonNumEqualsTest { public final class JsonNumEqualsTest {
private static final JsonNodeFactory FACTORY = JsonNodeFactory.instance; private static final JsonNodeFactory FACTORY = JsonNodeFactory.instance;
@ -62,7 +62,7 @@ public final class JsonNumEqualsTest {
private Iterator<Object[]> getInputs() throws IOException { private Iterator<Object[]> getInputs() throws IOException {
final List<Object[]> list = new ArrayList<>(); final List<Object[]> list = new ArrayList<>();
JsonNode reference; JsonNode reference;
JsonNode testData = JsonLoader.fromResource(this.getClass().getClassLoader(), "testfile.json"); JsonNode testData = JsonLoader.fromResource(getClass().getResourceAsStream("testfile.json"));
for (final JsonNode element : testData) { for (final JsonNode element : testData) {
reference = element.get("reference"); reference = element.get("reference");
for (final JsonNode node : element.get("equivalences")) { for (final JsonNode node : element.get("equivalences")) {

View file

@ -1,7 +1,9 @@
package org.xbib.content.json.jackson; package org.xbib.content.json.test.jackson;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.xbib.content.json.jackson.JacksonUtils;
import org.xbib.content.json.jackson.NodeType;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;

View file

@ -1,4 +1,4 @@
package org.xbib.content.json.pointer; package org.xbib.content.json.test.pointer;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
@ -9,7 +9,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.xbib.content.json.jackson.JacksonUtils; import org.xbib.content.json.jackson.JacksonUtils;
import org.xbib.content.json.jackson.NodeType; import org.xbib.content.json.jackson.NodeType;
import org.xbib.content.json.jackson.SampleNodeProvider; import org.xbib.content.json.pointer.JsonNodeResolver;
import org.xbib.content.json.pointer.ReferenceToken;
import org.xbib.content.json.test.jackson.SampleNodeProvider;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View file

@ -1,4 +1,4 @@
package org.xbib.content.json.pointer; package org.xbib.content.json.test.pointer;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
@ -7,7 +7,9 @@ import org.junit.jupiter.api.Test;
import org.xbib.content.json.jackson.JacksonUtils; import org.xbib.content.json.jackson.JacksonUtils;
import org.xbib.content.json.jackson.JsonLoader; import org.xbib.content.json.jackson.JsonLoader;
import org.xbib.content.json.jackson.NodeType; import org.xbib.content.json.jackson.NodeType;
import org.xbib.content.json.jackson.SampleNodeProvider; import org.xbib.content.json.pointer.JsonPointer;
import org.xbib.content.json.pointer.JsonPointerException;
import org.xbib.content.json.test.jackson.SampleNodeProvider;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -17,19 +19,14 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
*
*/
public final class JsonPointerTest { public final class JsonPointerTest {
private static final String PACKAGE = JsonPointerTest.class.getPackage().getName().replace('.', '/');
private final JsonNode testData; private final JsonNode testData;
private final JsonNode document; private final JsonNode document;
public JsonPointerTest() public JsonPointerTest() throws IOException {
throws IOException { testData = JsonLoader.fromResource(getClass().getResourceAsStream("jsonpointer.json"));
testData = JsonLoader.fromResource(this.getClass().getClassLoader(),
PACKAGE + "/jsonpointer.json");
document = testData.get("document"); document = testData.get("document");
} }

View file

@ -1,9 +1,12 @@
package org.xbib.content.json.pointer; package org.xbib.content.json.test.pointer;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.xbib.content.json.pointer.JsonPointerException;
import org.xbib.content.json.pointer.ReferenceToken;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

View file

@ -1,4 +1,4 @@
package org.xbib.content.json.pointer; package org.xbib.content.json.test.pointer;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
@ -14,14 +14,16 @@ import static org.mockito.Mockito.when;
import com.fasterxml.jackson.core.TreeNode; import com.fasterxml.jackson.core.TreeNode;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.xbib.content.json.pointer.JsonPointerException;
import org.xbib.content.json.pointer.ReferenceToken;
import org.xbib.content.json.pointer.TokenResolver;
import org.xbib.content.json.pointer.TreePointer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
/**
*
*/
public final class TreePointerTest { public final class TreePointerTest {
@Test @Test
@ -146,8 +148,7 @@ public final class TreePointerTest {
assertTrue(dummy.isEmpty()); assertTrue(dummy.isEmpty());
} }
private static final class DummyPointer private static final class DummyPointer extends TreePointer<TreeNode> {
extends TreePointer<TreeNode> {
private DummyPointer(final TreeNode missing, final List<TokenResolver<TreeNode>> tokenResolvers) { private DummyPointer(final TreeNode missing, final List<TokenResolver<TreeNode>> tokenResolvers) {
super(missing, tokenResolvers); super(missing, tokenResolvers);
} }

View file

@ -176,11 +176,11 @@ public final class Lang extends SubtagSet {
Subtag region = getRegion(); Subtag region = getRegion();
Subtag variant = getVariant(); Subtag variant = getVariant();
if (variant != null && region != null) { if (variant != null && region != null) {
return new Locale(primary.toString(), region.toString(), variant.toString()); return Locale.of(primary.toString(), region.toString(), variant.toString());
} else if (region != null) { } else if (region != null) {
return new Locale(primary.toString(), region.toString()); return Locale.of(primary.toString(), region.toString());
} else { } else {
return new Locale(primary.toString()); return Locale.of(primary.toString());
} }
} }

View file

@ -3,3 +3,13 @@ dependencies {
implementation project(':content-xml') implementation project(':content-xml')
implementation project(':content-json') implementation project(':content-json')
} }
def patchArgs = ['--patch-module', "org.xbib.content.rdf.test=" + sourceSets.test.resources.sourceDirectories.singleFile]
tasks.named('compileTestJava') {
options.compilerArgs += patchArgs
}
tasks.named('test') {
jvmArgs += patchArgs
}

View file

@ -11,7 +11,7 @@ public interface RdfContent<P extends RdfContentParams> {
StandardRdfContentType type(); StandardRdfContentType type();
RdfContentGenerator<P> createGenerator(OutputStream out) throws IOException; RdfContentGenerator<P> createGenerator(P params, OutputStream out) throws IOException;
RdfContentParser<P> createParser(InputStream in) throws IOException; RdfContentParser<P> createParser(P params, InputStream in) throws IOException;
} }

View file

@ -17,7 +17,7 @@ public class RdfContentBuilder<P extends RdfContentParams> implements RdfContent
private final RdfContentGenerator<P> generator; private final RdfContentGenerator<P> generator;
private final OutputStream out; private final OutputStream outputStream;
private IRI subject; private IRI subject;
@ -25,9 +25,9 @@ public class RdfContentBuilder<P extends RdfContentParams> implements RdfContent
this(rdfContent, rdfParams, new BytesStreamOutput()); this(rdfContent, rdfParams, new BytesStreamOutput());
} }
public RdfContentBuilder(RdfContent<P> rdfContent, P rdfContentParams, OutputStream out) throws IOException { public RdfContentBuilder(RdfContent<P> rdfContent, P rdfContentParams, OutputStream outputStream) throws IOException {
this.out = out; this.outputStream = outputStream;
this.generator = rdfContent.createGenerator(out); this.generator = rdfContent.createGenerator(rdfContentParams, outputStream);
this.generator.setParams(rdfContentParams); this.generator.setParams(rdfContentParams);
} }
@ -54,7 +54,7 @@ public class RdfContentBuilder<P extends RdfContentParams> implements RdfContent
public BytesReference bytes() throws IOException { public BytesReference bytes() throws IOException {
close(); close();
return ((BytesStreamOutput) out).bytes(); return ((BytesStreamOutput) outputStream).bytes();
} }
public InputStream streamInput() throws IOException { public InputStream streamInput() throws IOException {

View file

@ -14,74 +14,42 @@ import org.xbib.content.rdf.io.xml.XmlContentParams;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
/**
*
*/
public class RdfContentFactory { public class RdfContentFactory {
private RdfContentFactory() { private RdfContentFactory() {
} }
public static RdfContentBuilder<NTripleContentParams> ntripleBuilder() throws IOException {
return NTripleContent.contentBuilder(NTripleContentParams.N_TRIPLE_CONTENT_PARAMS);
}
public static RdfContentBuilder<NTripleContentParams> ntripleBuilder(NTripleContentParams params) throws IOException { public static RdfContentBuilder<NTripleContentParams> ntripleBuilder(NTripleContentParams params) throws IOException {
return NTripleContent.contentBuilder(params); return NTripleContent.contentBuilder(params);
} }
public static RdfContentBuilder<NTripleContentParams> ntripleBuilder(OutputStream out) throws IOException { public static RdfContentBuilder<NTripleContentParams> ntripleBuilder(NTripleContentParams params, OutputStream outputStream)
return NTripleContent.contentBuilder(out, NTripleContentParams.N_TRIPLE_CONTENT_PARAMS);
}
public static RdfContentBuilder<NTripleContentParams> ntripleBuilder(OutputStream out, NTripleContentParams params)
throws IOException { throws IOException {
return NTripleContent.contentBuilder(out, params); return NTripleContent.contentBuilder(params, outputStream);
}
public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder() throws IOException {
return RdfXmlContent.contentBuilder(RdfXmlContentParams.RDF_XML_CONTENT_PARAMS);
} }
public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder(RdfXmlContentParams params) throws IOException { public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder(RdfXmlContentParams params) throws IOException {
return RdfXmlContent.contentBuilder(params); return RdfXmlContent.contentBuilder(params);
} }
public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder(OutputStream out) throws IOException { public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder(RdfXmlContentParams params, OutputStream outputStream)
return RdfXmlContent.contentBuilder(out, RdfXmlContentParams.RDF_XML_CONTENT_PARAMS);
}
public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder(OutputStream out, RdfXmlContentParams params)
throws IOException { throws IOException {
return RdfXmlContent.contentBuilder(out, params); return RdfXmlContent.contentBuilder(params, outputStream);
}
public static RdfContentBuilder<TurtleContentParams> turtleBuilder() throws IOException {
return TurtleContent.contentBuilder(TurtleContentParams.TURTLE_CONTENT_PARAMS);
} }
public static RdfContentBuilder<TurtleContentParams> turtleBuilder(TurtleContentParams params) throws IOException { public static RdfContentBuilder<TurtleContentParams> turtleBuilder(TurtleContentParams params) throws IOException {
return TurtleContent.contentBuilder(params); return TurtleContent.contentBuilder(params);
} }
public static RdfContentBuilder<TurtleContentParams> turtleBuilder(OutputStream out) throws IOException { public static RdfContentBuilder<TurtleContentParams> turtleBuilder(TurtleContentParams params, OutputStream outputStream) throws IOException {
return TurtleContent.contentBuilder(out, TurtleContentParams.TURTLE_CONTENT_PARAMS); return TurtleContent.contentBuilder(params, outputStream);
}
public static RdfContentBuilder<TurtleContentParams> turtleBuilder(OutputStream out, TurtleContentParams params)
throws IOException {
return TurtleContent.contentBuilder(out, params);
}
public static RdfContentBuilder<XmlContentParams> xmlBuilder() throws IOException {
return XmlContent.contentBuilder(XmlContentParams.XML_CONTENT_PARAMS);
} }
public static RdfContentBuilder<XmlContentParams> xmlBuilder(XmlContentParams params) throws IOException { public static RdfContentBuilder<XmlContentParams> xmlBuilder(XmlContentParams params) throws IOException {
return XmlContent.contentBuilder(params); return XmlContent.contentBuilder(params);
} }
public static RdfContentBuilder<JsonContentParams> jsonBuilder() throws IOException { public static RdfContentBuilder<JsonContentParams> jsonBuilder(JsonContentParams params) throws IOException {
return JsonContent.contentBuilder(JsonContentParams.JSON_CONTENT_PARAMS); return JsonContent.contentBuilder(params);
} }
} }

View file

@ -28,12 +28,12 @@ public class RdfXContent implements RdfContent<RdfXContentParams> {
} }
@Override @Override
public RdfContentGenerator<RdfXContentParams> createGenerator(OutputStream out) { public RdfContentGenerator<RdfXContentParams> createGenerator(RdfXContentParams params, OutputStream outputStream) {
return new RdfXContentGenerator<>(out); return new RdfXContentGenerator<>(params, outputStream);
} }
@Override @Override
public RdfContentParser<RdfXContentParams> createParser(InputStream in) { public RdfContentParser<RdfXContentParams> createParser(RdfXContentParams params, InputStream inputStream) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }

View file

@ -11,61 +11,34 @@ import org.xbib.content.rdf.io.xml.XmlContentParams;
import java.io.IOException; import java.io.IOException;
/**
*
*/
public class RdfXContentFactory { public class RdfXContentFactory {
private RdfXContentFactory() { private RdfXContentFactory() {
} }
public static RdfContentBuilder<NTripleContentParams> ntripleBuilder() throws IOException {
return NTripleContent.contentBuilder(NTripleContentParams.N_TRIPLE_CONTENT_PARAMS);
}
public static RdfContentBuilder<NTripleContentParams> ntripleBuilder(NTripleContentParams params) throws IOException { public static RdfContentBuilder<NTripleContentParams> ntripleBuilder(NTripleContentParams params) throws IOException {
return NTripleContent.contentBuilder(params); return NTripleContent.contentBuilder(params);
} }
public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder() throws IOException {
return RdfXmlContent.contentBuilder(RdfXmlContentParams.RDF_XML_CONTENT_PARAMS);
}
public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder(RdfXmlContentParams params) throws IOException { public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder(RdfXmlContentParams params) throws IOException {
return RdfXmlContent.contentBuilder(params); return RdfXmlContent.contentBuilder(params);
} }
public static RdfContentBuilder<TurtleContentParams> turtleBuilder() throws IOException {
return TurtleContent.contentBuilder(TurtleContentParams.TURTLE_CONTENT_PARAMS);
}
public static RdfContentBuilder<TurtleContentParams> turtleBuilder(TurtleContentParams params) throws IOException { public static RdfContentBuilder<TurtleContentParams> turtleBuilder(TurtleContentParams params) throws IOException {
return TurtleContent.contentBuilder(params); return TurtleContent.contentBuilder(params);
} }
public static RdfContentBuilder<XmlContentParams> xmlBuilder() throws IOException {
return XmlContent.contentBuilder(XmlContentParams.XML_CONTENT_PARAMS);
}
public static RdfContentBuilder<XmlContentParams> xmlBuilder(XmlContentParams params) throws IOException { public static RdfContentBuilder<XmlContentParams> xmlBuilder(XmlContentParams params) throws IOException {
return XmlContent.contentBuilder(params); return XmlContent.contentBuilder(params);
} }
public static RdfContentBuilder<RdfXContentParams> rdfXContentBuilder() throws IOException {
return RdfXContent.contentBuilder(RdfXContentParams.RDF_X_CONTENT_PARAMS);
}
public static RdfContentBuilder<RdfXContentParams> rdfXContentBuilder(RdfXContentParams params) throws IOException { public static RdfContentBuilder<RdfXContentParams> rdfXContentBuilder(RdfXContentParams params) throws IOException {
return RdfXContent.contentBuilder(params); return RdfXContent.contentBuilder(params);
} }
public static RdfContentBuilder<RouteRdfXContentParams> routeRdfXContentBuilder() throws IOException {
return RouteRdfXContent.contentBuilder(RouteRdfXContentParams.ROUTE_RDF_X_CONTENT_PARAMS);
}
public static RdfContentBuilder<RouteRdfXContentParams> routeRdfXContentBuilder(RouteRdfXContentParams params) public static RdfContentBuilder<RouteRdfXContentParams> routeRdfXContentBuilder(RouteRdfXContentParams params)
throws IOException { throws IOException {
return RouteRdfXContent.contentBuilder(params); return RouteRdfXContent.contentBuilder(params);
} }
} }

View file

@ -19,7 +19,7 @@ import java.util.List;
*/ */
public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfContentGenerator<P> { public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfContentGenerator<P> {
protected final OutputStream out; protected final OutputStream outputStream;
protected Resource resource; protected Resource resource;
@ -29,8 +29,9 @@ public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfCon
private boolean flushed; private boolean flushed;
RdfXContentGenerator(OutputStream out) { RdfXContentGenerator(P params, OutputStream outputStream) {
this.out = out; this.params = params;
this.outputStream = outputStream;
} }
@Override @Override
@ -105,7 +106,7 @@ public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfCon
return; return;
} }
flushed = true; flushed = true;
builder = DefaultXContentBuilder.builder(JsonXContent.jsonContent(), out); builder = DefaultXContentBuilder.builder(JsonXContent.jsonContent(), outputStream);
builder.startObject(); builder.startObject();
build(this.resource); build(this.resource);
builder.endObject(); builder.endObject();

View file

@ -2,21 +2,12 @@ package org.xbib.content.rdf;
import org.xbib.content.resource.IRINamespaceContext; import org.xbib.content.resource.IRINamespaceContext;
/**
*
*/
public class RdfXContentParams implements RdfContentParams { public class RdfXContentParams implements RdfContentParams {
public static final RdfXContentParams RDF_X_CONTENT_PARAMS = new RdfXContentParams();
private final IRINamespaceContext namespaceContext; private final IRINamespaceContext namespaceContext;
private RdfXContentGenerator<RdfXContentParams> generator; private RdfXContentGenerator<RdfXContentParams> generator;
public RdfXContentParams() {
this.namespaceContext = IRINamespaceContext.newInstance();
}
public RdfXContentParams(IRINamespaceContext namespaceContext) { public RdfXContentParams(IRINamespaceContext namespaceContext) {
this.namespaceContext = namespaceContext; this.namespaceContext = namespaceContext;
} }

View file

@ -4,9 +4,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
/**
*
*/
public class RouteRdfXContent implements RdfContent<RouteRdfXContentParams> { public class RouteRdfXContent implements RdfContent<RouteRdfXContentParams> {
private static final RouteRdfXContent ROUTE_RDF_X_CONTENT = new RouteRdfXContent(); private static final RouteRdfXContent ROUTE_RDF_X_CONTENT = new RouteRdfXContent();
@ -28,18 +25,15 @@ public class RouteRdfXContent implements RdfContent<RouteRdfXContentParams> {
} }
@Override @Override
public RdfContentGenerator<RouteRdfXContentParams> createGenerator(OutputStream out) { public RdfContentGenerator<RouteRdfXContentParams> createGenerator(RouteRdfXContentParams params, OutputStream outputStream) {
return new RouteRdfXContentGenerator<>(out); return new RouteRdfXContentGenerator<>(params, outputStream);
} }
@Override @Override
public RdfContentParser<RouteRdfXContentParams> createParser(InputStream in) { public RdfContentParser<RouteRdfXContentParams> createParser(RouteRdfXContentParams params, InputStream inputStream) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
/**
*
*/
@FunctionalInterface @FunctionalInterface
public interface RouteHandler { public interface RouteHandler {
void complete(String content, RouteRdfXContentParams params) throws IOException; void complete(String content, RouteRdfXContentParams params) throws IOException;

View file

@ -13,8 +13,8 @@ public class RouteRdfXContentGenerator<R extends RouteRdfXContentParams> extends
private boolean flushed; private boolean flushed;
RouteRdfXContentGenerator(OutputStream out) { RouteRdfXContentGenerator(R params, OutputStream outputStream) {
super(out); super(params, outputStream);
} }
@Override @Override

View file

@ -2,13 +2,8 @@ package org.xbib.content.rdf;
import org.xbib.content.resource.IRINamespaceContext; import org.xbib.content.resource.IRINamespaceContext;
/**
*
*/
public class RouteRdfXContentParams extends RdfXContentParams { public class RouteRdfXContentParams extends RdfXContentParams {
public static final RouteRdfXContentParams ROUTE_RDF_X_CONTENT_PARAMS = new RouteRdfXContentParams();
private String index; private String index;
private String type; private String type;
@ -23,20 +18,6 @@ public class RouteRdfXContentParams extends RdfXContentParams {
private RouteRdfXContent.RouteHandler handler; private RouteRdfXContent.RouteHandler handler;
public RouteRdfXContentParams() {
super();
}
public RouteRdfXContentParams(String index, String type) {
super();
this.index = index;
this.type = type;
}
public RouteRdfXContentParams(IRINamespaceContext namespaceContext) {
super(namespaceContext);
}
public RouteRdfXContentParams(IRINamespaceContext namespaceContext, String index, String type) { public RouteRdfXContentParams(IRINamespaceContext namespaceContext, String index, String type) {
super(namespaceContext); super(namespaceContext);
this.index = index; this.index = index;

View file

@ -14,16 +14,14 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
*
*/
public class DefaultRdfGraph implements RdfGraph<RdfGraphParams> { public class DefaultRdfGraph implements RdfGraph<RdfGraphParams> {
private RdfGraphParams params = DefaultRdfGraphParams.DEFAULT_PARAMS; private RdfGraphParams params;
private final Map<IRI, Resource> resources = new LinkedHashMap<>(); private final Map<IRI, Resource> resources = new LinkedHashMap<>();
public DefaultRdfGraph() { public DefaultRdfGraph(RdfGraphParams params) {
this.params = params;
} }
@Override @Override

View file

@ -3,17 +3,14 @@ package org.xbib.content.rdf.internal;
import org.xbib.content.rdf.RdfGraphParams; import org.xbib.content.rdf.RdfGraphParams;
import org.xbib.content.resource.IRINamespaceContext; import org.xbib.content.resource.IRINamespaceContext;
/**
*
*/
public class DefaultRdfGraphParams implements RdfGraphParams { public class DefaultRdfGraphParams implements RdfGraphParams {
public static final DefaultRdfGraphParams DEFAULT_PARAMS = new DefaultRdfGraphParams();
private final IRINamespaceContext namespaceContext; private final IRINamespaceContext namespaceContext;
private final boolean writeNamespaceContext; private final boolean writeNamespaceContext;
public DefaultRdfGraphParams() { public DefaultRdfGraphParams(IRINamespaceContext namespaceContext) {
this.namespaceContext = IRINamespaceContext.newInstance(); this.namespaceContext = namespaceContext;
this.writeNamespaceContext = true; this.writeNamespaceContext = true;
} }

View file

@ -45,11 +45,13 @@ public class DefaultResource implements Resource, Comparable<Resource>, XSDResou
this(iri, new LinkedHashMultiMap<>(), new LinkedHashMap<>()); this(iri, new LinkedHashMultiMap<>(), new LinkedHashMap<>());
} }
@SuppressWarnings("this-escape")
public DefaultResource(DefaultResource resource) { public DefaultResource(DefaultResource resource) {
this(resource.id(), resource.getAttributes(), resource.getChildren()); this(resource.id(), resource.getAttributes(), resource.getChildren());
this.deleted = resource.isDeleted(); this.deleted = resource.isDeleted();
} }
@SuppressWarnings("this-escape")
public DefaultResource(IRI iri, MultiMap<IRI, Node> attributes, Map<IRI, Resource> children) { public DefaultResource(IRI iri, MultiMap<IRI, Node> attributes, Map<IRI, Resource> children) {
setId(iri); setId(iri);
this.attributes = attributes; this.attributes = attributes;

View file

@ -10,9 +10,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
/**
*
*/
public class JsonContent implements RdfContent<JsonContentParams> { public class JsonContent implements RdfContent<JsonContentParams> {
private static final JsonContent JSON_CONTENT = new JsonContent(); private static final JsonContent JSON_CONTENT = new JsonContent();
@ -39,12 +36,12 @@ public class JsonContent implements RdfContent<JsonContentParams> {
} }
@Override @Override
public RdfContentGenerator<JsonContentParams> createGenerator(OutputStream out) throws IOException { public RdfContentGenerator<JsonContentParams> createGenerator(JsonContentParams params, OutputStream outputStream) throws IOException {
return new JsonContentGenerator(out); return new JsonContentGenerator(params, outputStream);
} }
@Override @Override
public RdfContentParser<JsonContentParams> createParser(InputStream in) throws IOException { public RdfContentParser<JsonContentParams> createParser(JsonContentParams params, InputStream inputStream) throws IOException {
return new JsonContentParser<>(in); return new JsonContentParser<>(params, inputStream);
} }
} }

View file

@ -24,13 +24,14 @@ public class JsonContentGenerator implements RdfContentGenerator<JsonContentPara
private Resource resource; private Resource resource;
private JsonContentParams params = JsonContentParams.JSON_CONTENT_PARAMS; private JsonContentParams params;
JsonContentGenerator(OutputStream out) { JsonContentGenerator(JsonContentParams params, OutputStream out) {
this(new OutputStreamWriter(out, StandardCharsets.UTF_8)); this(params, new OutputStreamWriter(out, StandardCharsets.UTF_8));
} }
JsonContentGenerator(Writer writer) { JsonContentGenerator(JsonContentParams params, Writer writer) {
this.params = params;
this.writer = writer; this.writer = writer;
this.nsWritten = false; this.nsWritten = false;
this.resource = new DefaultAnonymousResource(); this.resource = new DefaultAnonymousResource();

View file

@ -4,13 +4,8 @@ import org.xbib.content.rdf.RdfContentParams;
import org.xbib.content.rdf.io.xml.XmlContentParams; import org.xbib.content.rdf.io.xml.XmlContentParams;
import org.xbib.content.resource.IRINamespaceContext; import org.xbib.content.resource.IRINamespaceContext;
/**
*
*/
public class JsonContentParams extends XmlContentParams implements RdfContentParams { public class JsonContentParams extends XmlContentParams implements RdfContentParams {
public static final JsonContentParams JSON_CONTENT_PARAMS = new JsonContentParams(NAMESPACE_CONTEXT);
public JsonContentParams(IRINamespaceContext namespaceContext) { public JsonContentParams(IRINamespaceContext namespaceContext) {
super(namespaceContext); super(namespaceContext);
} }

View file

@ -23,6 +23,8 @@ import javax.xml.namespace.QName;
*/ */
public class JsonContentParser<R extends RdfContentParams> implements RdfContentParser<R> { public class JsonContentParser<R extends RdfContentParams> implements RdfContentParser<R> {
private final JsonContentParams params;
private final Reader reader; private final Reader reader;
private XmlHandler<R> handler; private XmlHandler<R> handler;
@ -31,11 +33,12 @@ public class JsonContentParser<R extends RdfContentParams> implements RdfContent
private QName root; private QName root;
public JsonContentParser(InputStream in) throws IOException { public JsonContentParser(JsonContentParams params, InputStream inputStream) throws IOException {
this(new InputStreamReader(in, StandardCharsets.UTF_8)); this(params, new InputStreamReader(inputStream, StandardCharsets.UTF_8));
} }
public JsonContentParser(Reader reader) { public JsonContentParser(JsonContentParams params, Reader reader) {
this.params = params;
this.reader = reader; this.reader = reader;
} }

View file

@ -2,14 +2,11 @@ package org.xbib.content.rdf.io.json;
import org.xbib.content.rdf.io.xml.AbstractXmlResourceHandler; import org.xbib.content.rdf.io.xml.AbstractXmlResourceHandler;
/**
*
*/
public abstract class JsonResourceHandler extends AbstractXmlResourceHandler<JsonContentParams> { public abstract class JsonResourceHandler extends AbstractXmlResourceHandler<JsonContentParams> {
@SuppressWarnings("this-escape")
public JsonResourceHandler(JsonContentParams params) { public JsonResourceHandler(JsonContentParams params) {
super(params); super(params);
super.setDefaultNamespace("", "http://json.org"); super.setDefaultNamespace("", "http://json.org");
} }
} }

View file

@ -1,4 +0,0 @@
/**
* Classes for RDF JSON.
*/
package org.xbib.content.rdf.io.json;

View file

@ -1,4 +0,0 @@
/**
* Classes for RDF N-Quads.
*/
package org.xbib.content.rdf.io.nquads;

View file

@ -10,9 +10,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
/**
*
*/
public class NTripleContent implements RdfContent<NTripleContentParams> { public class NTripleContent implements RdfContent<NTripleContentParams> {
private static final NTripleContent N_TRIPLE_CONTENT = new NTripleContent(); private static final NTripleContent N_TRIPLE_CONTENT = new NTripleContent();
@ -28,9 +25,9 @@ public class NTripleContent implements RdfContent<NTripleContentParams> {
return new RdfContentBuilder<>(N_TRIPLE_CONTENT, params); return new RdfContentBuilder<>(N_TRIPLE_CONTENT, params);
} }
public static RdfContentBuilder<NTripleContentParams> contentBuilder(OutputStream out, NTripleContentParams params) public static RdfContentBuilder<NTripleContentParams> contentBuilder(NTripleContentParams params, OutputStream outputStream)
throws IOException { throws IOException {
return new RdfContentBuilder<>(N_TRIPLE_CONTENT, params, out); return new RdfContentBuilder<>(N_TRIPLE_CONTENT, params, outputStream);
} }
@Override @Override
@ -39,12 +36,12 @@ public class NTripleContent implements RdfContent<NTripleContentParams> {
} }
@Override @Override
public RdfContentGenerator<NTripleContentParams> createGenerator(OutputStream out) throws IOException { public RdfContentGenerator<NTripleContentParams> createGenerator(NTripleContentParams params, OutputStream outputStream) throws IOException {
return new NTripleContentGenerator(out); return new NTripleContentGenerator(params, outputStream);
} }
@Override @Override
public RdfContentParser<NTripleContentParams> createParser(InputStream in) throws IOException { public RdfContentParser<NTripleContentParams> createParser(NTripleContentParams params, InputStream inputStream) throws IOException {
return new NTripleContentParser<>(in); return new NTripleContentParser<>(params, inputStream);
} }
} }

View file

@ -24,13 +24,14 @@ public class NTripleContentGenerator
private final Writer writer; private final Writer writer;
private NTripleContentParams params = NTripleContentParams.N_TRIPLE_CONTENT_PARAMS; private NTripleContentParams params;
NTripleContentGenerator(OutputStream out) throws IOException { NTripleContentGenerator(NTripleContentParams params, OutputStream out) throws IOException {
this(new OutputStreamWriter(out, StandardCharsets.UTF_8)); this(params, new OutputStreamWriter(out, StandardCharsets.UTF_8));
} }
NTripleContentGenerator(Writer writer) throws IOException { NTripleContentGenerator(NTripleContentParams params, Writer writer) throws IOException {
this.params = params;
this.writer = writer; this.writer = writer;
} }

View file

@ -3,18 +3,10 @@ package org.xbib.content.rdf.io.ntriple;
import org.xbib.content.rdf.RdfContentParams; import org.xbib.content.rdf.RdfContentParams;
import org.xbib.content.resource.IRINamespaceContext; import org.xbib.content.resource.IRINamespaceContext;
/**
*
*/
public class NTripleContentParams implements RdfContentParams { public class NTripleContentParams implements RdfContentParams {
public static final NTripleContentParams N_TRIPLE_CONTENT_PARAMS = new NTripleContentParams();
private final IRINamespaceContext namespaceContext; private final IRINamespaceContext namespaceContext;
public NTripleContentParams() {
this.namespaceContext = IRINamespaceContext.newInstance();
}
public NTripleContentParams(IRINamespaceContext namespaceContext) { public NTripleContentParams(IRINamespaceContext namespaceContext) {
this.namespaceContext = namespaceContext; this.namespaceContext = namespaceContext;
} }

View file

@ -52,11 +52,14 @@ public class NTripleContentParser<R extends RdfContentParams> implements RdfCont
private RdfContentBuilder<R> builder; private RdfContentBuilder<R> builder;
public NTripleContentParser(InputStream in) throws IOException { private NTripleContentParams params;
this(new InputStreamReader(in, StandardCharsets.UTF_8));
public NTripleContentParser(NTripleContentParams params, InputStream inputStream) throws IOException {
this(params, new InputStreamReader(inputStream, StandardCharsets.UTF_8));
} }
public NTripleContentParser(Reader reader) { public NTripleContentParser(NTripleContentParams params, Reader reader) {
this.params = params;
this.reader = reader; this.reader = reader;
} }

View file

@ -1,4 +0,0 @@
/**
* Classes for RDF N-Triples.
*/
package org.xbib.content.rdf.io.ntriple;

View file

@ -10,9 +10,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
/**
*
*/
public class RdfXmlContent implements RdfContent<RdfXmlContentParams> { public class RdfXmlContent implements RdfContent<RdfXmlContentParams> {
private static final RdfXmlContent RDF_XML_CONTENT = new RdfXmlContent(); private static final RdfXmlContent RDF_XML_CONTENT = new RdfXmlContent();
@ -28,9 +25,9 @@ public class RdfXmlContent implements RdfContent<RdfXmlContentParams> {
return new RdfContentBuilder<>(RDF_XML_CONTENT, params); return new RdfContentBuilder<>(RDF_XML_CONTENT, params);
} }
public static RdfContentBuilder<RdfXmlContentParams> contentBuilder(OutputStream out, RdfXmlContentParams params) public static RdfContentBuilder<RdfXmlContentParams> contentBuilder(RdfXmlContentParams params, OutputStream outputStream)
throws IOException { throws IOException {
return new RdfContentBuilder<>(RDF_XML_CONTENT, params, out); return new RdfContentBuilder<>(RDF_XML_CONTENT, params, outputStream);
} }
@Override @Override
@ -39,12 +36,12 @@ public class RdfXmlContent implements RdfContent<RdfXmlContentParams> {
} }
@Override @Override
public RdfContentGenerator<RdfXmlContentParams> createGenerator(OutputStream os) throws IOException { public RdfContentGenerator<RdfXmlContentParams> createGenerator(RdfXmlContentParams params, OutputStream outputStream) throws IOException {
return new RdfXmlContentGenerator(os); return new RdfXmlContentGenerator(params, outputStream);
} }
@Override @Override
public RdfContentParser<RdfXmlContentParams> createParser(InputStream in) throws IOException { public RdfContentParser<RdfXmlContentParams> createParser(RdfXmlContentParams params, InputStream inputStream) throws IOException {
return new RdfXmlContentParser<>(in); return new RdfXmlContentParser<>(params, inputStream);
} }
} }

View file

@ -19,9 +19,6 @@ import java.io.Writer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
/**
* RDF/XML writer.
*/
public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContentParams>, Flushable, RdfConstants { public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContentParams>, Flushable, RdfConstants {
private final Writer writer; private final Writer writer;
@ -34,18 +31,18 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
private Resource resource; private Resource resource;
private RdfXmlContentParams params = RdfXmlContentParams.RDF_XML_CONTENT_PARAMS; private RdfXmlContentParams params;
public RdfXmlContentGenerator(OutputStream out) throws IOException { public RdfXmlContentGenerator(RdfXmlContentParams params, OutputStream outputStream) throws IOException {
this(new OutputStreamWriter(out, StandardCharsets.UTF_8)); this(params, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
} }
public RdfXmlContentGenerator(Writer writer) { public RdfXmlContentGenerator(RdfXmlContentParams params, Writer writer) {
this.params = params;
this.writer = writer; this.writer = writer;
this.resource = new DefaultAnonymousResource(); this.resource = new DefaultAnonymousResource();
} }
@Override @Override
public void flush() throws IOException { public void flush() throws IOException {
writer.flush(); writer.flush();

View file

@ -3,18 +3,10 @@ package org.xbib.content.rdf.io.rdfxml;
import org.xbib.content.rdf.RdfContentParams; import org.xbib.content.rdf.RdfContentParams;
import org.xbib.content.resource.IRINamespaceContext; import org.xbib.content.resource.IRINamespaceContext;
/**
*
*/
public class RdfXmlContentParams implements RdfContentParams { public class RdfXmlContentParams implements RdfContentParams {
public static final RdfXmlContentParams RDF_XML_CONTENT_PARAMS = new RdfXmlContentParams();
private final IRINamespaceContext namespaceContext; private final IRINamespaceContext namespaceContext;
public RdfXmlContentParams() {
this.namespaceContext = IRINamespaceContext.newInstance();
}
public RdfXmlContentParams(IRINamespaceContext namespaceContext) { public RdfXmlContentParams(IRINamespaceContext namespaceContext) {
this.namespaceContext = namespaceContext; this.namespaceContext = namespaceContext;
} }

View file

@ -54,6 +54,8 @@ import javax.xml.parsers.SAXParserFactory;
*/ */
public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConstants, RdfContentParser<R> { public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConstants, RdfContentParser<R> {
private R params;
private final Reader reader; private final Reader reader;
private final Resource resource = new DefaultAnonymousResource(); private final Resource resource = new DefaultAnonymousResource();
@ -69,11 +71,12 @@ public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConst
// counter for blank node generation // counter for blank node generation
private int bn = 0; private int bn = 0;
public RdfXmlContentParser(InputStream inputStream) { public RdfXmlContentParser(R params, InputStream inputStream) {
this(createReader(inputStream)); this(params, createReader(inputStream));
} }
public RdfXmlContentParser(Reader reader) { public RdfXmlContentParser(R params, Reader reader) {
this.params = params;
this.reader = reader; this.reader = reader;
} }

View file

@ -1,4 +0,0 @@
/**
* Classes for RDF XML.
*/
package org.xbib.content.rdf.io.rdfxml;

View file

@ -3,11 +3,10 @@ package org.xbib.content.rdf.io.source;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Reader; import java.io.Reader;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
/**
*/
public abstract class BaseStreamProcessor { public abstract class BaseStreamProcessor {
public BaseStreamProcessor() { public BaseStreamProcessor() {
@ -39,7 +38,7 @@ public abstract class BaseStreamProcessor {
* @throws IOException if process fails * @throws IOException if process fails
*/ */
public final void process(String uri, String baseUri) throws IOException { public final void process(String uri, String baseUri) throws IOException {
URL url = new URL(uri); URL url = URI.create(uri).toURL();
URLConnection urlConnection = url.openConnection(); URLConnection urlConnection = url.openConnection();
String mimeType = urlConnection.getContentType(); String mimeType = urlConnection.getContentType();
try (InputStream inputStream = urlConnection.getInputStream()) { try (InputStream inputStream = urlConnection.getInputStream()) {

View file

@ -28,9 +28,9 @@ public class TurtleContent implements RdfContent<TurtleContentParams> {
return new RdfContentBuilder<>(TURTLE_CONTENT, params); return new RdfContentBuilder<>(TURTLE_CONTENT, params);
} }
public static RdfContentBuilder<TurtleContentParams> contentBuilder(OutputStream out, TurtleContentParams params) public static RdfContentBuilder<TurtleContentParams> contentBuilder(TurtleContentParams params, OutputStream outputStream)
throws IOException { throws IOException {
return new RdfContentBuilder<>(TURTLE_CONTENT, params, out); return new RdfContentBuilder<>(TURTLE_CONTENT, params, outputStream);
} }
@Override @Override
@ -39,13 +39,13 @@ public class TurtleContent implements RdfContent<TurtleContentParams> {
} }
@Override @Override
public RdfContentGenerator<TurtleContentParams> createGenerator(OutputStream outputStream) throws IOException { public RdfContentGenerator<TurtleContentParams> createGenerator(TurtleContentParams params, OutputStream outputStream) throws IOException {
return new TurtleContentGenerator(outputStream); return new TurtleContentGenerator(params, outputStream);
} }
@Override @Override
public RdfContentParser<TurtleContentParams> createParser(InputStream inputStream) throws IOException { public RdfContentParser<TurtleContentParams> createParser(TurtleContentParams params, InputStream inputStream) throws IOException {
return new TurtleContentParser<>(inputStream); return new TurtleContentParser<>(params, inputStream);
} }
} }

View file

@ -53,13 +53,14 @@ public class TurtleContentGenerator implements RdfContentGenerator<TurtleContent
private boolean closed; private boolean closed;
private TurtleContentParams params = TurtleContentParams.TURTLE_CONTENT_PARAMS; private TurtleContentParams params;
TurtleContentGenerator(OutputStream out) throws IOException { public TurtleContentGenerator(TurtleContentParams params, OutputStream outputStream) throws IOException {
this(new OutputStreamWriter(out, StandardCharsets.UTF_8)); this(params, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
} }
TurtleContentGenerator(Writer writer) throws IOException { public TurtleContentGenerator(TurtleContentParams params, Writer writer) throws IOException {
this.params = params;
this.writer = writer; this.writer = writer;
this.resource = new DefaultAnonymousResource(); this.resource = new DefaultAnonymousResource();
this.nsWritten = false; this.nsWritten = false;

View file

@ -3,19 +3,11 @@ package org.xbib.content.rdf.io.turtle;
import org.xbib.content.rdf.RdfContentParams; import org.xbib.content.rdf.RdfContentParams;
import org.xbib.content.resource.IRINamespaceContext; import org.xbib.content.resource.IRINamespaceContext;
/**
*
*/
public class TurtleContentParams implements RdfContentParams { public class TurtleContentParams implements RdfContentParams {
public static final TurtleContentParams TURTLE_CONTENT_PARAMS = new TurtleContentParams();
private final IRINamespaceContext namespaceContext; private final IRINamespaceContext namespaceContext;
private final boolean writeNamespaceContext;
public TurtleContentParams() { private final boolean writeNamespaceContext;
this.namespaceContext = IRINamespaceContext.newInstance();
this.writeNamespaceContext = true;
}
public TurtleContentParams(IRINamespaceContext namespaceContext, boolean writeNamespaceContext) { public TurtleContentParams(IRINamespaceContext namespaceContext, boolean writeNamespaceContext) {
this.namespaceContext = namespaceContext; this.namespaceContext = namespaceContext;

View file

@ -40,6 +40,8 @@ import java.util.LinkedList;
*/ */
public class TurtleContentParser<R extends RdfContentParams> implements RdfContentParser<R> { public class TurtleContentParser<R extends RdfContentParams> implements RdfContentParser<R> {
private TurtleContentParams params;
private final Resource resource = new DefaultAnonymousResource(); private final Resource resource = new DefaultAnonymousResource();
private final HashMap<String, Node> bnodes = new HashMap<>(); private final HashMap<String, Node> bnodes = new HashMap<>();
@ -92,11 +94,12 @@ public class TurtleContentParser<R extends RdfContentParams> implements RdfConte
*/ */
private NamespaceContext context; private NamespaceContext context;
public TurtleContentParser(InputStream in) throws IOException { public TurtleContentParser(TurtleContentParams params, InputStream inputStream) throws IOException {
this(new InputStreamReader(in, StandardCharsets.UTF_8)); this(params, new InputStreamReader(inputStream, StandardCharsets.UTF_8));
} }
public TurtleContentParser(Reader reader) { public TurtleContentParser(TurtleContentParams params, Reader reader) {
this.params = params;
this.reader = new PushbackReader(reader, 2); this.reader = new PushbackReader(reader, 2);
this.context = XmlNamespaceContext.newInstance(); this.context = XmlNamespaceContext.newInstance();
} }

View file

@ -23,7 +23,7 @@ import javax.xml.namespace.QName;
public abstract class AbstractXmlHandler<P extends RdfContentParams> public abstract class AbstractXmlHandler<P extends RdfContentParams>
extends DefaultHandler implements XmlHandler<P> { extends DefaultHandler implements XmlHandler<P> {
protected final RdfContentParams params; protected final P params;
protected final StringBuilder content; protected final StringBuilder content;
@ -39,14 +39,14 @@ public abstract class AbstractXmlHandler<P extends RdfContentParams>
private int lastlevel; private int lastlevel;
public AbstractXmlHandler(RdfContentParams params) { public AbstractXmlHandler(P params) {
this.params = params; this.params = params;
this.content = new StringBuilder(); this.content = new StringBuilder();
this.parents = new LinkedList<>(); this.parents = new LinkedList<>();
this.resource = new DefaultAnonymousResource(); this.resource = new DefaultAnonymousResource();
} }
public RdfContentParams getParams() { public P getParams() {
return params; return params;
} }

View file

@ -20,7 +20,7 @@ public abstract class AbstractXmlResourceHandler<P extends RdfContentParams>
protected final LinkedList<Resource> stack = new LinkedList<>(); protected final LinkedList<Resource> stack = new LinkedList<>();
public AbstractXmlResourceHandler(RdfContentParams params) { public AbstractXmlResourceHandler(P params) {
super(params); super(params);
} }

View file

@ -10,9 +10,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
/**
*
*/
public class XmlContent implements RdfContent<XmlContentParams> { public class XmlContent implements RdfContent<XmlContentParams> {
private static final XmlContent XML_CONTENT = new XmlContent(); private static final XmlContent XML_CONTENT = new XmlContent();
@ -39,12 +36,12 @@ public class XmlContent implements RdfContent<XmlContentParams> {
} }
@Override @Override
public RdfContentGenerator<XmlContentParams> createGenerator(OutputStream outputStream) throws IOException { public RdfContentGenerator<XmlContentParams> createGenerator(XmlContentParams params, OutputStream outputStream) throws IOException {
return new XmlContentGenerator(outputStream); return new XmlContentGenerator(params, outputStream);
} }
@Override @Override
public RdfContentParser<XmlContentParams> createParser(InputStream inputStream) throws IOException { public RdfContentParser<XmlContentParams> createParser(XmlContentParams params, InputStream inputStream) throws IOException {
return new XmlContentParser<>(inputStream); return new XmlContentParser<>(params, inputStream);
} }
} }

View file

@ -36,13 +36,14 @@ public class XmlContentGenerator implements RdfContentGenerator<XmlContentParams
private Resource resource; private Resource resource;
private XmlContentParams params = XmlContentParams.XML_CONTENT_PARAMS; private XmlContentParams params;
public XmlContentGenerator(OutputStream out) { public XmlContentGenerator(XmlContentParams params, OutputStream outputStream) {
this(new OutputStreamWriter(out, StandardCharsets.UTF_8)); this(params, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
} }
public XmlContentGenerator(Writer writer) { public XmlContentGenerator(XmlContentParams params, Writer writer) {
this.params = params;
this.writer = writer; this.writer = writer;
} }

View file

@ -3,13 +3,8 @@ package org.xbib.content.rdf.io.xml;
import org.xbib.content.rdf.RdfContentParams; import org.xbib.content.rdf.RdfContentParams;
import org.xbib.content.resource.IRINamespaceContext; import org.xbib.content.resource.IRINamespaceContext;
/**
*
*/
public class XmlContentParams implements RdfContentParams { public class XmlContentParams implements RdfContentParams {
protected static final IRINamespaceContext NAMESPACE_CONTEXT = IRINamespaceContext.newInstance();
public static final XmlContentParams XML_CONTENT_PARAMS = new XmlContentParams(NAMESPACE_CONTEXT);
private final IRINamespaceContext namespaceContext; private final IRINamespaceContext namespaceContext;
public XmlContentParams(IRINamespaceContext namespaceContext) { public XmlContentParams(IRINamespaceContext namespaceContext) {

View file

@ -25,6 +25,8 @@ import javax.xml.parsers.SAXParserFactory;
*/ */
public class XmlContentParser<P extends RdfContentParams> implements RdfContentParser<P> { public class XmlContentParser<P extends RdfContentParams> implements RdfContentParser<P> {
private final P params;
private final Reader reader; private final Reader reader;
private RdfContentBuilder<P> builder; private RdfContentBuilder<P> builder;
@ -35,11 +37,12 @@ public class XmlContentParser<P extends RdfContentParams> implements RdfContentP
private boolean validate = false; private boolean validate = false;
public XmlContentParser(InputStream in) { public XmlContentParser(P params, InputStream inputStream) {
this(new InputStreamReader(in, StandardCharsets.UTF_8)); this(params, new InputStreamReader(inputStream, StandardCharsets.UTF_8));
} }
public XmlContentParser(Reader reader) { public XmlContentParser(P params, Reader reader) {
this.params = params;
this.reader = new NormalizeEolFilter(reader, System.getProperty("line.separator"), true); this.reader = new NormalizeEolFilter(reader, System.getProperty("line.separator"), true);
} }

View file

@ -4,7 +4,6 @@ import java.util.Collection;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
/** /**
@ -20,14 +19,6 @@ public class LinkedHashMultiMap<K, V> implements MultiMap<K, V> {
this.map = new LinkedHashMap<>(); this.map = new LinkedHashMap<>();
} }
public LinkedHashMultiMap(MultiMap<K, V> multiMap) {
Objects.requireNonNull(multiMap);
this.map = new LinkedHashMap<>();
for (K k : multiMap.keySet()) {
putAll(k, multiMap.get(k));
}
}
@Override @Override
public int size() { public int size() {
return map.size(); return map.size();
@ -98,7 +89,7 @@ public class LinkedHashMultiMap<K, V> implements MultiMap<K, V> {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj != null && obj instanceof LinkedHashMultiMap && map.equals(((LinkedHashMultiMap) obj).map); return obj instanceof LinkedHashMultiMap && map.equals(((LinkedHashMultiMap<?, ?>) obj).map);
} }
@Override @Override

View file

@ -0,0 +1,17 @@
module org.xbib.content.rdf.test {
requires java.logging;
requires java.xml;
requires org.junit.jupiter.api;
requires org.xbib.content.rdf;
requires org.xbib.content.resource;
requires org.xbib.net;
opens org.xbib.content.rdf.test to org.junit.platform.commons;
opens org.xbib.content.rdf.test.internal to org.junit.platform.commons;
opens org.xbib.content.rdf.test.io to org.junit.platform.commons;
opens org.xbib.content.rdf.test.io.json to org.junit.platform.commons;
opens org.xbib.content.rdf.test.io.ntriple to org.junit.platform.commons;
opens org.xbib.content.rdf.test.io.rdfxml to org.junit.platform.commons;
opens org.xbib.content.rdf.test.io.turtle to org.junit.platform.commons;
opens org.xbib.content.rdf.test.io.xml to org.junit.platform.commons;
opens org.xbib.content.rdf.test.util to org.junit.platform.commons;
}

View file

@ -1,4 +0,0 @@
/**
* Classes for testing internal RDF.
*/
package org.xbib.content.rdf.internal;

View file

@ -1,4 +0,0 @@
/**
* Classes for testing RDF JSON.
*/
package org.xbib.content.rdf.io.json;

View file

@ -1,29 +0,0 @@
package org.xbib.content.rdf.io.ntriple;
import static org.xbib.content.rdf.RdfContentFactory.ntripleBuilder;
import org.junit.jupiter.api.Test;
import org.xbib.content.rdf.RdfContentBuilder;
import org.xbib.content.rdf.StreamTester;
import java.io.IOException;
import java.io.InputStream;
public class NTripleReaderTest extends StreamTester {
@Test
public void testReader() throws Exception {
String filename = "list.nt";
InputStream in = getClass().getResourceAsStream(filename);
if (in == null) {
throw new IOException("file " + filename + " not found");
}
RdfContentBuilder<NTripleContentParams> builder = ntripleBuilder();
NTripleContentParser<NTripleContentParams> reader = new NTripleContentParser<>(in);
reader.setBuilder(builder);
reader.parse();
assertStream("", getClass().getResource("rdfxml.ttl").openStream(),
builder.streamInput());
}
}

View file

@ -1,4 +0,0 @@
/**
* Classes for testing RDF N-Triples.
*/
package org.xbib.content.rdf.io.ntriple;

View file

@ -1,4 +0,0 @@
/**
* Classes for testing RDF input/output.
*/
package org.xbib.content.rdf.io;

Some files were not shown because too many files have changed in this diff Show more