@Override protected void writeLiteralLongForm(AWriter w, String lex, String datatypeURI) { if ( ! writeAsMultiLine(w, lex) ) { super.writeLiteralOneLine(w, lex, datatypeURI); return ; } writeLexicalMultiLine(w, lex, ()-> { w.print("^^") ; formatURI(w, datatypeURI) ; }) ; }
@Override public void formatLitString(AWriter w, String lex) { if ( ! writeAsMultiLine(w, lex) ) { writeLexicalSingleLine(w, lex, noop); return ; } writeLexicalMultiLine(w, lex, noop) ; }
@Override public void formatLitLang(AWriter w, String lex, String langTag) { if ( ! writeAsMultiLine(w, lex) ) { super.formatLitLang(w, lex, langTag); return ; } writeLexicalMultiLine(w, lex, ()->{ w.print('@') ; w.print(langTag) ; }) ; }
/** Output a string and run the Runnable at the same indentation level */ private void writeLexicalSingleLine(AWriter writer, String str, Runnable action) { QuotedStringOutput proc = chooseEscapeProcessor(str) ; proc.writeStr(writer, str); }
static public NodeFormatter createNodeFormatter(PrefixMap pmap, String baseURI, Context context) { if ( context != null && context.isTrue(RIOT.multilineLiterals) ) return new NodeFormatterTTL_MultiLine(baseURI, pmap, NodeToLabel.createScopeByDocument()) ; else return new NodeFormatterTTL(baseURI, pmap, NodeToLabel.createScopeByDocument()) ; }
/** 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); } }