Package org.eclipse.rdf4j.rio.helpers
Class RDFParserHelper
java.lang.Object
org.eclipse.rdf4j.rio.helpers.RDFParserHelper
Helper methods that may be used by
RDFParser
implementations.
This class contains reference implementations of the workflows for ParseErrorListener
,
RDFParseException
, ParserConfig
, DatatypeHandler
and LanguageHandler
related methods
- Author:
- Peter Ansell
-
Constructor Summary
ModifierConstructorDescriptionprotected
Protected constructor to prevent direct instantiation. -
Method Summary
Modifier and TypeMethodDescriptionstatic final Literal
createLiteral
(String label, String lang, IRI datatype, ParserConfig parserConfig, ParseErrorListener errListener, ValueFactory valueFactory) Create a literal using the given parameters, including iterative verification and normalization by anyDatatypeHandler
orLanguageHandler
implementations that are found in theParserConfig
.static final Literal
createLiteral
(String label, String lang, IRI datatype, ParserConfig parserConfig, ParseErrorListener errListener, ValueFactory valueFactory, long lineNo, long columnNo) Create a literal using the given parameters, including iterative verification and normalization by anyDatatypeHandler
orLanguageHandler
implementations that are found in theParserConfig
.static void
reportError
(Exception e, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting, ParserConfig parserConfig, ParseErrorListener errListener) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.static void
reportError
(String msg, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting, ParserConfig parserConfig, ParseErrorListener errListener) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.static void
reportError
(String msg, RioSetting<Boolean> relevantSetting, ParserConfig parserConfig, ParseErrorListener errListener) Reports an error with associated line- and column number to the registered ParseErrorListener, if the given setting has been set to true.static void
reportFatalError
(Exception e, long lineNo, long columnNo, ParseErrorListener errListener) 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.static void
reportFatalError
(Exception e, ParseErrorListener errListener) Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards.static void
reportFatalError
(String msg, long lineNo, long columnNo, ParseErrorListener errListener) Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException afterwards.static void
reportFatalError
(String message, Exception e, long lineNo, long columnNo, ParseErrorListener errListener) 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.static void
reportFatalError
(String msg, ParseErrorListener errListener) Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards.
-
Constructor Details
-
RDFParserHelper
protected RDFParserHelper()Protected constructor to prevent direct instantiation.
-
-
Method Details
-
createLiteral
public static final Literal createLiteral(String label, String lang, IRI datatype, ParserConfig parserConfig, ParseErrorListener errListener, ValueFactory valueFactory) throws RDFParseException Create a literal using the given parameters, including iterative verification and normalization by anyDatatypeHandler
orLanguageHandler
implementations that are found in theParserConfig
.- Parameters:
label
- The value forLiteral.getLabel()
, which may be iteratively normalized.lang
- If this is not null, and the datatype is either not null, or is equal toRDF.LANGSTRING
, then a language literal will be created.datatype
- If datatype is not null, and the datatype is not equal toRDF.LANGSTRING
with a non-null lang, then a datatype literal will be created.parserConfig
- The source of parser settings, including the desired list ofDatatypeHandler
andLanguageHandler
s to use for verification and normalization of datatype and language literals respectively.errListener
- TheParseErrorListener
to use for signalling errors. This will be called if a setting is enabled by setting it to true in theParserConfig
, after which the error may trigger anRDFParseException
if the setting is not present inParserConfig.getNonFatalErrors()
.valueFactory
- TheValueFactory
to use for creating newLiteral
s using this method.- Returns:
- A
Literal
created based on the given parameters. - Throws:
RDFParseException
- If there was an error during the process that could not be recovered from, based on settings in the given parser config.
-
createLiteral
public static final Literal createLiteral(String label, String lang, IRI datatype, ParserConfig parserConfig, ParseErrorListener errListener, ValueFactory valueFactory, long lineNo, long columnNo) throws RDFParseException Create a literal using the given parameters, including iterative verification and normalization by anyDatatypeHandler
orLanguageHandler
implementations that are found in theParserConfig
.- Parameters:
label
- The value forLiteral.getLabel()
, which may be iteratively normalized.lang
- If this is not null, and the datatype is either not null, or is equal toRDF.LANGSTRING
, then a language literal will be created.datatype
- If datatype is not null, and the datatype is not equal toRDF.LANGSTRING
with a non-null lang, then a datatype literal will be created.parserConfig
- The source of parser settings, including the desired list ofDatatypeHandler
andLanguageHandler
s to use for verification and normalization of datatype and language literals respectively.errListener
- TheParseErrorListener
to use for signalling errors. This will be called if a setting is enabled by setting it to true in theParserConfig
, after which the error may trigger anRDFParseException
if the setting is not present inParserConfig.getNonFatalErrors()
.valueFactory
- TheValueFactory
to use for creating newLiteral
s using this method.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)
.- Returns:
- A
Literal
created based on the given parameters. - Throws:
RDFParseException
- If there was an error during the process that could not be recovered from, based on settings in the given parser config.
-
reportError
public static void reportError(String msg, RioSetting<Boolean> relevantSetting, ParserConfig parserConfig, ParseErrorListener errListener) 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.parserConfig
- TheParserConfig
to use for determining if the error is first sent to the ParseErrorListener, and whether it is then also non-fatal to avoid throwing anRDFParseException
.errListener
- TheParseErrorListener
that will be sent messages about errors that are enabled.- Throws:
RDFParseException
- IfRioConfig.get(RioSetting)
returns true, andParserConfig.isNonFatalError(RioSetting)
returns true for the given setting.
-
reportError
public static void reportError(String msg, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting, ParserConfig parserConfig, ParseErrorListener errListener) 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.parserConfig
- TheParserConfig
to use for determining if the error is first sent to the ParseErrorListener, and whether it is then also non-fatal to avoid throwing anRDFParseException
.errListener
- TheParseErrorListener
that will be sent messages about errors that are enabled.- Throws:
RDFParseException
- IfRioConfig.get(RioSetting)
returns true, andParserConfig.isNonFatalError(RioSetting)
returns true for the given setting.
-
reportError
public static void reportError(Exception e, long lineNo, long columnNo, RioSetting<Boolean> relevantSetting, ParserConfig parserConfig, ParseErrorListener errListener) 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 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.parserConfig
- TheParserConfig
to use for determining if the error is first sent to the ParseErrorListener, and whether it is then also non-fatal to avoid throwing anRDFParseException
.errListener
- TheParseErrorListener
that will be sent messages about errors that are enabled.- Throws:
RDFParseException
- IfRioConfig.get(RioSetting)
returns true, andParserConfig.isNonFatalError(RioSetting)
returns true for the given setting.
-
reportFatalError
public static void reportFatalError(String msg, ParseErrorListener errListener) throws RDFParseException Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards. This method simply callsreportFatalError(String, long, long, ParseErrorListener)
supplying -1 for the line- and column number.- Throws:
RDFParseException
-
reportFatalError
public static void reportFatalError(String msg, long lineNo, long columnNo, ParseErrorListener errListener) throws RDFParseException Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException afterwards.- Throws:
RDFParseException
-
reportFatalError
public static void reportFatalError(Exception e, ParseErrorListener errListener) throws RDFParseException 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, ParseErrorListener)
supplying -1 for the line- and column number.- Throws:
RDFParseException
-
reportFatalError
public static void reportFatalError(Exception e, long lineNo, long columnNo, ParseErrorListener errListener) 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
-
reportFatalError
public static void reportFatalError(String message, Exception e, long lineNo, long columnNo, ParseErrorListener errListener) 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
-