Class SAXFilter

  • All Implemented Interfaces:
    org.xml.sax.ContentHandler

    class SAXFilter
    extends java.lang.Object
    implements org.xml.sax.ContentHandler
    A filter on SAX events to make life easier on the RDF parser itself. This filter does things like combining a call to startElement() that is directly followed by a call to endElement() to a single call to emptyElement().
    • Field Detail

      • rdfParser

        private final RDFXMLParser rdfParser
        The RDF parser to supply the filtered SAX events to.
      • locator

        private org.xml.sax.Locator locator
        A Locator indicating a position in the text that is currently being parsed by the SAX parser.
      • elInfoStack

        private final java.util.Stack<SAXFilter.ElementInfo> elInfoStack
        Stack of ElementInfo objects.
      • charBuf

        private final java.lang.StringBuilder charBuf
        StringBuilder used to collect text during parsing.
      • documentURI

        private ParsedIRI documentURI
        The document's URI.
      • parseStandAloneDocuments

        private boolean parseStandAloneDocuments
        Flag indicating whether the parser parses stand-alone RDF documents. In stand-alone documents, the rdf:RDF element is optional if it contains just one element.
      • deferredElement

        private SAXFilter.ElementInfo deferredElement
        Variable used to defer reporting of start tags. Reporting start tags is deferred to be able to combine a start tag and an immediately following end tag to a single call to emptyElement().
      • newNamespaceMappings

        private final java.util.Map<java.lang.String,​java.lang.String> newNamespaceMappings
        New namespace mappings that have been reported for the next start tag by the SAX parser, but that are not yet assigned to an ElementInfo object.
      • inRDFContext

        private boolean inRDFContext
        Flag indicating whether we're currently parsing RDF elements.
      • rdfContextStackHeight

        private int rdfContextStackHeight
        The number of elements on the stack that are in the RDF context.
      • parseLiteralMode

        private boolean parseLiteralMode
        Flag indicating whether we're currently parsing an XML literal.
      • xmlLiteralStackHeight

        private int xmlLiteralStackHeight
        The number of elements on the stack that are part of an XML literal.
      • xmlLiteralPrefixes

        private final java.util.List<java.lang.String> xmlLiteralPrefixes
        The prefixes that are defined in the XML literal itself (this in contrast to the namespaces from the XML literal's context).
      • unknownPrefixesInXMLLiteral

        private final java.util.List<java.lang.String> unknownPrefixesInXMLLiteral
        The prefixes that were used in an XML literal, but that were not defined in it (but rather in the XML literal's context).
    • Constructor Detail

    • Method Detail

      • getLocator

        public org.xml.sax.Locator getLocator()
      • clear

        public void clear()
      • setDocumentURI

        public void setDocumentURI​(java.lang.String documentURI)
      • setParseStandAloneDocuments

        public void setParseStandAloneDocuments​(boolean standAloneDocs)
      • getParseStandAloneDocuments

        public boolean getParseStandAloneDocuments()
      • setDocumentLocator

        public void setDocumentLocator​(org.xml.sax.Locator loc)
        Specified by:
        setDocumentLocator in interface org.xml.sax.ContentHandler
      • startDocument

        public void startDocument()
                           throws org.xml.sax.SAXException
        Specified by:
        startDocument in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • endDocument

        public void endDocument()
                         throws org.xml.sax.SAXException
        Specified by:
        endDocument in interface org.xml.sax.ContentHandler
        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
        Throws:
        org.xml.sax.SAXException
      • endPrefixMapping

        public void endPrefixMapping​(java.lang.String prefix)
        Specified by:
        endPrefixMapping in interface org.xml.sax.ContentHandler
      • startElement

        public void startElement​(java.lang.String namespaceURI,
                                 java.lang.String localName,
                                 java.lang.String qName,
                                 org.xml.sax.Attributes attributes)
                          throws org.xml.sax.SAXException
        Specified by:
        startElement in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • endElement

        public void endElement​(java.lang.String namespaceURI,
                               java.lang.String localName,
                               java.lang.String qName)
                        throws org.xml.sax.SAXException
        Specified by:
        endElement in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • characters

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

        public void ignorableWhitespace​(char[] ch,
                                        int start,
                                        int length)
        Specified by:
        ignorableWhitespace in interface org.xml.sax.ContentHandler
      • processingInstruction

        public void processingInstruction​(java.lang.String target,
                                          java.lang.String data)
        Specified by:
        processingInstruction in interface org.xml.sax.ContentHandler
      • skippedEntity

        public void skippedEntity​(java.lang.String name)
        Specified by:
        skippedEntity in interface org.xml.sax.ContentHandler
      • setParseLiteralMode

        public void setParseLiteralMode()
      • createBaseURI

        private ParsedIRI createBaseURI​(java.lang.String uriString)
      • appendStartTag

        private void appendStartTag​(java.lang.String qName,
                                    org.xml.sax.Attributes attributes)
        Appends a start tag to charBuf. This method is used during the parsing of an XML Literal.
      • appendEndTag

        private void appendEndTag​(java.lang.String qName)
        Appends an end tag to charBuf. This method is used during the parsing of an XML Literal.
      • insertUsedContextPrefixes

        private void insertUsedContextPrefixes()
        Inserts prefix mappings from an XML Literal's context for all prefixes that are used in the XML Literal and that are not defined in the XML Literal itself.
      • appendNamespaceDecl

        private void appendNamespaceDecl​(java.lang.StringBuilder sb,
                                         java.lang.String prefix,
                                         java.lang.String namespace)
      • appendAttribute

        private void appendAttribute​(java.lang.StringBuilder sb,
                                     java.lang.String name,
                                     java.lang.String value)