org.eclipse.rdf4j.rio.helpers

## Class RDFParserHelper

- java.lang.Object
- - org.eclipse.rdf4j.rio.helpers.RDFParserHelper

-     public class RDFParserHelper
      extends Object

  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

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `RDFParserHelper()` Protected constructor to prevent direct instantiation.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static 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 any `DatatypeHandler` or `LanguageHandler` implementations that are found in the `ParserConfig`.
    `static 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 any `DatatypeHandler` or `LanguageHandler` implementations that are found in the `ParserConfig`.
    `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 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, 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 msg, ParseErrorListener errListener)` Reports a fatal error to the registered ParseErrorListener, if any, and throws a `ParseException` afterwards.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RDFParserHelper

          protected RDFParserHelper()

      Protected constructor to prevent direct instantiation.

  - ### Method Detail

    - #### 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 any `DatatypeHandler` or `LanguageHandler` implementations that are found in the `ParserConfig`.
      Parameters:
        `label` - The value for `Literal.getLabel()`, which may be iteratively normalized.
        `lang` - If this is not null, and the datatype is either not null, or is equal to `RDF.LANGSTRING`, then a language literal will be created.
        `datatype` - If datatype is not null, and the datatype is not equal to `RDF.LANGSTRING` with a non-null lang, then a datatype literal will be created.
        `parserConfig` - The source of parser settings, including the desired list of `DatatypeHandler` and `LanguageHandler`s to use for verification and normalization of datatype and language literals respectively.
        `errListener` - The `ParseErrorListener` to use for signalling errors. This will be called if a setting is enabled by setting it to true in the `ParserConfig`, after which the error may trigger an `RDFParseException` if the setting is not present in `ParserConfig.getNonFatalErrors()`.
        `valueFactory` - The `ValueFactory` to use for creating new `Literal`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 any `DatatypeHandler` or `LanguageHandler` implementations that are found in the `ParserConfig`.
      Parameters:
        `label` - The value for `Literal.getLabel()`, which may be iteratively normalized.
        `lang` - If this is not null, and the datatype is either not null, or is equal to `RDF.LANGSTRING`, then a language literal will be created.
        `datatype` - If datatype is not null, and the datatype is not equal to `RDF.LANGSTRING` with a non-null lang, then a datatype literal will be created.
        `parserConfig` - The source of parser settings, including the desired list of `DatatypeHandler` and `LanguageHandler`s to use for verification and normalization of datatype and language literals respectively.
        `errListener` - The `ParseErrorListener` to use for signalling errors. This will be called if a setting is enabled by setting it to true in the `ParserConfig`, after which the error may trigger an `RDFParseException` if the setting is not present in `ParserConfig.getNonFatalErrors()`.
        `valueFactory` - The `ValueFactory` to use for creating new `Literal`s using this method.
        `lineNo` - Optional line number, should default to setting this as -1 if not known. Used for `ParseErrorListener.error(String, long, long)` and for `RDFParseException(String, long, long)`.
        `columnNo` - Optional column number, should default to setting this as -1 if not known. Used for `ParseErrorListener.error(String, long, long)` and for `RDFParseException(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 for `ParseErrorListener.error(String, long, long)` and for `RDFParseException(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 if `ParserConfig.isNonFatalError(RioSetting)` returns true an exception will be thrown.
        `parserConfig` - The `ParserConfig` to use for determining if the error is first sent to the ParseErrorListener, and whether it is then also non-fatal to avoid throwing an `RDFParseException`.
        `errListener` - The `ParseErrorListener` that will be sent messages about errors that are enabled.
      Throws:
        `RDFParseException` - If `RioConfig.get(RioSetting)` returns true, and `ParserConfig.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 for `ParseErrorListener.error(String, long, long)` and for `RDFParseException(String, long, long)`.
        `lineNo` - Optional line number, should default to setting this as -1 if not known. Used for `ParseErrorListener.error(String, long, long)` and for `RDFParseException(String, long, long)`.
        `columnNo` - Optional column number, should default to setting this as -1 if not known. Used for `ParseErrorListener.error(String, long, long)` and for `RDFParseException(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 if `ParserConfig.isNonFatalError(RioSetting)` returns true an exception will be thrown.
        `parserConfig` - The `ParserConfig` to use for determining if the error is first sent to the ParseErrorListener, and whether it is then also non-fatal to avoid throwing an `RDFParseException`.
        `errListener` - The `ParseErrorListener` that will be sent messages about errors that are enabled.
      Throws:
        `RDFParseException` - If `RioConfig.get(RioSetting)` returns true, and `ParserConfig.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 for `ParseErrorListener.error(String, long, long)` and for `RDFParseException(String, long, long)`.
        `lineNo` - Optional line number, should default to setting this as -1 if not known. Used for `ParseErrorListener.error(String, long, long)` and for `RDFParseException(String, long, long)`.
        `columnNo` - Optional column number, should default to setting this as -1 if not known. Used for `ParseErrorListener.error(String, long, long)` and for `RDFParseException(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 if `ParserConfig.isNonFatalError(RioSetting)` returns true an exception will be thrown.
        `parserConfig` - The `ParserConfig` to use for determining if the error is first sent to the ParseErrorListener, and whether it is then also non-fatal to avoid throwing an `RDFParseException`.
        `errListener` - The `ParseErrorListener` that will be sent messages about errors that are enabled.
      Throws:
        `RDFParseException` - If `RioConfig.get(RioSetting)` returns true, and `ParserConfig.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 calls `reportFatalError(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 a `RDFParseException`; 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 a `RDFParseException`; 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 a `RDFParseException`; 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`

Copyright © 2015-2022 Eclipse Foundation. All Rights Reserved.