Class ParseStatus
- java.lang.Object
-
- org.attoparser.ParseStatus
-
public final class ParseStatus extends java.lang.Object
Class used for reporting the status of current parsing operations to handlers.
Instances of this class operate at a very low level, and are only useful in very specific scenarios, so most
IMarkupHandler
implementations should just ignore its existence and consider it only for internal use.- Since:
- 2.0.0
-
-
Field Summary
Fields Modifier and Type Field Description (package private) char[][]
autoCloseLimits
(package private) char[][]
autoCloseRequired
(package private) boolean
autoOpenCloseDone
(package private) char[][]
autoOpenLimits
(package private) char[][]
autoOpenParents
(package private) boolean
avoidStacking
(package private) int
col
(package private) boolean
inStructure
(package private) int
line
(package private) int
offset
(package private) boolean
parsingDisabled
(package private) char[]
parsingDisabledLimitSequence
(package private) boolean
shouldDisableParsing
-
Constructor Summary
Constructors Constructor Description ParseStatus()
Builds a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getCol()
Returns the column in the current line in the document the parser is currently located at.int
getLine()
Returns the line in the document the parser is currently located at.boolean
isAutoOpenCloseDone()
Indicates whether the parser has already performed a required auto-open or auto-close operation.boolean
isParsingDisabled()
Determines whether parsing is currently disabled or not.void
setAutoCloseRequired(char[][] autoCloseRequired, char[][] autoCloseLimits)
Force the parser to (possibly) perform a series of auto-close operations for elements that might be open at the moment in the element stack.void
setAutoOpenRequired(char[][] autoOpenParents, char[][] autoOpenLimits)
Force the parser to (possibly) perform a series of auto-open operations for elements that should be considered parents of the one being open at a specific moment per the markup spec (made for HTML).void
setAvoidStacking(boolean avoidStacking)
Indicate the parser whether the element being handled (in the start event of a standalone or open element) should be stacked or not.void
setParsingDisabled(char[] limitSequence)
Disable parsing until the specified sequence is found in markup.
-
-
-
Field Detail
-
offset
int offset
-
line
int line
-
col
int col
-
inStructure
boolean inStructure
-
shouldDisableParsing
boolean shouldDisableParsing
-
parsingDisabled
boolean parsingDisabled
-
parsingDisabledLimitSequence
char[] parsingDisabledLimitSequence
-
avoidStacking
boolean avoidStacking
-
autoOpenParents
char[][] autoOpenParents
-
autoOpenLimits
char[][] autoOpenLimits
-
autoCloseRequired
char[][] autoCloseRequired
-
autoCloseLimits
char[][] autoCloseLimits
-
autoOpenCloseDone
boolean autoOpenCloseDone
-
-
Method Detail
-
getLine
public int getLine()
Returns the line in the document the parser is currently located at.
Note this should not be used for event reference, because the parser cursor might be ahead of the events it is reporting. In order to know the lines and cols an event was found at, use the (line,col) pairs reported with every event handler.
- Returns:
- the line number.
-
getCol
public int getCol()
Returns the column in the current line in the document the parser is currently located at.
Note this should not be used for event reference, because the parser cursor might be ahead of the events it is reporting. In order to know the lines and cols an event was found at, use the (line,col) pairs reported with every event handler.
- Returns:
- the column number.
-
isParsingDisabled
public boolean isParsingDisabled()
Determines whether parsing is currently disabled or not. This only happens if an event handler calls the
setParsingDisabled(char[])
method. In such case, every Text event that will be reported until the specified limit sequence is found will return false for this method.- Returns:
- whether parsing is currently disabled or not.
-
setParsingDisabled
public void setParsingDisabled(char[] limitSequence)
Disable parsing until the specified sequence is found in markup. All markup found between the event handler that calls this method and the limit sequence will be reported as Text.
This is used by HTML parsers (like
MarkupParser
itself, internally) in order to being able to correctly report HTML elements such as <script> or <style>, which bodies should not be parsed (they are CDATA).- Parameters:
limitSequence
- the char sequence that, once found in markup, will enable parsing again.
-
isAutoOpenCloseDone
public boolean isAutoOpenCloseDone()
Indicates whether the parser has already performed a required auto-open or auto-close operation. This flag set to true means that these operations have already been performed and that the event is being relaunched after that (so the event can be propagated if needed).
- Returns:
- true if the auto-open and auto-close operations have already been performed.
-
setAutoOpenRequired
public void setAutoOpenRequired(char[][] autoOpenParents, char[][] autoOpenLimits)
Force the parser to (possibly) perform a series of auto-open operations for elements that should be considered parents of the one being open at a specific moment per the markup spec (made for HTML).
These attributes instruct the event processor to make sure an element is correctly stacked inside the elements it needs to. For example, a <tr> element will ask for the auto-opening of a <tbody> element as its parent, but it will specify as limits also <thead> and <tfoot> because these two elements are also valid parents for it (just not default).
The limits array will be used for specifying: if not null, the IMMEDIATE parents that will be considered valid. If not null, that the parent element sequence should only be considered from the document root, and that it should be completed if something is missing (e.g. there is <html> but no <body>).
When in HTML, the auto-open elements will be:
-
<tr>
RULE: if (parent != <tbody> && parent != <tfoot> && parent != <thead>) : AUTO-OPEN <tbody>
PARENTS: (tbody) LIMITS: (tbody,tfoot,thead) -
<col>
RULE: if (parent != <colgroup>) : AUTO-OPEN <colgroup>
PARENTS: (colgroup) LIMITS: (colgroup) -
<meta>, <link>, <script>, <style>, <template>, <base>, <object>
RULE: if (parent == null) : AUTO-OPEN <html>, <head>
if (parent == <html> && <html>.parent == null) : AUTO-OPEN <head>
PARENTS: (html,head) LIMITS: (null) -
All other standard HTML tags
RULE: if (parent == null) : AUTO-OPEN <html>, <body>
if (parent == <html> && <html>.parent == null) : AUTO-OPEN <body>
PARENTS: (html,body) LIMITS: (null)
- Parameters:
autoOpenParents
- the parent sequence to be (potentially) auto-open.autoOpenLimits
- the names of the elements that will serve as limits for the auto-open operation. If null, the parent sequence will only be applied if at root level, or of the sequence is incomplete.
-
<tr>
-
setAutoCloseRequired
public void setAutoCloseRequired(char[][] autoCloseRequired, char[][] autoCloseLimits)
Force the parser to (possibly) perform a series of auto-close operations for elements that might be open at the moment in the element stack.
The parser will auto-close all elements which names match one from the autoCloseRequired array, popping them from the stack until it finds an element with any of the names in the autoCloseLimits array.
For example, when parsing HTML an open <li> will require closing all currently open <li>'s until an <ul> or <ol> is found.
These flags will only be honored by the parser in start events for standalone or open elements, and after setting them the handler should never propagate the event to its delegate handler (if it exists), returning control back to the parser instead and letting the parser re-launch the event. When the event is re-launched, the parser will have set the autoOpenCloseDone flag to true, which can be checked with the
isAutoOpenCloseDone()
method.- Parameters:
autoCloseRequired
- the names of the elements that should be auto-closed.autoCloseLimits
- the names of the elements that will serve as limits for the auto-closing operation.
-
setAvoidStacking
public void setAvoidStacking(boolean avoidStacking)
Indicate the parser whether the element being handled (in the start event of a standalone or open element) should be stacked or not.
Minimized elements (e.g. <hr />) will never be stacked, and it might happen that some open tags that represent HTML void elements should not be stacked either, like <hr>.
This flag will only be honored by the parser in start events for standalone or open elements.
- Parameters:
avoidStacking
- whether the parser should avoid stacking this element or not.
-
-