RdfContentGenerator needs close()
This commit is contained in:
parent
9dd9a097c7
commit
5b15e5edac
12 changed files with 166 additions and 83 deletions
|
@ -55,7 +55,7 @@ public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfCon
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RdfContentGenerator<P> setBaseUri(String baseUri) {
|
public RdfContentGenerator<P> setBaseUri(String baseUri) {
|
||||||
startPrefixMapping("", baseUri);
|
params.getNamespaceContext().addNamespace("", baseUri);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,8 +92,11 @@ public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfCon
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public RdfXContentGenerator<P> receive(Resource resource) throws IOException {
|
||||||
flush();
|
if (resource != null) {
|
||||||
|
this.resource = resource;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,7 +105,6 @@ public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfCon
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
flushed = true;
|
flushed = true;
|
||||||
// JSON output
|
|
||||||
builder = DefaultXContentBuilder.builder(JsonXContent.jsonContent(), out);
|
builder = DefaultXContentBuilder.builder(JsonXContent.jsonContent(), out);
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
build(this.resource);
|
build(this.resource);
|
||||||
|
@ -110,12 +112,8 @@ public class RdfXContentGenerator<P extends RdfXContentParams> implements RdfCon
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RdfXContentGenerator<P> receive(Resource resource) throws IOException {
|
public void close() throws IOException {
|
||||||
if (resource != null) {
|
|
||||||
this.resource = resource;
|
|
||||||
}
|
|
||||||
flush();
|
flush();
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String string() throws IOException {
|
public String string() throws IOException {
|
||||||
|
|
|
@ -28,12 +28,12 @@ public class RouteRdfXContent implements RdfContent<RouteRdfXContentParams> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RdfContentGenerator<RouteRdfXContentParams> createGenerator(OutputStream out) throws IOException {
|
public RdfContentGenerator<RouteRdfXContentParams> createGenerator(OutputStream out) {
|
||||||
return new RouteRdfXContentGenerator<>(out);
|
return new RouteRdfXContentGenerator<>(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RdfContentParser<RouteRdfXContentParams> createParser(InputStream in) throws IOException {
|
public RdfContentParser<RouteRdfXContentParams> createParser(InputStream in) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class RouteRdfXContentGenerator<R extends RouteRdfXContentParams> extends
|
||||||
|
|
||||||
private boolean flushed;
|
private boolean flushed;
|
||||||
|
|
||||||
RouteRdfXContentGenerator(OutputStream out) throws IOException {
|
RouteRdfXContentGenerator(OutputStream out) {
|
||||||
super(out);
|
super(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,5 +65,4 @@ public class RouteRdfXContentGenerator<R extends RouteRdfXContentParams> extends
|
||||||
getParams().setId(object.toString());
|
getParams().setId(object.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,6 @@ import java.io.Writer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class JsonContentGenerator implements RdfContentGenerator<JsonContentParams>, Flushable {
|
public class JsonContentGenerator implements RdfContentGenerator<JsonContentParams>, Flushable {
|
||||||
|
|
||||||
private final Writer writer;
|
private final Writer writer;
|
||||||
|
@ -29,11 +26,11 @@ public class JsonContentGenerator implements RdfContentGenerator<JsonContentPara
|
||||||
|
|
||||||
private JsonContentParams params = JsonContentParams.JSON_CONTENT_PARAMS;
|
private JsonContentParams params = JsonContentParams.JSON_CONTENT_PARAMS;
|
||||||
|
|
||||||
JsonContentGenerator(OutputStream out) throws IOException {
|
JsonContentGenerator(OutputStream out) {
|
||||||
this(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
this(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonContentGenerator(Writer writer) throws IOException {
|
JsonContentGenerator(Writer writer) {
|
||||||
this.writer = writer;
|
this.writer = writer;
|
||||||
this.nsWritten = false;
|
this.nsWritten = false;
|
||||||
this.resource = new DefaultAnonymousResource();
|
this.resource = new DefaultAnonymousResource();
|
||||||
|
@ -44,10 +41,20 @@ public class JsonContentGenerator implements RdfContentGenerator<JsonContentPara
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonContentGenerator receive(Resource resource) throws IOException {
|
||||||
|
this.resource = resource;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() throws IOException {
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
// write last resource
|
writer.close();
|
||||||
receive(resource);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -98,8 +105,7 @@ public class JsonContentGenerator implements RdfContentGenerator<JsonContentPara
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonContentGenerator writeNamespaces() throws IOException {
|
private void writeNamespaces() {
|
||||||
nsWritten = false;
|
|
||||||
for (Map.Entry<String, String> entry : params.getNamespaceContext().getNamespaces().entrySet()) {
|
for (Map.Entry<String, String> entry : params.getNamespaceContext().getNamespaces().entrySet()) {
|
||||||
if (entry.getValue().length() > 0) {
|
if (entry.getValue().length() > 0) {
|
||||||
String nsURI = entry.getValue();
|
String nsURI = entry.getValue();
|
||||||
|
@ -108,16 +114,5 @@ public class JsonContentGenerator implements RdfContentGenerator<JsonContentPara
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flush() throws IOException {
|
|
||||||
writer.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonContentGenerator receive(Resource resource) throws IOException {
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,15 +40,21 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
|
||||||
this(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
this(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public RdfXmlContentGenerator(Writer writer) throws IOException {
|
public RdfXmlContentGenerator(Writer writer) {
|
||||||
this.writer = writer;
|
this.writer = writer;
|
||||||
this.resource = new DefaultAnonymousResource();
|
this.resource = new DefaultAnonymousResource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() throws IOException {
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
// write last resource
|
flush();
|
||||||
receive(resource);
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -78,7 +84,7 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RdfContentGenerator<RdfXmlContentParams> setBaseUri(String baseUri) {
|
public RdfContentGenerator<RdfXmlContentParams> setBaseUri(String baseUri) {
|
||||||
startPrefixMapping("", baseUri);
|
params.getNamespaceContext().addNamespace("", baseUri);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +117,7 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
|
||||||
this.headerWritten = false;
|
this.headerWritten = false;
|
||||||
this.lastWrittenSubject = null;
|
this.lastWrittenSubject = null;
|
||||||
for (Map.Entry<String, String> entry : params.getNamespaceContext().getNamespaces().entrySet()) {
|
for (Map.Entry<String, String> entry : params.getNamespaceContext().getNamespaces().entrySet()) {
|
||||||
handleNamespace(entry.getKey(), entry.getValue());
|
setNamespace(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
startRDF();
|
startRDF();
|
||||||
writeHeader();
|
writeHeader();
|
||||||
|
@ -122,11 +128,6 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flush() throws IOException {
|
|
||||||
writer.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startRDF() throws IOException {
|
private void startRDF() throws IOException {
|
||||||
if (writingStarted) {
|
if (writingStarted) {
|
||||||
throw new IOException("writing has already started");
|
throw new IOException("writing has already started");
|
||||||
|
@ -136,7 +137,7 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
|
||||||
|
|
||||||
private void writeHeader() throws IOException {
|
private void writeHeader() throws IOException {
|
||||||
try {
|
try {
|
||||||
setNamespace("rdf", NS_URI, false);
|
setNamespace("rdf", NS_URI);
|
||||||
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
||||||
writeStartOfStartTag(NS_URI, "RDF");
|
writeStartOfStartTag(NS_URI, "RDF");
|
||||||
for (Map.Entry<String, String> entry : params.getNamespaceContext().getNamespaces().entrySet()) {
|
for (Map.Entry<String, String> entry : params.getNamespaceContext().getNamespaces().entrySet()) {
|
||||||
|
@ -178,11 +179,7 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNamespace(String prefix, String name) {
|
private void setNamespace(String prefix, String name) {
|
||||||
setNamespace(prefix, name, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setNamespace(String prefix, String name, boolean fixedPrefix) {
|
|
||||||
if (headerWritten) {
|
if (headerWritten) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -191,13 +188,6 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
|
||||||
String p = prefix;
|
String p = prefix;
|
||||||
boolean isLegalPrefix = p.length() == 0 || XMLUtil.isNCName(p);
|
boolean isLegalPrefix = p.length() == 0 || XMLUtil.isNCName(p);
|
||||||
if (!isLegalPrefix || map.containsValue(p)) {
|
if (!isLegalPrefix || map.containsValue(p)) {
|
||||||
if (fixedPrefix) {
|
|
||||||
if (isLegalPrefix) {
|
|
||||||
throw new IllegalArgumentException("Prefix is already in use: " + prefix);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Prefix is not a valid XML namespace prefix: " + prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (p.length() == 0 || !isLegalPrefix) {
|
if (p.length() == 0 || !isLegalPrefix) {
|
||||||
p = "ns";
|
p = "ns";
|
||||||
}
|
}
|
||||||
|
@ -211,7 +201,7 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RdfXmlContentGenerator writeTriple(Triple triple) throws IOException {
|
private void writeTriple(Triple triple) throws IOException {
|
||||||
if (!writingStarted) {
|
if (!writingStarted) {
|
||||||
throw new IOException("document writing has not yet been started");
|
throw new IOException("document writing has not yet been started");
|
||||||
}
|
}
|
||||||
|
@ -275,7 +265,6 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
|
||||||
writeEndTag(predNamespace, predLocalName);
|
writeEndTag(predNamespace, predLocalName);
|
||||||
}
|
}
|
||||||
writeNewLine();
|
writeNewLine();
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void flushPendingStatements() throws IOException {
|
private void flushPendingStatements() throws IOException {
|
||||||
|
@ -389,7 +378,7 @@ public class RdfXmlContentGenerator implements RdfContentGenerator<RdfXmlContent
|
||||||
StringBuilder buf = new StringBuilder(text.length());
|
StringBuilder buf = new StringBuilder(text.length());
|
||||||
int prevIndex = 0;
|
int prevIndex = 0;
|
||||||
while (oldsIndex >= 0) {
|
while (oldsIndex >= 0) {
|
||||||
buf.append(text.substring(prevIndex, oldsIndex));
|
buf.append(text, prevIndex, oldsIndex);
|
||||||
buf.append(news);
|
buf.append(news);
|
||||||
prevIndex = oldsIndex + olds.length();
|
prevIndex = oldsIndex + olds.length();
|
||||||
oldsIndex = text.indexOf(olds, prevIndex);
|
oldsIndex = text.indexOf(olds, prevIndex);
|
||||||
|
|
|
@ -69,14 +69,22 @@ public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConst
|
||||||
// counter for blank node generation
|
// counter for blank node generation
|
||||||
private int bn = 0;
|
private int bn = 0;
|
||||||
|
|
||||||
public RdfXmlContentParser(InputStream in) {
|
public RdfXmlContentParser(InputStream inputStream) {
|
||||||
this(new InputStreamReader(in, StandardCharsets.UTF_8));
|
this(createReader(inputStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
public RdfXmlContentParser(Reader reader) {
|
public RdfXmlContentParser(Reader reader) {
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Reader createReader(InputStream inputStream) {
|
||||||
|
if (inputStream != null) {
|
||||||
|
return new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RdfContentType contentType() {
|
public RdfContentType contentType() {
|
||||||
return StandardRdfContentType.RDFXML;
|
return StandardRdfContentType.RDFXML;
|
||||||
|
|
|
@ -22,8 +22,9 @@ public class RdfXContentGeneratorTest {
|
||||||
.add("urn:date", l)
|
.add("urn:date", l)
|
||||||
.add("urn:link", IRI.create("urn:pointer"));
|
.add("urn:link", IRI.create("urn:pointer"));
|
||||||
RdfXContentParams params = new RdfXContentParams();
|
RdfXContentParams params = new RdfXContentParams();
|
||||||
RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params);
|
try (RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params)) {
|
||||||
builder.receive(resource);
|
builder.receive(resource);
|
||||||
|
}
|
||||||
String result = params.getGenerator().get();
|
String result = params.getGenerator().get();
|
||||||
assertEquals(result,
|
assertEquals(result,
|
||||||
"{\"urn:property\":\"Hello World\",\"urn:date\":2013,\"urn:link\":\"urn:pointer\"}");
|
"{\"urn:property\":\"Hello World\",\"urn:date\":2013,\"urn:link\":\"urn:pointer\"}");
|
||||||
|
@ -40,8 +41,9 @@ public class RdfXContentGeneratorTest {
|
||||||
.newResource("urn:embedded")
|
.newResource("urn:embedded")
|
||||||
.add("rdf:type", IRI.create("urn:type2"));
|
.add("rdf:type", IRI.create("urn:type2"));
|
||||||
RdfXContentParams params = new RdfXContentParams();
|
RdfXContentParams params = new RdfXContentParams();
|
||||||
RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params);
|
try (RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params)) {
|
||||||
builder.receive(resource);
|
builder.receive(resource);
|
||||||
|
}
|
||||||
String result = params.getGenerator().get();
|
String result = params.getGenerator().get();
|
||||||
assertEquals("{\"urn:property\":\"Hello World\",\"urn:date\":2013,\"rdf:type\":\"urn:type1\","
|
assertEquals("{\"urn:property\":\"Hello World\",\"urn:date\":2013,\"rdf:type\":\"urn:type1\","
|
||||||
+ "\"urn:embedded\":{\"rdf:type\":\"urn:type2\"}}", result);
|
+ "\"urn:embedded\":{\"rdf:type\":\"urn:type2\"}}", result);
|
||||||
|
@ -60,8 +62,9 @@ public class RdfXContentGeneratorTest {
|
||||||
resource.newResource("urn:embedded2")
|
resource.newResource("urn:embedded2")
|
||||||
.add("rdf:type", IRI.create("urn:type3"));
|
.add("rdf:type", IRI.create("urn:type3"));
|
||||||
RdfXContentParams params = new RdfXContentParams();
|
RdfXContentParams params = new RdfXContentParams();
|
||||||
RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params);
|
try (RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params)) {
|
||||||
builder.receive(resource);
|
builder.receive(resource);
|
||||||
|
}
|
||||||
String result = params.getGenerator().get();
|
String result = params.getGenerator().get();
|
||||||
assertEquals("{\"urn:property\":\"Hello World\",\"urn:date\":2013,\"rdf:type\":\"urn:type1\","
|
assertEquals("{\"urn:property\":\"Hello World\",\"urn:date\":2013,\"rdf:type\":\"urn:type1\","
|
||||||
+ "\"urn:embedded\":{\"rdf:type\":\"urn:type2\"},\"urn:embedded2\":{\"rdf:type\":\"urn:type3\"}}", result);
|
+ "\"urn:embedded\":{\"rdf:type\":\"urn:type2\"},\"urn:embedded2\":{\"rdf:type\":\"urn:type3\"}}", result);
|
||||||
|
@ -77,8 +80,9 @@ public class RdfXContentGeneratorTest {
|
||||||
.add("rdf:type", IRI.create("urn:type1"))
|
.add("rdf:type", IRI.create("urn:type1"))
|
||||||
.newResource("urn:embedded"); // empty resource, do not copy
|
.newResource("urn:embedded"); // empty resource, do not copy
|
||||||
RdfXContentParams params = new RdfXContentParams();
|
RdfXContentParams params = new RdfXContentParams();
|
||||||
RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params);
|
try (RdfContentBuilder<RdfXContentParams> builder = rdfXContentBuilder(params)) {
|
||||||
builder.receive(resource);
|
builder.receive(resource);
|
||||||
|
}
|
||||||
String result = params.getGenerator().get();
|
String result = params.getGenerator().get();
|
||||||
assertEquals(result,
|
assertEquals(result,
|
||||||
"{\"urn:property\":\"Hello World\",\"urn:date\":2013,\"rdf:type\":\"urn:type1\"}");
|
"{\"urn:property\":\"Hello World\",\"urn:date\":2013,\"rdf:type\":\"urn:type1\"}");
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
package org.xbib.content.rdf;
|
package org.xbib.content.rdf;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
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.RdfXContentFactory.routeRdfXContentBuilder;
|
||||||
import static org.xbib.content.rdf.StreamTester.assertStream;
|
import static org.xbib.content.rdf.StreamTester.assertStream;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.xbib.content.rdf.internal.DefaultLiteral;
|
import org.xbib.content.rdf.internal.DefaultLiteral;
|
||||||
import org.xbib.content.rdf.internal.DefaultResource;
|
import org.xbib.content.rdf.internal.DefaultResource;
|
||||||
|
@ -15,6 +21,8 @@ import java.io.InputStream;
|
||||||
|
|
||||||
public class RouteRdfXContentBuilderTest {
|
public class RouteRdfXContentBuilderTest {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(RouteRdfXContentBuilderTest.class.getName());
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRoute() throws Exception {
|
public void testRoute() throws Exception {
|
||||||
Resource resource = new DefaultResource(IRI.create("urn:res"));
|
Resource resource = new DefaultResource(IRI.create("urn:res"));
|
||||||
|
@ -24,11 +32,16 @@ public class RouteRdfXContentBuilderTest {
|
||||||
.add("urn:date", l)
|
.add("urn:date", l)
|
||||||
.add("urn:link", IRI.create("urn:pointer"));
|
.add("urn:link", IRI.create("urn:pointer"));
|
||||||
RouteRdfXContentParams params = new RouteRdfXContentParams("index", "type");
|
RouteRdfXContentParams params = new RouteRdfXContentParams("index", "type");
|
||||||
params.setHandler((content, p) -> assertEquals(p.getIndex() + " " + p.getType() + " 1 " + content,
|
AtomicBoolean found = new AtomicBoolean();
|
||||||
"index type 1 {\"urn:property\":\"Hello World\",\"urn:date\":2013,\"urn:link\":\"urn:pointer\"}"
|
params.setHandler((content, p) -> {
|
||||||
));
|
assertEquals(p.getIndex() + " " + p.getType() + " 1 " + content,
|
||||||
RdfContentBuilder<RouteRdfXContentParams> builder = routeRdfXContentBuilder(params);
|
"index type 1 {\"urn:property\":\"Hello World\",\"urn:date\":2013,\"urn:link\":\"urn:pointer\"}");
|
||||||
builder.receive(resource);
|
found.set(true);
|
||||||
|
});
|
||||||
|
try (RdfContentBuilder<RouteRdfXContentParams> builder = routeRdfXContentBuilder(params)) {
|
||||||
|
builder.receive(resource);
|
||||||
|
}
|
||||||
|
assertTrue(found.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -39,8 +52,11 @@ public class RouteRdfXContentBuilderTest {
|
||||||
}
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
RouteRdfXContentParams params = new RouteRdfXContentParams("index", "type");
|
RouteRdfXContentParams params = new RouteRdfXContentParams("index", "type");
|
||||||
|
AtomicInteger counter = new AtomicInteger();
|
||||||
params.setHandler((content, p) -> {
|
params.setHandler((content, p) -> {
|
||||||
//logger.info("handle: {} {} {} {}", p.getIndex(), p.getType(), p.getId(), content);
|
logger.log(Level.INFO, MessageFormat.format("handle: {0} {1} {2} {3}",
|
||||||
|
p.getIndex(), p.getType(), p.getId(), content));
|
||||||
|
counter.incrementAndGet();
|
||||||
});
|
});
|
||||||
new RdfXmlContentParser<RouteRdfXContentParams>(in)
|
new RdfXmlContentParser<RouteRdfXContentParams>(in)
|
||||||
.setRdfContentBuilderProvider(() -> routeRdfXContentBuilder(params))
|
.setRdfContentBuilderProvider(() -> routeRdfXContentBuilder(params))
|
||||||
|
@ -53,5 +69,6 @@ public class RouteRdfXContentBuilderTest {
|
||||||
.parse();
|
.parse();
|
||||||
assertStream("viaf.json", getClass().getResourceAsStream("viaf.json"),
|
assertStream("viaf.json", getClass().getResourceAsStream("viaf.json"),
|
||||||
sb.toString());
|
sb.toString());
|
||||||
|
assertEquals(5, counter.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,12 @@ public class JsonReaderTest extends StreamTester {
|
||||||
if (in == null) {
|
if (in == null) {
|
||||||
throw new IOException("file " + filename + " not found");
|
throw new IOException("file " + filename + " not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance();
|
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance();
|
||||||
namespaceContext.addNamespace("dc", "http://purl.org/dc/elements/1.1/");
|
namespaceContext.addNamespace("dc", "http://purl.org/dc/elements/1.1/");
|
||||||
namespaceContext.addNamespace("dcterms", "http://purl.org/dc/terms/");
|
namespaceContext.addNamespace("dcterms", "http://purl.org/dc/terms/");
|
||||||
namespaceContext.addNamespace("bib", "info:srw/cql-context-set/1/bib-v1/");
|
namespaceContext.addNamespace("bib", "info:srw/cql-context-set/1/bib-v1/");
|
||||||
namespaceContext.addNamespace("xbib", "http://xbib.org/");
|
namespaceContext.addNamespace("xbib", "http://xbib.org/");
|
||||||
namespaceContext.addNamespace("lia", "http://xbib.org/lia/");
|
namespaceContext.addNamespace("lia", "http://xbib.org/lia/");
|
||||||
|
|
||||||
JsonContentParams params = new JsonContentParams(namespaceContext);
|
JsonContentParams params = new JsonContentParams(namespaceContext);
|
||||||
JsonResourceHandler jsonHandler = new JsonResourceHandler(params) {
|
JsonResourceHandler jsonHandler = new JsonResourceHandler(params) {
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,6 @@ import org.xbib.content.rdf.StreamTester;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class NTripleReaderTest extends StreamTester {
|
public class NTripleReaderTest extends StreamTester {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -25,8 +22,8 @@ public class NTripleReaderTest extends StreamTester {
|
||||||
NTripleContentParser<NTripleContentParams> reader = new NTripleContentParser<>(in);
|
NTripleContentParser<NTripleContentParams> reader = new NTripleContentParser<>(in);
|
||||||
reader.setBuilder(builder);
|
reader.setBuilder(builder);
|
||||||
reader.parse();
|
reader.parse();
|
||||||
//assertStream(getClass().getResource("rdfxml.ttl").openStream(),
|
assertStream("", getClass().getResource("rdfxml.ttl").openStream(),
|
||||||
// builder.streamInput());
|
builder.streamInput());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#ComplexSubject> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Authority> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#authoritativeLabel> "Nobility--Ireland"@en .
|
||||||
|
_:genid1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://id.loc.gov/authorities/sh85092138> .
|
||||||
|
<http://id.loc.gov/authorities/sh85092138> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Topic> .
|
||||||
|
_:genid2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://id.loc.gov/authorities/sh85067964> .
|
||||||
|
_:genid1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:genid2 .
|
||||||
|
<http://id.loc.gov/authorities/sh85067964> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Geographic> .
|
||||||
|
_:genid2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#componentList> _:genid1 .
|
||||||
|
_:genid3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#ComplexSubject> .
|
||||||
|
_:genid3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Variant> .
|
||||||
|
_:genid3 <http://www.loc.gov/mads/rdf/v1#variantLabel> "Ireland--Nobility"@en .
|
||||||
|
_:genid5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:genid4 .
|
||||||
|
_:genid4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Geographic> .
|
||||||
|
_:genid4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Variant> .
|
||||||
|
_:genid4 <http://www.loc.gov/mads/rdf/v1#variantLabel> "Ireland"@en .
|
||||||
|
_:genid7 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:genid6 .
|
||||||
|
_:genid6 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#GeographicElement> .
|
||||||
|
_:genid6 <http://www.loc.gov/mads/rdf/v1#elementValue> "Ireland" .
|
||||||
|
_:genid7 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
||||||
|
_:genid4 <http://www.loc.gov/mads/rdf/v1#elementList> _:genid7 .
|
||||||
|
_:genid9 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:genid8 .
|
||||||
|
_:genid5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:genid9 .
|
||||||
|
_:genid8 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Topic> .
|
||||||
|
_:genid8 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Variant> .
|
||||||
|
_:genid8 <http://www.loc.gov/mads/rdf/v1#variantLabel> "Nobility"@en .
|
||||||
|
_:genid11 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:genid10 .
|
||||||
|
_:genid10 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#TopicElement> .
|
||||||
|
_:genid10 <http://www.loc.gov/mads/rdf/v1#elementValue> "Nobility" .
|
||||||
|
_:genid11 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
||||||
|
_:genid8 <http://www.loc.gov/mads/rdf/v1#elementList> _:genid11 .
|
||||||
|
_:genid9 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
||||||
|
_:genid3 <http://www.loc.gov/mads/rdf/v1#componentList> _:genid5 .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#hasVariant> _:genid3 .
|
||||||
|
_:genid12 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#ComplexSubject> .
|
||||||
|
_:genid12 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Variant> .
|
||||||
|
_:genid12 <http://www.loc.gov/mads/rdf/v1#variantLabel> "Ireland--Peerage"@en .
|
||||||
|
_:genid14 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:genid13 .
|
||||||
|
_:genid13 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Geographic> .
|
||||||
|
_:genid13 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Variant> .
|
||||||
|
_:genid13 <http://www.loc.gov/mads/rdf/v1#variantLabel> "Ireland"@en .
|
||||||
|
_:genid16 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:genid15 .
|
||||||
|
_:genid15 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#GeographicElement> .
|
||||||
|
_:genid15 <http://www.loc.gov/mads/rdf/v1#elementValue> "Ireland" .
|
||||||
|
_:genid16 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
||||||
|
_:genid13 <http://www.loc.gov/mads/rdf/v1#elementList> _:genid16 .
|
||||||
|
_:genid18 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:genid17 .
|
||||||
|
_:genid14 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:genid18 .
|
||||||
|
_:genid17 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Topic> .
|
||||||
|
_:genid17 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Variant> .
|
||||||
|
_:genid17 <http://www.loc.gov/mads/rdf/v1#variantLabel> "Peerage"@en .
|
||||||
|
_:genid20 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:genid19 .
|
||||||
|
_:genid19 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#TopicElement> .
|
||||||
|
_:genid19 <http://www.loc.gov/mads/rdf/v1#elementValue> "Peerage" .
|
||||||
|
_:genid20 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
||||||
|
_:genid17 <http://www.loc.gov/mads/rdf/v1#elementList> _:genid20 .
|
||||||
|
_:genid18 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
|
||||||
|
_:genid12 <http://www.loc.gov/mads/rdf/v1#componentList> _:genid14 .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#hasVariant> _:genid12 .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#hasEarlierEstablishedForm> <http://id.loc.gov/authorities/sh85068030> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#hasEarlierEstablishedForm> <http://id.loc.gov/authorities/sh85068030> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#hasNarrowerAuthority> <http://id.loc.gov/authorities/sh85075905> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#isMemberOfMADSCollection> <http://id.loc.gov/authorities/collection_AuthorizedHeadings> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#isMemberOfMADSScheme> <http://id.loc.gov/authorities/lcsh> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#isMemberOfMADSCollection> <http://id.loc.gov/authorities/collection_LCSH_General> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.w3.org/2002/07/owl#sameAs> <info:lc/authorities/sh85068030> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.w3.org/2002/07/owl#sameAs> <http://id.loc.gov/authorities/sh85068030#concept> .
|
||||||
|
_:genid21 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.loc.gov/ontologies/RecordInfo#RecordInfo> .
|
||||||
|
_:genid21 <http://id.loc.gov/ontologies/RecordInfo#recordChangeDate> "1986-02-11T00:00:00" .
|
||||||
|
_:genid21 <http://id.loc.gov/ontologies/RecordInfo#recordStatus> "new" .
|
||||||
|
_:genid21 <http://id.loc.gov/ontologies/RecordInfo#recordContentSource> <http://id.loc.gov/vocabulary/organizations/dlc> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#adminMetadata> _:genid21 .
|
||||||
|
_:genid22 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.loc.gov/ontologies/RecordInfo#RecordInfo> .
|
||||||
|
_:genid22 <http://id.loc.gov/ontologies/RecordInfo#recordChangeDate> "2000-10-02T10:44:24" .
|
||||||
|
_:genid22 <http://id.loc.gov/ontologies/RecordInfo#recordStatus> "revised" .
|
||||||
|
_:genid22 <http://id.loc.gov/ontologies/RecordInfo#recordContentSource> <http://id.loc.gov/vocabulary/organizations/dlc> .
|
||||||
|
<http://id.loc.gov/authorities/sh85068030> <http://www.loc.gov/mads/rdf/v1#adminMetadata> _:genid22 .
|
|
@ -1,5 +1,5 @@
|
||||||
group = org.xbib
|
group = org.xbib
|
||||||
name = content
|
name = content
|
||||||
version = 5.0.1
|
version = 5.0.2
|
||||||
|
|
||||||
org.gradle.warning.mode = ALL
|
org.gradle.warning.mode = ALL
|
||||||
|
|
Loading…
Reference in a new issue