Class ContentReader

  • All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

    class ContentReader
    extends org.xml.sax.helpers.DefaultHandler
    Content reader part.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ContentReader.State  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void characters​(char[] ch, int start, int length)  
      private boolean checkRdfQName​(java.lang.String localName, java.lang.String qName)
      Returns true if the given qualified name is in the RDF namespace and is equal to the given local name.
      void endDocument()  
      void endElement​(java.lang.String uri, java.lang.String localName, java.lang.String name)  
      void endPrefixMapping​(java.lang.String prefix)  
      private ContentReader.State getCurrentState()
      Returns the state at the top of the heap.
      private Reference getCurrentSubject()
      Returns the subject at the top of the heap.
      private Literal getLiteral​(java.lang.String value, java.lang.String datatype, Language language)
      Returns a Literal object according to the given parameters.
      private void link()
      A new statement has been detected with the current subject, predicate and object.
      private void link​(Reference subject, Reference predicate, Reference object)
      Creates a statement and reify it, if necessary.
      private void link​(Reference subject, Reference predicate, Literal object)
      Creates a statement and reify it, if necessary.
      private static java.lang.String newBlankNodeId()
      Returns the identifier of a new blank node.
      private Reference parseNode​(java.lang.String uri, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes attributes)
      Returns the RDF URI of the given node represented by its namespace uri, local name, name, and attributes.
      private ContentReader.State popState()
      Returns the state at the top of the heap and removes it from the heap.
      private Reference popSubject()
      Returns the subject at the top of the heap and removes it from the heap.
      private void pushState​(ContentReader.State state)
      Adds a new state at the top of the heap.
      private void pushSubject​(Reference subject)
      Adds a new subject at the top of the heap.
      private Reference resolve​(java.lang.String value, boolean fragment)
      Returns the absolute reference for a given value.
      private Reference resolve​(java.lang.String uri, java.lang.String qName)
      Returns the absolute reference of a parsed element according to its URI, qualified name.
      void startDocument()  
      void startElement​(java.lang.String uri, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes attributes)  
      void startPrefixMapping​(java.lang.String prefix, java.lang.String uri)  
      • Methods inherited from class org.xml.sax.helpers.DefaultHandler

        error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, unparsedEntityDecl, warning
      • Methods inherited from class java.lang.Object

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

      • blankNodeId

        private static int blankNodeId
        Increment used to identify inner blank nodes.
      • builder

        private java.lang.StringBuilder builder
        Container for string content.
      • consumingContent

        private boolean consumingContent
        Indicates if the string content must be consumed.
      • currentDataType

        private java.lang.String currentDataType
        Current data type.
      • currentObject

        private java.lang.Object currentObject
        Current object.
      • currentPredicate

        private Reference currentPredicate
        Current predicate.
      • graphHandler

        private GraphHandler graphHandler
        The graph handler to call when a link is detected.
      • nodeDepth

        private int nodeDepth
        Used to get the content of XMl literal.
      • prefixes

        private java.util.Map<java.lang.String,​java.lang.String> prefixes
        The list of known prefixes.
      • rdfDefaultNamespace

        private boolean rdfDefaultNamespace
        True if RdfRepresentation#RDF_SYNTAX is the default namespace.
      • reifiedRef

        private Reference reifiedRef
        Used when a statement must be reified.
      • subjects

        private java.util.List<Reference> subjects
        Heap of subjects.
    • Constructor Detail

      • ContentReader

        public ContentReader​(Representation representation,
                             GraphHandler graphHandler)
        Constructor.
        Parameters:
        graphHandler - The graph handler to call when a link is detected.
        representation - The input representation.
    • Method Detail

      • newBlankNodeId

        private static java.lang.String newBlankNodeId()
        Returns the identifier of a new blank node.
        Returns:
        The identifier of a new blank node.
      • characters

        public void characters​(char[] ch,
                               int start,
                               int length)
                        throws org.xml.sax.SAXException
        Specified by:
        characters in interface org.xml.sax.ContentHandler
        Overrides:
        characters in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • checkRdfQName

        private boolean checkRdfQName​(java.lang.String localName,
                                      java.lang.String qName)
        Returns true if the given qualified name is in the RDF namespace and is equal to the given local name.
        Parameters:
        localName - The local name to compare to.
        qName - The qualified name
      • endDocument

        public void endDocument()
                         throws org.xml.sax.SAXException
        Specified by:
        endDocument in interface org.xml.sax.ContentHandler
        Overrides:
        endDocument in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • endElement

        public void endElement​(java.lang.String uri,
                               java.lang.String localName,
                               java.lang.String name)
                        throws org.xml.sax.SAXException
        Specified by:
        endElement in interface org.xml.sax.ContentHandler
        Overrides:
        endElement in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • endPrefixMapping

        public void endPrefixMapping​(java.lang.String prefix)
                              throws org.xml.sax.SAXException
        Specified by:
        endPrefixMapping in interface org.xml.sax.ContentHandler
        Overrides:
        endPrefixMapping in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • getCurrentState

        private ContentReader.State getCurrentState()
        Returns the state at the top of the heap.
        Returns:
        The state at the top of the heap.
      • getCurrentSubject

        private Reference getCurrentSubject()
        Returns the subject at the top of the heap.
        Returns:
        The subject at the top of the heap.
      • getLiteral

        private Literal getLiteral​(java.lang.String value,
                                   java.lang.String datatype,
                                   Language language)
        Returns a Literal object according to the given parameters.
        Parameters:
        value - The value of the literal.
        datatype - The datatype of the literal.
        language - The language of the literal.
        Returns:
        A Literal object
      • link

        private void link()
        A new statement has been detected with the current subject, predicate and object.
      • link

        private void link​(Reference subject,
                          Reference predicate,
                          Literal object)
        Creates a statement and reify it, if necessary.
        Parameters:
        subject - The subject of the statement.
        predicate - The predicate of the statement.
        object - The object of the statement.
      • link

        private void link​(Reference subject,
                          Reference predicate,
                          Reference object)
        Creates a statement and reify it, if necessary.
        Parameters:
        subject - The subject of the statement.
        predicate - The predicate of the statement.
        object - The object of the statement.
      • parseNode

        private Reference parseNode​(java.lang.String uri,
                                    java.lang.String localName,
                                    java.lang.String name,
                                    org.xml.sax.Attributes attributes)
        Returns the RDF URI of the given node represented by its namespace uri, local name, name, and attributes. It also generates the available statements, thanks to some shortcuts provided by the RDF XML syntax.
        Parameters:
        uri -
        localName -
        name -
        attributes -
        Returns:
        The RDF URI of the given node.
      • popState

        private ContentReader.State popState()
        Returns the state at the top of the heap and removes it from the heap.
        Returns:
        The state at the top of the heap.
      • popSubject

        private Reference popSubject()
        Returns the subject at the top of the heap and removes it from the heap.
        Returns:
        The subject at the top of the heap.
      • pushState

        private void pushState​(ContentReader.State state)
        Adds a new state at the top of the heap.
        Parameters:
        state - The state to add.
      • pushSubject

        private void pushSubject​(Reference subject)
        Adds a new subject at the top of the heap.
        Parameters:
        subject - The subject to add.
      • resolve

        private Reference resolve​(java.lang.String value,
                                  boolean fragment)
        Returns the absolute reference for a given value. If this value is not an absolute URI, then the base URI is used.
        Parameters:
        value - The value.
        fragment - True if the value is a fragment to add to the base reference.
        Returns:
        Returns the absolute reference for a given value.
      • resolve

        private Reference resolve​(java.lang.String uri,
                                  java.lang.String qName)
        Returns the absolute reference of a parsed element according to its URI, qualified name. In case the base URI is null or empty, then an attempt is made to look for the mapped URI according to the qName.
        Parameters:
        uri - The base URI.
        qName - The qualified name of the parsed element.
        Returns:
        Returns the absolute reference of a parsed element.
      • startDocument

        public void startDocument()
                           throws org.xml.sax.SAXException
        Specified by:
        startDocument in interface org.xml.sax.ContentHandler
        Overrides:
        startDocument in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • startElement

        public void startElement​(java.lang.String uri,
                                 java.lang.String localName,
                                 java.lang.String name,
                                 org.xml.sax.Attributes attributes)
                          throws org.xml.sax.SAXException
        Specified by:
        startElement in interface org.xml.sax.ContentHandler
        Overrides:
        startElement in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • startPrefixMapping

        public void startPrefixMapping​(java.lang.String prefix,
                                       java.lang.String uri)
                                throws org.xml.sax.SAXException
        Specified by:
        startPrefixMapping in interface org.xml.sax.ContentHandler
        Overrides:
        startPrefixMapping in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException