Package com.stardog.stark.io.rdfxml
Class RDFXMLWriter
- java.lang.Object
-
- com.stardog.stark.io.rdfxml.RDFXMLWriter
-
- All Implemented Interfaces:
RDFHandler
,RDFWriter
- Direct Known Subclasses:
RDFXMLPrettyWriter
public class RDFXMLWriter extends java.lang.Object implements RDFWriter
Default writer for the RDF/XML serialization
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Michael Grove
- See Also:
RDFXMLParser
,RDFFormats.RDFXML
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RDFXMLWriter.RDFXMLWriterFactory
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
defaultNamespace
protected boolean
headerWritten
protected Resource
lastWrittenSubject
protected Options
mOptions
protected java.io.Writer
mWriter
protected java.util.Map<java.lang.String,java.lang.String>
namespaceTable
protected boolean
writingStarted
-
Constructor Summary
Constructors Constructor Description RDFXMLWriter(java.io.OutputStream theStream, Options theOptions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
comment(java.lang.String comment)
Write a comment to the output.void
end()
Signals the writing process is completed.protected void
flushPendingStatements()
RDFFormat
format()
Theformat
this writer will serialize output in.protected java.lang.String
getValidNodeId(BNode theBNode)
Create a syntactically valid node id from the supplied blank node id.void
handle(Statement theStmt)
Write the givenStatement
void
namespace(java.lang.String prefix, java.lang.String name)
Provide a namespace to the writer.protected java.lang.String
setNamespace(java.lang.String prefix, java.lang.String name)
void
start()
Signals that the RDF writing process is starting.protected void
writeAttribute(java.lang.String attName, java.lang.String value)
protected void
writeAttribute(java.lang.String namespace, java.lang.String attName, java.lang.String value)
protected void
writeCharacterData(java.lang.String chars)
protected void
writeEndOfEmptyTag()
protected void
writeEndOfStartTag()
protected void
writeEndTag(java.lang.String namespace, java.lang.String localName)
protected void
writeHeader()
protected void
writeIndent()
protected void
writeNewLine()
protected void
writeStartOfStartTag(java.lang.String theNamespace, java.lang.String theLocalName)
-
-
-
Field Detail
-
mWriter
protected final java.io.Writer mWriter
-
mOptions
protected final Options mOptions
-
defaultNamespace
protected java.lang.String defaultNamespace
-
writingStarted
protected boolean writingStarted
-
headerWritten
protected boolean headerWritten
-
lastWrittenSubject
protected Resource lastWrittenSubject
-
namespaceTable
protected java.util.Map<java.lang.String,java.lang.String> namespaceTable
-
-
Constructor Detail
-
RDFXMLWriter
public RDFXMLWriter(java.io.OutputStream theStream, Options theOptions)
-
-
Method Detail
-
start
public void start() throws WritingFailed
Signals that the RDF writing process is starting.- Specified by:
start
in interfaceRDFHandler
- Specified by:
start
in interfaceRDFWriter
- Throws:
WritingFailed
-
writeHeader
protected void writeHeader() throws java.io.IOException
- Throws:
java.io.IOException
-
end
public void end() throws WritingFailed
Signals the writing process is completed. The underlyingInputStream
is *not* closed, but the caller should not call additional methods on this writer as that will normally yield syntax errors in the output.- Specified by:
end
in interfaceRDFHandler
- Specified by:
end
in interfaceRDFWriter
- Throws:
WritingFailed
-
namespace
public void namespace(@Nonnull java.lang.String prefix, @Nonnull java.lang.String name)
Provide a namespace to the writer. This method can be called before writing hasstarted
, in which case, the namespace bindings are buffered and written when appropriate after writing has begun.- Specified by:
namespace
in interfaceRDFHandler
- Specified by:
namespace
in interfaceRDFWriter
- Parameters:
prefix
- the namespace prefixname
- the associated IRI
-
setNamespace
protected java.lang.String setNamespace(java.lang.String prefix, java.lang.String name)
-
handle
public void handle(@Nonnull Statement theStmt) throws WritingFailed
Write the givenStatement
- Specified by:
handle
in interfaceRDFHandler
- Specified by:
handle
in interfaceRDFWriter
- Parameters:
theStmt
- the statement to write- Throws:
WritingFailed
-
comment
public void comment(@Nonnull java.lang.String comment) throws WritingFailed
Write a comment to the output. Writing need not bestarted
at this point; comments can be written prior to any actual serialized RDF- Specified by:
comment
in interfaceRDFWriter
- Parameters:
comment
- the comment to write- Throws:
WritingFailed
-
flushPendingStatements
protected void flushPendingStatements() throws java.io.IOException, WritingFailed
- Throws:
java.io.IOException
WritingFailed
-
writeStartOfStartTag
protected void writeStartOfStartTag(@Nonnull java.lang.String theNamespace, @Nonnull java.lang.String theLocalName) throws java.io.IOException
- Throws:
java.io.IOException
-
writeAttribute
protected void writeAttribute(java.lang.String attName, java.lang.String value) throws java.io.IOException
- Throws:
java.io.IOException
-
writeAttribute
protected void writeAttribute(java.lang.String namespace, java.lang.String attName, java.lang.String value) throws java.io.IOException, WritingFailed
- Throws:
java.io.IOException
WritingFailed
-
writeEndOfStartTag
protected void writeEndOfStartTag() throws java.io.IOException
- Throws:
java.io.IOException
-
writeEndOfEmptyTag
protected void writeEndOfEmptyTag() throws java.io.IOException
- Throws:
java.io.IOException
-
writeEndTag
protected void writeEndTag(java.lang.String namespace, java.lang.String localName) throws java.io.IOException
- Throws:
java.io.IOException
-
writeCharacterData
protected void writeCharacterData(java.lang.String chars) throws java.io.IOException
- Throws:
java.io.IOException
-
writeIndent
protected void writeIndent() throws java.io.IOException
- Throws:
java.io.IOException
-
writeNewLine
protected void writeNewLine() throws java.io.IOException
- Throws:
java.io.IOException
-
getValidNodeId
protected java.lang.String getValidNodeId(@Nonnull BNode theBNode) throws java.io.IOException
Create a syntactically valid node id from the supplied blank node id. This is necessary because RDF/XML syntax enforces the blank node id is a valid NCName.- Parameters:
theBNode
- a blank node identifier- Returns:
- the blank node identifier converted to a form that is a valid NCName.
- Throws:
java.io.IOException
- See Also:
- section 7.2.34 of the RDF/XML Syntax specification
-
-