lift to module path based compiling and testing

This commit is contained in:
Jörg Prante 2024-04-08 16:04:18 +02:00
parent 6811c4a8e0
commit 2805b97026
337 changed files with 1712 additions and 1583 deletions

View file

@ -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
View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,9 @@
package org.xbib.content.csv;
package org.xbib.content.csv.test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import 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()) {

View file

@ -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;

View file

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

View file

@ -1,5 +1,15 @@
dependencies {
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
}

View file

@ -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);

View file

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

View file

@ -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;

View file

@ -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) {

View file

@ -45,8 +45,7 @@ public abstract class TreePointer<T extends TreeNode> implements Iterable<TokenR
* @param missing the representation of a missing node (may be null)
* @param 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<>();

View file

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

View file

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

View file

@ -1,4 +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;

View file

@ -1,8 +1,10 @@
package org.xbib.content.json;
package org.xbib.content.json.test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import 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;

View file

@ -1,4 +1,4 @@
package org.xbib.content.json.jackson;
package org.xbib.content.json.test.jackson;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.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

View file

@ -1,4 +1,4 @@
package org.xbib.content.json.jackson;
package org.xbib.content.json.test.jackson;
import static org.junit.jupiter.api.Assertions.assertTrue;
import 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")) {

View file

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

View file

@ -1,4 +1,4 @@
package org.xbib.content.json.pointer;
package org.xbib.content.json.test.pointer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.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;

View file

@ -1,4 +1,4 @@
package org.xbib.content.json.pointer;
package org.xbib.content.json.test.pointer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import 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");
}

View file

@ -1,9 +1,12 @@
package org.xbib.content.json.pointer;
package org.xbib.content.json.test.pointer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.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;

View file

@ -1,4 +1,4 @@
package org.xbib.content.json.pointer;
package org.xbib.content.json.test.pointer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.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);
}

View file

@ -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());
}
}

View file

@ -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
}

View file

@ -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;
}

View file

@ -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 {

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -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);
}
}

View file

@ -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();

View file

@ -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;
}

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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;
}

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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();

View file

@ -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);
}

9