Package org.eclipse.rdf4j.rio.helpers
Class AbstractRDFParser
java.lang.Object
org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
- All Implemented Interfaces:
RDFParser
- Direct Known Subclasses:
BinaryRDFParser
,HDTParser
,JSONLDParser
,NTriplesParser
,RDFJSONParser
,TurtleParser
,XMLReaderBasedParser
Base class for
RDFParser
s offering common functionality for RDF parsers.- Author:
- Arjohn Kampman
-
Field Summary
Modifier and TypeFieldDescriptionprotected RDFHandler
The RDFHandler that will handle the parsed RDF.protected ValueFactory
The ValueFactory to use for creating RDF model objects. -
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new RDFParserBase that will use aSimpleValueFactory
to create RDF model objects.protected
AbstractRDFParser
(ValueFactory valueFactory) Creates a new RDFParserBase that will use the supplied ValueFactory to create RDF model objects. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
clear()
Clears any information that has been collected while parsing.protected void
Deprecated.protected BNode
Deprecated.protected BNode
createBNode
(String nodeID) Deprecated.protected Literal
createLiteral
(String label, String lang, CoreDatatype datatype, long lineNo, long columnNo) Creates aLiteral
object with the supplied parameters, using the lineNo and columnNo to enhance error messages or exceptions that may be generated during the creation of the literal.protected Literal
createLiteral
(String label, String lang, IRI datatype) Creates aLiteral
object with the supplied parameters.protected Literal
createLiteral
(String label, String lang, IRI datatype, long lineNo, long columnNo) Creates aLiteral
object with the supplied parameters, using the lineNo and columnNo to enhance error messages or exceptions that may be generated during the creation of the literal.protected Resource
protected Resource
createNode
(String nodeID) protected Statement
createStatement
(Resource subj, IRI pred, Value obj) Creates a newStatement
object with the supplied components.protected Statement
createStatement
(Resource subj, IRI pred, Value obj, Resource context) Creates a newStatement
object with the supplied components.protected IRI
Creates aIRI
object for the specified URI-string.protected String
getNamespace
(String prefix) Gets the namespace that is associated with the specified prefix or throws anRDFParseException
.Retrieves the current parser configuration as a single object.Collection
<RioSetting<?>> protected void
boolean
protected void
reportError
(Exception e, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.protected void
reportError
(Exception e, RioSetting<Boolean> relevantSetting) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.protected void
reportError
(String msg, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.protected void
reportError
(String msg, Exception e, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.protected void
reportError
(String msg, RioSetting<Boolean> relevantSetting) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.protected void
Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards.protected void
reportFatalError
(Exception e, long lineNo, long columnNo) Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException wrapped the supplied exception afterwards.protected void
reportFatalError
(String msg) Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards.protected void
reportFatalError
(String msg, long lineNo, long columnNo) Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException afterwards.protected void
reportFatalError
(String message, Exception e, long lineNo, long columnNo) Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException wrapped the supplied exception afterwards.protected void
reportLocation
(long lineNo, long columnNo) Reports the specified line- and column number to the registeredParseLocationListener
, if any.protected void
reportWarning
(String msg) Reports a warning to the registered ParseErrorListener, if any.protected void
reportWarning
(String msg, long lineNo, long columnNo) Reports a warning with associated line- and column number to the registered ParseErrorListener, if any.protected IRI
resolveURI
(String uriSpec) Resolves a URI-string against the base URI and creates aIRI
object for it.<T> RDFParser
set
(RioSetting<T> setting, T value) Set a setting on the parser, and return this parser object to allow chaining.protected void
setBaseURI
(String uriSpec) Parses the supplied URI-string and sets it as the base URI for resolving relative URIs.protected void
setBaseURI
(ParsedIRI baseURI) Sets the base URI for resolving relative URIs.protected void
setNamespace
(String prefix, String namespace) Associates the specified prefix to the specified namespace.Sets the ParseErrorListener that will be notified of any errors that this parser finds during parsing.Sets the ParseLocationListener that will be notified of the parser's progress during the parse process.setParserConfig
(ParserConfig config) Sets all supplied parser configuration options.void
setPreserveBNodeIDs
(boolean preserveBNodeIDs) Set whether the parser should preserve bnode identifiers specified in the source (default is false).setRDFHandler
(RDFHandler handler) Sets the RDFHandler that will handle the parsed RDF data.setValueFactory
(ValueFactory valueFactory) Sets the ValueFactory that the parser will use to create Value objects for the parsed RDF data.
-
Field Details
-
rdfHandler
The RDFHandler that will handle the parsed RDF. -
valueFactory
The ValueFactory to use for creating RDF model objects.
-
-
Constructor Details
-
AbstractRDFParser
protected AbstractRDFParser()Creates a new RDFParserBase that will use aSimpleValueFactory
to create RDF model objects. -
AbstractRDFParser
Creates a new RDFParserBase that will use the supplied ValueFactory to create RDF model objects.- Parameters:
valueFactory
- A ValueFactory.
-
-
Method Details
-
setValueFactory
Description copied from interface:RDFParser
Sets the ValueFactory that the parser will use to create Value objects for the parsed RDF data.- Specified by:
setValueFactory
in interfaceRDFParser
- Parameters:
valueFactory
- The value factory that the parser should use.- Returns:
- Either a copy of this parser, if it is immutable, or this object, to allow chaining of method calls.
-
setRDFHandler
Description copied from interface:RDFParser
Sets the RDFHandler that will handle the parsed RDF data.- Specified by:
setRDFHandler
in interfaceRDFParser
- Parameters:
handler
- The RDFHandler to handle the parsed data.- Returns:
- Either a copy of this parser, if it is immutable, or this object, to allow chaining of method calls.
-
getRDFHandler
-
setParseErrorListener
Description copied from interface:RDFParser
Sets the ParseErrorListener that will be notified of any errors that this parser finds during parsing.- Specified by:
setParseErrorListener
in interfaceRDFParser
- Parameters:
el
- The ParseErrorListener that will be notified of errors or warnings.- Returns:
- Either a copy of this parser, if it is immutable, or this object, to allow chaining of method calls.
-
getParseErrorListener
-
setParseLocationListener
Description copied from interface:RDFParser
Sets the ParseLocationListener that will be notified of the parser's progress during the parse process.- Specified by:
setParseLocationListener
in interfaceRDFParser
- Parameters:
el
- The ParseLocationListener that will be notified of the parser's progress.- Returns:
- Either a copy of this parser, if it is immutable, or this object, to allow chaining of method calls.
-
getParseLocationListener
-
setParserConfig
Description copied from interface:RDFParser
Sets all supplied parser configuration options.- Specified by:
setParserConfig
in interfaceRDFParser
- Parameters:
config
- a parser configuration object.- Returns:
- Either a copy of this parser, if it is immutable, or this object, to allow chaining of method calls.
-
getParserConfig
Description copied from interface:RDFParser
Retrieves the current parser configuration as a single object.- Specified by:
getParserConfig
in interfaceRDFParser
- Returns:
- a parser configuration object representing the current configuration of the parser.
-
getSupportedSettings
- Specified by:
getSupportedSettings
in interfaceRDFParser
- Returns:
- A collection of
RioSetting
s that are supported by this RDFParser.
-
set
Description copied from interface:RDFParser
Set a setting on the parser, and return this parser object to allow chaining. -
setPreserveBNodeIDs
public void setPreserveBNodeIDs(boolean preserveBNodeIDs) Description copied from interface:RDFParser
Set whether the parser should preserve bnode identifiers specified in the source (default is false).- Specified by:
setPreserveBNodeIDs
in interfaceRDFParser
-
preserveBNodeIDs
public boolean preserveBNodeIDs() -
setBaseURI
Parses the supplied URI-string and sets it as the base URI for resolving relative URIs. -
setBaseURI
Sets the base URI for resolving relative URIs. -
setNamespace
Associates the specified prefix to the specified namespace. -
getNamespace
Gets the namespace that is associated with the specified prefix or throws anRDFParseException
.- Throws:
RDFParseException
- if no namespace is associated with this prefix
-
clear
protected void clear()Clears any information that has been collected while parsing. This method must be called by subclasses when finishing the parse process. -
initializeNamespaceTableFromConfiguration
protected void initializeNamespaceTableFromConfiguration() -
clearBNodeIDMap
Deprecated.Map is no longer used, callclear()
instead.Clears the map that keeps track of blank nodes that have been parsed. Normally, this map is clear when the document has been parsed completely, but subclasses can clear the map at other moments too, for example when a bnode scope ends. -
resolveURI
Resolves a URI-string against the base URI and creates aIRI
object for it.- Throws:
RDFParseException
-
createURI
Creates aIRI
object for the specified URI-string.- Throws:
RDFParseException
-
createNode
- Returns:
- blank node or skolem IRI
- Throws:
RDFParseException
-
createNode
- Parameters:
nodeID
- node identifier- Returns:
- blank node or skolem IRI
- Throws:
RDFParseException
-
createBNode
Deprecated.Creates a newBNode
object.- Throws:
RDFParseException
-
createBNode
Deprecated.Creates aBNode
object for the specified identifier.- Throws:
RDFParseException
-
createLiteral
Creates aLiteral
object with the supplied parameters.- Throws:
RDFParseException
-
createLiteral
protected Literal createLiteral(String label, String lang, IRI datatype, long lineNo, long columnNo) throws RDFParseException Creates aLiteral
object with the supplied parameters, using the lineNo and columnNo to enhance error messages or exceptions that may be generated during the creation of the literal.- Throws:
RDFParseException
- See Also:
-
createLiteral
protected Literal createLiteral(String label, String lang, CoreDatatype datatype, long lineNo, long columnNo) throws RDFParseException Creates aLiteral
object with the supplied parameters, using the lineNo and columnNo to enhance error messages or exceptions that may be generated during the creation of the literal.- Throws:
RDFParseException
- See Also:
-
createStatement
Creates a newStatement
object with the supplied components.- Throws:
RDFParseException
-
createStatement
protected Statement createStatement(Resource subj, IRI pred, Value obj, Resource context) throws RDFParseException Creates a newStatement
object with the supplied components.- Throws:
RDFParseException
-
reportLocation
protected void reportLocation(long lineNo, long columnNo) Reports the specified line- and column number to the registeredParseLocationListener
, if any. -
reportWarning
Reports a warning to the registered ParseErrorListener, if any. This method simply callsreportWarning(String, long, long)
supplying -1 for the line- and column number. -
reportWarning
Reports a warning with associated line- and column number to the registered ParseErrorListener, if any. -
reportError
protected void reportError(String msg, RioSetting<Boolean> relevantSetting) throws RDFParseException Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.This method also throws an
RDFParseException
when the given setting has been set to true and it is not a nonFatalError.- Parameters:
msg
- The message to use forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.relevantSetting
- The boolean setting that will be checked to determine if this is an issue that we need to look at at all. If this setting is true, then the error listener will receive the error, and ifParserConfig.isNonFatalError(RioSetting)
returns true an exception will be thrown.- Throws:
RDFParseException
- IfRioConfig.get(RioSetting)
returns true, andParserConfig.isNonFatalError(RioSetting)
returns true for the given setting.
-
reportError
protected void reportError(String msg, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting) throws RDFParseException Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.This method also throws an
RDFParseException
when the given setting has been set to true and it is not a nonFatalError.- Parameters:
msg
- The message to use forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.lineNo
- Optional line number, should default to setting this as -1 if not known. Used forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.columnNo
- Optional column number, should default to setting this as -1 if not known. Used forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.relevantSetting
- The boolean setting that will be checked to determine if this is an issue that we need to look at at all. If this setting is true, then the error listener will receive the error, and ifParserConfig.isNonFatalError(RioSetting)
returns true an exception will be thrown.- Throws:
RDFParseException
- IfRioConfig.get(RioSetting)
returns true, andParserConfig.isNonFatalError(RioSetting)
returns true for the given setting.
-
reportError
protected void reportError(Exception e, RioSetting<Boolean> relevantSetting) throws RDFParseException Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.This method also throws an
RDFParseException
when the given setting has been set to true and it is not a nonFatalError.- Parameters:
e
- The exception whose message will be used forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.relevantSetting
- The boolean setting that will be checked to determine if this is an issue that we need to look at at all. If this setting is true, then the error listener will receive the error, and ifParserConfig.isNonFatalError(RioSetting)
returns true an exception will be thrown.- Throws:
RDFParseException
- IfRioConfig.get(RioSetting)
returns true, andParserConfig.isNonFatalError(RioSetting)
returns true for the given setting.
-
reportError
protected void reportError(Exception e, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting) throws RDFParseException Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.This method also throws an
RDFParseException
when the given setting has been set to true and it is not a nonFatalError.- Parameters:
e
- The exception whose message will be used forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.lineNo
- Optional line number, should default to setting this as -1 if not known. Used forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.columnNo
- Optional column number, should default to setting this as -1 if not known. Used forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.relevantSetting
- The boolean setting that will be checked to determine if this is an issue that we need to look at at all. If this setting is true, then the error listener will receive the error, and ifParserConfig.isNonFatalError(RioSetting)
returns true an exception will be thrown.- Throws:
RDFParseException
- IfRioConfig.get(RioSetting)
returns true, andParserConfig.isNonFatalError(RioSetting)
returns true for the given setting.
-
reportError
protected void reportError(String msg, Exception e, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting) throws RDFParseException Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.This method also throws an
RDFParseException
when the given setting has been set to true and it is not a nonFatalError.- Parameters:
msg
- The message to use forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.e
- The exception whose message will be used forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.lineNo
- Optional line number, should default to setting this as -1 if not known. Used forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.columnNo
- Optional column number, should default to setting this as -1 if not known. Used forParseErrorListener.error(String, long, long)
and forRDFParseException(String, long, long)
.relevantSetting
- The boolean setting that will be checked to determine if this is an issue that we need to look at at all. If this setting is true, then the error listener will receive the error, and ifParserConfig.isNonFatalError(RioSetting)
returns true an exception will be thrown.- Throws:
RDFParseException
- IfRioConfig.get(RioSetting)
returns true, andParserConfig.isNonFatalError(RioSetting)
returns true for the given setting.
-
reportFatalError
Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards. This method simply callsreportFatalError(String, long, long)
supplying -1 for the line- and column number.- Throws:
RDFParseException
-
reportFatalError
Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException afterwards.- Throws:
RDFParseException
-
reportFatalError
Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards. An exception is made for the case where the supplied exception is aRDFParseException
; in that case the supplied exception is not wrapped in another ParseException and the error message is not reported to the ParseErrorListener, assuming that it has already been reported when the original ParseException was thrown.This method simply calls
reportFatalError(Exception, long, long)
supplying -1 for the line- and column number.- Throws:
RDFParseException
-
reportFatalError
Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException wrapped the supplied exception afterwards. An exception is made for the case where the supplied exception is aRDFParseException
; in that case the supplied exception is not wrapped in another ParseException and the error message is not reported to the ParseErrorListener, assuming that it has already been reported when the original ParseException was thrown.- Throws:
RDFParseException
-
reportFatalError
protected void reportFatalError(String message, Exception e, long lineNo, long columnNo) throws RDFParseException Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException wrapped the supplied exception afterwards. An exception is made for the case where the supplied exception is aRDFParseException
; in that case the supplied exception is not wrapped in another ParseException and the error message is not reported to the ParseErrorListener, assuming that it has already been reported when the original ParseException was thrown.- Throws:
RDFParseException
-
clear()
instead.