Search in sources :

Example 1 with Indenter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter in project rdf4j by eclipse.

the class RDFJSONWriter method modelToRdfJsonInternal.

public static void modelToRdfJsonInternal(final Model graph, final WriterConfig writerConfig, final JsonGenerator jg) throws IOException, JsonGenerationException {
    if (writerConfig.get(BasicWriterSettings.PRETTY_PRINT)) {
        // SES-2011: Always use \n for consistency
        Indenter indenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
        // By default Jackson does not pretty print, so enable this unless
        // PRETTY_PRINT setting is disabled
        DefaultPrettyPrinter pp = new DefaultPrettyPrinter().withArrayIndenter(indenter).withObjectIndenter(indenter);
        jg.setPrettyPrinter(pp);
    }
    jg.writeStartObject();
    for (final Resource nextSubject : graph.subjects()) {
        jg.writeObjectFieldStart(RDFJSONWriter.resourceToString(nextSubject));
        for (final IRI nextPredicate : graph.filter(nextSubject, null, null).predicates()) {
            jg.writeArrayFieldStart(nextPredicate.stringValue());
            for (final Value nextObject : graph.filter(nextSubject, nextPredicate, null).objects()) {
                // contexts are optional, so this may return empty in some
                // scenarios depending on the interpretation of the way contexts
                // work
                final Set<Resource> contexts = graph.filter(nextSubject, nextPredicate, nextObject).contexts();
                RDFJSONWriter.writeObject(nextObject, contexts, jg);
            }
            jg.writeEndArray();
        }
        jg.writeEndObject();
    }
    jg.writeEndObject();
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) IRI(org.eclipse.rdf4j.model.IRI) Indenter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter) DefaultIndenter(com.fasterxml.jackson.core.util.DefaultIndenter) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value)

Example 2 with Indenter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter in project rdf4j by eclipse.

the class AbstractSPARQLJSONWriter method startDocument.

@Override
public void startDocument() throws QueryResultHandlerException {
    if (!documentOpen) {
        documentOpen = true;
        headerOpen = false;
        headerComplete = false;
        tupleVariablesFound = false;
        firstTupleWritten = false;
        linksFound = false;
        if (getWriterConfig().get(BasicWriterSettings.PRETTY_PRINT)) {
            // SES-2011: Always use \n for consistency
            Indenter indenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
            // By default Jackson does not pretty print, so enable this unless
            // PRETTY_PRINT setting is disabled
            DefaultPrettyPrinter pp = new DefaultPrettyPrinter().withArrayIndenter(indenter).withObjectIndenter(indenter);
            jg.setPrettyPrinter(pp);
        }
        try {
            if (getWriterConfig().isSet(BasicQueryWriterSettings.JSONP_CALLBACK)) {
                // SES-1019 : Write the callbackfunction name as a wrapper for
                // the results here
                String callbackName = getWriterConfig().get(BasicQueryWriterSettings.JSONP_CALLBACK);
                jg.writeRaw(callbackName);
                jg.writeRaw("(");
            }
            jg.writeStartObject();
        } catch (IOException e) {
            throw new QueryResultHandlerException(e);
        }
    }
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) Indenter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter) DefaultIndenter(com.fasterxml.jackson.core.util.DefaultIndenter) IOException(java.io.IOException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException)

Aggregations

DefaultIndenter (com.fasterxml.jackson.core.util.DefaultIndenter)2 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)2 Indenter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter)2 IOException (java.io.IOException)1 IRI (org.eclipse.rdf4j.model.IRI)1 Resource (org.eclipse.rdf4j.model.Resource)1 Value (org.eclipse.rdf4j.model.Value)1 QueryResultHandlerException (org.eclipse.rdf4j.query.QueryResultHandlerException)1 TupleQueryResultHandlerException (org.eclipse.rdf4j.query.TupleQueryResultHandlerException)1