Class AbstractSimpleMarkupHandler

  • All Implemented Interfaces:
    ISimpleMarkupHandler

    public abstract class AbstractSimpleMarkupHandler
    extends java.lang.Object
    implements ISimpleMarkupHandler

    Base abstract implementation of ISimpleMarkupHandler that implements all of its methods as no-ops.

    This class allows the easy creation of new handler implementations by extending it and simply overriding the methods that are of interest for the developer.

    Since:
    2.0.0
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void handleAutoCloseElement​(java.lang.String elementName, int line, int col)
      Called when a close element (a close tag) is needed in order to correctly balance the markup.
      void handleAutoOpenElement​(java.lang.String elementName, java.util.Map<java.lang.String,​java.lang.String> attributes, int line, int col)
      Called when an element (an open tag) is automatically added in order to shape markup according to the spec (made for HTML parsing).
      void handleCDATASection​(char[] buffer, int offset, int len, int line, int col)
      Called when a CDATA section is found.
      void handleCloseElement​(java.lang.String elementName, int line, int col)
      Called when a close element (a close tag) is found.
      void handleComment​(char[] buffer, int offset, int len, int line, int col)
      Called when a comment is found.
      void handleDocType​(java.lang.String elementName, java.lang.String publicId, java.lang.String systemId, java.lang.String internalSubset, int line, int col)
      Called when a DOCTYPE clause is found.
      void handleDocumentEnd​(long endTimeNanos, long totalTimeNanos, int line, int col)
      Called at the end of document parsing.
      void handleDocumentStart​(long startTimeNanos, int line, int col)
      Called at the beginning of document parsing.
      void handleOpenElement​(java.lang.String elementName, java.util.Map<java.lang.String,​java.lang.String> attributes, int line, int col)
      Called when an open element (an open tag) is found.
      void handleProcessingInstruction​(java.lang.String target, java.lang.String content, int line, int col)
      Called when a Processing Instruction is found.
      void handleStandaloneElement​(java.lang.String elementName, java.util.Map<java.lang.String,​java.lang.String> attributes, boolean minimized, int line, int col)
      Called when a standalone element (an element with no closing tag) is found.
      void handleText​(char[] buffer, int offset, int len, int line, int col)
      Called when a text artifact is found.
      void handleUnmatchedCloseElement​(java.lang.String elementName, int line, int col)
      Called when a close element (a close tag) appears without a corresponding open element.
      void handleXmlDeclaration​(java.lang.String version, java.lang.String encoding, java.lang.String standalone, int line, int col)
      Called when an XML Declaration is found.
      • Methods inherited from class java.lang.Object

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

      • AbstractSimpleMarkupHandler

        protected AbstractSimpleMarkupHandler()
    • Method Detail

      • handleDocumentStart

        public void handleDocumentStart​(long startTimeNanos,
                                        int line,
                                        int col)
                                 throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called at the beginning of document parsing.

        Specified by:
        handleDocumentStart in interface ISimpleMarkupHandler
        Parameters:
        startTimeNanos - the current time (in nanoseconds) obtained when parsing starts.
        line - the line of the document where parsing starts (usually number 1).
        col - the column of the document where parsing starts (usually number 1).
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleDocumentEnd

        public void handleDocumentEnd​(long endTimeNanos,
                                      long totalTimeNanos,
                                      int line,
                                      int col)
                               throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called at the end of document parsing.

        Specified by:
        handleDocumentEnd in interface ISimpleMarkupHandler
        Parameters:
        endTimeNanos - the current time (in nanoseconds) obtained when parsing ends.
        totalTimeNanos - the difference between current times at the start and end of parsing (in nanoseconds)
        line - the line of the document where parsing ends (usually the last one)
        col - the column of the document where the parsing ends (usually the last one)
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleXmlDeclaration

        public void handleXmlDeclaration​(java.lang.String version,
                                         java.lang.String encoding,
                                         java.lang.String standalone,
                                         int line,
                                         int col)
                                  throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when an XML Declaration is found.

        Specified by:
        handleXmlDeclaration in interface ISimpleMarkupHandler
        Parameters:
        version - the version value specified (cannot be null).
        encoding - the encoding value specified (can be null).
        standalone - the standalone value specified (can be null).
        line - the line in the document where this elements appears.
        col - the column in the document where this element appears.
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleDocType

        public void handleDocType​(java.lang.String elementName,
                                  java.lang.String publicId,
                                  java.lang.String systemId,
                                  java.lang.String internalSubset,
                                  int line,
                                  int col)
                           throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when a DOCTYPE clause is found.

        Specified by:
        handleDocType in interface ISimpleMarkupHandler
        Parameters:
        elementName - the root element name present in the DOCTYPE clause (e.g. "html").
        publicId - the public ID specified, if present (might be null).
        systemId - the system ID specified, if present (might be null).
        internalSubset - the internal subset specified, if present (might be null).
        line - the line in the document where this elements appears.
        col - the column in the document where this element appears.
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleCDATASection

        public void handleCDATASection​(char[] buffer,
                                       int offset,
                                       int len,
                                       int line,
                                       int col)
                                throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when a CDATA section is found.

        This artifact is returned as a char[] instead of a String because its contents can be large (so creating a String is avoided if it is not considered relevant). In order to convert it to a String, just do new String(buffer, offset, len).

        Please note the returned char[] buffer should never be modified.

        Specified by:
        handleCDATASection in interface ISimpleMarkupHandler
        Parameters:
        buffer - the document buffer.
        offset - the offset of the artifact in the document buffer.
        len - the length (in chars) of the artifact.
        line - the line in the document where this elements appears.
        col - the column in the document where this element appears.
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleComment

        public void handleComment​(char[] buffer,
                                  int offset,
                                  int len,
                                  int line,
                                  int col)
                           throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when a comment is found.

        This artifact is returned as a char[] instead of a String because its contents can be large (so creating a String is avoided if it is not considered relevant). In order to convert it to a String, just do new String(buffer, offset, len).

        Please note the returned char[] buffer should never be modified.

        Specified by:
        handleComment in interface ISimpleMarkupHandler
        Parameters:
        buffer - the document buffer.
        offset - the offset of the artifact in the document buffer.
        len - the length (in chars) of the artifact.
        line - the line in the document where this elements appears.
        col - the column in the document where this element appears.
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleText

        public void handleText​(char[] buffer,
                               int offset,
                               int len,
                               int line,
                               int col)
                        throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when a text artifact is found.

        A sequence of chars is considered to be text when no structures of any kind are contained inside it. This means no tags (a.k.a. elements), DOCTYPE's, processing instructions, etc. are contained in the sequence.

        Text sequences might include any number of new line and/or control characters.

        This artifact is returned as a char[] instead of a String because its contents can be large (so creating a String is avoided if it is not considered relevant). In order to convert it to a String, just do new String(buffer, offset, len).

        Please note the returned char[] buffer should never be modified.

        Specified by:
        handleText in interface ISimpleMarkupHandler
        Parameters:
        buffer - the document buffer (not copied)
        offset - the offset (position in buffer) where the text artifact starts.
        len - the length (in chars) of the text artifact, starting in offset.
        line - the line in the original document where this text artifact starts.
        col - the column in the original document where this text artifact starts.
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleStandaloneElement

        public void handleStandaloneElement​(java.lang.String elementName,
                                            java.util.Map<java.lang.String,​java.lang.String> attributes,
                                            boolean minimized,
                                            int line,
                                            int col)
                                     throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when a standalone element (an element with no closing tag) is found.

        Note that the element attributes map can be null if no attributes are present.

        Specified by:
        handleStandaloneElement in interface ISimpleMarkupHandler
        Parameters:
        elementName - the element name (e.g. "<img src="logo.png">" -> "img").
        attributes - the element attributes map, or null if no attributes are present.
        minimized - whether the element has been found minimized (<element/>)in code or not.
        line - the line in the document where this elements appears.
        col - the column in the document where this element appears.
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleOpenElement

        public void handleOpenElement​(java.lang.String elementName,
                                      java.util.Map<java.lang.String,​java.lang.String> attributes,
                                      int line,
                                      int col)
                               throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when an open element (an open tag) is found.

        Note that the element attributes map can be null if no attributes are present.

        Specified by:
        handleOpenElement in interface ISimpleMarkupHandler
        Parameters:
        elementName - the element name (e.g. "<div class="content">" -> "div").
        attributes - the element attributes map, or null if no attributes are present.
        line - the line in the document where this elements appears.
        col - the column in the document where this element appears.
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleAutoOpenElement

        public void handleAutoOpenElement​(java.lang.String elementName,
                                          java.util.Map<java.lang.String,​java.lang.String> attributes,
                                          int line,
                                          int col)
                                   throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when an element (an open tag) is automatically added in order to shape markup according to the spec (made for HTML parsing). See ParseConfiguration.ElementBalancing.AUTO_OPEN_CLOSE for more info.

        Note that the element attributes map can be null if no attributes are present.

        Specified by:
        handleAutoOpenElement in interface ISimpleMarkupHandler
        Parameters:
        elementName - the element name (e.g. "<div class="content">" -> "div").
        attributes - the element attributes map, or null if no attributes are present.
        line - the line in the document where this elements appears.
        col - the column in the document where this element appears.
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleCloseElement

        public void handleCloseElement​(java.lang.String elementName,
                                       int line,
                                       int col)
                                throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when a close element (a close tag) is found.

        Specified by:
        handleCloseElement in interface ISimpleMarkupHandler
        Parameters:
        elementName - the element name (e.g. "</div>" -> "div").
        line - the line in the document where this elements appears.
        col - the column in the document where this element appears.
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleAutoCloseElement

        public void handleAutoCloseElement​(java.lang.String elementName,
                                           int line,
                                           int col)
                                    throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when a close element (a close tag) is needed in order to correctly balance the markup. This is called auto-closing.

        Implementors might choose to ignore these autoclosing events.

        Specified by:
        handleAutoCloseElement in interface ISimpleMarkupHandler
        Parameters:
        elementName - the element name (e.g. "</div>" -> "div").
        line - the line in the document where this elements appears.
        col - the column in the document where this element appears.
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleUnmatchedCloseElement

        public void handleUnmatchedCloseElement​(java.lang.String elementName,
                                                int line,
                                                int col)
                                         throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when a close element (a close tag) appears without a corresponding open element.

        Implementors might choose to ignore these events.

        Specified by:
        handleUnmatchedCloseElement in interface ISimpleMarkupHandler
        Parameters:
        elementName - the element name (e.g. "</div>" -> "div").
        line - the line in the document where this elements appears.
        col - the column in the document where this element appears.
        Throws:
        ParseException - if any exceptions occur during handling.
      • handleProcessingInstruction

        public void handleProcessingInstruction​(java.lang.String target,
                                                java.lang.String content,
                                                int line,
                                                int col)
                                         throws ParseException
        Description copied from interface: ISimpleMarkupHandler

        Called when a Processing Instruction is found.

        Specified by:
        handleProcessingInstruction in interface ISimpleMarkupHandler
        Parameters:
        target - the target specified in the processing instruction.
        content - the content of the processing instruction, if specified (might be null).
        line - the line in the document where this elements appears.
        col - the column in the document where this element appears.
        Throws:
        ParseException - if any exceptions occur during handling.