Class AttributeSelectionMarkingMarkupHandler
- java.lang.Object
-
- org.attoparser.AbstractMarkupHandler
-
- org.attoparser.AbstractChainedMarkupHandler
-
- org.attoparser.select.AttributeSelectionMarkingMarkupHandler
-
- All Implemented Interfaces:
IAttributeSequenceHandler
,ICDATASectionHandler
,ICommentHandler
,IDocTypeHandler
,IDocumentHandler
,IElementHandler
,IMarkupHandler
,IProcessingInstructionHandler
,ITextHandler
,IXMLDeclarationHandler
public final class AttributeSelectionMarkingMarkupHandler extends AbstractChainedMarkupHandler
Implementation of the
IMarkupHandler
that adds an attribute (with a user-specified name) to all elements that match one or more selectors, as determined by aBlockSelectorMarkupHandler
orNodeSelectorMarkupHandler
handler.So for example, given an instance of this handler configured to use "selectors" as its attribute name and an <img href="logo.png"> tag that matches both selectors "//img" and "div/img", this handler would transform such tag in: <img href="logo.png" selectors="[//img,div/img]">
- Since:
- 2.0.0
-
-
Field Summary
Fields Modifier and Type Field Description private static char[]
INNER_WHITESPACE_BUFFER
private boolean
lastWasInnerWhiteSpace
private ParseSelection
selection
private char[]
selectorAttributeBuffer
private char[]
selectorAttributeName
private int
selectorAttributeNameLen
-
Constructor Summary
Constructors Constructor Description AttributeSelectionMarkingMarkupHandler(java.lang.String selectorAttributeName, IMarkupHandler handler)
Build a new instance of this class, specifying the name of the attribute to be added to the matching elements and also the handler all events should be delegated to.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkSelectorAttributeLen(int valueLen)
void
handleAttribute(char[] buffer, int nameOffset, int nameLen, int nameLine, int nameCol, int operatorOffset, int operatorLen, int operatorLine, int operatorCol, int valueContentOffset, int valueContentLen, int valueOuterOffset, int valueOuterLen, int valueLine, int valueCol)
Called when an attribute is found.void
handleInnerWhiteSpace(char[] buffer, int offset, int len, int line, int col)
Called when an amount of white space is found inside an element.void
handleOpenElementEnd(char[] buffer, int nameOffset, int nameLen, int line, int col)
Called when the end of an open element (an open tag) is found.void
handleStandaloneElementEnd(char[] buffer, int nameOffset, int nameLen, boolean minimized, int line, int col)
Called when the end of a standalone element (an element with no closing tag) is foundvoid
setParseSelection(ParseSelection selection)
Sets theParseSelection
object that represents the different levels of selectors (if any) that are currently active for the fired events.-
Methods inherited from class org.attoparser.AbstractChainedMarkupHandler
getNext, handleAutoCloseElementEnd, handleAutoCloseElementStart, handleAutoOpenElementEnd, handleAutoOpenElementStart, handleCDATASection, handleCloseElementEnd, handleCloseElementStart, handleComment, handleDocType, handleDocumentEnd, handleDocumentStart, handleOpenElementStart, handleProcessingInstruction, handleStandaloneElementStart, handleText, handleUnmatchedCloseElementEnd, handleUnmatchedCloseElementStart, handleXmlDeclaration, setParseConfiguration, setParseStatus
-
-
-
-
Field Detail
-
INNER_WHITESPACE_BUFFER
private static final char[] INNER_WHITESPACE_BUFFER
-
selectorAttributeName
private final char[] selectorAttributeName
-
selectorAttributeNameLen
private final int selectorAttributeNameLen
-
selection
private ParseSelection selection
-
lastWasInnerWhiteSpace
private boolean lastWasInnerWhiteSpace
-
selectorAttributeBuffer
private char[] selectorAttributeBuffer
-
-
Constructor Detail
-
AttributeSelectionMarkingMarkupHandler
public AttributeSelectionMarkingMarkupHandler(java.lang.String selectorAttributeName, IMarkupHandler handler)
Build a new instance of this class, specifying the name of the attribute to be added to the matching elements and also the handler all events should be delegated to.
- Parameters:
selectorAttributeName
- the name of the marking attribute.handler
- the handler to delegate events to.
-
-
Method Detail
-
setParseSelection
public void setParseSelection(ParseSelection selection)
Description copied from interface:IMarkupHandler
Sets the
ParseSelection
object that represents the different levels of selectors (if any) that are currently active for the fired events.This method is always called by the parser before calling any other event handling method.
Note that this method can be safely ignored by most implementations, as there are very few scenarios in which this kind of interaction would be consisdered relevant.
- Specified by:
setParseSelection
in interfaceIMarkupHandler
- Overrides:
setParseSelection
in classAbstractChainedMarkupHandler
- Parameters:
selection
- the selection object.
-
handleAttribute
public void handleAttribute(char[] buffer, int nameOffset, int nameLen, int nameLine, int nameCol, int operatorOffset, int operatorLen, int operatorLine, int operatorCol, int valueContentOffset, int valueContentLen, int valueOuterOffset, int valueOuterLen, int valueLine, int valueCol) throws ParseException
Description copied from interface:IAttributeSequenceHandler
Called when an attribute is found.
Three [offset, len] pairs are provided for three partitions (name, operator, valueContent and valueOuter):
class="basic_column"
[NAM]* [VALUECONTE]| (*) = [OPERATOR]
| [VALUEOUTER--]
[OUTER-------------]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:
handleAttribute
in interfaceIAttributeSequenceHandler
- Overrides:
handleAttribute
in classAbstractChainedMarkupHandler
- Parameters:
buffer
- the document buffer (not copied)nameOffset
- offset for the name partition.nameLen
- length of the name partition.nameLine
- the line in the original document where the name partition starts.nameCol
- the column in the original document where the name partition starts.operatorOffset
- offset for the operator partition.operatorLen
- length of the operator partition.operatorLine
- the line in the original document where the operator partition starts.operatorCol
- the column in the original document where the operator partition starts.valueContentOffset
- offset for the valueContent partition.valueContentLen
- length of the valueContent partition.valueOuterOffset
- offset for the valueOuter partition.valueOuterLen
- length of the valueOuter partition.valueLine
- the line in the original document where the value (outer) partition starts.valueCol
- the column in the original document where the value (outer) partition starts.- Throws:
ParseException
- if any exceptions occur during handling.
-
handleStandaloneElementEnd
public void handleStandaloneElementEnd(char[] buffer, int nameOffset, int nameLen, boolean minimized, int line, int col) throws ParseException
Description copied from interface:IElementHandler
Called when the end of a standalone element (an element with no closing tag) is found
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:
handleStandaloneElementEnd
in interfaceIElementHandler
- Overrides:
handleStandaloneElementEnd
in classAbstractChainedMarkupHandler
- Parameters:
buffer
- the document buffer (not copied)nameOffset
- the offset (position in buffer) where the element name appears.nameLen
- the length (in chars) of the element name.minimized
- whether the element has been found minimized (<element/>)in code or not.line
- the line in the original document where the element ending structure appears.col
- the column in the original document where the element ending structure appears.- Throws:
ParseException
- if any exceptions occur during handling.
-
handleOpenElementEnd
public void handleOpenElementEnd(char[] buffer, int nameOffset, int nameLen, int line, int col) throws ParseException
Description copied from interface:IElementHandler
Called when the end of an open element (an open tag) is found.
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:
handleOpenElementEnd
in interfaceIElementHandler
- Overrides:
handleOpenElementEnd
in classAbstractChainedMarkupHandler
- Parameters:
buffer
- the document buffer (not copied)nameOffset
- the offset (position in buffer) where the element name appears.nameLen
- the length (in chars) of the element name.line
- the line in the original document where the element ending structure appears.col
- the column in the original document where the element ending structure appears.- Throws:
ParseException
- if any exceptions occur during handling.
-
handleInnerWhiteSpace
public void handleInnerWhiteSpace(char[] buffer, int offset, int len, int line, int col) throws ParseException
Description copied from interface:IAttributeSequenceHandler
Called when an amount of white space is found inside an element.
This attribute separators can contain any amount of whitespace, including line feeds:
<div id="main" class="basic_column">
[INNWSP]
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:
handleInnerWhiteSpace
in interfaceIAttributeSequenceHandler
- Overrides:
handleInnerWhiteSpace
in classAbstractChainedMarkupHandler
- Parameters:
buffer
- the document buffer (not copied)offset
- offset for the artifact.len
- length of the artifact.line
- the line in the original document where the artifact starts.col
- the column in the original document where the artifact starts.- Throws:
ParseException
- if any exceptions occur during handling.
-
checkSelectorAttributeLen
private void checkSelectorAttributeLen(int valueLen)
-
-