org.htmlparser.parserapplications.filterbuilder.wrappers

Class RegexFilterWrapper

public class RegexFilterWrapper extends Filter implements ActionListener, DocumentListener

Wrapper for RegexFilters.
Field Summary
protected RegexFiltermFilter
The underlying filter.
static Object[][]mMap
Mapping for RegexFilter constants to strings.
protected JTextAreamPattern
Text to check for
protected JComboBoxmStrategy
Combo box for strategy.
Constructor Summary
RegexFilterWrapper()
Create a wrapper over a new RegexFilter.
Method Summary
booleanaccept(Node node)
Predicate to determine whether or not to keep the given node.
voidactionPerformed(ActionEvent event)
Invoked when an action occurs on the combo box.
voidchangedUpdate(DocumentEvent e)
Handle a change update event.
StringgetDescription()
Get the name of the filter.
StringgetIconSpec()
Get the resource name for the icon.
NodeFiltergetNodeFilter()
Get the underlying node filter object.
NodeFilter[]getSubNodeFilters()
Get the underlying node filter's subordinate filters.
intindexToStrategy(int index)
Convert an index into a regex strategy.
voidinsertUpdate(DocumentEvent e)
Handle an insert update event.
voidremoveUpdate(DocumentEvent e)
Handle a remove update event.
voidsetNodeFilter(NodeFilter filter, Parser context)
Assign the underlying node filter for this wrapper.
voidsetSubNodeFilters(NodeFilter[] filters)
Assign the underlying node filter's subordinate filters.
intstrategyToIndex(int strategy)
Convert the regex strategy to an index into the map.
StringstrategyToString(int strategy)
Convert the regex strategy to a string.
intstringToStrategy(String strategy)
Convert a string to a regex strategy.
StringtoJavaCode(StringBuffer out, int[] context)
Convert this filter into Java code.

Field Detail

mFilter

protected RegexFilter mFilter
The underlying filter.

mMap

public static Object[][] mMap
Mapping for RegexFilter constants to strings.

mPattern

protected JTextArea mPattern
Text to check for

mStrategy

protected JComboBox mStrategy
Combo box for strategy.

Constructor Detail

RegexFilterWrapper

public RegexFilterWrapper()
Create a wrapper over a new RegexFilter.

Method Detail

accept

public boolean accept(Node node)
Predicate to determine whether or not to keep the given node. The behaviour based on this outcome is determined by the context in which it is called. It may lead to the node being added to a list or printed out. See the calling routine for details.

Parameters: node The node to test.

Returns: true if the node is to be kept, false if it is to be discarded.

actionPerformed

public void actionPerformed(ActionEvent event)
Invoked when an action occurs on the combo box.

Parameters: event Details about the action event.

changedUpdate

public void changedUpdate(DocumentEvent e)
Handle a change update event.

Parameters: e Details about the change event.

getDescription

public String getDescription()
Get the name of the filter.

Returns: A descriptive name for the filter.

getIconSpec

public String getIconSpec()
Get the resource name for the icon.

Returns: The icon resource specification.

getNodeFilter

public NodeFilter getNodeFilter()
Get the underlying node filter object.

Returns: The node filter object suitable for serialization.

getSubNodeFilters

public NodeFilter[] getSubNodeFilters()
Get the underlying node filter's subordinate filters.

Returns: The node filter object's contained filters.

indexToStrategy

public int indexToStrategy(int index)
Convert an index into a regex strategy.

Parameters: index The index of the regex strategy in the map.

Returns: The regex strategy at that inxdex.

insertUpdate

public void insertUpdate(DocumentEvent e)
Handle an insert update event.

Parameters: e Details about the insert event.

removeUpdate

public void removeUpdate(DocumentEvent e)
Handle a remove update event.

Parameters: e Details about the remove event.

setNodeFilter

public void setNodeFilter(NodeFilter filter, Parser context)
Assign the underlying node filter for this wrapper.

Parameters: filter The filter to wrap. context The parser to use for conditioning this filter. Some filters need contextual information to provide to the user, i.e. for tag names or attribute names or values, so the Parser context is provided.

setSubNodeFilters

public void setSubNodeFilters(NodeFilter[] filters)
Assign the underlying node filter's subordinate filters.

Parameters: filters The filters to insert into the underlying node filter.

strategyToIndex

public int strategyToIndex(int strategy)
Convert the regex strategy to an index into the map.

Parameters: strategy The regex strategy.

Returns: The index of the regex strategy in the map.

strategyToString

public String strategyToString(int strategy)
Convert the regex strategy to a string.

Parameters: strategy The regex strategy.

Returns: A string for display in the GUI or in the Java program.

stringToStrategy

public int stringToStrategy(String strategy)
Convert a string to a regex strategy.

Parameters: strategy The string equivalent of a regex strategy.

Returns: The regex strategy to use in executing the regular expression.

toJavaCode

public String toJavaCode(StringBuffer out, int[] context)
Convert this filter into Java code. Output whatever text necessary and return the variable name.

Parameters: out The output buffer. context Three integers as follows:

  • indent level - the number of spaces to insert at the beginning of each line
  • filter number - the next available filter number
  • filter array number - the next available array of filters number
  • Returns: The variable name to use when referencing this filter (usually "filter" + context[1]++)

    HTML Parser is an open source library released under LGPL. SourceForge.net