Class AbstractSPARQLXMLWriter
- java.lang.Object
-
- org.eclipse.rdf4j.query.resultio.AbstractQueryResultWriter
-
- org.eclipse.rdf4j.query.resultio.sparqlxml.AbstractSPARQLXMLWriter
-
- All Implemented Interfaces:
CharSink,Sink,QueryResultHandler,QueryResultWriter
- Direct Known Subclasses:
SPARQLBooleanXMLWriter,SPARQLResultsXMLWriter
abstract class AbstractSPARQLXMLWriter extends AbstractQueryResultWriter implements CharSink
An abstract class to implement the base functionality for both SPARQLBooleanXMLWriter and SPARQLResultsXMLWriter.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleandocumentOpenprotected booleanheaderCompleteprotected booleanheaderOpenprivate org.slf4j.Loggerlogprivate java.util.Map<java.lang.String,java.lang.String>namespaceTableMap with keys as namespace URI strings and the values as the shortened prefixes.protected booleantupleVariablesFoundprotected XMLWriterxmlWriterXMLWriter to write XML to.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSPARQLXMLWriter(java.io.OutputStream out)protectedAbstractSPARQLXMLWriter(java.io.Writer writer)protectedAbstractSPARQLXMLWriter(XMLWriter xmlWriter)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidendDocument()voidendHeader()Indicates the end of the header.voidendQueryResult()Indicates the end of a sequence of solutions.java.util.Collection<RioSetting<?>>getSupportedSettings()java.io.WritergetWriter()get theWriterused by thisCharSink.voidhandleBoolean(boolean value)Handles the specified boolean value.voidhandleLinks(java.util.List<java.lang.String> linkUrls)Handles the links elements which are present in SPARQL Results JSON and SPARQL Results XML documents in the header.voidhandleNamespace(java.lang.String prefix, java.lang.String uri)Handles a namespace prefix declaration.protected voidhandleSolutionImpl(BindingSet bindingSet)Extending classes must implement this method instead of overridingAbstractQueryResultWriter.handleSolution(BindingSet)in order to benefit from automatic handling of RDF-star encoding.voidhandleStylesheet(java.lang.String url)Handles a stylesheet URL.private booleanisQName(IRI nextUri)voidsetPrettyPrint(boolean prettyPrint)Deprecated.UseAbstractQueryResultWriter.getWriterConfig().set(BasicWriterSettings.PRETTY_PRINT, prettyPrint) instead.voidstartDocument()Indicates the start of the document.voidstartHeader()Indicates the start of the header.voidstartQueryResult(java.util.List<java.lang.String> bindingNames)Indicates the start of a sequence of Solutions.private voidwriteBNode(BNode bNode)private voidwriteLiteral(Literal literal)private voidwriteQName(IRI nextUri)Write a QName for the given URI if and only if theBasicQueryWriterSettings.ADD_SESAME_QNAMEsetting has been set to true.private voidwriteTriple(Triple triple)private voidwriteURI(IRI uri)private voidwriteValue(Value value)-
Methods inherited from class org.eclipse.rdf4j.query.resultio.AbstractQueryResultWriter
getFileFormat, getWriterConfig, handleSolution, setWriterConfig, xsdStringToPlainLiteral
-
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.query.resultio.QueryResultWriter
getQueryResultFormat
-
Methods inherited from interface org.eclipse.rdf4j.common.io.Sink
acceptsFileFormat, getFileFormat
-
-
-
-
Field Detail
-
xmlWriter
protected XMLWriter xmlWriter
XMLWriter to write XML to.
-
documentOpen
protected boolean documentOpen
-
headerOpen
protected boolean headerOpen
-
headerComplete
protected boolean headerComplete
-
tupleVariablesFound
protected boolean tupleVariablesFound
-
namespaceTable
private final java.util.Map<java.lang.String,java.lang.String> namespaceTable
Map with keys as namespace URI strings and the values as the shortened prefixes.
-
log
private final org.slf4j.Logger log
-
-
Constructor Detail
-
AbstractSPARQLXMLWriter
protected AbstractSPARQLXMLWriter(java.io.OutputStream out)
-
AbstractSPARQLXMLWriter
protected AbstractSPARQLXMLWriter(java.io.Writer writer)
-
AbstractSPARQLXMLWriter
protected AbstractSPARQLXMLWriter(XMLWriter xmlWriter)
-
-
Method Detail
-
getWriter
public java.io.Writer getWriter()
Description copied from interface:CharSinkget theWriterused by thisCharSink.
-
setPrettyPrint
@Deprecated public void setPrettyPrint(boolean prettyPrint)
Deprecated.UseAbstractQueryResultWriter.getWriterConfig().set(BasicWriterSettings.PRETTY_PRINT, prettyPrint) instead.Enables/disables addition of indentation characters and newlines in the XML document. By default, pretty-printing is set to true. If set to false, no indentation and newlines are added to the XML document. This method has to be used before writing starts (that is, beforestartDocument()is called).
-
endDocument
protected void endDocument() throws java.io.IOException- Throws:
java.io.IOException
-
handleBoolean
public void handleBoolean(boolean value) throws QueryResultHandlerExceptionDescription copied from interface:QueryResultHandlerHandles the specified boolean value.- Specified by:
handleBooleanin interfaceQueryResultHandler- Parameters:
value- The boolean value to handle.- Throws:
QueryResultHandlerException- If there was an error during the handling of this value. This exception may be thrown if theQueryResultHandler.startQueryResult(List),QueryResultHandler.handleSolution(BindingSet)orQueryResultHandler.endQueryResult()methods were called before this method was called, and the handler cannot process both boolean and tuple results simultaneously.
-
startDocument
public void startDocument() throws QueryResultHandlerExceptionDescription copied from interface:QueryResultWriterIndicates the start of the document.- Specified by:
startDocumentin interfaceQueryResultWriter- Throws:
QueryResultHandlerException- If there was an error starting the writing of the results.
-
handleStylesheet
public void handleStylesheet(java.lang.String url) throws QueryResultHandlerExceptionDescription copied from interface:QueryResultWriterHandles a stylesheet URL. If this is called, it must be called afterQueryResultWriter.startDocument()and beforeQueryResultWriter.startHeader().NOTE: If the format does not support stylesheets, it must silently ignore calls to this method.
- Specified by:
handleStylesheetin interfaceQueryResultWriter- Parameters:
url- The URL of the stylesheet to be used to style the results.- Throws:
QueryResultHandlerException- If there was an error handling the stylesheet. This error is not thrown in cases where stylesheets are not supported.
-
startHeader
public void startHeader() throws QueryResultHandlerExceptionDescription copied from interface:QueryResultWriterIndicates the start of the header.- Specified by:
startHeaderin interfaceQueryResultWriter- Throws:
QueryResultHandlerException- If there was an error writing the start of the header.- See Also:
- SPARQL Query Results XML Format documentation for head element.
-
handleLinks
public void handleLinks(java.util.List<java.lang.String> linkUrls) throws QueryResultHandlerExceptionDescription copied from interface:QueryResultHandlerHandles the links elements which are present in SPARQL Results JSON and SPARQL Results XML documents in the header.NOTE: If the format does not support links, it must silently ignore a call to this method.
An accumulating handler should accumulate these links.
- Specified by:
handleLinksin interfaceQueryResultHandler- Parameters:
linkUrls- The URLs of the links to handle.- Throws:
QueryResultHandlerException- If there was an error handling the set of link URLs. This error is not thrown in cases where links are not supported.- See Also:
- "link"
-
endHeader
public void endHeader() throws QueryResultHandlerExceptionDescription copied from interface:QueryResultWriterIndicates the end of the header. This must be called afterQueryResultWriter.startHeader()and before any calls toQueryResultHandler.handleSolution(org.eclipse.rdf4j.query.BindingSet).- Specified by:
endHeaderin interfaceQueryResultWriter- Throws:
QueryResultHandlerException- If there was an error writing the end of the header.
-
startQueryResult
public void startQueryResult(java.util.List<java.lang.String> bindingNames) throws TupleQueryResultHandlerExceptionDescription copied from interface:QueryResultHandlerIndicates the start of a sequence of Solutions. The supplied bindingNames are an indication of the values that are in the Solutions. For example, a SPARQL query like select ?X ?Y where { ?X ?P ?Y } will have binding names X and Y.- Specified by:
startQueryResultin interfaceQueryResultHandler- Overrides:
startQueryResultin classAbstractQueryResultWriter- Parameters:
bindingNames- An ordered set of binding names.- Throws:
TupleQueryResultHandlerException- If there was an error during the starting of the query result handler. This exception may be thrown if theQueryResultHandler.handleBoolean(boolean)method was called before this method and the handler cannot process both boolean and tuple results simultaneously.
-
endQueryResult
public void endQueryResult() throws TupleQueryResultHandlerExceptionDescription copied from interface:QueryResultHandlerIndicates the end of a sequence of solutions.- Specified by:
endQueryResultin interfaceQueryResultHandler- Throws:
TupleQueryResultHandlerException- If there was an error during the ending of the query result handler. This exception may be thrown if theQueryResultHandler.handleBoolean(boolean)method was called before this method and the handler cannot process both boolean and tuple results simultaneously.
-
handleSolutionImpl
protected void handleSolutionImpl(BindingSet bindingSet) throws TupleQueryResultHandlerException
Description copied from class:AbstractQueryResultWriterExtending classes must implement this method instead of overridingAbstractQueryResultWriter.handleSolution(BindingSet)in order to benefit from automatic handling of RDF-star encoding.- Overrides:
handleSolutionImplin classAbstractQueryResultWriter- Parameters:
bindingSet- the solution to handle- Throws:
TupleQueryResultHandlerException
-
getSupportedSettings
public final java.util.Collection<RioSetting<?>> getSupportedSettings()
- Specified by:
getSupportedSettingsin interfaceQueryResultWriter- Overrides:
getSupportedSettingsin classAbstractQueryResultWriter- Returns:
- A collection of
RioSettings that are supported by thisQueryResultWriter.
-
handleNamespace
public void handleNamespace(java.lang.String prefix, java.lang.String uri) throws QueryResultHandlerExceptionDescription copied from interface:QueryResultWriterHandles a namespace prefix declaration. If this is called, it should be called beforeQueryResultWriter.startDocument()to ensure that it has a document wide effect.NOTE: If the format does not support namespaces, it must silently ignore calls to this method.
- Specified by:
handleNamespacein interfaceQueryResultWriter- Parameters:
prefix- The prefix to use for the namespaceuri- The full URI that is to be represented by the prefix.- Throws:
QueryResultHandlerException
-
writeValue
private void writeValue(Value value) throws java.io.IOException
- Throws:
java.io.IOException
-
isQName
private boolean isQName(IRI nextUri)
-
writeTriple
private void writeTriple(Triple triple) throws java.io.IOException
- Throws:
java.io.IOException
-
writeQName
private void writeQName(IRI nextUri)
Write a QName for the given URI if and only if theBasicQueryWriterSettings.ADD_SESAME_QNAMEsetting has been set to true. By default it is false, to ensure that this implementation stays within the specification by default.- Parameters:
nextUri- The prefixed URI to be written as a sesame qname attribute.
-
writeURI
private void writeURI(IRI uri) throws java.io.IOException
- Throws:
java.io.IOException
-
writeBNode
private void writeBNode(BNode bNode) throws java.io.IOException
- Throws:
java.io.IOException
-
writeLiteral
private void writeLiteral(Literal literal) throws java.io.IOException
- Throws:
java.io.IOException
-
-