Search in sources :

Example 6 with IndentedLineBuffer

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

the class BasicPattern method toString.

@Override
public String toString() {
    IndentedLineBuffer out = new IndentedLineBuffer();
    SerializationContext sCxt = SSE.sCxt(SSE.getPrefixMapString());
    boolean first = true;
    for (Triple t : triples) {
        if (!first)
            out.print("\n");
        else
            first = false;
        // Adds (triple ...)
        // SSE.write(buff.getIndentedWriter(), t) ;
        out.print("(");
        WriterNode.outputPlain(out, t, sCxt);
        out.print(")");
    }
    out.flush();
    return out.toString();
}
Also used : SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) Triple(org.apache.jena.graph.Triple) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 7 with IndentedLineBuffer

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

the class QuadPattern method toString.

@Override
public String toString() {
    IndentedLineBuffer out = new IndentedLineBuffer();
    SerializationContext sCxt = SSE.sCxt((SSE.getPrefixMapWrite()));
    boolean first = true;
    for (Quad quad : quads) {
        if (!first)
            out.print(" ");
        else
            first = false;
        // Adds (quad ...)
        // SSE.write(buff.getIndentedWriter(), t) ;
        out.print("(");
        WriterNode.outputPlain(out, quad, sCxt);
        out.print(")");
    }
    out.flush();
    return out.toString();
}
Also used : SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 8 with IndentedLineBuffer

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

the class ExprUtils method fmtSPARQL.

public static String fmtSPARQL(ExprList exprs) {
    IndentedLineBuffer buff = new IndentedLineBuffer();
    fmtSPARQL(buff, exprs);
    return buff.toString();
}
Also used : IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 9 with IndentedLineBuffer

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

the class QueryOutputUtils method toString.

// ---- PrintSerializable
public static String toString(PrintSerializable item, PrefixMapping pmap) {
    IndentedLineBuffer buff = new IndentedLineBuffer();
    SerializationContext sCxt = new SerializationContext(pmap);
    item.output(buff, sCxt);
    return buff.toString();
}
Also used : SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 10 with IndentedLineBuffer

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

the class QueryUtils method checkParse.

public static void checkParse(Query query) {
    if (!SPARQLParserRegistry.get().containsFactory(query.getSyntax()))
        return;
    IndentedLineBuffer buff = new IndentedLineBuffer();
    query.serialize(buff, query.getSyntax());
    String tmp = buff.toString();
    Query query2 = null;
    try {
        String baseURI = null;
        if (!query.explicitlySetBaseURI())
            // Not in query - use the same one (e.g. file read from) .  
            baseURI = query.getBaseURI();
        query2 = QueryFactory.create(tmp, baseURI, query.getSyntax());
        if (query2 == null)
            return;
    } catch (UnsupportedOperationException ex) {
        // No parser after all.
        return;
    } catch (QueryException ex) {
        System.err.println(tmp);
        throw new QueryCheckException("could not parse output query", ex);
    }
    if (query.hashCode() != query2.hashCode())
        throw new QueryCheckException("reparsed query hashCode does not equal parsed input query \nQuery (hashCode: " + query.hashCode() + ")=\n" + query + "\n\nQuery2 (hashCode: " + query2.hashCode() + ")=\n" + query2);
    if (!query.equals(query2))
        throw new QueryCheckException("reparsed output does not equal parsed input");
}
Also used : QueryException(org.apache.jena.query.QueryException) Query(org.apache.jena.query.Query) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Aggregations

IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)63 Test (org.junit.Test)10 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)5 Expr (org.apache.jena.sparql.expr.Expr)3 WriterExpr (org.apache.jena.sparql.sse.writers.WriterExpr)3 BasicPattern (org.apache.jena.sparql.core.BasicPattern)2 QueryCheckException (org.apache.jena.sparql.core.QueryCheckException)2 SSEParseException (org.apache.jena.sparql.sse.SSEParseException)2 UpdateRequest (org.apache.jena.update.UpdateRequest)2 Version (org.apache.jena.atlas.lib.Version)1 DatasetRef (org.apache.jena.fuseki.server.DatasetRef)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 Query (org.apache.jena.query.Query)1 QueryException (org.apache.jena.query.QueryException)1 QueryParseException (org.apache.jena.query.QueryParseException)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 PrefixMapping (org.apache.jena.shared.PrefixMapping)1 Op (org.apache.jena.sparql.algebra.Op)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1