public abstract class AbstractSimpleMarkupHandler extends 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.
Modifier | Constructor and Description |
---|---|
protected |
AbstractSimpleMarkupHandler() |
Modifier and Type | Method and Description |
---|---|
void |
handleAutoCloseElement(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(String elementName,
Map<String,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(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(String elementName,
String publicId,
String systemId,
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(String elementName,
Map<String,String> attributes,
int line,
int col)
Called when an open element (an open tag) is found.
|
void |
handleProcessingInstruction(String target,
String content,
int line,
int col)
Called when a Processing Instruction is found.
|
void |
handleStandaloneElement(String elementName,
Map<String,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(String elementName,
int line,
int col)
Called when a close element (a close tag) appears without
a corresponding open element.
|
void |
handleXmlDeclaration(String version,
String encoding,
String standalone,
int line,
int col)
Called when an XML Declaration is found.
|
public void handleDocumentStart(long startTimeNanos, int line, int col) throws ParseException
ISimpleMarkupHandler
Called at the beginning of document parsing.
handleDocumentStart
in interface ISimpleMarkupHandler
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).ParseException
- if any exceptions occur during handling.public void handleDocumentEnd(long endTimeNanos, long totalTimeNanos, int line, int col) throws ParseException
ISimpleMarkupHandler
Called at the end of document parsing.
handleDocumentEnd
in interface ISimpleMarkupHandler
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)ParseException
- if any exceptions occur during handling.public void handleXmlDeclaration(String version, String encoding, String standalone, int line, int col) throws ParseException
ISimpleMarkupHandler
Called when an XML Declaration is found.
handleXmlDeclaration
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.public void handleDocType(String elementName, String publicId, String systemId, String internalSubset, int line, int col) throws ParseException
ISimpleMarkupHandler
Called when a DOCTYPE clause is found.
handleDocType
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.public void handleCDATASection(char[] buffer, int offset, int len, int line, int col) throws ParseException
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.
handleCDATASection
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.public void handleComment(char[] buffer, int offset, int len, int line, int col) throws ParseException
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.
handleComment
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.public void handleText(char[] buffer, int offset, int len, int line, int col) throws ParseException
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.
handleText
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.public void handleStandaloneElement(String elementName, Map<String,String> attributes, boolean minimized, int line, int col) throws ParseException
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.
handleStandaloneElement
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.public void handleOpenElement(String elementName, Map<String,String> attributes, int line, int col) throws ParseException
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.
handleOpenElement
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.public void handleAutoOpenElement(String elementName, Map<String,String> attributes, int line, int col) throws ParseException
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.
handleAutoOpenElement
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.public void handleCloseElement(String elementName, int line, int col) throws ParseException
ISimpleMarkupHandler
Called when a close element (a close tag) is found.
handleCloseElement
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.public void handleAutoCloseElement(String elementName, int line, int col) throws ParseException
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.
handleAutoCloseElement
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.public void handleUnmatchedCloseElement(String elementName, int line, int col) throws ParseException
ISimpleMarkupHandler
Called when a close element (a close tag) appears without a corresponding open element.
Implementors might choose to ignore these events.
handleUnmatchedCloseElement
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.public void handleProcessingInstruction(String target, String content, int line, int col) throws ParseException
ISimpleMarkupHandler
Called when a Processing Instruction is found.
handleProcessingInstruction
in interface ISimpleMarkupHandler
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.ParseException
- if any exceptions occur during handling.Copyright © 2023 The ATTOPARSER team. All rights reserved.