Package org.htmlparser.filters
Class StringFilter
- java.lang.Object
-
- org.htmlparser.filters.StringFilter
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,NodeFilter
public class StringFilter extends java.lang.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 aRegexFilter
instead.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
mCaseSensitive
Case sensitive toggle.protected java.util.Locale
mLocale
The locale to use converting to uppercase in case insensitive searches.protected java.lang.String
mPattern
The string to search for.protected java.lang.String
mUpperPattern
The string to really search for (converted to uppercase if necessary).
-
Constructor Summary
Constructors Constructor Description StringFilter()
Creates a new instance of StringFilter that accepts all string nodes.StringFilter(java.lang.String pattern)
Creates a StringFilter that accepts text nodes containing a string.StringFilter(java.lang.String pattern, boolean sensitive)
Creates a StringFilter that accepts text nodes containing a string.StringFilter(java.lang.String pattern, boolean sensitive, java.util.Locale locale)
Creates a StringFilter that accepts text nodes containing a string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(Node node)
Accept string nodes that contain the string.boolean
getCaseSensitive()
Get the case sensitivity.java.util.Locale
getLocale()
Get the locale for uppercase conversion.java.lang.String
getPattern()
Get the search pattern.void
setCaseSensitive(boolean sensitive)
Set case sensitivity on or off.void
setLocale(java.util.Locale locale)
Set the locale for uppercase conversion.void
setPattern(java.lang.String pattern)
Set the search pattern.protected void
setUpperPattern()
Set the real (upper case) comparison string.
-
-
-
Field Detail
-
mPattern
protected java.lang.String mPattern
The string to search for.
-
mUpperPattern
protected java.lang.String mUpperPattern
The string to really search for (converted to uppercase if necessary).
-
mCaseSensitive
protected boolean mCaseSensitive
Case sensitive toggle. Iftrue
strings are compared with case sensitivity.
-
mLocale
protected java.util.Locale mLocale
The locale to use converting to uppercase in case insensitive searches.
-
-
Constructor Detail
-
StringFilter
public StringFilter()
Creates a new instance of StringFilter that accepts all string nodes.
-
StringFilter
public StringFilter(java.lang.String pattern)
Creates a StringFilter that accepts text nodes containing a string. The comparison is case insensitive, with conversions done using the defaultLocale
.- Parameters:
pattern
- The pattern to search for.
-
StringFilter
public StringFilter(java.lang.String pattern, boolean sensitive)
Creates a StringFilter that accepts text nodes containing a string.- Parameters:
pattern
- The pattern to search for.sensitive
- Iftrue
, comparisons are performed respecting case, with conversions done using the defaultLocale
.
-
StringFilter
public StringFilter(java.lang.String pattern, boolean sensitive, java.util.Locale locale)
Creates a StringFilter that accepts text nodes containing a string.- Parameters:
pattern
- The pattern to search for.sensitive
- Iftrue
, comparisons are performed respecting case.locale
- The locale to use when converting to uppercase. Ifnull
, the defaultLocale
is used.
-
-
Method Detail
-
setUpperPattern
protected void setUpperPattern()
Set the real (upper case) comparison string.
-
getCaseSensitive
public boolean getCaseSensitive()
Get the case sensitivity.- Returns:
- Returns the case sensitivity.
-
setCaseSensitive
public void setCaseSensitive(boolean sensitive)
Set case sensitivity on or off.- Parameters:
sensitive
- Iffalse
searches for the string are case insensitive.
-
getLocale
public java.util.Locale getLocale()
Get the locale for uppercase conversion.- Returns:
- Returns the locale.
-
setLocale
public void setLocale(java.util.Locale locale)
Set the locale for uppercase conversion.- Parameters:
locale
- The locale to set.
-
getPattern
public java.lang.String getPattern()
Get the search pattern.- Returns:
- Returns the pattern.
-
setPattern
public void setPattern(java.lang.String pattern)
Set the search pattern.- Parameters:
pattern
- The pattern to set.
-
accept
public boolean accept(Node node)
Accept string nodes that contain the string.- Specified by:
accept
in interfaceNodeFilter
- Parameters:
node
- The node to check.- Returns:
true
ifnode
is aText
node and contains the pattern string,false
otherwise.
-
-