Search in sources :

Example 16 with SerializationContext

use of org.apache.jena.sparql.serializer.SerializationContext in project jena by apache.

the class TestFmtUtils method formatPattern_2_triples.

@Test
public void formatPattern_2_triples() {
    BasicPattern basicPattern = new BasicPattern();
    basicPattern.add(getTriple());
    basicPattern.add(getTriple2());
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try (IndentedWriter iw = new IndentedWriter(os)) {
        SerializationContext sc = new SerializationContext();
        FmtUtils.formatPattern(iw, basicPattern, sc);
    }
    assertEquals("<n1> <n2> \"l3\" .\n" + "<nb1> <nb2> \"lb3\" .", new String(os.toByteArray()));
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) BasicPattern(org.apache.jena.sparql.core.BasicPattern) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 17 with SerializationContext

use of org.apache.jena.sparql.serializer.SerializationContext in project jena by apache.

the class QueryValidatorJSON method string.

private static String string(Query query, Op op) {
    final SerializationContext sCxt = new SerializationContext(query);
    IndentedLineBuffer out = new IndentedLineBuffer();
    op.output(out, sCxt);
    return out.asString();
}
Also used : SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 18 with SerializationContext

use of org.apache.jena.sparql.serializer.SerializationContext in project jena by apache.

the class QueryValidatorHTML method outputQueryOp.

private static void outputQueryOp(ServletOutputStream outStream, Query query, final Op op, boolean lineNumbers) throws IOException {
    final SerializationContext sCxt = new SerializationContext(query);
    output(outStream, out -> op.output(out, sCxt), lineNumbers);
}
Also used : SerializationContext(org.apache.jena.sparql.serializer.SerializationContext)

Example 19 with SerializationContext

use of org.apache.jena.sparql.serializer.SerializationContext in project jena by apache.

the class QueryValidator method output.

private void output(ServletOutputStream outStream, Query query, final Op op, boolean lineNumbers) throws IOException {
    final SerializationContext sCxt = new SerializationContext(query);
    Content c = new Content() {

        @Override
        public void print(IndentedWriter out) {
            op.output(out, sCxt);
        }
    };
    output(outStream, c, lineNumbers);
}
Also used : SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter)

Example 20 with SerializationContext

use of org.apache.jena.sparql.serializer.SerializationContext in project jena by apache.

the class ParameterizedSparqlString method appendNode.

/**
     * Appends a Node to the command text as a constant using appropriate
     * formatting
     * 
     * @param n
     *            Node to append
     */
public void appendNode(Node n) {
    SerializationContext context = new SerializationContext(this.prefixes);
    context.setBaseIRI(this.baseUri);
    this.cmd.append(this.stringForNode(n, context));
}
Also used : SerializationContext(org.apache.jena.sparql.serializer.SerializationContext)

Aggregations

SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)22 IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)5 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)5 Triple (org.apache.jena.graph.Triple)3 PrefixMapping (org.apache.jena.shared.PrefixMapping)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 MatchResult (java.util.regex.MatchResult)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 TerminationException (jena.cmd.TerminationException)1 Node (org.apache.jena.graph.Node)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 BasicPattern (org.apache.jena.sparql.core.BasicPattern)1 Prologue (org.apache.jena.sparql.core.Prologue)1 Quad (org.apache.jena.sparql.core.Quad)1 Plan (org.apache.jena.sparql.engine.Plan)1 QueryEngineFactory (org.apache.jena.sparql.engine.QueryEngineFactory)1 FmtExprSPARQL (org.apache.jena.sparql.serializer.FmtExprSPARQL)1 NodeToLabelMapBNode (org.apache.jena.sparql.util.NodeToLabelMapBNode)1 Test (org.junit.Test)1