lift to module path based compiling and testing
This commit is contained in:
parent
6811c4a8e0
commit
2805b97026
337 changed files with 1712 additions and 1583 deletions
12
build.gradle
12
build.gradle
|
@ -1,18 +1,13 @@
|
|||
|
||||
plugins {
|
||||
id "checkstyle"
|
||||
id "pmd"
|
||||
id 'maven-publish'
|
||||
id 'signing'
|
||||
id "io.github.gradle-nexus.publish-plugin" version "2.0.0-rc-1"
|
||||
id "com.github.spotbugs" version "6.0.0-beta.3"
|
||||
id "org.cyclonedx.bom" version "1.7.4"
|
||||
id "org.xbib.gradle.plugin.asciidoctor" version "3.0.0"
|
||||
}
|
||||
|
||||
wrapper {
|
||||
gradleVersion = libs.versions.gradle.get()
|
||||
distributionType = Wrapper.DistributionType.ALL
|
||||
distributionType = Wrapper.DistributionType.BIN
|
||||
}
|
||||
|
||||
ext {
|
||||
|
@ -31,15 +26,10 @@ ext {
|
|||
}
|
||||
|
||||
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/test/junit5.gradle')
|
||||
apply from: rootProject.file('gradle/quality/checkstyle.gradle')
|
||||
apply from: rootProject.file('gradle/quality/pmd.gradle')
|
||||
//apply from: rootProject.file('gradle/quality/spotbugs.gradle')
|
||||
apply from: rootProject.file('gradle/publish/maven.gradle')
|
||||
}
|
||||
apply from: rootProject.file('gradle/publish/sonatype.gradle')
|
||||
apply from: rootProject.file('gradle/publish/forgejo.gradle')
|
||||
apply from: rootProject.file('gradle/quality/cyclonedx.gradle')
|
||||
|
|
11
content-csv/build.gradle
Normal file
11
content-csv/build.gradle
Normal 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
|
||||
}
|
6
content-csv/src/test/java/module-info.java
Normal file
6
content-csv/src/test/java/module-info.java
Normal 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;
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for testing CSV content.
|
||||
*/
|
||||
package org.xbib.content.csv;
|
|
@ -1,6 +1,8 @@
|
|||
package org.xbib.content.csv;
|
||||
package org.xbib.content.csv.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.csv.CSVGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
|
@ -1,7 +1,9 @@
|
|||
package org.xbib.content.csv;
|
||||
package org.xbib.content.csv.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.csv.CSVParser;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -10,16 +12,13 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class CSVParserTest {
|
||||
|
||||
@Test
|
||||
public void testCommaSeparated() throws IOException {
|
||||
InputStream in = getClass().getResourceAsStream("test.csv");
|
||||
InputStream inputStream = getClass().getResourceAsStream("test.csv");
|
||||
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);
|
||||
Iterator<List<String>> it = csvParser.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
@ -32,9 +31,9 @@ public class CSVParserTest {
|
|||
|
||||
@Test
|
||||
public void testLargeFile() throws IOException {
|
||||
InputStream in = getClass().getResourceAsStream("titleFile.csv");
|
||||
InputStream inputStream = getClass().getResourceAsStream("titleFile.csv");
|
||||
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);
|
||||
Iterator<List<String>> it = csvParser.iterator();
|
||||
while (it.hasNext()) {
|
|
@ -1,4 +1,4 @@
|
|||
package org.xbib.content.csv;
|
||||
package org.xbib.content.csv.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.io.BufferedReader;
|
|
@ -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>
|
Can't render this file because it is too large.
|
|
@ -1,5 +1,15 @@
|
|||
dependencies {
|
||||
api project(':content-core')
|
||||
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
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ public class JsonXContentGenerator extends AbstractXContentGenerator {
|
|||
|
||||
private final JsonGeneratorDelegate delegate;
|
||||
|
||||
@SuppressWarnings("this-escape")
|
||||
public JsonXContentGenerator(JsonGenerator generator) {
|
||||
this.delegate = new JsonGeneratorDelegate(generator);
|
||||
super.setGenerator(delegate);
|
||||
|
|
|
@ -53,7 +53,7 @@ public class JsonXContentParser extends AbstractXContentParser {
|
|||
|
||||
@Override
|
||||
public String currentName() throws IOException {
|
||||
return parser.getCurrentName();
|
||||
return parser.currentName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,11 +6,9 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
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.
|
||||
*
|
||||
* This class uses a {@link JsonNodeReader} to parse JSON inputs.
|
||||
*
|
||||
* @see JsonNodeReader
|
||||
|
@ -25,34 +23,28 @@ public final class JsonLoader {
|
|||
}
|
||||
|
||||
/**
|
||||
* Read a {@link com.fasterxml.jackson.databind.JsonNode} from a resource path.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Read a {@link com.fasterxml.jackson.databind.JsonNode} from an input stream.
|
||||
* This method throws an {@link java.io.IOException} if the resource does not
|
||||
* exist.
|
||||
*
|
||||
* @param classLoader the class loader
|
||||
* @param resource the path to the resource (must begin
|
||||
* with a {@code /})
|
||||
* @param inputStream the input stream
|
||||
* @return the JSON document at the resource
|
||||
* @throws IllegalArgumentException resource path does not begin with a
|
||||
* {@code /}
|
||||
* @throws java.io.IOException there was a problem loading the resource, or the JSON
|
||||
* document is invalid
|
||||
*/
|
||||
public static JsonNode fromResource(ClassLoader classLoader, final String resource)
|
||||
public static JsonNode fromResource(InputStream inputStream)
|
||||
throws IOException {
|
||||
URL url = JsonLoader.class.getResource(resource);
|
||||
InputStream in = url != null ? url.openStream() : classLoader.getResourceAsStream(resource);
|
||||
final JsonNode ret;
|
||||
try {
|
||||
ret = READER.fromInputStream(in);
|
||||
if (inputStream == null) {
|
||||
throw new IOException("not found");
|
||||
}
|
||||
ret = READER.fromInputStream(inputStream);
|
||||
} finally {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.xbib.content.json.jackson;
|
||||
|
||||
import com.fasterxml.jackson.core.ErrorReportConfiguration;
|
||||
import com.fasterxml.jackson.core.JsonLocation;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
@ -35,7 +36,7 @@ public final class JsonNodeReader {
|
|||
private final ObjectReader reader;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -64,13 +65,14 @@ public final class JsonNodeReader {
|
|||
/**
|
||||
* Read a JSON value from an {@link java.io.InputStream}.
|
||||
*
|
||||
* @param in the input stream
|
||||
* @param inputStream the input stream
|
||||
* @return the value
|
||||
* @throws java.io.IOException malformed input, or problem encountered when reading
|
||||
* from the stream
|
||||
*/
|
||||
public JsonNode fromInputStream(final InputStream in) throws IOException {
|
||||
try (JsonParser parser = reader.getFactory().createParser(in); MappingIterator<JsonNode> iterator = reader.readValues(parser)) {
|
||||
public JsonNode fromInputStream(final InputStream inputStream) throws IOException {
|
||||
try (JsonParser parser = reader.getFactory().createParser(inputStream);
|
||||
MappingIterator<JsonNode> iterator = reader.readValues(parser)) {
|
||||
return readNode(iterator);
|
||||
}
|
||||
}
|
||||
|
@ -78,13 +80,14 @@ public final class JsonNodeReader {
|
|||
/**
|
||||
* Read a JSON value from a {@link java.io.Reader}.
|
||||
*
|
||||
* @param r the reader
|
||||
* @param reader the reader
|
||||
* @return the value
|
||||
* @throws java.io.IOException malformed input, or problem encountered when reading
|
||||
* from the reader
|
||||
*/
|
||||
public JsonNode fromReader(final Reader r) throws IOException {
|
||||
try (JsonParser parser = reader.getFactory().createParser(r); MappingIterator<JsonNode> iterator = reader.readValues(parser)) {
|
||||
public JsonNode fromReader(final Reader reader) throws IOException {
|
||||
try (JsonParser parser = this.reader.getFactory().createParser(reader);
|
||||
MappingIterator<JsonNode> iterator = this.reader.readValues(parser)) {
|
||||
return readNode(iterator);
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +100,7 @@ public final class JsonNodeReader {
|
|||
|
||||
private JsonParseExceptionBuilder(final JsonParser jsonParser, final Object source) {
|
||||
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) {
|
||||
|
|
|
@ -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 tokenResolvers the list of reference token resolvers
|
||||
*/
|
||||
TreePointer(final T missing,
|
||||
final List<TokenResolver<T>> tokenResolvers) {
|
||||
protected TreePointer(final T missing, final List<TokenResolver<T>> tokenResolvers) {
|
||||
this.missing = missing;
|
||||
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
|
||||
*/
|
||||
protected TreePointer(final List<TokenResolver<T>> tokenResolvers) {
|
||||
TreePointer(final List<TokenResolver<T>> 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 NullPointerException input is null
|
||||
*/
|
||||
protected static List<ReferenceToken> tokensFromInput(final String input)
|
||||
public static List<ReferenceToken> tokensFromInput(final String input)
|
||||
throws JsonPointerException {
|
||||
String s = input;
|
||||
final List<ReferenceToken> ret = new ArrayList<>();
|
||||
|
|
17
content-json/src/test/java/module-info.java
Normal file
17
content-json/src/test/java/module-info.java
Normal 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;
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* Classes for testing JSON jackson.
|
||||
*/
|
||||
package org.xbib.content.json.jackson;
|
||||
|
|
@ -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.assertThrows;
|
|
@ -1,8 +1,10 @@
|
|||
package org.xbib.content.json;
|
||||
package org.xbib.content.json.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.XContentParser;
|
||||
import org.xbib.content.json.JsonXContent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
|
@ -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.mockito.Mockito.spy;
|
||||
|
@ -7,8 +7,9 @@ import com.fasterxml.jackson.core.JsonParseException;
|
|||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.json.jackson.JsonNodeReader;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -16,7 +17,6 @@ import java.io.Reader;
|
|||
import java.io.StringReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Disabled("mockito defunct")
|
||||
public final class JsonNodeReaderTest {
|
||||
|
||||
@Test
|
|
@ -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 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.ObjectNode;
|
||||
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.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final class JsonNumEqualsTest {
|
||||
|
||||
private static final JsonNodeFactory FACTORY = JsonNodeFactory.instance;
|
||||
|
@ -62,7 +62,7 @@ public final class JsonNumEqualsTest {
|
|||
private Iterator<Object[]> getInputs() throws IOException {
|
||||
final List<Object[]> list = new ArrayList<>();
|
||||
JsonNode reference;
|
||||
JsonNode testData = JsonLoader.fromResource(this.getClass().getClassLoader(), "testfile.json");
|
||||
JsonNode testData = JsonLoader.fromResource(getClass().getResourceAsStream("testfile.json"));
|
||||
for (final JsonNode element : testData) {
|
||||
reference = element.get("reference");
|
||||
for (final JsonNode node : element.get("equivalences")) {
|
|
@ -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.node.JsonNodeFactory;
|
||||
import org.xbib.content.json.jackson.JacksonUtils;
|
||||
import org.xbib.content.json.jackson.NodeType;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
|
@ -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.assertNull;
|
||||
|
@ -9,7 +9,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.json.jackson.JacksonUtils;
|
||||
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.List;
|
||||
|
|
@ -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 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.JsonLoader;
|
||||
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.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
@ -17,19 +19,14 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final class JsonPointerTest {
|
||||
|
||||
private static final String PACKAGE = JsonPointerTest.class.getPackage().getName().replace('.', '/');
|
||||
private final JsonNode testData;
|
||||
|
||||
private final JsonNode document;
|
||||
|
||||
public JsonPointerTest()
|
||||
throws IOException {
|
||||
testData = JsonLoader.fromResource(this.getClass().getClassLoader(),
|
||||
PACKAGE + "/jsonpointer.json");
|
||||
public JsonPointerTest() throws IOException {
|
||||
testData = JsonLoader.fromResource(getClass().getResourceAsStream("jsonpointer.json"));
|
||||
document = testData.get("document");
|
||||
}
|
||||
|
|
@ -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.assertNotEquals;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
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.List;
|
||||
|
|
@ -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.assertFalse;
|
||||
|
@ -13,14 +13,17 @@ import static org.mockito.Mockito.verify;
|
|||
import static org.mockito.Mockito.when;
|
||||
import com.fasterxml.jackson.core.TreeNode;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
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.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Disabled("mockito defunct")
|
||||
public final class TreePointerTest {
|
||||
|
||||
@Test
|
||||
|
@ -145,8 +148,7 @@ public final class TreePointerTest {
|
|||
assertTrue(dummy.isEmpty());
|
||||
}
|
||||
|
||||
private static final class DummyPointer
|
||||
extends TreePointer<TreeNode> {
|
||||
private static final class DummyPointer extends TreePointer<TreeNode> {
|
||||
private DummyPointer(final TreeNode missing, final List<TokenResolver<TreeNode>> tokenResolvers) {
|
||||
super(missing, tokenResolvers);
|
||||
}
|
|
@ -176,11 +176,11 @@ public final class Lang extends SubtagSet {
|
|||
Subtag region = getRegion();
|
||||
Subtag variant = getVariant();
|
||||
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) {
|
||||
return new Locale(primary.toString(), region.toString());
|
||||
return Locale.of(primary.toString(), region.toString());
|
||||
} else {
|
||||
return new Locale(primary.toString());
|
||||
return Locale.of(primary.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,3 +3,13 @@ dependencies {
|
|||
implementation project(':content-xml')
|
||||
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
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public interface RdfContent<P extends RdfContentParams> {
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class RdfContentBuilder<P extends RdfContentParams> implements RdfContent
|
|||
|
||||
private final RdfContentGenerator<P> generator;
|
||||
|
||||
private final OutputStream out;
|
||||
private final OutputStream outputStream;
|
||||
|
||||
private IRI subject;
|
||||
|
||||
|
@ -25,9 +25,9 @@ public class RdfContentBuilder<P extends RdfContentParams> implements RdfContent
|
|||
this(rdfContent, rdfParams, new BytesStreamOutput());
|
||||
}
|
||||
|
||||
public RdfContentBuilder(RdfContent<P> rdfContent, P rdfContentParams, OutputStream out) throws IOException {
|
||||
this.out = out;
|
||||
this.generator = rdfContent.createGenerator(out);
|
||||
public RdfContentBuilder(RdfContent<P> rdfContent, P rdfContentParams, OutputStream outputStream) throws IOException {
|
||||
this.outputStream = outputStream;
|
||||
this.generator = rdfContent.createGenerator(rdfContentParams, outputStream);
|
||||
this.generator.setParams(rdfContentParams);
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class RdfContentBuilder<P extends RdfContentParams> implements RdfContent
|
|||
|
||||
public BytesReference bytes() throws IOException {
|
||||
close();
|
||||
return ((BytesStreamOutput) out).bytes();
|
||||
return ((BytesStreamOutput) outputStream).bytes();
|
||||
}
|
||||
|
||||
public InputStream streamInput() throws IOException {
|
||||
|
|
|
@ -14,74 +14,42 @@ import org.xbib.content.rdf.io.xml.XmlContentParams;
|
|||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class 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 {
|
||||
return NTripleContent.contentBuilder(params);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<NTripleContentParams> ntripleBuilder(OutputStream out) throws IOException {
|
||||
return NTripleContent.contentBuilder(out, NTripleContentParams.N_TRIPLE_CONTENT_PARAMS);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<NTripleContentParams> ntripleBuilder(OutputStream out, NTripleContentParams params)
|
||||
public static RdfContentBuilder<NTripleContentParams> ntripleBuilder(NTripleContentParams params, OutputStream outputStream)
|
||||
throws IOException {
|
||||
return NTripleContent.contentBuilder(out, params);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder() throws IOException {
|
||||
return RdfXmlContent.contentBuilder(RdfXmlContentParams.RDF_XML_CONTENT_PARAMS);
|
||||
return NTripleContent.contentBuilder(params, outputStream);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder(RdfXmlContentParams params) throws IOException {
|
||||
return RdfXmlContent.contentBuilder(params);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder(OutputStream out) throws IOException {
|
||||
return RdfXmlContent.contentBuilder(out, RdfXmlContentParams.RDF_XML_CONTENT_PARAMS);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder(OutputStream out, RdfXmlContentParams params)
|
||||
public static RdfContentBuilder<RdfXmlContentParams> rdfXmlBuilder(RdfXmlContentParams params, OutputStream outputStream)
|
||||
throws IOException {
|
||||
return RdfXmlContent.contentBuilder(out, params);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<TurtleContentParams> turtleBuilder() throws IOException {
|
||||
return TurtleContent.contentBuilder(TurtleContentParams.TURTLE_CONTENT_PARAMS);
|
||||
return RdfXmlContent.contentBuilder(params, outputStream);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<TurtleContentParams> turtleBuilder(TurtleContentParams params) throws IOException {
|
||||
return TurtleContent.contentBuilder(params);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<TurtleContentParams> turtleBuilder(OutputStream out) throws IOException {
|
||||
return TurtleContent.contentBuilder(out, TurtleContentParams.TURTLE_CONTENT_PARAMS);
|
||||
}
|
||||
|
||||
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<TurtleContentParams> turtleBuilder(TurtleContentParams params, OutputStream outputStream) throws IOException {
|
||||
return TurtleContent.contentBuilder(params, outputStream);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<XmlContentParams> xmlBuilder(XmlContentParams params) throws IOException {
|
||||
return XmlContent.contentBuilder(params);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<JsonContentParams> jsonBuilder() throws IOException {
|
||||
return JsonContent.contentBuilder(JsonContentParams.JSON_CONTENT_PARAMS);
|
||||
public static RdfContentBuilder<JsonContentParams> jsonBuilder(JsonContentParams params) throws IOException {
|
||||
return JsonContent.contentBuilder(params);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,12 +28,12 @@ public class RdfXContent implements RdfContent<RdfXContentParams> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RdfContentGenerator<RdfXContentParams> createGenerator(OutputStream out) {
|
||||
return new RdfXContentGenerator<>(out);
|
||||
public RdfContentGenerator<RdfXContentParams> createGenerator(RdfXContentParams params, OutputStream outputStream) {
|
||||
return new RdfXContentGenerator<>(params, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RdfContentParser<RdfXContentParams> createParser(InputStream in) {
|
||||
public RdfContentParser<RdfXContentParams> createParser(RdfXContentParams params, InputStream inputStream) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,61 +11,34 @@ import org.xbib.content.rdf.io.xml.XmlContentParams;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class 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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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)
|
||||
throws IOException {
|
||||
return RouteRdfXContent.contentBuilder(params);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.util.List;
|
|||
*/
|
||||
public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfContentGenerator<P> {
|
||||
|
||||
protected final OutputStream out;
|
||||
protected final OutputStream outputStream;
|
||||
|
||||
protected Resource resource;
|
||||
|
||||
|
@ -29,8 +29,9 @@ public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfCon
|
|||
|
||||
private boolean flushed;
|
||||
|
||||
RdfXContentGenerator(OutputStream out) {
|
||||
this.out = out;
|
||||
RdfXContentGenerator(P params, OutputStream outputStream) {
|
||||
this.params = params;
|
||||
this.outputStream = outputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -105,7 +106,7 @@ public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfCon
|
|||
return;
|
||||
}
|
||||
flushed = true;
|
||||
builder = DefaultXContentBuilder.builder(JsonXContent.jsonContent(), out);
|
||||
builder = DefaultXContentBuilder.builder(JsonXContent.jsonContent(), outputStream);
|
||||
builder.startObject();
|
||||
build(this.resource);
|
||||
builder.endObject();
|
||||
|
|
|
@ -2,21 +2,12 @@ package org.xbib.content.rdf;
|
|||
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RdfXContentParams implements RdfContentParams {
|
||||
|
||||
public static final RdfXContentParams RDF_X_CONTENT_PARAMS = new RdfXContentParams();
|
||||
|
||||
private final IRINamespaceContext namespaceContext;
|
||||
|
||||
private RdfXContentGenerator<RdfXContentParams> generator;
|
||||
|
||||
public RdfXContentParams() {
|
||||
this.namespaceContext = IRINamespaceContext.newInstance();
|
||||
}
|
||||
|
||||
public RdfXContentParams(IRINamespaceContext namespaceContext) {
|
||||
this.namespaceContext = namespaceContext;
|
||||
}
|
||||
|
|
|
@ -4,9 +4,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RouteRdfXContent implements RdfContent<RouteRdfXContentParams> {
|
||||
|
||||
private static final RouteRdfXContent ROUTE_RDF_X_CONTENT = new RouteRdfXContent();
|
||||
|
@ -28,18 +25,15 @@ public class RouteRdfXContent implements RdfContent<RouteRdfXContentParams> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RdfContentGenerator<RouteRdfXContentParams> createGenerator(OutputStream out) {
|
||||
return new RouteRdfXContentGenerator<>(out);
|
||||
public RdfContentGenerator<RouteRdfXContentParams> createGenerator(RouteRdfXContentParams params, OutputStream outputStream) {
|
||||
return new RouteRdfXContentGenerator<>(params, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RdfContentParser<RouteRdfXContentParams> createParser(InputStream in) {
|
||||
public RdfContentParser<RouteRdfXContentParams> createParser(RouteRdfXContentParams params, InputStream inputStream) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface RouteHandler {
|
||||
void complete(String content, RouteRdfXContentParams params) throws IOException;
|
||||
|
|
|
@ -13,8 +13,8 @@ public class RouteRdfXContentGenerator<R extends RouteRdfXContentParams> extends
|
|||
|
||||
private boolean flushed;
|
||||
|
||||
RouteRdfXContentGenerator(OutputStream out) {
|
||||
super(out);
|
||||
RouteRdfXContentGenerator(R params, OutputStream outputStream) {
|
||||
super(params, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,13 +2,8 @@ package org.xbib.content.rdf;
|
|||
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RouteRdfXContentParams extends RdfXContentParams {
|
||||
|
||||
public static final RouteRdfXContentParams ROUTE_RDF_X_CONTENT_PARAMS = new RouteRdfXContentParams();
|
||||
|
||||
private String index;
|
||||
|
||||
private String type;
|
||||
|
@ -23,20 +18,6 @@ public class RouteRdfXContentParams extends RdfXContentParams {
|
|||
|
||||
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) {
|
||||
super(namespaceContext);
|
||||
this.index = index;
|
||||
|
|
|
@ -14,16 +14,14 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DefaultRdfGraph implements RdfGraph<RdfGraphParams> {
|
||||
|
||||
private RdfGraphParams params = DefaultRdfGraphParams.DEFAULT_PARAMS;
|
||||
private RdfGraphParams params;
|
||||
|
||||
private final Map<IRI, Resource> resources = new LinkedHashMap<>();
|
||||
|
||||
public DefaultRdfGraph() {
|
||||
public DefaultRdfGraph(RdfGraphParams params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,17 +3,14 @@ package org.xbib.content.rdf.internal;
|
|||
import org.xbib.content.rdf.RdfGraphParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DefaultRdfGraphParams implements RdfGraphParams {
|
||||
|
||||
public static final DefaultRdfGraphParams DEFAULT_PARAMS = new DefaultRdfGraphParams();
|
||||
private final IRINamespaceContext namespaceContext;
|
||||
|
||||
private final boolean writeNamespaceContext;
|
||||
|
||||
public DefaultRdfGraphParams() {
|
||||
this.namespaceContext = IRINamespaceContext.newInstance();
|
||||
public DefaultRdfGraphParams(IRINamespaceContext namespaceContext) {
|
||||
this.namespaceContext = namespaceContext;
|
||||
this.writeNamespaceContext = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,11 +45,13 @@ public class DefaultResource implements Resource, Comparable<Resource>, XSDResou
|
|||
this(iri, new LinkedHashMultiMap<>(), new LinkedHashMap<>());
|
||||
}
|
||||
|
||||
@SuppressWarnings("this-escape")
|
||||
public DefaultResource(DefaultResource resource) {
|
||||
this(resource.id(), resource.getAttributes(), resource.getChildren());
|
||||
this.deleted = resource.isDeleted();
|
||||
}
|
||||
|
||||
@SuppressWarnings("this-escape")
|
||||
public DefaultResource(IRI iri, MultiMap<IRI, Node> attributes, Map<IRI, Resource> children) {
|
||||
setId(iri);
|
||||
this.attributes = attributes;
|
||||
|
|
|
@ -10,9 +10,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JsonContent implements RdfContent<JsonContentParams> {
|
||||
|
||||
private static final JsonContent JSON_CONTENT = new JsonContent();
|
||||
|
@ -39,12 +36,12 @@ public class JsonContent implements RdfContent<JsonContentParams> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RdfContentGenerator<JsonContentParams> createGenerator(OutputStream out) throws IOException {
|
||||
return new JsonContentGenerator(out);
|
||||
public RdfContentGenerator<JsonContentParams> createGenerator(JsonContentParams params, OutputStream outputStream) throws IOException {
|
||||
return new JsonContentGenerator(params, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RdfContentParser<JsonContentParams> createParser(InputStream in) throws IOException {
|
||||
return new JsonContentParser<>(in);
|
||||
public RdfContentParser<JsonContentParams> createParser(JsonContentParams params, InputStream inputStream) throws IOException {
|
||||
return new JsonContentParser<>(params, inputStream);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,13 +24,14 @@ public class JsonContentGenerator implements RdfContentGenerator<JsonContentPara
|
|||
|
||||
private Resource resource;
|
||||
|
||||
private JsonContentParams params = JsonContentParams.JSON_CONTENT_PARAMS;
|
||||
private JsonContentParams params;
|
||||
|
||||
JsonContentGenerator(OutputStream out) {
|
||||
this(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
||||
JsonContentGenerator(JsonContentParams params, OutputStream out) {
|
||||
this(params, new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
JsonContentGenerator(Writer writer) {
|
||||
JsonContentGenerator(JsonContentParams params, Writer writer) {
|
||||
this.params = params;
|
||||
this.writer = writer;
|
||||
this.nsWritten = false;
|
||||
this.resource = new DefaultAnonymousResource();
|
||||
|
|
|
@ -4,13 +4,8 @@ import org.xbib.content.rdf.RdfContentParams;
|
|||
import org.xbib.content.rdf.io.xml.XmlContentParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JsonContentParams extends XmlContentParams implements RdfContentParams {
|
||||
|
||||
public static final JsonContentParams JSON_CONTENT_PARAMS = new JsonContentParams(NAMESPACE_CONTEXT);
|
||||
|
||||
public JsonContentParams(IRINamespaceContext namespaceContext) {
|
||||
super(namespaceContext);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import javax.xml.namespace.QName;
|
|||
*/
|
||||
public class JsonContentParser<R extends RdfContentParams> implements RdfContentParser<R> {
|
||||
|
||||
private final JsonContentParams params;
|
||||
|
||||
private final Reader reader;
|
||||
|
||||
private XmlHandler<R> handler;
|
||||
|
@ -31,11 +33,12 @@ public class JsonContentParser<R extends RdfContentParams> implements RdfContent
|
|||
|
||||
private QName root;
|
||||
|
||||
public JsonContentParser(InputStream in) throws IOException {
|
||||
this(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
public JsonContentParser(JsonContentParams params, InputStream inputStream) throws IOException {
|
||||
this(params, new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public JsonContentParser(Reader reader) {
|
||||
public JsonContentParser(JsonContentParams params, Reader reader) {
|
||||
this.params = params;
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,11 @@ package org.xbib.content.rdf.io.json;
|
|||
|
||||
import org.xbib.content.rdf.io.xml.AbstractXmlResourceHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public abstract class JsonResourceHandler extends AbstractXmlResourceHandler<JsonContentParams> {
|
||||
|
||||
@SuppressWarnings("this-escape")
|
||||
public JsonResourceHandler(JsonContentParams params) {
|
||||
super(params);
|
||||
super.setDefaultNamespace("", "http://json.org");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for RDF JSON.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.json;
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for RDF N-Quads.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.nquads;
|
|
@ -10,9 +10,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class NTripleContent implements RdfContent<NTripleContentParams> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<NTripleContentParams> contentBuilder(OutputStream out, NTripleContentParams params)
|
||||
public static RdfContentBuilder<NTripleContentParams> contentBuilder(NTripleContentParams params, OutputStream outputStream)
|
||||
throws IOException {
|
||||
return new RdfContentBuilder<>(N_TRIPLE_CONTENT, params, out);
|
||||
return new RdfContentBuilder<>(N_TRIPLE_CONTENT, params, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,12 +36,12 @@ public class NTripleContent implements RdfContent<NTripleContentParams> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RdfContentGenerator<NTripleContentParams> createGenerator(OutputStream out) throws IOException {
|
||||
return new NTripleContentGenerator(out);
|
||||
public RdfContentGenerator<NTripleContentParams> createGenerator(NTripleContentParams params, OutputStream outputStream) throws IOException {
|
||||
return new NTripleContentGenerator(params, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RdfContentParser<NTripleContentParams> createParser(InputStream in) throws IOException {
|
||||
return new NTripleContentParser<>(in);
|
||||
public RdfContentParser<NTripleContentParams> createParser(NTripleContentParams params, InputStream inputStream) throws IOException {
|
||||
return new NTripleContentParser<>(params, inputStream);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,13 +24,14 @@ public class NTripleContentGenerator
|
|||
|
||||
private final Writer writer;
|
||||
|
||||
private NTripleContentParams params = NTripleContentParams.N_TRIPLE_CONTENT_PARAMS;
|
||||
private NTripleContentParams params;
|
||||
|
||||
NTripleContentGenerator(OutputStream out) throws IOException {
|
||||
this(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
||||
NTripleContentGenerator(NTripleContentParams params, OutputStream out) throws IOException {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,18 +3,10 @@ package org.xbib.content.rdf.io.ntriple;
|
|||
import org.xbib.content.rdf.RdfContentParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class NTripleContentParams implements RdfContentParams {
|
||||
|
||||
public static final NTripleContentParams N_TRIPLE_CONTENT_PARAMS = new NTripleContentParams();
|
||||
private final IRINamespaceContext namespaceContext;
|
||||
|
||||
public NTripleContentParams() {
|
||||
this.namespaceContext = IRINamespaceContext.newInstance();
|
||||
}
|
||||
|
||||
public NTripleContentParams(IRINamespaceContext namespaceContext) {
|
||||
this.namespaceContext = namespaceContext;
|
||||
}
|
||||
|
|
|
@ -52,11 +52,14 @@ public class NTripleContentParser<R extends RdfContentParams> implements RdfCont
|
|||
|
||||
private RdfContentBuilder<R> builder;
|
||||
|
||||
public NTripleContentParser(InputStream in) throws IOException {
|
||||
this(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
private NTripleContentParams params;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for RDF N-Triples.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.ntriple;
|
|
@ -10,9 +10,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RdfXmlContent implements RdfContent<RdfXmlContentParams> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public static RdfContentBuilder<RdfXmlContentParams> contentBuilder(OutputStream out, RdfXmlContentParams params)
|
||||
public static RdfContentBuilder<RdfXmlContentParams> contentBuilder(RdfXmlContentParams params, OutputStream outputStream)
|
||||
throws IOException {
|
||||
return new RdfContentBuilder<>(RDF_XML_CONTENT, params, out);
|
||||
return new RdfContentBuilder<>(RDF_XML_CONTENT, params, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,12 +36,12 @@ public class RdfXmlContent implements RdfContent<RdfXmlContentParams> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RdfContentGenerator<RdfXmlContentParams> createGenerator(OutputStream os) throws IOException {
|
||||
return new RdfXmlContentGenerator(os);
|
||||
public RdfContentGenerator<RdfXmlContentParams> createGenerator(RdfXmlContentParams params, OutputStream outputStream) throws IOException {
|
||||
return new RdfXmlContentGenerator(params, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RdfContentParser<RdfXmlContentParams> createParser(InputStream in) throws IOException {
|
||||
return new RdfXmlContentParser<>(in);
|
||||
public RdfContentParser<RdfXmlContentParams> createParser(RdfXmlContentParams params, InputStream inputStream) throws IOException {
|
||||
return new RdfXmlContentParser<>(params, inputStream);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,9 +19,6 @@ import java.io.Writer;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* RDF/XML writer.
|
||||
*/
|
||||
public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContentParams>, Flushable, RdfConstants {
|
||||
|
||||
private final Writer writer;
|
||||
|
@ -34,18 +31,18 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
|
|||
|
||||
private Resource resource;
|
||||
|
||||
private RdfXmlContentParams params = RdfXmlContentParams.RDF_XML_CONTENT_PARAMS;
|
||||
private RdfXmlContentParams params;
|
||||
|
||||
public RdfXmlContentGenerator(OutputStream out) throws IOException {
|
||||
this(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
||||
public RdfXmlContentGenerator(RdfXmlContentParams params, OutputStream outputStream) throws IOException {
|
||||
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.resource = new DefaultAnonymousResource();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
writer.flush();
|
||||
|
|
|
@ -3,18 +3,10 @@ package org.xbib.content.rdf.io.rdfxml;
|
|||
import org.xbib.content.rdf.RdfContentParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RdfXmlContentParams implements RdfContentParams {
|
||||
|
||||
public static final RdfXmlContentParams RDF_XML_CONTENT_PARAMS = new RdfXmlContentParams();
|
||||
private final IRINamespaceContext namespaceContext;
|
||||
|
||||
public RdfXmlContentParams() {
|
||||
this.namespaceContext = IRINamespaceContext.newInstance();
|
||||
}
|
||||
|
||||
public RdfXmlContentParams(IRINamespaceContext namespaceContext) {
|
||||
this.namespaceContext = namespaceContext;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ import javax.xml.parsers.SAXParserFactory;
|
|||
*/
|
||||
public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConstants, RdfContentParser<R> {
|
||||
|
||||
private R params;
|
||||
|
||||
private final Reader reader;
|
||||
|
||||
private final Resource resource = new DefaultAnonymousResource();
|
||||
|
@ -69,11 +71,12 @@ public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConst
|
|||
// counter for blank node generation
|
||||
private int bn = 0;
|
||||
|
||||
public RdfXmlContentParser(InputStream inputStream) {
|
||||
this(createReader(inputStream));
|
||||
public RdfXmlContentParser(R params, InputStream inputStream) {
|
||||
this(params, createReader(inputStream));
|
||||
}
|
||||
|
||||
public RdfXmlContentParser(Reader reader) {
|
||||
public RdfXmlContentParser(R params, Reader reader) {
|
||||
this.params = params;
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for RDF XML.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.rdfxml;
|
|
@ -3,11 +3,10 @@ package org.xbib.content.rdf.io.source;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
/**
|
||||
*/
|
||||
public abstract class BaseStreamProcessor {
|
||||
|
||||
public BaseStreamProcessor() {
|
||||
|
@ -39,7 +38,7 @@ public abstract class BaseStreamProcessor {
|
|||
* @throws IOException if process fails
|
||||
*/
|
||||
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();
|
||||
String mimeType = urlConnection.getContentType();
|
||||
try (InputStream inputStream = urlConnection.getInputStream()) {
|
||||
|
|
|
@ -28,9 +28,9 @@ public class TurtleContent implements RdfContent<TurtleContentParams> {
|
|||
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 {
|
||||
return new RdfContentBuilder<>(TURTLE_CONTENT, params, out);
|
||||
return new RdfContentBuilder<>(TURTLE_CONTENT, params, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,13 +39,13 @@ public class TurtleContent implements RdfContent<TurtleContentParams> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RdfContentGenerator<TurtleContentParams> createGenerator(OutputStream outputStream) throws IOException {
|
||||
return new TurtleContentGenerator(outputStream);
|
||||
public RdfContentGenerator<TurtleContentParams> createGenerator(TurtleContentParams params, OutputStream outputStream) throws IOException {
|
||||
return new TurtleContentGenerator(params, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RdfContentParser<TurtleContentParams> createParser(InputStream inputStream) throws IOException {
|
||||
return new TurtleContentParser<>(inputStream);
|
||||
public RdfContentParser<TurtleContentParams> createParser(TurtleContentParams params, InputStream inputStream) throws IOException {
|
||||
return new TurtleContentParser<>(params, inputStream);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,13 +53,14 @@ public class TurtleContentGenerator implements RdfContentGenerator<TurtleContent
|
|||
|
||||
private boolean closed;
|
||||
|
||||
private TurtleContentParams params = TurtleContentParams.TURTLE_CONTENT_PARAMS;
|
||||
private TurtleContentParams params;
|
||||
|
||||
TurtleContentGenerator(OutputStream out) throws IOException {
|
||||
this(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
||||
public TurtleContentGenerator(TurtleContentParams params, OutputStream outputStream) throws IOException {
|
||||
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.resource = new DefaultAnonymousResource();
|
||||
this.nsWritten = false;
|
||||
|
|
|
@ -3,19 +3,11 @@ package org.xbib.content.rdf.io.turtle;
|
|||
import org.xbib.content.rdf.RdfContentParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TurtleContentParams implements RdfContentParams {
|
||||
|
||||
public static final TurtleContentParams TURTLE_CONTENT_PARAMS = new TurtleContentParams();
|
||||
private final IRINamespaceContext namespaceContext;
|
||||
private final boolean writeNamespaceContext;
|
||||
|
||||
public TurtleContentParams() {
|
||||
this.namespaceContext = IRINamespaceContext.newInstance();
|
||||
this.writeNamespaceContext = true;
|
||||
}
|
||||
private final boolean writeNamespaceContext;
|
||||
|
||||
public TurtleContentParams(IRINamespaceContext namespaceContext, boolean writeNamespaceContext) {
|
||||
this.namespaceContext = namespaceContext;
|
||||
|
|
|
@ -40,6 +40,8 @@ import java.util.LinkedList;
|
|||
*/
|
||||
public class TurtleContentParser<R extends RdfContentParams> implements RdfContentParser<R> {
|
||||
|
||||
private TurtleContentParams params;
|
||||
|
||||
private final Resource resource = new DefaultAnonymousResource();
|
||||
|
||||
private final HashMap<String, Node> bnodes = new HashMap<>();
|
||||
|
@ -92,11 +94,12 @@ public class TurtleContentParser<R extends RdfContentParams> implements RdfConte
|
|||
*/
|
||||
private NamespaceContext context;
|
||||
|
||||
public TurtleContentParser(InputStream in) throws IOException {
|
||||
this(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
public TurtleContentParser(TurtleContentParams params, InputStream inputStream) throws IOException {
|
||||
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.context = XmlNamespaceContext.newInstance();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import javax.xml.namespace.QName;
|
|||
public abstract class AbstractXmlHandler<P extends RdfContentParams>
|
||||
extends DefaultHandler implements XmlHandler<P> {
|
||||
|
||||
protected final RdfContentParams params;
|
||||
protected final P params;
|
||||
|
||||
protected final StringBuilder content;
|
||||
|
||||
|
@ -39,14 +39,14 @@ public abstract class AbstractXmlHandler<P extends RdfContentParams>
|
|||
|
||||
private int lastlevel;
|
||||
|
||||
public AbstractXmlHandler(RdfContentParams params) {
|
||||
public AbstractXmlHandler(P params) {
|
||||
this.params = params;
|
||||
this.content = new StringBuilder();
|
||||
this.parents = new LinkedList<>();
|
||||
this.resource = new DefaultAnonymousResource();
|
||||
}
|
||||
|
||||
public RdfContentParams getParams() {
|
||||
public P getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ public abstract class AbstractXmlResourceHandler<P extends RdfContentParams>
|
|||
|
||||
protected final LinkedList<Resource> stack = new LinkedList<>();
|
||||
|
||||
public AbstractXmlResourceHandler(RdfContentParams params) {
|
||||
public AbstractXmlResourceHandler(P params) {
|
||||
super(params);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class XmlContent implements RdfContent<XmlContentParams> {
|
||||
|
||||
private static final XmlContent XML_CONTENT = new XmlContent();
|
||||
|
@ -39,12 +36,12 @@ public class XmlContent implements RdfContent<XmlContentParams> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RdfContentGenerator<XmlContentParams> createGenerator(OutputStream outputStream) throws IOException {
|
||||
return new XmlContentGenerator(outputStream);
|
||||
public RdfContentGenerator<XmlContentParams> createGenerator(XmlContentParams params, OutputStream outputStream) throws IOException {
|
||||
return new XmlContentGenerator(params, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RdfContentParser<XmlContentParams> createParser(InputStream inputStream) throws IOException {
|
||||
return new XmlContentParser<>(inputStream);
|
||||
public RdfContentParser<XmlContentParams> createParser(XmlContentParams params, InputStream inputStream) throws IOException {
|
||||
return new XmlContentParser<>(params, inputStream);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,13 +36,14 @@ public class XmlContentGenerator implements RdfContentGenerator<XmlContentParams
|
|||
|
||||
private Resource resource;
|
||||
|
||||
private XmlContentParams params = XmlContentParams.XML_CONTENT_PARAMS;
|
||||
private XmlContentParams params;
|
||||
|
||||
public XmlContentGenerator(OutputStream out) {
|
||||
this(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
||||
public XmlContentGenerator(XmlContentParams params, OutputStream outputStream) {
|
||||
this(params, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public XmlContentGenerator(Writer writer) {
|
||||
public XmlContentGenerator(XmlContentParams params, Writer writer) {
|
||||
this.params = params;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,8 @@ package org.xbib.content.rdf.io.xml;
|
|||
import org.xbib.content.rdf.RdfContentParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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;
|
||||
|
||||
public XmlContentParams(IRINamespaceContext namespaceContext) {
|
||||
|
|
|
@ -25,6 +25,8 @@ import javax.xml.parsers.SAXParserFactory;
|
|||
*/
|
||||
public class XmlContentParser<P extends RdfContentParams> implements RdfContentParser<P> {
|
||||
|
||||
private final P params;
|
||||
|
||||
private final Reader reader;
|
||||
|
||||
private RdfContentBuilder<P> builder;
|
||||
|
@ -35,11 +37,12 @@ public class XmlContentParser<P extends RdfContentParams> implements RdfContentP
|
|||
|
||||
private boolean validate = false;
|
||||
|
||||
public XmlContentParser(InputStream in) {
|
||||
this(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
public XmlContentParser(P params, InputStream inputStream) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.Collection;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -20,14 +19,6 @@ public class LinkedHashMultiMap<K, V> implements MultiMap<K, V> {
|
|||
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
|
||||
public int size() {
|
||||
return map.size();
|
||||
|
@ -98,7 +89,7 @@ public class LinkedHashMultiMap<K, V> implements MultiMap<K, V> {
|
|||
|
||||
@Override
|
||||
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
|
||||
|
|
17
content-rdf/src/test/java/module-info.java
Normal file
17
content-rdf/src/test/java/module-info.java
Normal 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;
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for testing internal RDF.
|
||||
*/
|
||||
package org.xbib.content.rdf.internal;
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for testing RDF JSON.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.json;
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for testing RDF N-Triples.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.ntriple;
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for testing RDF input/output.
|
||||
*/
|
||||
package org.xbib.content.rdf.io;
|
|
@ -1,54 +0,0 @@
|
|||
package org.xbib.content.rdf.io.rdfxml;
|
||||
|
||||
import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.RdfContentFactory;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContentParams;
|
||||
import org.xbib.content.rdf.io.turtle.TurtleContentParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class GNDRdfXmlReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testGNDfromRdfXmltoTurtle() throws Exception {
|
||||
String filename = "GND.rdf";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
TurtleContentParams params = new TurtleContentParams(IRINamespaceContext.newInstance(), false);
|
||||
RdfXmlContentParser<TurtleContentParams> reader = new RdfXmlContentParser<>(in);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
reader.setRdfContentBuilderProvider(() -> turtleBuilder(params));
|
||||
reader.setRdfContentBuilderHandler(builder -> sb.append(builder.string()));
|
||||
reader.parse();
|
||||
assertStream("gnd.ttl", getClass().getResourceAsStream("gnd.ttl"), sb.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnotherGNDfromRdfXmltoTurtle() throws Exception {
|
||||
String filename = "GND.rdf";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
TurtleContentParams params = new TurtleContentParams(IRINamespaceContext.newInstance(), false);
|
||||
RdfXmlContentParser<TurtleContentParams> reader = new RdfXmlContentParser<>(in);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
reader.setRdfContentBuilderProvider(() -> turtleBuilder(params));
|
||||
reader.setRdfContentBuilderHandler(builder -> sb.append(builder.string()));
|
||||
reader.parse();
|
||||
assertStream("gnd.ttl", getClass().getResourceAsStream("gnd.ttl"), sb.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGNDtoNtriple() throws Exception {
|
||||
String filename = "GND.rdf";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
RdfXmlContentParser<NTripleContentParams> reader = new RdfXmlContentParser<>(in);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
reader.setRdfContentBuilderProvider(RdfContentFactory::ntripleBuilder);
|
||||
reader.setRdfContentBuilderHandler(builder -> sb.append(builder.string()));
|
||||
reader.parse();
|
||||
assertStream("GND.nt", getClass().getResourceAsStream("GND.nt"), sb.toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package org.xbib.content.rdf.io.rdfxml;
|
||||
|
||||
import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.internal.DefaultAnonymousResource;
|
||||
import org.xbib.content.rdf.io.turtle.TurtleContentParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class RdfXmlReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testReader() throws Exception {
|
||||
String filename = "118540238.xml";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
DefaultAnonymousResource.reset();
|
||||
TurtleContentParams params = new TurtleContentParams(IRINamespaceContext.getInstance(), false);
|
||||
RdfXmlContentParser<TurtleContentParams> reader = new RdfXmlContentParser<>(in);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
reader.setRdfContentBuilderProvider(() -> turtleBuilder(params));
|
||||
reader.setRdfContentBuilderHandler(builder -> sb.append(builder.string()));
|
||||
reader.parse();
|
||||
assertStream("118540238.ttl", getClass().getResourceAsStream("118540238.ttl"), sb.toString());
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package org.xbib.content.rdf.io.rdfxml;
|
||||
|
||||
import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.io.turtle.TurtleContentParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class VIAFRdfXmlReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testVIAF() throws Exception {
|
||||
InputStream in = getClass().getResource("VIAF.rdf").openStream();
|
||||
if (in == null) {
|
||||
throw new IOException("VIAF.rdf not found");
|
||||
}
|
||||
TurtleContentParams params = new TurtleContentParams(IRINamespaceContext.newInstance(), false);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
new RdfXmlContentParser<TurtleContentParams>(in)
|
||||
.setRdfContentBuilderProvider(() -> turtleBuilder(params))
|
||||
.setRdfContentBuilderHandler(builder -> sb.append(builder.string()))
|
||||
.parse();
|
||||
assertStream("viaf.ttl", getClass().getResource("viaf.ttl").openStream(), sb.toString());
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for testing RDF XML.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.rdfxml;
|
|
@ -1,30 +0,0 @@
|
|||
package org.xbib.content.rdf.io.turtle;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.RdfContentFactory;
|
||||
import org.xbib.content.resource.IRI;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TurtleConformanceTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void conformance() throws Exception {
|
||||
for (int n = 0; n < 30; n++) {
|
||||
String testNum = String.format("%02d", n);
|
||||
InputStream in = getClass().getResource("/turtle/test-" + testNum + ".ttl").openStream();
|
||||
TurtleContentParser<TurtleContentParams> turtleParser = new TurtleContentParser<TurtleContentParams>(in)
|
||||
.setBaseIRI(IRI.create("http://example/base/"));
|
||||
turtleParser.setRdfContentBuilderProvider(RdfContentFactory::turtleBuilder);
|
||||
turtleParser.setRdfContentBuilderHandler(b -> {
|
||||
//logger.log(Level.INFO, MessageFormat.format("turtle test {0}", b.string()));
|
||||
});
|
||||
turtleParser.parse();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for testing RDF Turtle.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.turtle;
|
|
@ -1,217 +0,0 @@
|
|||
package org.xbib.content.rdf.io.xml;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.RdfContentBuilder;
|
||||
import org.xbib.content.rdf.Resource;
|
||||
import org.xbib.content.rdf.Triple;
|
||||
import org.xbib.content.rdf.internal.DefaultAnonymousResource;
|
||||
import org.xbib.content.rdf.internal.DefaultResource;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContent;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContentParams;
|
||||
import org.xbib.content.rdf.io.turtle.TurtleContentParams;
|
||||
import org.xbib.content.resource.IRI;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
import org.xbib.content.resource.NamespaceContext;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
import org.xbib.net.PercentEncoders;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class XmlReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testOAIDC() throws Exception {
|
||||
String filename = "oro-eprint-25656.xml";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
if (in == null) {
|
||||
throw new IOException("file " + filename + " not found");
|
||||
}
|
||||
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance();
|
||||
namespaceContext.addNamespace("oaidc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
|
||||
namespaceContext.addNamespace("dc", "http://purl.org/dc/elements/1.1/");
|
||||
|
||||
XmlContentParams params = new XmlContentParams(namespaceContext);
|
||||
XmlHandler<TurtleContentParams> xmlHandler = new AbstractXmlResourceHandler<>(params) {
|
||||
|
||||
@Override
|
||||
public boolean isResourceDelimiter(QName name) {
|
||||
return "oai_dc".equals(name.getLocalPart());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void identify(QName name, String value, IRI identifier) {
|
||||
if ("identifier".equals(name.getLocalPart()) && DefaultResource.isBlank(getResource())) {
|
||||
try {
|
||||
// make sure we can build an opaque IRI, whatever is out there
|
||||
getResource().setId(IRI.create("id:" +
|
||||
PercentEncoders.getRegNameEncoder(StandardCharsets.UTF_8).encode(value)));
|
||||
} catch (IOException e) {
|
||||
// swallow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skip(QName name) {
|
||||
// skip dc:dc element
|
||||
return "dc".equals(name.getLocalPart());
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlHandler<TurtleContentParams> setNamespaceContext(NamespaceContext namespaceContext) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRINamespaceContext getNamespaceContext() {
|
||||
return namespaceContext;
|
||||
}
|
||||
};
|
||||
TurtleContentParams turtleParams = new TurtleContentParams(namespaceContext, true);
|
||||
RdfContentBuilder<TurtleContentParams> builder = turtleBuilder(turtleParams);
|
||||
xmlHandler.setBuilder(builder);
|
||||
new XmlContentParser<TurtleContentParams>(in)
|
||||
.setHandler(xmlHandler)
|
||||
.parse();
|
||||
assertStream("dc.ttl", getClass().getResource("dc.ttl").openStream(),
|
||||
builder.streamInput());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlArray() throws Exception {
|
||||
String filename = "array.xml";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
if (in == null) {
|
||||
throw new IOException("file " + filename + " not found");
|
||||
}
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance();
|
||||
XmlContentParams params = new XmlContentParams(namespaceContext);
|
||||
AbstractXmlHandler<NTripleContentParams> xmlHandler = new AbstractXmlResourceHandler<>(params) {
|
||||
|
||||
@Override
|
||||
public boolean isResourceDelimiter(QName name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void identify(QName name, String value, IRI identifier) {
|
||||
getResource().setId(IRI.create("id:1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skip(QName name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlHandler<NTripleContentParams> setNamespaceContext(NamespaceContext namespaceContext) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRINamespaceContext getNamespaceContext() {
|
||||
return namespaceContext;
|
||||
}
|
||||
};
|
||||
|
||||
MyBuilder builder = new MyBuilder();
|
||||
xmlHandler.setDefaultNamespace("xml", "http://xmltest")
|
||||
.setBuilder(builder);
|
||||
DefaultAnonymousResource.reset();
|
||||
new XmlContentParser<NTripleContentParams>(in)
|
||||
.setHandler(xmlHandler)
|
||||
.parse();
|
||||
assertEquals("[id:1 xml:dates _:b2, _:b2 xml:date 2001, _:b2 xml:date 2002, _:b2 xml:date 2003]",
|
||||
builder.getTriples().toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlAttribute() throws Exception {
|
||||
String filename = "attribute.xml";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
if (in == null) {
|
||||
throw new IOException("file " + filename + " not found");
|
||||
}
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance();
|
||||
XmlContentParams params = new XmlContentParams(namespaceContext);
|
||||
AbstractXmlHandler<NTripleContentParams> xmlHandler = new AbstractXmlResourceHandler<>(params) {
|
||||
@Override
|
||||
public boolean isResourceDelimiter(QName name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void identify(QName name, String value, IRI identifier) {
|
||||
getResource().setId(IRI.create("id:1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skip(QName name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlHandler<NTripleContentParams> setNamespaceContext(NamespaceContext namespaceContext) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRINamespaceContext getNamespaceContext() {
|
||||
return namespaceContext;
|
||||
}
|
||||
};
|
||||
|
||||
MyBuilder builder = new MyBuilder();
|
||||
|
||||
xmlHandler.setDefaultNamespace("xml", "http://localhost")
|
||||
.setBuilder(builder);
|
||||
DefaultAnonymousResource.reset();
|
||||
new XmlContentParser<NTripleContentParams>(in)
|
||||
.setHandler(xmlHandler)
|
||||
.parse();
|
||||
assertEquals("[id:1 xml:dates _:b2, _:b2 xml:date _:b3, _:b3 xml:@href 1, _:b2 xml:date _:b5, "
|
||||
+ "_:b5 xml:@href 2, _:b2 xml:date _:b7, _:b7 xml:@href 3, _:b2 xml:date _:b9, _:b9 xml:hello World]",
|
||||
builder.getTriples().toString()
|
||||
);
|
||||
}
|
||||
|
||||
private static class MyBuilder extends RdfContentBuilder<NTripleContentParams> {
|
||||
|
||||
final List<Triple> triples = new LinkedList<>();
|
||||
|
||||
MyBuilder() throws IOException {
|
||||
super(NTripleContent.nTripleContent(), NTripleContentParams.N_TRIPLE_CONTENT_PARAMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyBuilder receive(Triple triple) {
|
||||
triples.add(triple);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyBuilder receive(Resource resource) throws IOException {
|
||||
triples.addAll(resource.triples());
|
||||
return this;
|
||||
}
|
||||
|
||||
List<Triple> getTriples() {
|
||||
return triples;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for testing XML to RDF.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.xml;
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* Classes for testing RDF content.
|
||||
*/
|
||||
package org.xbib.content.rdf;
|
|
@ -1,12 +1,16 @@
|
|||
package org.xbib.content.rdf;
|
||||
package org.xbib.content.rdf.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.xbib.content.rdf.RdfXContentFactory.rdfXContentBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.RdfContentBuilder;
|
||||
import org.xbib.content.rdf.RdfXContentParams;
|
||||
import org.xbib.content.rdf.Resource;
|
||||
import org.xbib.content.rdf.internal.DefaultLiteral;
|
||||
import org.xbib.content.rdf.internal.DefaultResource;
|
||||
import org.xbib.content.resource.IRI;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -21,7 +25,8 @@ public class RdfXContentGeneratorTest {
|
|||
resource.add("urn:property", "Hello World")
|
||||
.add("urn:date", l)
|
||||
.add("urn:link", IRI.create("urn:pointer"));
|
||||
RdfXContentParams params = new RdfXContentParams();
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
RdfXContentParams params = new RdfXContentParams(namespaceContext);
|
||||
try (RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params)) {
|
||||
builder.receive(resource);
|
||||
}
|
||||
|
@ -40,7 +45,8 @@ public class RdfXContentGeneratorTest {
|
|||
.add("rdf:type", IRI.create("urn:type1"))
|
||||
.newResource("urn:embedded")
|
||||
.add("rdf:type", IRI.create("urn:type2"));
|
||||
RdfXContentParams params = new RdfXContentParams();
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
RdfXContentParams params = new RdfXContentParams(namespaceContext);
|
||||
try (RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params)) {
|
||||
builder.receive(resource);
|
||||
}
|
||||
|
@ -61,7 +67,8 @@ public class RdfXContentGeneratorTest {
|
|||
.add("rdf:type", IRI.create("urn:type2"));
|
||||
resource.newResource("urn:embedded2")
|
||||
.add("rdf:type", IRI.create("urn:type3"));
|
||||
RdfXContentParams params = new RdfXContentParams();
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
RdfXContentParams params = new RdfXContentParams(namespaceContext);
|
||||
try (RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params)) {
|
||||
builder.receive(resource);
|
||||
}
|
||||
|
@ -79,7 +86,8 @@ public class RdfXContentGeneratorTest {
|
|||
.add("urn:date", l)
|
||||
.add("rdf:type", IRI.create("urn:type1"))
|
||||
.newResource("urn:embedded"); // empty resource, do not copy
|
||||
RdfXContentParams params = new RdfXContentParams();
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
RdfXContentParams params = new RdfXContentParams(namespaceContext);
|
||||
try (RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params)) {
|
||||
builder.receive(resource);
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package org.xbib.content.rdf;
|
||||
package org.xbib.content.rdf.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.xbib.content.rdf.RdfXContentFactory.routeRdfXContentBuilder;
|
||||
import static org.xbib.content.rdf.StreamTester.assertStream;
|
||||
import static org.xbib.content.rdf.test.StreamTester.assertStream;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
@ -11,10 +11,14 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.RdfContentBuilder;
|
||||
import org.xbib.content.rdf.Resource;
|
||||
import org.xbib.content.rdf.RouteRdfXContentParams;
|
||||
import org.xbib.content.rdf.internal.DefaultLiteral;
|
||||
import org.xbib.content.rdf.internal.DefaultResource;
|
||||
import org.xbib.content.rdf.io.rdfxml.RdfXmlContentParser;
|
||||
import org.xbib.content.resource.IRI;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -31,7 +35,8 @@ public class RouteRdfXContentBuilderTest {
|
|||
resource.add("urn:property", "Hello World")
|
||||
.add("urn:date", l)
|
||||
.add("urn:link", IRI.create("urn:pointer"));
|
||||
RouteRdfXContentParams params = new RouteRdfXContentParams("index", "type");
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
RouteRdfXContentParams params = new RouteRdfXContentParams(namespaceContext, "index", "type");
|
||||
AtomicBoolean found = new AtomicBoolean();
|
||||
params.setHandler((content, p) -> {
|
||||
assertEquals(p.getIndex() + " " + p.getType() + " 1 " + content,
|
||||
|
@ -46,29 +51,31 @@ public class RouteRdfXContentBuilderTest {
|
|||
|
||||
@Test
|
||||
public void testVIAF() throws Exception {
|
||||
InputStream in = getClass().getResourceAsStream("VIAF.rdf");
|
||||
if (in == null) {
|
||||
throw new IOException("VIAF.rdf not found");
|
||||
try (InputStream inputStream = getClass().getResourceAsStream("VIAF.rdf")) {
|
||||
if (inputStream == null) {
|
||||
throw new IOException("VIAF.rdf not found");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
RouteRdfXContentParams params = new RouteRdfXContentParams(namespaceContext, "index", "type");
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
params.setHandler((content, p) -> {
|
||||
logger.log(Level.INFO, MessageFormat.format("handle: {0} {1} {2} {3}",
|
||||
p.getIndex(), p.getType(), p.getId(), content));
|
||||
counter.incrementAndGet();
|
||||
});
|
||||
RdfXmlContentParser<RouteRdfXContentParams> parser = new RdfXmlContentParser<>(params, inputStream);
|
||||
parser.setRdfContentBuilderProvider(() -> routeRdfXContentBuilder(params))
|
||||
.setRdfContentBuilderHandler(builder -> {
|
||||
if (!sb.isEmpty()) {
|
||||
sb.append("\n");
|
||||
}
|
||||
sb.append(builder.string());
|
||||
})
|
||||
.parse();
|
||||
assertStream("viaf.json", getClass().getResourceAsStream("viaf.json"),
|
||||
sb.toString());
|
||||
assertEquals(5, counter.get());
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
RouteRdfXContentParams params = new RouteRdfXContentParams("index", "type");
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
params.setHandler((content, p) -> {
|
||||
logger.log(Level.INFO, MessageFormat.format("handle: {0} {1} {2} {3}",
|
||||
p.getIndex(), p.getType(), p.getId(), content));
|
||||
counter.incrementAndGet();
|
||||
});
|
||||
new RdfXmlContentParser<RouteRdfXContentParams>(in)
|
||||
.setRdfContentBuilderProvider(() -> routeRdfXContentBuilder(params))
|
||||
.setRdfContentBuilderHandler(builder -> {
|
||||
if (sb.length() > 0) {
|
||||
sb.append("\n");
|
||||
}
|
||||
sb.append(builder.string());
|
||||
})
|
||||
.parse();
|
||||
assertStream("viaf.json", getClass().getResourceAsStream("viaf.json"),
|
||||
sb.toString());
|
||||
assertEquals(5, counter.get());
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.xbib.content.rdf;
|
||||
package org.xbib.content.rdf.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import java.io.ByteArrayInputStream;
|
|
@ -1,20 +1,19 @@
|
|||
package org.xbib.content.rdf.internal;
|
||||
package org.xbib.content.rdf.test.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.Resource;
|
||||
import org.xbib.content.rdf.Triple;
|
||||
import org.xbib.content.rdf.internal.DefaultAnonymousResource;
|
||||
import org.xbib.content.rdf.internal.DefaultResource;
|
||||
import org.xbib.content.resource.IRI;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class BlankNodeTest {
|
||||
|
||||
@Test
|
||||
public void testBlankNodeRenumbering() throws Exception {
|
||||
public void testBlankNodeRenumbering() {
|
||||
DefaultAnonymousResource.reset();
|
||||
Resource r = new DefaultResource(IRI.create("urn:meta1"));
|
||||
// test order of adding
|
|
@ -1,7 +1,8 @@
|
|||
package org.xbib.content.rdf.internal;
|
||||
package org.xbib.content.rdf.test.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.internal.DefaultLiteral;
|
||||
import org.xbib.content.resource.IRI;
|
||||
|
||||
/**
|
|
@ -1,4 +1,4 @@
|
|||
package org.xbib.content.rdf.internal;
|
||||
package org.xbib.content.rdf.test.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
@ -10,6 +10,10 @@ import org.xbib.content.rdf.Literal;
|
|||
import org.xbib.content.rdf.RdfContentBuilder;
|
||||
import org.xbib.content.rdf.Resource;
|
||||
import org.xbib.content.rdf.Triple;
|
||||
import org.xbib.content.rdf.internal.DefaultAnonymousResource;
|
||||
import org.xbib.content.rdf.internal.DefaultLiteral;
|
||||
import org.xbib.content.rdf.internal.DefaultResource;
|
||||
import org.xbib.content.rdf.internal.DefaultTriple;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContentParams;
|
||||
import org.xbib.content.resource.IRI;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
@ -133,7 +137,6 @@ public class ResourceTest {
|
|||
assertEquals("urn:doc1 urn:res1 _:b2", it.next().toString());
|
||||
assertEquals("_:b2 urn:has a second res value", it.next().toString());
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
Iterator<IRI> itp = r.predicates().iterator();
|
||||
IRI pred = itp.next();
|
||||
assertEquals("urn:valueURI", pred.toString());
|
||||
|
@ -227,11 +230,11 @@ public class ResourceTest {
|
|||
|
||||
@Test
|
||||
public void testTripleAdder() throws IOException {
|
||||
IRINamespaceContext context = IRINamespaceContext.newInstance();
|
||||
context.addNamespace("vcard", "http://www.w3.org/2006/vcard/ns#");
|
||||
context.addNamespace("owl", "http://www.w3.org/2002/07/owl#");
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
namespaceContext.addNamespace("vcard", "http://www.w3.org/2006/vcard/ns#");
|
||||
namespaceContext.addNamespace("owl", "http://www.w3.org/2002/07/owl#");
|
||||
// ID with compact IRI, will be expanded
|
||||
Resource r = DefaultResource.create(context, "vcard:value");
|
||||
Resource r = DefaultResource.create(namespaceContext, "vcard:value");
|
||||
// triples with expanded IRIs
|
||||
Triple t1 = new DefaultTriple(DefaultResource.create("http://www.w3.org/2006/vcard/ns#value"),
|
||||
IRI.create("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
|
||||
|
@ -240,7 +243,7 @@ public class ResourceTest {
|
|||
IRI.create("http://www.w3.org/1999/02/22-rdf-syntax-ns#label"),
|
||||
new DefaultLiteral("value@en"));
|
||||
r.add(t1).add(t2);
|
||||
NTripleContentParams params = new NTripleContentParams(context);
|
||||
NTripleContentParams params = new NTripleContentParams(namespaceContext);
|
||||
RdfContentBuilder<NTripleContentParams> builder = ntripleBuilder(params);
|
||||
builder.receive(r);
|
||||
assertEquals("<http://www.w3.org/2006/vcard/ns#value> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#DatatypeProperty> .\n" +
|
|
@ -1,8 +1,11 @@
|
|||
package org.xbib.content.rdf.internal;
|
||||
package org.xbib.content.rdf.test.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.Resource;
|
||||
import org.xbib.content.rdf.internal.DefaultLiteral;
|
||||
import org.xbib.content.rdf.internal.DefaultResource;
|
||||
import org.xbib.content.rdf.internal.DefaultTriple;
|
||||
import org.xbib.content.resource.IRI;
|
||||
import org.xbib.content.resource.Node;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.xbib.content.rdf.io;
|
||||
package org.xbib.content.rdf.test.io;
|
||||
|
||||
/**
|
||||
*
|
|
@ -1,33 +1,33 @@
|
|||
package org.xbib.content.rdf.io.json;
|
||||
package org.xbib.content.rdf.test.io.json;
|
||||
|
||||
import static org.xbib.content.rdf.RdfContentFactory.jsonBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.RdfContentBuilder;
|
||||
import org.xbib.content.rdf.io.json.JsonContentParams;
|
||||
import org.xbib.content.rdf.io.json.JsonContentParser;
|
||||
import org.xbib.content.rdf.io.json.JsonResourceHandler;
|
||||
import org.xbib.content.rdf.io.xml.XmlHandler;
|
||||
import org.xbib.content.resource.IRI;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
import org.xbib.content.resource.NamespaceContext;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
import org.xbib.content.rdf.test.StreamTester;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JsonReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testGenericJsonReader() throws Exception {
|
||||
String filename = "dc.json";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
if (in == null) {
|
||||
InputStream inputStream = getClass().getResourceAsStream(filename);
|
||||
if (inputStream == null) {
|
||||
throw new IOException("file " + filename + " not found");
|
||||
}
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance();
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
namespaceContext.addNamespace("dc", "http://purl.org/dc/elements/1.1/");
|
||||
namespaceContext.addNamespace("dcterms", "http://purl.org/dc/terms/");
|
||||
namespaceContext.addNamespace("bib", "info:srw/cql-context-set/1/bib-v1/");
|
||||
|
@ -63,12 +63,11 @@ public class JsonReaderTest extends StreamTester {
|
|||
return namespaceContext;
|
||||
}
|
||||
};
|
||||
RdfContentBuilder<JsonContentParams> builder = jsonBuilder();
|
||||
RdfContentBuilder<JsonContentParams> builder = jsonBuilder(params);
|
||||
jsonHandler.setBuilder(builder);
|
||||
new JsonContentParser<JsonContentParams>(in)
|
||||
.setHandler(jsonHandler)
|
||||
JsonContentParser<JsonContentParams> parser = new JsonContentParser<JsonContentParams>(params, inputStream);
|
||||
parser.setHandler(jsonHandler)
|
||||
.root(new QName("http://purl.org/dc/elements/1.1/", "root", "dc"))
|
||||
.parse();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.xbib.content.rdf.test.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.test.StreamTester;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContentParams;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContentParser;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class NTripleReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testReader() throws Exception {
|
||||
String filename = "list.nt";
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
NTripleContentParams params = new NTripleContentParams(namespaceContext);
|
||||
try (InputStream inputStream = getClass().getResourceAsStream(filename)) {
|
||||
if (inputStream == null) {
|
||||
throw new IOException("file " + filename + " not found");
|
||||
}
|
||||
RdfContentBuilder<NTripleContentParams> builder = ntripleBuilder(params);
|
||||
NTripleContentParser<NTripleContentParams> reader = new NTripleContentParser<>(params, inputStream);
|
||||
reader.setBuilder(builder);
|
||||
reader.parse();
|
||||
assertStream("", getClass().getResource("rdfxml.ttl").openStream(),
|
||||
builder.streamInput());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package org.xbib.content.rdf.io.ntriple;
|
||||
package org.xbib.content.rdf.test.io.ntriple;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.xbib.content.rdf.RdfContentFactory.ntripleBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -10,28 +10,33 @@ import org.xbib.content.rdf.Resource;
|
|||
import org.xbib.content.rdf.XSDResourceIdentifiers;
|
||||
import org.xbib.content.rdf.internal.DefaultLiteral;
|
||||
import org.xbib.content.rdf.internal.DefaultResource;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContentParams;
|
||||
import org.xbib.content.resource.IRI;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class NTripleTest {
|
||||
|
||||
@Test
|
||||
public void testNTripleBuilder() throws Exception {
|
||||
RdfContentBuilder<NTripleContentParams> builder = ntripleBuilder();
|
||||
Resource resource = createResource();
|
||||
builder.receive(resource);
|
||||
assertTrue(builder.string().length() > 0);
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
NTripleContentParams params = new NTripleContentParams(namespaceContext);
|
||||
try (RdfContentBuilder<NTripleContentParams> builder = ntripleBuilder(params)) {
|
||||
Resource resource = createResource();
|
||||
builder.receive(resource);
|
||||
assertFalse(builder.string().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNTripleWriteInt() throws Exception {
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
NTripleContentParams params = new NTripleContentParams(namespaceContext);
|
||||
Resource resource = new DefaultResource(IRI.create("urn:doc1"));
|
||||
resource.add("http://purl.org/dc/elements/1.1/date", new DefaultLiteral("2010").type(XSDResourceIdentifiers.INTEGER));
|
||||
RdfContentBuilder<NTripleContentParams> builder = ntripleBuilder();
|
||||
builder.receive(resource);
|
||||
assertEquals("<urn:doc1> <http://purl.org/dc/elements/1.1/date> \"2010\"^^<xsd:integer> .\n", builder.string());
|
||||
try (RdfContentBuilder<NTripleContentParams> builder = ntripleBuilder(params)) {
|
||||
builder.receive(resource);
|
||||
assertEquals("<urn:doc1> <http://purl.org/dc/elements/1.1/date> \"2010\"^^<xsd:integer> .\n", builder.string());
|
||||
}
|
||||
}
|
||||
|
||||
private Resource createResource() {
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue