Skip to content

Commit

Permalink
Reformat white space in RIOT writer
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Apr 20, 2024
1 parent b0571b6 commit 4f85cf4
Show file tree
Hide file tree
Showing 40 changed files with 1,070 additions and 1,095 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

package org.apache.jena.riot.out;

import org.apache.jena.atlas.io.AWriter ;
import org.apache.jena.datatypes.RDFDatatype ;
import org.apache.jena.datatypes.xsd.XSDDatatype ;
import org.apache.jena.graph.Node ;
import org.apache.jena.atlas.io.AWriter;
import org.apache.jena.datatypes.RDFDatatype;
import org.apache.jena.datatypes.xsd.XSDDatatype;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.Node_Triple;
import org.apache.jena.graph.Triple;
import org.apache.jena.sparql.ARQInternalErrorException ;
import org.apache.jena.sparql.ARQInternalErrorException;

/**
* Provide implementations of the operations of {@link NodeFormatter} in terms
Expand All @@ -33,25 +33,23 @@
public abstract class NodeFormatterBase implements NodeFormatter
{
@Override
public void format(AWriter w, Node n)
{
// Can't use a fixed visitor because of the writer?
public void format(AWriter w, Node n) {
if ( n.isBlank() )
formatBNode(w, n) ;
formatBNode(w, n);
else if ( n.isURI() )
formatURI(w, n) ;
formatURI(w, n);
else if ( n.isLiteral() )
formatLiteral(w, n) ;
formatLiteral(w, n);
else if ( n.isVariable() )
formatVar(w, n) ;
formatVar(w, n);
else if ( Node.ANY.equals(n) )
w.print("ANY") ;
w.print("ANY");
else if ( n instanceof Node_Triple )
formatNodeTriple(w, n);
// else if ( n instanceof Node_Graph )
// formatNodeGraph(w, (Node_Graph)n);
else
throw new ARQInternalErrorException("Unknown node type: "+n) ;
throw new ARQInternalErrorException("Unknown node type: "+n);
}

protected void formatNodeTriple(AWriter w, Node n) {
Expand All @@ -66,32 +64,31 @@ protected void formatNodeTriple(AWriter w, Node n) {
}

@Override
public void formatURI(AWriter w, Node n) { formatURI(w, n.getURI()) ; }
public void formatURI(AWriter w, Node n) { formatURI(w, n.getURI()); }

@Override
public void formatBNode(AWriter w, Node n) { formatBNode(w, n.getBlankNodeLabel()) ; }
public void formatBNode(AWriter w, Node n) { formatBNode(w, n.getBlankNodeLabel()); }

@Override
public void formatLiteral(AWriter w, Node n)
{
RDFDatatype dt = n.getLiteralDatatype() ;
String lang = n.getLiteralLanguage() ;
String lex = n.getLiteralLexicalForm() ;
public void formatLiteral(AWriter w, Node n) {
RDFDatatype dt = n.getLiteralDatatype();
String lang = n.getLiteralLanguage();
String lex = n.getLiteralLexicalForm();

if ( lang != null && ! lang.equals("") ) {
formatLitLang(w, lex, lang) ;
formatLitLang(w, lex, lang);
} else if ( dt == null ) {
// RDF 1.0, simple literal.
formatLitString(w, lex) ;
formatLitString(w, lex);
} else if ( dt.equals(XSDDatatype.XSDstring) ) {
// RDF 1.1, xsd:string - output as short string.
formatLitString(w, lex) ;
formatLitString(w, lex);
} else {
// Datatype, no language tag, not short string.
formatLitDT(w, lex, dt.getURI()) ;
formatLitDT(w, lex, dt.getURI());
}
}

@Override
public void formatVar(AWriter w, Node n) { formatVar(w, n.getName()) ; }
public void formatVar(AWriter w, Node n) { formatVar(w, n.getName()); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@

package org.apache.jena.riot.out;

import org.apache.jena.atlas.io.AWriter ;
import org.apache.jena.atlas.lib.CharSpace ;
import org.apache.jena.atlas.lib.EscapeStr ;
import org.apache.jena.riot.out.quoted.QuotedStringOutput ;
import org.apache.jena.riot.out.quoted.QuotedStringOutputNT ;
import org.apache.jena.riot.out.quoted.QuotedURI ;
import org.apache.jena.atlas.io.AWriter;
import org.apache.jena.atlas.lib.CharSpace;
import org.apache.jena.atlas.lib.EscapeStr;
import org.apache.jena.riot.out.quoted.QuotedStringOutput;
import org.apache.jena.riot.out.quoted.QuotedStringOutputNT;
import org.apache.jena.riot.out.quoted.QuotedURI;

public class NodeFormatterNT extends NodeFormatterBase
{
// Formatting for NTriples
// Turtles extends this class to intercept forms it can do better.

private final QuotedStringOutput quotedStringProc ;
private final QuotedURI quotedUriProc ;
private final QuotedStringOutput quotedStringProc;
private final QuotedURI quotedUriProc;

public NodeFormatterNT() { this(CharSpace.UTF8) ; }
public NodeFormatterNT() { this(CharSpace.UTF8); }

public NodeFormatterNT(CharSpace charSpace) {
quotedStringProc = new QuotedStringOutputNT(charSpace);
quotedUriProc = new QuotedURI(charSpace) ;
quotedUriProc = new QuotedURI(charSpace);
}

@Override
Expand Down
Loading

0 comments on commit 4f85cf4

Please sign in to comment.