Search in sources :

Example 16 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class StatsMatcher method printSSE.

public void printSSE(OutputStream ps) {
    IndentedWriter out = new IndentedWriter(ps);
    out.println("(stats");
    out.incIndent();
    for (Pattern p : patterns) {
        p.output(out);
        out.println();
    }
    out.decIndent();
    out.println(")");
    out.flush();
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter)

Example 17 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class SerializerRegistry method init.

private static synchronized void init() {
    SerializerRegistry reg = new SerializerRegistry();
    // Register standard serializers
    QuerySerializerFactory arqQuerySerializerFactory = new QuerySerializerFactory() {

        @Override
        public QueryVisitor create(Syntax syntax, Prologue prologue, IndentedWriter writer) {
            // For the query pattern
            SerializationContext cxt1 = new SerializationContext(prologue, new NodeToLabelMapBNode("b", false));
            // For the construct pattern
            SerializationContext cxt2 = new SerializationContext(prologue, new NodeToLabelMapBNode("c", false));
            return new QuerySerializer(writer, new FormatterElement(writer, cxt1), new FmtExprSPARQL(writer, cxt1), new FmtTemplate(writer, cxt2));
        }

        @Override
        public QueryVisitor create(Syntax syntax, SerializationContext context, IndentedWriter writer) {
            return new QuerySerializer(writer, new FormatterElement(writer, context), new FmtExprSPARQL(writer, context), new FmtTemplate(writer, context));
        }

        @Override
        public boolean accept(Syntax syntax) {
            // and SPARQL 1.1 can be serialized by the same serializer
            return Syntax.syntaxARQ.equals(syntax) || Syntax.syntaxSPARQL_10.equals(syntax) || Syntax.syntaxSPARQL_11.equals(syntax);
        }
    };
    reg.addQuerySerializer(Syntax.syntaxARQ, arqQuerySerializerFactory);
    reg.addQuerySerializer(Syntax.syntaxSPARQL_10, arqQuerySerializerFactory);
    reg.addQuerySerializer(Syntax.syntaxSPARQL_11, arqQuerySerializerFactory);
    UpdateSerializerFactory arqUpdateSerializerFactory = new UpdateSerializerFactory() {

        @Override
        public UpdateSerializer create(Syntax syntax, Prologue prologue, IndentedWriter writer) {
            if (!prologue.explicitlySetBaseURI())
                prologue = new Prologue(prologue.getPrefixMapping());
            SerializationContext context = new SerializationContext(prologue);
            return new UpdateWriter(writer, context);
        }

        @Override
        public boolean accept(Syntax syntax) {
            // and SPARQL 1.1 can be serialized by the same serializer
            return Syntax.syntaxARQ.equals(syntax) || Syntax.syntaxSPARQL_10.equals(syntax) || Syntax.syntaxSPARQL_11.equals(syntax);
        }
    };
    reg.addUpdateSerializer(Syntax.syntaxARQ, arqUpdateSerializerFactory);
    reg.addUpdateSerializer(Syntax.syntaxSPARQL_10, arqUpdateSerializerFactory);
    reg.addUpdateSerializer(Syntax.syntaxSPARQL_11, arqUpdateSerializerFactory);
    registry = reg;
}
Also used : NodeToLabelMapBNode(org.apache.jena.sparql.util.NodeToLabelMapBNode) UpdateWriter(org.apache.jena.sparql.modify.request.UpdateWriter) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) Prologue(org.apache.jena.sparql.core.Prologue) Syntax(org.apache.jena.query.Syntax)

Example 18 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class JSON method write.

/**
 * Write out a JSON value - pass a JSON Object to get legal exchangeable JSON
 */
public static void write(OutputStream output, JsonValue jValue) {
    IndentedWriter iOut = new IndentedWriter(output);
    write(iOut, jValue);
    iOut.flush();
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter)

Example 19 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class RowSetWriterJSON method write.

@Override
public void write(OutputStream outStream, RowSet rowSet, Context context) {
    IndentedWriter out = new IndentedWriter(outStream);
    try {
        ResultSetWriterTableJSON x = new ResultSetWriterTableJSON(out, context);
        x.write(rowSet);
    } finally {
        IO.flush(out);
    }
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter)

Example 20 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class NodeFormatterTTL_MultiLine method writeLexicalMultiLine.

/**
 * Output a string and run the Runnable at the same indentation level
 */
private void writeLexicalMultiLine(AWriter writer, String str, Runnable action) {
    QuotedStringOutput escapeProc = chooseEscapeProcessor(str);
    int indent = -1;
    IndentedWriter iw = null;
    if (writer instanceof IndentedWriter) {
        iw = (IndentedWriter) writer;
        iw.pad();
        indent = iw.getAbsoluteIndent();
        iw.setAbsoluteIndent(0);
    }
    escapeProc.writeStrMultiLine(writer, str);
    if (action != null)
        action.run();
    if (indent >= 0)
        iw.setAbsoluteIndent(indent);
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) QuotedStringOutput(org.apache.jena.riot.out.quoted.QuotedStringOutput)

Aggregations

IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)57 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)5 TerminationException (org.apache.jena.cmd.TerminationException)4 Node (org.apache.jena.graph.Node)4 PrefixMapping (org.apache.jena.shared.PrefixMapping)4 CmdException (org.apache.jena.cmd.CmdException)3 Triple (org.apache.jena.graph.Triple)3 Syntax (org.apache.jena.query.Syntax)3 IOException (java.io.IOException)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 Pair (org.apache.jena.atlas.lib.Pair)2 RiotException (org.apache.jena.riot.RiotException)2 RiotNotFoundException (org.apache.jena.riot.RiotNotFoundException)2 NodeFormatter (org.apache.jena.riot.out.NodeFormatter)2 NodeFormatterTTL (org.apache.jena.riot.out.NodeFormatterTTL)2 JenaException (org.apache.jena.shared.JenaException)2 ARQException (org.apache.jena.sparql.ARQException)2 Var (org.apache.jena.sparql.core.Var)2 Plan (org.apache.jena.sparql.engine.Plan)2 Expr (org.apache.jena.sparql.expr.Expr)2