Class RDFXMLPrettyWriter
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, CharSink, Sink, RDFHandler, RDFWriter
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 ClassesModifier and TypeClassDescriptionprivate static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stack<RDFXMLPrettyWriter.Node> Stack for remembering the nodes (subjects/objects) of statements at each level.Stack for remembering the predicate of statements at each level.private booleanFields inherited from class RDFXMLWriter
baseIRI, defaultNamespace, entityQuote, headerWritten, lastWrittenSubject, quote, writerFields inherited from class AbstractRDFWriter
namespaceTable, statementConsumer -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new RDFXMLPrintWriter that will write to the supplied OutputStream.RDFXMLPrettyWriter(OutputStream out, ParsedIRI baseIRI) Creates a new RDFXMLPrintWriter that will write to the supplied OutputStream.RDFXMLPrettyWriter(Writer out) Creates a new RDFXMLPrintWriter that will write to the supplied Writer.RDFXMLPrettyWriter(Writer writer, ParsedIRI baseIRI) Creates a new RDFXMLPrintWriter that will write to the supplied Writer. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidConsume a statement.voidendRDF()Signals the end of the RDF data.voidflush()protected voidCollection<RioSetting<?>> private voidWrite out the stacks until we find subject.private voidwriteAbbreviatedPredicate(IRI pred, Value obj) Write out an empty property element.protected voidprotected voidwriteIndents(int n) Writes n indents.private voidWrite out an empty tag for the subject or object of a statement.private voidWrite out the closing tag for the subject or object of a statement.private voidWrite out the opening tag of the subject or object of a statement up to (but not including) the end of the tag.private voidWrite out the opening tag of the subject or object of a statement.protected voidwriteStartTag(String namespace, String localName) Methods inherited from class RDFXMLWriter
getRDFFormat, getValidNodeId, getWriter, handleComment, handleNamespace, setNamespace, writeAttribute, writeAttribute, writeCharacterData, writeEndOfEmptyTag, writeEndOfStartTag, writeEndTag, writeIndent, writeNewLine, writeQuotedAttribute, writeStartOfStartTagMethods inherited from class AbstractRDFWriter
checkWritingStarted, getFileFormat, getWriterConfig, handleStatement, isWritingStarted, set, setWriterConfig, startRDFMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Sink
acceptsFileFormat, getFileFormat
-
Field Details
-
nodeStack
Stack for remembering the nodes (subjects/objects) of statements at each level. -
predicateStack
-
writingEnded
private boolean writingEnded
-
-
Constructor Details
-
RDFXMLPrettyWriter
Creates a new RDFXMLPrintWriter that will write to the supplied OutputStream.- Parameters:
out- The OutputStream to write the RDF/XML document to.
-
RDFXMLPrettyWriter
Creates a new RDFXMLPrintWriter that will write to the supplied OutputStream.- Parameters:
out- The OutputStream to write the RDF/XML document to.
-
RDFXMLPrettyWriter
Creates a new RDFXMLPrintWriter that will write to the supplied Writer.- Parameters:
out- The Writer to write the RDF/XML document to.
-
RDFXMLPrettyWriter
-
-
Method Details
-
endRDF
Description 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
- Overrides:
writeHeaderin classRDFXMLWriter- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Throws:
IOException
-
getSupportedSettings
- Specified by:
getSupportedSettingsin interfaceRDFWriter- Overrides:
getSupportedSettingsin classRDFXMLWriter- Returns:
- A collection of
RioSettings that are supported by this RDFWriter.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
flushPendingStatements
- Overrides:
flushPendingStatementsin classRDFXMLWriter- Throws:
IOExceptionRDFHandlerException
-
popStacks
Write out the stacks until we find subject. If subject == null, write out the entire stack- Parameters:
newSubject-- Throws:
IOExceptionRDFHandlerException
-
consumeStatement
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 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:
IOExceptionRDFHandlerException
-
writeNodeStartTag
private void writeNodeStartTag(RDFXMLPrettyWriter.Node node) throws IOException, RDFHandlerException Write out the opening tag of the subject or object of a statement.- Throws:
IOExceptionRDFHandlerException
-
writeNodeEndTag
Write out the closing tag for the subject or object of a statement.- Throws:
IOException
-
writeNodeEmptyTag
private void writeNodeEmptyTag(RDFXMLPrettyWriter.Node node) throws IOException, RDFHandlerException Write out an empty tag for the subject or object of a statement.- Throws:
IOExceptionRDFHandlerException
-
writeAbbreviatedPredicate
Write out an empty property element.- Throws:
IOExceptionRDFHandlerException
-
writeStartTag
- Throws:
IOException
-
writeIndents
-