org.htmlparser.filters

Class StringFilter

public class StringFilter extends Object implements NodeFilter

This class accepts all string nodes containing the given string. This is a fairly simplistic filter, so for more sophisticated string matching, for example newline and whitespace handling, use a {@link RegexFilter} instead.
Field Summary
protected booleanmCaseSensitive
Case sensitive toggle.
protected LocalemLocale
The locale to use converting to uppercase in case insensitive searches.
protected StringmPattern
The string to search for.
protected StringmUpperPattern
The string to really search for (converted to uppercase if necessary).
Constructor Summary
StringFilter()
Creates a new instance of StringFilter that accepts all string nodes.
StringFilter(String pattern)
Creates a StringFilter that accepts text nodes containing a string.
StringFilter(String pattern, boolean sensitive)
Creates a StringFilter that accepts text nodes containing a string.
StringFilter(String pattern, boolean sensitive, Locale locale)
Creates a StringFilter that accepts text nodes containing a string.
Method Summary
booleanaccept(Node node)
Accept string nodes that contain the string.
booleangetCaseSensitive()
Get the case sensitivity.
LocalegetLocale()
Get the locale for uppercase conversion.
StringgetPattern()
Get the search pattern.
voidsetCaseSensitive(boolean sensitive)
Set case sensitivity on or off.
voidsetLocale(Locale locale)
Set the locale for uppercase conversion.
voidsetPattern(String pattern)
Set the search pattern.
protected voidsetUpperPattern()
Set the real (upper case) comparison string.

Field Detail

mCaseSensitive

protected boolean mCaseSensitive
Case sensitive toggle. If true strings are compared with case sensitivity.

mLocale

protected Locale mLocale
The locale to use converting to uppercase in case insensitive searches.

mPattern

protected String mPattern
The string to search for.

mUpperPattern

protected String mUpperPattern
The string to really search for (converted to uppercase if necessary).

Constructor Detail

StringFilter

public StringFilter()
Creates a new instance of StringFilter that accepts all string nodes.

StringFilter

public StringFilter(String pattern)
Creates a StringFilter that accepts text nodes containing a string. The comparison is case insensitive, with conversions done using the default Locale.

Parameters: pattern The pattern to search for.

StringFilter

public StringFilter(String pattern, boolean sensitive)
Creates a StringFilter that accepts text nodes containing a string.

Parameters: pattern The pattern to search for. sensitive If true, comparisons are performed respecting case, with conversions done using the default Locale.

StringFilter

public StringFilter(String pattern, boolean sensitive, Locale locale)
Creates a StringFilter that accepts text nodes containing a string.

Parameters: pattern The pattern to search for. sensitive If true, comparisons are performed respecting case. locale The locale to use when converting to uppercase. If null, the default Locale is used.

Method Detail

accept

public boolean accept(Node node)
Accept string nodes that contain the string.

Parameters: node The node to check.

Returns: true if node is a {@link Text} node and contains the pattern string, false otherwise.

getCaseSensitive

public boolean getCaseSensitive()
Get the case sensitivity.

Returns: Returns the case sensitivity.

getLocale

public Locale getLocale()
Get the locale for uppercase conversion.

Returns: Returns the locale.

getPattern

public String getPattern()
Get the search pattern.

Returns: Returns the pattern.

setCaseSensitive

public void setCaseSensitive(boolean sensitive)
Set case sensitivity on or off.

Parameters: sensitive If false searches for the string are case insensitive.

setLocale

public void setLocale(Locale locale)
Set the locale for uppercase conversion.

Parameters: locale The locale to set.

setPattern

public void setPattern(String pattern)
Set the search pattern.

Parameters: pattern The pattern to set.

setUpperPattern

protected void setUpperPattern()
Set the real (upper case) comparison string.
HTML Parser is an open source library released under LGPL. SourceForge.net