Java Code Examples for org.apache.jena.atlas.io.IndentedWriter#print()
The following examples show how to use
org.apache.jena.atlas.io.IndentedWriter#print() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplatePlan.java From sparql-generate with Apache License 2.0 | 6 votes |
public void exec(List<Var> variables, List<Binding> values, Context context) { final IndentedWriter writer = ContextUtils.getTemplateOutput(context); boolean first = true; final FunctionEnv env = new FunctionEnvBase(context); String result; for(Iterator<Binding> it=values.iterator(); it.hasNext();) { Binding binding = it.next(); if (first && before != null) { result = getExprEval(before, binding, context, env); writer.print(result); } if (!first && separator != null) { result = getExprEval(separator, binding, context, env); writer.print(result); } result = getExprEval(expr, binding, context, env); writer.print(result); first = false; if (!it.hasNext() && after != null) { result = getExprEval(after, binding, context, env); writer.print(result); } writer.flush(); } }
Example 2
Source File: SPARQLExtQuerySerializer.java From sparql-generate with Apache License 2.0 | 6 votes |
private static void outputValuesOneRow(IndentedWriter out, List<Var> variables, Binding row, SerializationContext cxt) { // A value may be null for UNDEF for (Var var : variables) { out.print(" "); Node value = row.get(var); if (value == null) { out.print("UNDEF"); } else { // Context for bnodes. // Bnodes don't occur in legal syntax but a rewritten query may // have them. The output will not be legal SPARQL. // ARQ (SPARQL with extensions) does parse blankd nodes in VALUES. SPARQLExtFmtUtils.printNode(out, value, cxt); } } }
Example 3
Source File: SHACLCWriter.java From shacl with Apache License 2.0 | 6 votes |
private void writeExtraStatements(IndentedWriter out, Resource subject, Set<Property> specialProperties, boolean wrapped) { List<Statement> extras = getExtraStatements(subject, specialProperties); if(!extras.isEmpty()) { if(wrapped) { out.print("( "); } for(Statement s : extras) { out.print(" " + getPredicateName(s.getPredicate())); out.print("="); out.print(node(s.getObject())); } if(wrapped) { out.print(" )"); } } }
Example 4
Source File: SPARQLExtFmtUtils.java From sparql-generate with Apache License 2.0 | 5 votes |
public static void formatPattern(IndentedWriter out, BasicPattern pattern, SerializationContext sCxt) { boolean first = true; for (Triple triple : pattern) { if (!first) { out.print("\n"); } printTriple(out, triple, sCxt); out.print(" ."); first = false; } }
Example 5
Source File: SPARQLExtFmtUtils.java From sparql-generate with Apache License 2.0 | 5 votes |
public static void printTriple(IndentedWriter out, Triple triple, SerializationContext sCxt) { printNode(out, triple.getSubject(), sCxt); out.print(" "); printNode(out, triple.getPredicate(), sCxt); out.print(" "); printNode(out, triple.getObject(), sCxt); }
Example 6
Source File: SPARQLExtFmtUtils.java From sparql-generate with Apache License 2.0 | 5 votes |
public static void fmtSPARQL(IndentedWriter iOut, ExprList exprs, SerializationContext pmap) { SPARQLExtFmtExprSPARQL fmt = new SPARQLExtFmtExprSPARQL(iOut, pmap); String sep = ""; for (Expr expr : exprs) { iOut.print(sep); sep = " , "; fmt.format(expr); } }
Example 7
Source File: SPARQLExtQuerySerializer.java From sparql-generate with Apache License 2.0 | 5 votes |
void appendVarList(Query query, IndentedWriter sb, List<String> vars) { boolean first = true; for (String varName : vars) { Var var = Var.alloc(varName); if (!first) { sb.print(" "); } sb.print(var.toString()); first = false; } }
Example 8
Source File: SPARQLExtQuerySerializer.java From sparql-generate with Apache License 2.0 | 5 votes |
static void appendURIList(Query query, IndentedWriter sb, List<Node> vars) { SerializationContext cxt = new SerializationContext(query); boolean first = true; for (Node node : vars) { if (!first) { sb.print(" "); } SPARQLExtFmtUtils.printNode(sb, node, cxt); first = false; } }
Example 9
Source File: SHACLCWriter.java From shacl with Apache License 2.0 | 5 votes |
private void writeProperty(IndentedWriter out, Resource property) { out.print(getPathString(property)); out.print(" "); out.print(getPropertyTypes(property)); // Count block out.print(" "); out.print("["); Statement minCountS = property.getProperty(SH.minCount); if(minCountS != null) { out.print("" + minCountS.getInt()); } else { out.print("0"); } out.print(".."); Statement maxCountS = property.getProperty(SH.maxCount); if(maxCountS != null) { out.print("" + maxCountS.getInt()); } else { out.print("*"); } out.print("]"); writeExtraStatements(out, property, specialPropertyProperties, false); writeNestedShapes(out, property); out.println(" ."); }
Example 10
Source File: RDFChangesHTTP.java From rdf-delta with Apache License 2.0 | 4 votes |
private void send$() { long number = counter.incrementAndGet(); byte[] bytes = collected(); String idStr; if ( patchId != null ) idStr = Id.str(patchId); else idStr = Long.toString(number); FmtLog.info(LOG, "Send patch %s (%d bytes) -> %s", idStr, bytes.length, destLabel); if ( false ) { if ( LOG.isDebugEnabled() ) { String s = new String(bytes, StandardCharsets.UTF_8); LOG.debug("== Sending ..."); // Do NOT close! IndentedWriter w = IndentedWriter.stdout; String x = w.getLinePrefix(); w.setLinePrefix(">> "); w.print(s); w.setLinePrefix(x); if ( ! s.endsWith("\n") ) w.println(); w.flush(); LOG.debug("== =="); } } int attempts = 0 ; for(;;) { HttpPost postRequest = new HttpPost(urlSupplier.get()); postRequest.setEntity(new ByteArrayEntity(bytes)); try(CloseableHttpResponse r = httpClient.execute(postRequest) ) { attempts++; statusLine = r.getStatusLine(); response = readResponse(r); int sc = r.getStatusLine().getStatusCode(); if ( sc >= 200 && sc <= 299 ) return ; if ( sc >= 300 && sc <= 399 ) { FmtLog.info(LOG, "Send patch %s HTTP %d", idStr, sc); throw new DeltaHttpException(sc, "HTTP Redirect"); } if ( sc == 400 ) { // Bad request. // This includes being out of sync with the patch log due to a concurrent update. FmtLog.warn(LOG, "Patch %s : HTTP bad request: %s", idStr, r.getStatusLine().getReasonPhrase()); throw new DeltaBadPatchException(r.getStatusLine().getReasonPhrase()); } if ( sc == 401 && attempts == 1 && resetAction != null ) { resetAction.run(); continue; } if ( sc >= 400 && sc <= 499 ) throw new DeltaHttpException(sc, r.getStatusLine().getReasonPhrase()); if ( sc >= 500 ) throw new DeltaHttpException(sc, r.getStatusLine().getReasonPhrase()); break; } catch (DeltaHttpException ex) { throw ex; } catch (IOException e) { throw IOX.exception(e); } } }
Example 11
Source File: SPARQLExtQuerySerializer.java From sparql-generate with Apache License 2.0 | 4 votes |
void appendNamedExprList(Query query, IndentedWriter sb, VarExprList namedExprs) { boolean first = true; for (Var var : namedExprs.getVars()) { Expr expr = namedExprs.getExpr(var); if (!first) { sb.print(" "); } if (expr != null) { // The following are safe to write without () // Compare/merge with fmtExpr.format boolean needParens = true; if (expr.isFunction()) { needParens = false; } // else if ( expr instanceof E_Aggregator ) // // Aggregators are variables (the function maps to an internal variable // // that is accesses by the E_Aggregator // needParens = false ; else if (expr.isVariable()) { needParens = false; } if (!Var.isAllocVar(var)) // AS ==> need parens { needParens = true; } if (needParens) { out.print("("); } fmtExpr.format(expr); if (!Var.isAllocVar(var)) { sb.print(" AS "); sb.print(var.toString()); } if (needParens) { out.print(")"); } } else { sb.print(var.toString()); } first = false; } }
Example 12
Source File: SHACLCWriter.java From shacl with Apache License 2.0 | 4 votes |
private void writeShape(IndentedWriter out, Resource shape) { out.print("shape " + iri(shape)); writeShapeBody(out, shape); }