Class AbstractRDFParser

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractRDFParser()
      Creates a new RDFParserBase that will use a SimpleValueFactory 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

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected void clear()
      Clears any information that has been collected while parsing.
      protected void clearBNodeIDMap()
      Deprecated.
      Map is no longer used, call clear() instead.
      protected BNode createBNode()
      Deprecated.
      protected BNode createBNode​(java.lang.String nodeID)
      Deprecated.
      protected Literal createLiteral​(java.lang.String label, java.lang.String lang, IRI datatype)
      Creates a Literal object with the supplied parameters.
      protected Literal createLiteral​(java.lang.String label, java.lang.String lang, IRI datatype, long lineNo, long columnNo)
      Creates a Literal 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 createNode()
      Creates a new BNode or Skolem IRI object.
      protected Resource createNode​(java.lang.String nodeID)
      Creates a BNode or Skolem IRI object for the specified identifier.
      protected Statement createStatement​(Resource subj, IRI pred, Value obj)
      Creates a new Statement object with the supplied components.
      protected Statement createStatement​(Resource subj, IRI pred, Value obj, Resource context)
      Creates a new Statement object with the supplied components.
      private java.lang.String createUniqueBNodePrefix()  
      protected IRI createURI​(java.lang.String uri)
      Creates a IRI object for the specified URI-string.
      private ParsedIRI getCachedSkolemOrigin()
      Parse skolem origin, if set
      protected java.lang.String getNamespace​(java.lang.String prefix)
      Gets the namespace that is associated with the specified prefix or throws an RDFParseException.
      ParseErrorListener getParseErrorListener()  
      ParseLocationListener getParseLocationListener()  
      ParserConfig getParserConfig()
      Retrieves the current parser configuration as a single object.
      RDFHandler getRDFHandler()  
      java.util.Collection<RioSetting<?>> getSupportedSettings()  
      protected void initializeNamespaceTableFromConfiguration()  
      boolean preserveBNodeIDs()  
      protected void reportError​(java.lang.Exception e, long lineNo, long columnNo, RioSetting<java.lang.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​(java.lang.Exception e, RioSetting<java.lang.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​(java.lang.String msg, long lineNo, long columnNo, RioSetting<java.lang.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​(java.lang.String msg, java.lang.Exception e, long lineNo, long columnNo, RioSetting<java.lang.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​(java.lang.String msg, RioSetting<java.lang.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 reportFatalError​(java.lang.Exception e)
      Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards.
      protected void reportFatalError​(java.lang.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​(java.lang.String msg)
      Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards.
      protected void reportFatalError​(java.lang.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​(java.lang.String message, java.lang.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 registered ParseLocationListener, if any.
      protected void reportWarning​(java.lang.String msg)
      Reports a warning to the registered ParseErrorListener, if any.
      protected void reportWarning​(java.lang.String msg, long lineNo, long columnNo)
      Reports a warning with associated line- and column number to the registered ParseErrorListener, if any.
      protected IRI resolveURI​(java.lang.String uriSpec)
      Resolves a URI-string against the base URI and creates a IRI 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​(java.lang.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​(java.lang.String prefix, java.lang.String namespace)
      Associates the specified prefix to the specified namespace.
      RDFParser setParseErrorListener​(ParseErrorListener el)
      Sets the ParseErrorListener that will be notified of any errors that this parser finds during parsing.
      RDFParser setParseLocationListener​(ParseLocationListener el)
      Sets the ParseLocationListener that will be notified of the parser's progress during the parse process.
      RDFParser 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).
      RDFParser setRDFHandler​(RDFHandler handler)
      Sets the RDFHandler that will handle the parsed RDF data.
      RDFParser setValueFactory​(ValueFactory valueFactory)
      Sets the ValueFactory that the parser will use to create Value objects for the parsed RDF data.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • uniqueIdPrefix

        private static final java.lang.String uniqueIdPrefix
      • uniqueIdSuffix

        private static final java.util.concurrent.atomic.AtomicLong uniqueIdSuffix
      • md5

        private final java.security.MessageDigest md5
      • rdfHandler

        protected RDFHandler rdfHandler
        The RDFHandler that will handle the parsed RDF.
      • errListener

        private ParseErrorListener errListener
        An optional ParseErrorListener to report parse errors to.
      • locationListener

        private ParseLocationListener locationListener
        An optional ParseLocationListener to report parse progress in the form of line- and column numbers to.
      • valueFactory

        protected ValueFactory valueFactory
        The ValueFactory to use for creating RDF model objects.
      • originalValueFactory

        private ValueFactory originalValueFactory
      • baseURI

        private ParsedIRI baseURI
        The base URI for resolving relative URIs.
      • skolemOrigin

        private java.lang.String skolemOrigin
        The base URI for skolemizing IRIs.
      • parsedSkolemOrigin

        private ParsedIRI parsedSkolemOrigin
      • nextBNodePrefix

        private java.lang.String nextBNodePrefix
        Enables a consistent global mapping of blank node identifiers without using a map, but concatenating this as a prefix for the blank node identifiers supplied by the parser.
      • namespaceTable

        private final java.util.Map<java.lang.String,​java.lang.String> namespaceTable
        Mapping from namespace prefixes to namespace names.
      • parserConfig

        private ParserConfig parserConfig
        A collection of configuration options for this parser.
    • Constructor Detail

      • AbstractRDFParser

        protected AbstractRDFParser()
        Creates a new RDFParserBase that will use a SimpleValueFactory to create RDF model objects.
      • AbstractRDFParser

        protected AbstractRDFParser​(ValueFactory valueFactory)
        Creates a new RDFParserBase that will use the supplied ValueFactory to create RDF model objects.
        Parameters:
        valueFactory - A ValueFactory.
    • Method Detail

      • setValueFactory

        public RDFParser setValueFactory​(ValueFactory valueFactory)
        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 interface RDFParser
        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

        public RDFParser setRDFHandler​(RDFHandler handler)
        Description copied from interface: RDFParser
        Sets the RDFHandler that will handle the parsed RDF data.
        Specified by:
        setRDFHandler in interface RDFParser
        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

        public RDFHandler getRDFHandler()
      • setParseErrorListener

        public RDFParser setParseErrorListener​(ParseErrorListener el)
        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 interface RDFParser
        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.
      • setParseLocationListener

        public RDFParser setParseLocationListener​(ParseLocationListener el)
        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 interface RDFParser
        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.
      • setParserConfig

        public RDFParser setParserConfig​(ParserConfig config)
        Description copied from interface: RDFParser
        Sets all supplied parser configuration options.
        Specified by:
        setParserConfig in interface RDFParser
        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

        public ParserConfig getParserConfig()
        Description copied from interface: RDFParser
        Retrieves the current parser configuration as a single object.
        Specified by:
        getParserConfig in interface RDFParser
        Returns:
        a parser configuration object representing the current configuration of the parser.
      • set

        public <T> RDFParser set​(RioSetting<T> setting,
                                 T value)
        Description copied from interface: RDFParser
        Set a setting on the parser, and return this parser object to allow chaining.
        Specified by:
        set in interface RDFParser
        Parameters:
        setting - The setting to change.
        value - The value to change.
        Returns:
        Either a copy of this parser, if it is immutable, or this object, to allow chaining of method calls.
      • 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 interface RDFParser
      • preserveBNodeIDs

        public boolean preserveBNodeIDs()
      • setBaseURI

        protected void setBaseURI​(java.lang.String uriSpec)
        Parses the supplied URI-string and sets it as the base URI for resolving relative URIs.
      • setBaseURI

        protected void setBaseURI​(ParsedIRI baseURI)
        Sets the base URI for resolving relative URIs.
      • setNamespace

        protected void setNamespace​(java.lang.String prefix,
                                    java.lang.String namespace)
        Associates the specified prefix to the specified namespace.
      • getNamespace

        protected java.lang.String getNamespace​(java.lang.String prefix)
                                         throws RDFParseException
        Gets the namespace that is associated with the specified prefix or throws an RDFParseException.
        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
        protected void clearBNodeIDMap()
        Deprecated.
        Map is no longer used, call clear() 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.
      • createNode

        protected Resource createNode​(java.lang.String nodeID)
                               throws RDFParseException
        Creates a BNode or Skolem IRI object for the specified identifier.
        Parameters:
        nodeID - node identifier
        Returns:
        blank node or skolem IRI
        Throws:
        RDFParseException
      • reportLocation

        protected void reportLocation​(long lineNo,
                                      long columnNo)
        Reports the specified line- and column number to the registered ParseLocationListener, if any.
      • reportWarning

        protected void reportWarning​(java.lang.String msg)
        Reports a warning to the registered ParseErrorListener, if any. This method simply calls reportWarning(String, long, long) supplying -1 for the line- and column number.
      • reportWarning

        protected void reportWarning​(java.lang.String msg,
                                     long lineNo,
                                     long columnNo)
        Reports a warning with associated line- and column number to the registered ParseErrorListener, if any.
      • reportFatalError

        protected void reportFatalError​(java.lang.String msg,
                                        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 afterwards.
        Throws:
        RDFParseException
      • reportFatalError

        protected void reportFatalError​(java.lang.Exception e)
                                 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) supplying -1 for the line- and column number.

        Throws:
        RDFParseException
      • reportFatalError

        protected void reportFatalError​(java.lang.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 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

        protected void reportFatalError​(java.lang.String message,
                                        java.lang.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 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
      • createUniqueBNodePrefix

        private java.lang.String createUniqueBNodePrefix()
      • getCachedSkolemOrigin

        private ParsedIRI getCachedSkolemOrigin()
        Parse skolem origin, if set
        Returns:
        skolem origin or null