Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Control the RDF output format manually #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.RDFReaderI;
import org.apache.jena.rdf.model.RDFWriterI;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.RDFFormat;
import org.apache.jena.riot.RDFLanguages;
import org.apache.jena.util.FileUtils;
import org.eclipse.lyo.oslc4j.core.OSLC4JConstants;
Expand Down Expand Up @@ -149,9 +151,13 @@ private void writeObjectsTo(final Object[] objects, final OutputStream outputStr
String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
outputStream.write(xmlDeclaration.getBytes());
}
writer.write(model,
outputStream,
null);
if (writer instanceof RdfXmlAbbreviatedWriter) {
writer.write(model,
outputStream,
null);
} else {
RDFDataMgr.write(outputStream, model, resolveFormat(serializationLanguage));
}
Instant finish = Instant.now();
log.trace("writeObjectsTo - Execution Duration: {} ms", Duration.between(start, finish).toMillis());
}
Expand All @@ -162,7 +168,22 @@ private void writeObjectsTo(final Object[] objects, final OutputStream outputStr
}
}

private RDFWriterI getRdfWriter(final String serializationLanguage, final Model model) {
private RDFFormat resolveFormat(String serializationLanguage) {
switch (serializationLanguage) {
case RDFLanguages.strLangRDFXML:
return RDFFormat.RDFXML_PLAIN;
case RDFLanguages.strLangTurtle:
return RDFFormat.TURTLE_PRETTY;
case RDFLanguages.strLangNTriples:
return RDFFormat.NTRIPLES_UTF8;
case RDFLanguages.strLangJSONLD:
return RDFFormat.JSONLD10_COMPACT_PRETTY;
default:
throw new IllegalArgumentException();
}
}

private RDFWriterI getRdfWriter(final String serializationLanguage, final Model model) {
RDFWriterI writer;
if (serializationLanguage.equals(FileUtils.langXMLAbbrev))
{
Expand Down
Loading