Class RDFXMLPrettyWriter
- java.lang.Object
-
- org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter
-
- org.eclipse.rdf4j.rio.rdfxml.RDFXMLWriter
-
- org.eclipse.rdf4j.rio.rdfxml.util.RDFXMLPrettyWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable,CharSink,Sink,RDFHandler,RDFWriter
public class RDFXMLPrettyWriter extends RDFXMLWriter implements java.io.Closeable, java.io.Flushable
An extension of RDFXMLWriter that outputs a more concise form of RDF/XML. The resulting output is semantically equivalent to the output of an RDFXMLWriter (it produces the same set of statements), but it is usually easier to read for humans.This is a quasi-streaming RDFWriter. Statements are cached as long as the striped syntax is followed (i.e. the subject of the next statement is the object of the previous statement) and written to the output when the stripe is broken.
The abbreviations used are typed node elements, empty property elements and striped syntax. Note that these abbreviations require that statements are written in the appropriate order.
Striped syntax means that when the object of a statement is the subject of the next statement we can nest the descriptions in each other.
Example:
<rdf:Seq> <rdf:li> <foaf:Person> <foaf:knows> <foaf:Person> <foaf:mbox rdf:resource="..."/> </foaf:Person> </foaf:knows> </foaf:Person> </rdf:li> </rdf:Seq>Typed node elements means that we write out type information in the short form of
<foaf:Person rdf:about="..."> ... </foaf:Person>instead of
<rdf:Description rdf:about="..."> <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/> ... </rdf:Description>Empty property elements are of the form
<foaf:Person> <foaf:homepage rdf:resource="http://www.cs.vu.nl/˜marta"/> </foaf:Person>instead of
<foaf:Person> <foaf:homepage> <rdf:Description rdf:about="http://www.cs.vu.nl/˜marta"/> <foaf:homepage> </foaf:Person>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classRDFXMLPrettyWriter.Nodeprivate static classRDFXMLPrettyWriter.QName
-
Field Summary
Fields Modifier and Type Field Description private java.util.Stack<RDFXMLPrettyWriter.Node>nodeStackStack for remembering the nodes (subjects/objects) of statements at each level.private java.util.Stack<IRI>predicateStackStack for remembering the predicate of statements at each level.private booleanwritingEnded-
Fields inherited from class org.eclipse.rdf4j.rio.rdfxml.RDFXMLWriter
baseIRI, defaultNamespace, entityQuote, headerWritten, lastWrittenSubject, quote, writer
-
Fields inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter
namespaceTable, statementConsumer
-
-
Constructor Summary
Constructors Constructor Description RDFXMLPrettyWriter(java.io.OutputStream out)Creates a new RDFXMLPrintWriter that will write to the supplied OutputStream.RDFXMLPrettyWriter(java.io.OutputStream out, ParsedIRI baseIRI)Creates a new RDFXMLPrintWriter that will write to the supplied OutputStream.RDFXMLPrettyWriter(java.io.Writer out)Creates a new RDFXMLPrintWriter that will write to the supplied Writer.RDFXMLPrettyWriter(java.io.Writer writer, ParsedIRI baseIRI)Creates a new RDFXMLPrintWriter that will write to the supplied Writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidconsumeStatement(Statement st)Consume a statement.voidendRDF()Signals the end of the RDF data.voidflush()protected voidflushPendingStatements()java.util.Collection<RioSetting<?>>getSupportedSettings()private voidpopStacks(Resource newSubject)Write out the stacks until we find subject.private voidwriteAbbreviatedPredicate(IRI pred, Value obj)Write out an empty property element.protected voidwriteHeader()protected voidwriteIndents(int n)Writes n indents.private voidwriteNodeEmptyTag(RDFXMLPrettyWriter.Node node)Write out an empty tag for the subject or object of a statement.private voidwriteNodeEndTag(RDFXMLPrettyWriter.Node node)Write out the closing tag for the subject or object of a statement.private voidwriteNodeStartOfStartTag(RDFXMLPrettyWriter.Node node)Write out the opening tag of the subject or object of a statement up to (but not including) the end of the tag.private voidwriteNodeStartTag(RDFXMLPrettyWriter.Node node)Write out the opening tag of the subject or object of a statement.protected voidwriteStartTag(java.lang.String namespace, java.lang.String localName)-
Methods inherited from class org.eclipse.rdf4j.rio.rdfxml.RDFXMLWriter
getRDFFormat, getValidNodeId, getWriter, handleComment, handleNamespace, setNamespace, writeAttribute, writeAttribute, writeCharacterData, writeEndOfEmptyTag, writeEndOfStartTag, writeEndTag, writeIndent, writeNewLine, writeQuotedAttribute, writeStartOfStartTag
-
Methods inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter
checkWritingStarted, getFileFormat, getWriterConfig, handleStatement, isWritingStarted, set, setWriterConfig, startRDF
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.rdf4j.common.io.Sink
acceptsFileFormat, getFileFormat
-
-
-
-
Field Detail
-
nodeStack
private final java.util.Stack<RDFXMLPrettyWriter.Node> nodeStack
Stack for remembering the nodes (subjects/objects) of statements at each level.
-
predicateStack
private final java.util.Stack<IRI> predicateStack
Stack for remembering the predicate of statements at each level.
-
writingEnded
private boolean writingEnded
-
-
Constructor Detail
-
RDFXMLPrettyWriter
public RDFXMLPrettyWriter(java.io.OutputStream out)
Creates a new RDFXMLPrintWriter that will write to the supplied OutputStream.- Parameters:
out- The OutputStream to write the RDF/XML document to.
-
RDFXMLPrettyWriter
public RDFXMLPrettyWriter(java.io.OutputStream out, ParsedIRI baseIRI)Creates a new RDFXMLPrintWriter that will write to the supplied OutputStream.- Parameters:
out- The OutputStream to write the RDF/XML document to.
-
RDFXMLPrettyWriter
public RDFXMLPrettyWriter(java.io.Writer out)
Creates a new RDFXMLPrintWriter that will write to the supplied Writer.- Parameters:
out- The Writer to write the RDF/XML document to.
-
RDFXMLPrettyWriter
public RDFXMLPrettyWriter(java.io.Writer writer, ParsedIRI baseIRI)Creates a new RDFXMLPrintWriter that will write to the supplied Writer.- Parameters:
writer- the Writer to write the RDF/XML document tobaseIRI- base IRI
-
-
Method Detail
-
endRDF
public void endRDF() throws RDFHandlerExceptionDescription copied from interface:RDFHandlerSignals the end of the RDF data. This method is called when all data has been reported.- Specified by:
endRDFin interfaceRDFHandler- Overrides:
endRDFin classRDFXMLWriter- Throws:
RDFHandlerException- If the RDF handler has encountered an unrecoverable error.
-
writeHeader
protected void writeHeader() throws java.io.IOException- Overrides:
writeHeaderin classRDFXMLWriter- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Throws:
java.io.IOException
-
getSupportedSettings
public java.util.Collection<RioSetting<?>> getSupportedSettings()
- Specified by:
getSupportedSettingsin interfaceRDFWriter- Overrides:
getSupportedSettingsin classRDFXMLWriter- Returns:
- A collection of
RioSettings that are supported by this RDFWriter.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
flushPendingStatements
protected void flushPendingStatements() throws java.io.IOException, RDFHandlerException- Overrides:
flushPendingStatementsin classRDFXMLWriter- Throws:
java.io.IOExceptionRDFHandlerException
-
popStacks
private void popStacks(Resource newSubject) throws java.io.IOException, RDFHandlerException
Write out the stacks until we find subject. If subject == null, write out the entire stack- Parameters:
newSubject-- Throws:
java.io.IOExceptionRDFHandlerException
-
consumeStatement
public void consumeStatement(Statement st) throws RDFHandlerException
Description copied from class:AbstractRDFWriterConsume a statement.Extending classes must override this method instead of overriding
AbstractRDFWriter.handleStatement(Statement)in order to benefit from automatic handling of RDF-star conversion or encoding.- Overrides:
consumeStatementin classRDFXMLWriter- Parameters:
st- the statement to consume.- Throws:
RDFHandlerException
-
writeNodeStartOfStartTag
private void writeNodeStartOfStartTag(RDFXMLPrettyWriter.Node node) throws java.io.IOException, RDFHandlerException
Write out the opening tag of the subject or object of a statement up to (but not including) the end of the tag. Used both in writeStartSubject and writeEmptySubject.- Throws:
java.io.IOExceptionRDFHandlerException
-
writeNodeStartTag
private void writeNodeStartTag(RDFXMLPrettyWriter.Node node) throws java.io.IOException, RDFHandlerException
Write out the opening tag of the subject or object of a statement.- Throws:
java.io.IOExceptionRDFHandlerException
-
writeNodeEndTag
private void writeNodeEndTag(RDFXMLPrettyWriter.Node node) throws java.io.IOException
Write out the closing tag for the subject or object of a statement.- Throws:
java.io.IOException
-
writeNodeEmptyTag
private void writeNodeEmptyTag(RDFXMLPrettyWriter.Node node) throws java.io.IOException, RDFHandlerException
Write out an empty tag for the subject or object of a statement.- Throws:
java.io.IOExceptionRDFHandlerException
-
writeAbbreviatedPredicate
private void writeAbbreviatedPredicate(IRI pred, Value obj) throws java.io.IOException, RDFHandlerException
Write out an empty property element.- Throws:
java.io.IOExceptionRDFHandlerException
-
writeStartTag
protected void writeStartTag(java.lang.String namespace, java.lang.String localName) throws java.io.IOException- Throws:
java.io.IOException
-
writeIndents
protected void writeIndents(int n) throws java.io.IOExceptionWrites n indents.- Throws:
java.io.IOException
-
-