org.attoparser
Class AbstractAttoHandler

Object
  extended by org.attoparser.AbstractAttoHandler
All Implemented Interfaces:
IAttoHandler, ITimedDocumentHandling
Direct Known Subclasses:
AbstractBasicMarkupAttoHandler

public abstract class AbstractAttoHandler
extends Object
implements IAttoHandler, ITimedDocumentHandling

Base abstract class for IAttoHandler implementations, providing timing.

This class provides empty implementations for all event handlers, so that subclasses can override only the methods they need.

Since:
1.0
Author:
Daniel Fernández

Constructor Summary
protected AbstractAttoHandler()
           
 
Method Summary
 long getEndTimeNanos()
           Return the current time (in nanoseconds) obtained when parsing ends.
 long getStartTimeNanos()
           Return the current time (in nanoseconds) obtained when parsing starts.
 long getTotalTimeNanos()
           Return the difference (in nanoseconds) between parsing start and end times.
 void handleDocumentEnd(int line, int col)
           Called at the end of document parsing.
 void handleDocumentEnd(long endTimeNanos, long totalTimeNanos, int line, int col)
           Called at the end of document parsing, adding timing information.
 void handleDocumentStart(int line, int col)
           Called at the beginning of document parsing.
 void handleDocumentStart(long startTimeNanos, int line, int col)
           Called at the beginning of document parsing, adding timing information.
 void handleStructure(char[] buffer, int offset, int len, int line, int col)
           Called when a structure artifact is found.
 void handleText(char[] buffer, int offset, int len, int line, int col)
           Called when a text artifact is found.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractAttoHandler

protected AbstractAttoHandler()
Method Detail

handleDocumentStart

public final void handleDocumentStart(int line,
                                      int col)
                               throws AttoParseException
Description copied from interface: IAttoHandler

Called at the beginning of document parsing.

Specified by:
handleDocumentStart in interface IAttoHandler
Parameters:
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:
AttoParseException

handleDocumentEnd

public final void handleDocumentEnd(int line,
                                    int col)
                             throws AttoParseException
Description copied from interface: IAttoHandler

Called at the end of document parsing.

Specified by:
handleDocumentEnd in interface IAttoHandler
Parameters:
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:
AttoParseException

handleText

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

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. In markup parsers, for example, 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.

Text artifacts are reported using the document buffer directly, and this buffer should not be considered to be immutable, so reported texts should be copied if they need to be stored (either by copying len chars from the buffer char[] starting in offset or by creating a String from it using the same specification).

Implementations of this handler should never modify the document buffer.

Specified by:
handleText in interface IAttoHandler
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:
AttoParseException

handleStructure

public void handleStructure(char[] buffer,
                            int offset,
                            int len,
                            int line,
                            int col)
                     throws AttoParseException
Description copied from interface: IAttoHandler

Called when a structure artifact is found.

Depending on the specific IAttoParser implementation being used, "structure" might have a different meaning. In markup-oriented parsers (like the default MarkupAttoParser) implementation provided, structures like tags (a.k.a. elements), DOCTYPEs, XML Declarations, processing instructions, etc. are reported using this event handler.

Lower-level IAttoHandler implementations will usually provide a finer-grained differentiation among the different types of structures (see for example AbstractBasicMarkupAttoHandler or AbstractDetailedMarkupAttoHandler).

Structure artifacts are reported using the document buffer directly, and this buffer should not be considered to be immutable, so reported structures should be copied if they need to be stored (either by copying len chars from the buffer char[] starting in offset or by creating a String from it using the same specification).

Implementations of this handler should never modify the document buffer.

Specified by:
handleStructure in interface IAttoHandler
Parameters:
buffer - the document buffer (not copied)
offset - the offset (position in buffer) where the structure artifact starts.
len - the length (in chars) of the structure artifact, starting in offset.
line - the line in the original document where this structure artifact starts.
col - the column in the original document where this structure artifact starts.
Throws:
AttoParseException

handleDocumentStart

public void handleDocumentStart(long startTimeNanos,
                                int line,
                                int col)
                         throws AttoParseException
Description copied from interface: ITimedDocumentHandling

Called at the beginning of document parsing, adding timing information.

Specified by:
handleDocumentStart in interface ITimedDocumentHandling
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:
AttoParseException

handleDocumentEnd

public void handleDocumentEnd(long endTimeNanos,
                              long totalTimeNanos,
                              int line,
                              int col)
                       throws AttoParseException
Description copied from interface: ITimedDocumentHandling

Called at the end of document parsing, adding timing information.

Specified by:
handleDocumentEnd in interface ITimedDocumentHandling
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:
AttoParseException

getStartTimeNanos

public final long getStartTimeNanos()
Description copied from interface: ITimedDocumentHandling

Return the current time (in nanoseconds) obtained when parsing starts.

Specified by:
getStartTimeNanos in interface ITimedDocumentHandling
Returns:
the start time in nanos.

getEndTimeNanos

public final long getEndTimeNanos()
Description copied from interface: ITimedDocumentHandling

Return the current time (in nanoseconds) obtained when parsing ends.

Specified by:
getEndTimeNanos in interface ITimedDocumentHandling
Returns:
the end time in nanos.

getTotalTimeNanos

public final long getTotalTimeNanos()
Description copied from interface: ITimedDocumentHandling

Return the difference (in nanoseconds) between parsing start and end times.

Specified by:
getTotalTimeNanos in interface ITimedDocumentHandling
Returns:
the difference between parsing start and end times.


Copyright © 2013 The ATTOPARSER team. All Rights Reserved.