[Htmlparser-cvs] htmlparser/src/org/htmlparser/filters CssSelectorNodeFilter.java,1.5,1.6 HasAttribu
Brought to you by:
derrickoswald
From: Derrick O. <der...@us...> - 2005-05-15 11:49:14
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31674/src/org/htmlparser/filters Modified Files: CssSelectorNodeFilter.java HasAttributeFilter.java HasChildFilter.java HasParentFilter.java HasSiblingFilter.java IsEqualFilter.java LinkRegexFilter.java LinkStringFilter.java NodeClassFilter.java NotFilter.java OrFilter.java RegexFilter.java StringFilter.java TagNameFilter.java Log Message: Documentation revamp part four. Remove some checkstyle warnings. Index: StringFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/StringFilter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** StringFilter.java 13 Feb 2005 20:36:00 -0000 1.5 --- StringFilter.java 15 May 2005 11:49:04 -0000 1.6 *************** *** 37,45 **** * This is a fairly simplistic filter, so for more sophisticated * string matching, for example newline and whitespace handling, ! * use a {@link RegexFilter} instead. */ public class StringFilter ! implements ! NodeFilter { /** --- 37,45 ---- * This is a fairly simplistic filter, so for more sophisticated * string matching, for example newline and whitespace handling, ! * use a {@link RegexFilter} instead. */ public class StringFilter ! implements ! NodeFilter { /** *************** *** 73,78 **** /** ! * Creates a new instance of a StringFilter that accepts string nodes containing a certain string. ! * The comparison is case insensitive, with conversions done using the default <code>Locale</code>. * @param pattern The pattern to search for. */ --- 73,79 ---- /** ! * Creates a StringFilter that accepts text nodes containing a string. ! * The comparison is case insensitive, with conversions done using ! * the default <code>Locale</code>. * @param pattern The pattern to search for. */ *************** *** 83,108 **** /** ! * Creates a new instance of a StringFilter that accepts string nodes containing a certain string. * @param pattern The pattern to search for. ! * @param case_sensitive If <code>true</code>, comparisons are performed ! * respecting case, with conversions done using the default <code>Locale</code>. */ ! public StringFilter (String pattern, boolean case_sensitive) { ! this (pattern, case_sensitive, null); } ! /** ! * Creates a new instance of a StringFilter that accepts string nodes containing a certain string. * @param pattern The pattern to search for. ! * @param case_sensitive If <code>true</code>, comparisons are performed * respecting case. * @param locale The locale to use when converting to uppercase. * If <code>null</code>, the default <code>Locale</code> is used. */ ! public StringFilter (String pattern, boolean case_sensitive, Locale locale) { mPattern = pattern; ! mCaseSensitive = case_sensitive; mLocale = (null == locale) ? Locale.getDefault () : locale; setUpperPattern (); --- 84,110 ---- /** ! * Creates a StringFilter that accepts text nodes containing a string. * @param pattern The pattern to search for. ! * @param sensitive If <code>true</code>, comparisons are performed ! * respecting case, with conversions done using the default ! * <code>Locale</code>. */ ! public StringFilter (String pattern, boolean sensitive) { ! this (pattern, sensitive, null); } ! /** ! * Creates a StringFilter that accepts text nodes containing a string. * @param pattern The pattern to search for. ! * @param sensitive If <code>true</code>, comparisons are performed * respecting case. * @param locale The locale to use when converting to uppercase. * If <code>null</code>, the default <code>Locale</code> is used. */ ! public StringFilter (String pattern, boolean sensitive, Locale locale) { mPattern = pattern; ! mCaseSensitive = sensitive; mLocale = (null == locale) ? Locale.getDefault () : locale; setUpperPattern (); *************** *** 112,116 **** // protected methods // ! /** * Set the real (upper case) comparison string. --- 114,118 ---- // protected methods // ! /** * Set the real (upper case) comparison string. *************** *** 196,200 **** String string; boolean ret; ! ret = false; if (node instanceof Text) --- 198,202 ---- String string; boolean ret; ! ret = false; if (node instanceof Text) Index: IsEqualFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/IsEqualFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IsEqualFilter.java 24 Jan 2004 23:57:50 -0000 1.1 --- IsEqualFilter.java 15 May 2005 11:49:04 -0000 1.2 *************** *** 38,45 **** * The node to match. */ ! public Node mNode; /** ! * Creates a new instance of an IsEqualFilter that accepts only the node provided. * @param node The node to match. */ --- 38,45 ---- * The node to match. */ ! protected Node mNode; /** ! * Creates a new IsEqualFilter that accepts only the node provided. * @param node The node to match. */ Index: RegexFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/RegexFilter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RegexFilter.java 10 Apr 2005 23:20:43 -0000 1.3 --- RegexFilter.java 15 May 2005 11:49:04 -0000 1.4 *************** *** 60,64 **** * The month is matched by 0[1-9]|1[012], again enclosed by round brackets * to keep the two options together. By using character classes, the first ! * option matches a number between 01 and 09, and the second matches 10, 11 or 12. * The last part of the regex consists of three options. The first matches * the numbers 01 through 09, the second 10 through 29, and the third matches 30 or 31. --- 60,65 ---- * The month is matched by 0[1-9]|1[012], again enclosed by round brackets * to keep the two options together. By using character classes, the first ! * option matches a number between 01 and 09, and the second ! * matches 10, 11 or 12. * The last part of the regex consists of three options. The first matches * the numbers 01 through 09, the second 10 through 29, and the third matches 30 or 31. *************** *** 124,130 **** * @param strategy The type of match: * <ol> ! * <li>{@link #MATCH} use matches() method: attempts to match the entire input sequence against the pattern</li> ! * <li>{@link #LOOKINGAT} use lookingAt() method: attempts to match the input sequence, starting at the beginning, against the pattern</li> ! * <li>{@link #FIND} use find() method: scans the input sequence looking for the next subsequence that matches the pattern</li> * </ol> */ --- 125,134 ---- * @param strategy The type of match: * <ol> ! * <li>{@link #MATCH} use matches() method: attempts to match ! * the entire input sequence against the pattern</li> ! * <li>{@link #LOOKINGAT} use lookingAt() method: attempts to match ! * the input sequence, starting at the beginning, against the pattern</li> ! * <li>{@link #FIND} use find() method: scans the input sequence looking ! * for the next subsequence that matches the pattern</li> * </ol> */ *************** *** 169,172 **** --- 173,180 ---- public void setStrategy (int strategy) { + if ((strategy != MATCH) && (strategy != LOOKINGAT) + && (strategy != FIND)) + throw new IllegalArgumentException ("illegal strategy (" + + strategy + ")"); mStrategy = strategy; } *************** *** 175,179 **** * Accept string nodes that match the regular expression. * @param node The node to check. ! * @return <code>true</code> if the regular expression matches the * text of the node, <code>false</code> otherwise. */ --- 183,187 ---- * Accept string nodes that match the regular expression. * @param node The node to check. ! * @return <code>true</code> if the regular expression matches the * text of the node, <code>false</code> otherwise. */ *************** *** 183,187 **** Matcher matcher; boolean ret; ! ret = false; if (node instanceof Text) --- 191,195 ---- Matcher matcher; boolean ret; ! ret = false; if (node instanceof Text) *************** *** 198,201 **** --- 206,210 ---- break; case FIND: + default: ret = matcher.find (); break; Index: HasParentFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/HasParentFilter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** HasParentFilter.java 10 Apr 2005 23:20:43 -0000 1.7 --- HasParentFilter.java 15 May 2005 11:49:04 -0000 1.8 *************** *** 38,53 **** */ public class HasParentFilter ! implements ! NodeFilter { /** * The filter to apply to the parent. */ ! public NodeFilter mParentFilter; /** * Performs a recursive search up the node heirarchy if <code>true</code>. */ ! public boolean mRecursive; /** --- 38,53 ---- */ public class HasParentFilter ! implements ! NodeFilter { /** * The filter to apply to the parent. */ ! protected NodeFilter mParentFilter; /** * Performs a recursive search up the node heirarchy if <code>true</code>. */ ! protected boolean mRecursive; /** *************** *** 62,66 **** /** ! * Creates a new instance of HasParentFilter that accepts nodes with direct parent acceptable to the filter. * @param filter The filter to apply to the parent. */ --- 62,67 ---- /** ! * Creates a new instance of HasParentFilter that accepts nodes with ! * the direct parent acceptable to the filter. * @param filter The filter to apply to the parent. */ *************** *** 71,75 **** /** ! * Creates a new instance of HasParentFilter that accepts nodes with a parent acceptable to the filter. * @param filter The filter to apply to the parent. * @param recursive If <code>true</code>, any enclosing node acceptable --- 72,77 ---- /** ! * Creates a new instance of HasParentFilter that accepts nodes with ! * a parent acceptable to the filter. * @param filter The filter to apply to the parent. * @param recursive If <code>true</code>, any enclosing node acceptable *************** *** 92,96 **** return (mParentFilter); } ! /** * Set the filter for this HasParentFilter. --- 94,98 ---- return (mParentFilter); } ! /** * Set the filter for this HasParentFilter. *************** *** 109,113 **** public boolean getRecursive () { ! return mRecursive; } --- 111,115 ---- public boolean getRecursive () { ! return (mRecursive); } *************** *** 139,149 **** if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) { ! parent = node.getParent (); ! if ((null != parent) && (null != getParentFilter ())) ! { ! ret = getParentFilter ().accept (parent); ! if (!ret && getRecursive ()) ! ret = accept (parent); ! } } --- 141,151 ---- if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) { ! parent = node.getParent (); ! if ((null != parent) && (null != getParentFilter ())) ! { ! ret = getParentFilter ().accept (parent); ! if (!ret && getRecursive ()) ! ret = accept (parent); ! } } Index: LinkRegexFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/LinkRegexFilter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** LinkRegexFilter.java 10 Apr 2005 23:20:43 -0000 1.2 --- LinkRegexFilter.java 15 May 2005 11:49:04 -0000 1.3 *************** *** 27,31 **** package org.htmlparser.filters; ! import java.util.regex.*; import org.htmlparser.Node; --- 27,32 ---- package org.htmlparser.filters; ! import java.util.regex.Matcher; ! import java.util.regex.Pattern; import org.htmlparser.Node; *************** *** 42,51 **** /** * The regular expression to use on the link. ! */ protected Pattern mRegex; ! /** ! * Creates a new instance of LinkRegexFilter that accepts LinkTag nodes containing ! * a URL that matches the supplied regex pattern. The match is case insensitive. * @param regexPattern The pattern to match. */ --- 43,53 ---- /** * The regular expression to use on the link. ! */ protected Pattern mRegex; ! /** ! * Creates a LinkRegexFilter that accepts LinkTag nodes containing ! * a URL that matches the supplied regex pattern. ! * The match is case insensitive. * @param regexPattern The pattern to match. */ *************** *** 54,60 **** this (regexPattern, true); } ! /** ! * Creates a new instance of LinkRegexFilter that accepts LinkTag nodes containing * a URL that matches the supplied regex pattern. * @param regexPattern The regex pattern to match. --- 56,62 ---- this (regexPattern, true); } ! /** ! * Creates a LinkRegexFilter that accepts LinkTag nodes containing * a URL that matches the supplied regex pattern. * @param regexPattern The regex pattern to match. *************** *** 68,75 **** mRegex = Pattern.compile (regexPattern, Pattern.CASE_INSENSITIVE); } ! /** ! * Accept nodes that are assignable from the LinkTag class and have a URL that ! * matches the regex pattern supplied in the constructor. * @param node The node to check. * @return <code>true</code> if the node is a link with the pattern. --- 70,77 ---- mRegex = Pattern.compile (regexPattern, Pattern.CASE_INSENSITIVE); } ! /** ! * Accept nodes that are a LinkTag and have a URL ! * that matches the regex pattern supplied in the constructor. * @param node The node to check. * @return <code>true</code> if the node is a link with the pattern. *************** *** 78,82 **** { boolean ret; ! ret = false; if (LinkTag.class.isAssignableFrom (node.getClass ())) --- 80,84 ---- { boolean ret; ! ret = false; if (LinkTag.class.isAssignableFrom (node.getClass ())) Index: LinkStringFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/LinkStringFilter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** LinkStringFilter.java 10 Apr 2005 23:20:43 -0000 1.2 --- LinkStringFilter.java 15 May 2005 11:49:04 -0000 1.3 *************** *** 47,54 **** */ protected boolean mCaseSensitive; ! /** ! * Creates a new instance of LinkStringFilter that accepts LinkTag nodes containing ! * a URL that matches the supplied pattern. The match is case insensitive. * @param pattern The pattern to match. */ --- 47,55 ---- */ protected boolean mCaseSensitive; ! /** ! * Creates a LinkStringFilter that accepts LinkTag nodes containing ! * a URL that matches the supplied pattern. ! * The match is case insensitive. * @param pattern The pattern to match. */ *************** *** 57,63 **** this (pattern, false); } ! /** ! * Creates a new instance of LinkStringFilter that accepts LinkTag nodes containing * a URL that matches the supplied pattern. * @param pattern The pattern to match. --- 58,64 ---- this (pattern, false); } ! /** ! * Creates a LinkStringFilter that accepts LinkTag nodes containing * a URL that matches the supplied pattern. * @param pattern The pattern to match. *************** *** 69,76 **** mCaseSensitive = caseSensitive; } ! /** ! * Accept nodes that are assignable from the LinkTag class and have a URL that ! * matches the pattern supplied in the constructor. * @param node The node to check. * @return <code>true</code> if the node is a link with the pattern. --- 70,77 ---- mCaseSensitive = caseSensitive; } ! /** ! * Accept nodes that are a LinkTag and ! * have a URL that matches the pattern supplied in the constructor. * @param node The node to check. * @return <code>true</code> if the node is a link with the pattern. *************** *** 79,83 **** { boolean ret; ! ret = false; if (LinkTag.class.isAssignableFrom (node.getClass ())) --- 80,84 ---- { boolean ret; ! ret = false; if (LinkTag.class.isAssignableFrom (node.getClass ())) Index: NotFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/NotFilter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** NotFilter.java 10 Apr 2005 23:20:43 -0000 1.4 --- NotFilter.java 15 May 2005 11:49:04 -0000 1.5 *************** *** 52,56 **** /** ! * Creates a new instance of NotFilter that accepts nodes not acceptable to the predicate filter. * @param predicate The filter to consult. */ --- 52,56 ---- /** ! * Creates a NotFilter that accepts nodes not acceptable to the predicate. * @param predicate The filter to consult. */ *************** *** 68,72 **** return (mPredicate); } ! /** * Set the predicate for this NotFilter. --- 68,72 ---- return (mPredicate); } ! /** * Set the predicate for this NotFilter. Index: OrFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/OrFilter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** OrFilter.java 10 Apr 2005 23:20:43 -0000 1.3 --- OrFilter.java 15 May 2005 11:49:04 -0000 1.4 *************** *** 52,56 **** /** ! * Creates a new instance of an OrFilter that accepts nodes acceptable to either filter. * @param left One filter. * @param right The other filter. --- 52,56 ---- /** ! * Creates an OrFilter that accepts nodes acceptable to either filter. * @param left One filter. * @param right The other filter. *************** *** 59,63 **** { NodeFilter[] predicates; ! predicates = new NodeFilter[2]; predicates[0] = left; --- 59,63 ---- { NodeFilter[] predicates; ! predicates = new NodeFilter[2]; predicates[0] = left; *************** *** 74,78 **** return (mPredicates); } ! /** * Set the predicates for this OrFilter. --- 74,78 ---- return (mPredicates); } ! /** * Set the predicates for this OrFilter. *************** *** 99,109 **** { boolean ret; ! ret = false; ! for (int i = 0; !ret && (i < mPredicates.length); i++) if (mPredicates[i].accept (node)) ret = true; ! return (ret); } --- 99,109 ---- { boolean ret; ! ret = false; ! for (int i = 0; !ret && (i < mPredicates.length); i++) if (mPredicates[i].accept (node)) ret = true; ! return (ret); } Index: HasChildFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/HasChildFilter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** HasChildFilter.java 10 Apr 2005 23:20:43 -0000 1.4 --- HasChildFilter.java 15 May 2005 11:49:04 -0000 1.5 *************** *** 36,44 **** * It can be set to operate recursively, that is perform a scan down * through the node heirarchy in a breadth first traversal looking for any ! * descendant that matches the predicate filter (which stops the search). */ public class HasChildFilter ! implements ! NodeFilter { /** --- 36,44 ---- * It can be set to operate recursively, that is perform a scan down * through the node heirarchy in a breadth first traversal looking for any ! * descendant that matches the predicate filter (which stops the search). */ public class HasChildFilter ! implements ! NodeFilter { /** *************** *** 50,54 **** * Performs a recursive search down the node heirarchy if <code>true</code>. */ ! public boolean mRecursive; /** --- 50,54 ---- * Performs a recursive search down the node heirarchy if <code>true</code>. */ ! protected boolean mRecursive; /** *************** *** 63,67 **** /** ! * Creates a new instance of HasChildFilter that accepts nodes with a direct child acceptable to the filter. * @param filter The filter to apply to the children. */ --- 63,68 ---- /** ! * Creates a new instance of HasChildFilter that accepts nodes ! * with a direct child acceptable to the filter. * @param filter The filter to apply to the children. */ *************** *** 72,78 **** /** ! * Creates a new instance of HasChildFilter that accepts nodes with a child acceptable to the filter. * Of necessity, this applies only to composite tags, i.e. those that can ! * contain other nodes, for example <HTML></HTML>. * @param filter The filter to apply to children. * @param recursive If <code>true</code>, any enclosed node acceptable --- 73,80 ---- /** ! * Creates a new instance of HasChildFilter that accepts nodes ! * with a child acceptable to the filter. * Of necessity, this applies only to composite tags, i.e. those that can ! * contain other nodes, for example <HTML></HTML>. * @param filter The filter to apply to children. * @param recursive If <code>true</code>, any enclosed node acceptable *************** *** 94,98 **** return (mChildFilter); } ! /** * Set the filter for this HasParentFilter. --- 96,100 ---- return (mChildFilter); } ! /** * Set the filter for this HasParentFilter. *************** *** 111,115 **** public boolean getRecursive () { ! return mRecursive; } --- 113,117 ---- public boolean getRecursive () { ! return (mRecursive); } *************** *** 145,149 **** if (getChildFilter ().accept (children.elementAt (i))) ret = true; ! // do recursion after all children checked to get breadth first traversal if (!ret && getRecursive ()) for (int i = 0; !ret && i < children.size (); i++) --- 147,152 ---- if (getChildFilter ().accept (children.elementAt (i))) ret = true; ! // do recursion after all children are checked ! // to get breadth first traversal if (!ret && getRecursive ()) for (int i = 0; !ret && i < children.size (); i++) Index: HasSiblingFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/HasSiblingFilter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HasSiblingFilter.java 10 Apr 2005 23:20:43 -0000 1.2 --- HasSiblingFilter.java 15 May 2005 11:49:04 -0000 1.3 *************** *** 37,47 **** */ public class HasSiblingFilter ! implements ! NodeFilter { /** * The filter to apply to the sibling. */ ! public NodeFilter mSiblingFilter; /** --- 37,47 ---- */ public class HasSiblingFilter ! implements ! NodeFilter { /** * The filter to apply to the sibling. */ ! protected NodeFilter mSiblingFilter; /** *************** *** 56,60 **** /** ! * Creates a new instance of HasSiblingFilter that accepts nodes with sibling acceptable to the filter. * @param filter The filter to apply to the sibling. */ --- 56,61 ---- /** ! * Creates a new instance of HasSiblingFilter that accepts nodes ! * with sibling acceptable to the filter. * @param filter The filter to apply to the sibling. */ *************** *** 72,76 **** return (mSiblingFilter); } ! /** * Set the filter for this HasSiblingFilter. --- 73,77 ---- return (mSiblingFilter); } ! /** * Set the filter for this HasSiblingFilter. *************** *** 98,115 **** if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) { ! parent = node.getParent (); ! if (null != parent) ! { ! siblings = parent.getChildren (); ! if (null != siblings) ! { ! count = siblings.size (); ! for (int i = 0; !ret && (i < count); i++) ! if (getSiblingFilter ().accept (siblings.elementAt (i))) ! ret = true; ! } ! else ! System.out.println("gotcha"); ! } } --- 99,114 ---- if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) { ! parent = node.getParent (); ! if (null != parent) ! { ! siblings = parent.getChildren (); ! if (null != siblings) ! { ! count = siblings.size (); ! for (int i = 0; !ret && (i < count); i++) ! if (getSiblingFilter ().accept (siblings.elementAt (i))) ! ret = true; ! } ! } } Index: CssSelectorNodeFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/CssSelectorNodeFilter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CssSelectorNodeFilter.java 10 Apr 2005 23:20:43 -0000 1.5 --- CssSelectorNodeFilter.java 15 May 2005 11:49:04 -0000 1.6 *************** *** 44,47 **** --- 44,50 ---- public class CssSelectorNodeFilter implements NodeFilter { + /** + * Regular expression to split the selector into tokens. + */ private static Pattern tokens = Pattern.compile("(" *************** *** 64,75 **** , Pattern.CASE_INSENSITIVE ! |Pattern.DOTALL ! |Pattern.COMMENTS); ! private static final int COMMENT = 1, QUOTEDSTRING = 2, RELATION = 3, ! NAME = 4, COMBINATOR = 5, DELIM = 6, COMMA = 7; private NodeFilter therule; /** * Create a Cascading Style Sheet node filter. --- 67,114 ---- , Pattern.CASE_INSENSITIVE ! | Pattern.DOTALL ! | Pattern.COMMENTS); ! /** ! * Comment token type. ! */ ! private static final int COMMENT = 1; ! ! /** ! * quoted string token type. ! */ ! private static final int QUOTEDSTRING = 2; ! ! /** ! * Relation token type. ! */ ! private static final int RELATION = 3; ! ! /** ! * Name token type. ! */ ! private static final int NAME = 4; ! ! /** ! * Combinator token type. ! */ ! private static final int COMBINATOR = 5; ! ! /** ! * Delimiter token type. ! */ ! private static final int DELIM = 6; ! ! /** ! * Comma token type. ! */ ! private static final int COMMA = 7; private NodeFilter therule; + private Matcher m = null; + private int tokentype = 0; + private String token = null; + /** * Create a Cascading Style Sheet node filter. *************** *** 78,84 **** public CssSelectorNodeFilter(String selector) { ! m = tokens.matcher(selector); ! if (nextToken()) ! therule = parse(); } --- 117,123 ---- public CssSelectorNodeFilter(String selector) { ! m = tokens.matcher (selector); ! if (nextToken ()) ! therule = parse (); } *************** *** 89,119 **** * <code>false</code> otherwise. */ ! public boolean accept(Node node) { ! return therule.accept(node); } ! private Matcher m = null; ! private int tokentype = 0; ! private String token = null; ! ! private boolean nextToken() { ! if (m != null && m.find()) ! for (int i = 1; i < m.groupCount(); i++) ! if (m.group(i) != null) { tokentype = i; ! token = m.group(i); return true; } tokentype = 0; token = null; ! return false; } ! private NodeFilter parse() { ! NodeFilter n = null; do { --- 128,156 ---- * <code>false</code> otherwise. */ ! public boolean accept (Node node) { ! return (therule.accept (node)); } ! private boolean nextToken () { ! if (m != null && m.find ()) ! for (int i = 1; i < m.groupCount (); i++) ! if (null != m.group (i)) { tokentype = i; ! token = m.group (i); return true; } tokentype = 0; token = null; ! return (false); } ! private NodeFilter parse () { ! NodeFilter ret; ! ! ret = null; do { *************** *** 123,153 **** case NAME: case DELIM: ! if (n == null) ! n = parseSimple(); else ! n = new AndFilter(n, parseSimple()); break; case COMBINATOR: ! switch (token.charAt(0)) { case '+': ! n = new AdjacentFilter(n); break; case '>': ! n = new HasParentFilter(n); break; default: // whitespace ! n = new HasAncestorFilter(n); } ! nextToken(); break; case COMMA: ! n = new OrFilter(n, parse()); ! nextToken(); break; } } while (token != null); ! return n; } --- 160,191 ---- case NAME: case DELIM: ! if (ret == null) ! ret = parseSimple (); else ! ret = new AndFilter (ret, parseSimple ()); break; case COMBINATOR: ! switch (token.charAt (0)) { case '+': ! ret = new AdjacentFilter (ret); break; case '>': ! ret = new HasParentFilter (ret); break; default: // whitespace ! ret = new HasAncestorFilter (ret); } ! nextToken (); break; case COMMA: ! ret = new OrFilter (ret, parse ()); ! nextToken (); break; } } while (token != null); ! ! return (ret); } *************** *** 155,159 **** { boolean done = false; ! NodeFilter n = null; if (token != null) --- 193,197 ---- { boolean done = false; ! NodeFilter ret = null; if (token != null) *************** *** 167,175 **** case NAME: if ("*".equals(token)) ! n = new YesFilter(); ! else if (n == null) ! n = new TagNameFilter(unescape(token)); else ! n = new AndFilter(n, new TagNameFilter(unescape(token))); nextToken(); break; --- 205,213 ---- case NAME: if ("*".equals(token)) ! ret = new YesFilter(); ! else if (ret == null) ! ret = new TagNameFilter(unescape(token)); else ! ret = new AndFilter(ret, new TagNameFilter(unescape(token))); nextToken(); break; *************** *** 181,189 **** if (tokentype != NAME) throw new IllegalArgumentException("Syntax error at " + token); ! if (n == null) ! n = new HasAttributeFilter("class", unescape(token)); else ! n ! = new AndFilter(n, new HasAttributeFilter("class", unescape(token))); break; case '#': --- 219,227 ---- if (tokentype != NAME) throw new IllegalArgumentException("Syntax error at " + token); ! if (ret == null) ! ret = new HasAttributeFilter("class", unescape(token)); else ! ret ! = new AndFilter(ret, new HasAttributeFilter("class", unescape(token))); break; case '#': *************** *** 191,212 **** if (tokentype != NAME) throw new IllegalArgumentException("Syntax error at " + token); ! if (n == null) ! n = new HasAttributeFilter("id", unescape(token)); else ! n = new AndFilter(n, new HasAttributeFilter("id", unescape(token))); break; case ':': nextToken(); ! if (n == null) ! n = parsePseudoClass(); else ! n = new AndFilter(n, parsePseudoClass()); break; case '[': nextToken(); ! if (n == null) ! n = parseAttributeExp(); else ! n = new AndFilter(n, parseAttributeExp()); break; } --- 229,250 ---- if (tokentype != NAME) throw new IllegalArgumentException("Syntax error at " + token); ! if (ret == null) ! ret = new HasAttributeFilter("id", unescape(token)); else ! ret = new AndFilter(ret, new HasAttributeFilter("id", unescape(token))); break; case ':': nextToken(); ! if (ret == null) ! ret = parsePseudoClass(); else ! ret = new AndFilter(ret, parsePseudoClass()); break; case '[': nextToken(); ! if (ret == null) ! ret = parseAttributeExp(); else ! ret = new AndFilter(ret, parseAttributeExp()); break; } *************** *** 218,222 **** } while (!done && token != null); ! return n; } --- 256,260 ---- } while (!done && token != null); ! return ret; } *************** *** 228,232 **** private NodeFilter parseAttributeExp() { ! NodeFilter n = null; if (tokentype == NAME) { --- 266,270 ---- private NodeFilter parseAttributeExp() { ! NodeFilter ret = null; if (tokentype == NAME) { *************** *** 234,238 **** nextToken(); if ("]".equals(token)) ! n = new HasAttributeFilter(unescape(attrib)); else if (tokentype == RELATION) { --- 272,276 ---- nextToken(); if ("]".equals(token)) ! ret = new HasAttributeFilter(unescape(attrib)); else if (tokentype == RELATION) { *************** *** 244,260 **** val = unescape(token); if ("~=".equals(rel) && val != null) ! n = new AttribMatchFilter(unescape(attrib), "\\b" + val.replaceAll("([^a-zA-Z0-9])", "\\\\$1") + "\\b"); else if ("=".equals(rel) && val != null) ! n = new HasAttributeFilter(attrib, val); } } ! if (n == null) throw new IllegalArgumentException("Syntax error at " + token + tokentype); nextToken(); ! return n; } --- 282,298 ---- val = unescape(token); if ("~=".equals(rel) && val != null) ! ret = new AttribMatchFilter(unescape(attrib), "\\b" + val.replaceAll("([^a-zA-Z0-9])", "\\\\$1") + "\\b"); else if ("=".equals(rel) && val != null) ! ret = new HasAttributeFilter(attrib, val); } } ! if (ret == null) throw new IllegalArgumentException("Syntax error at " + token + tokentype); nextToken(); ! return ret; } Index: TagNameFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/TagNameFilter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TagNameFilter.java 10 Apr 2005 23:20:43 -0000 1.5 --- TagNameFilter.java 15 May 2005 11:49:04 -0000 1.6 *************** *** 56,60 **** /** ! * Creates a new instance of TagNameFilter that accepts tags with the given name. * @param name The tag name to match. */ --- 56,60 ---- /** ! * Creates a TagNameFilter that accepts tags with the given name. * @param name The tag name to match. */ *************** *** 92,98 **** public boolean accept (Node node) { ! return ((node instanceof Tag) && ! !((Tag)node).isEndTag () && ! ((Tag)node).getTagName ().equals (mName)); } } --- 92,98 ---- public boolean accept (Node node) { ! return ((node instanceof Tag) ! && !((Tag)node).isEndTag () ! && ((Tag)node).getTagName ().equals (mName)); } } Index: HasAttributeFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/HasAttributeFilter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** HasAttributeFilter.java 10 Apr 2005 23:20:43 -0000 1.6 --- HasAttributeFilter.java 15 May 2005 11:49:04 -0000 1.7 *************** *** 35,39 **** /** ! * This class accepts all tags that have a certain attribute, and optionally, with a certain value. */ public class HasAttributeFilter implements NodeFilter --- 35,40 ---- /** ! * This class accepts all tags that have a certain attribute, ! * and optionally, with a certain value. */ public class HasAttributeFilter implements NodeFilter *************** *** 60,64 **** /** ! * Creates a new instance of HasAttributeFilter that accepts tags with the given attribute. * @param attribute The attribute to search for. */ --- 61,66 ---- /** ! * Creates a new instance of HasAttributeFilter that accepts tags ! * with the given attribute. * @param attribute The attribute to search for. */ *************** *** 69,75 **** /** ! * Creates a new instance of HasAttributeFilter that accepts tags with the given attribute. * @param attribute The attribute to search for. ! * @param value The value that must be matched, or null if any value will match. */ public HasAttributeFilter (String attribute, String value) --- 71,79 ---- /** ! * Creates a new instance of HasAttributeFilter that accepts tags ! * with the given attribute and value. * @param attribute The attribute to search for. ! * @param value The value that must be matched, ! * or null if any value will match. */ public HasAttributeFilter (String attribute, String value) *************** *** 109,113 **** * Set the attribute value. * @param value The value of the attribute to accept. ! * If <code>null</code>, any tag with the attribute, no matter it's value is acceptable. */ public void setAttributeValue (String value) --- 113,118 ---- * Set the attribute value. * @param value The value of the attribute to accept. ! * If <code>null</code>, any tag with the attribute, ! * no matter what it's value is acceptable. */ public void setAttributeValue (String value) Index: NodeClassFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/NodeClassFilter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NodeClassFilter.java 10 Apr 2005 23:20:43 -0000 1.3 --- NodeClassFilter.java 15 May 2005 11:49:04 -0000 1.4 *************** *** 41,45 **** /** ! * Creates a new instance of NodeClassFilter that accepts tags of the Html (top level) class. */ public NodeClassFilter () --- 41,45 ---- /** ! * Creates a NodeClassFilter that accepts Html tags. */ public NodeClassFilter () *************** *** 49,54 **** /** ! * Creates a new instance of NodeClassFilter that accepts tags of the given class. ! * @param cls The cls to match. */ public NodeClassFilter (Class cls) --- 49,54 ---- /** ! * Creates a NodeClassFilter that accepts tags of the given class. ! * @param cls The class to match. */ public NodeClassFilter (Class cls) *************** *** 76,80 **** /** ! * Accept nodes that are assignable from the class provided in the constructor. * @param node The node to check. * @return <code>true</code> if the node is the right class, --- 76,81 ---- /** ! * Accept nodes that are assignable from the class provided in ! * the constructor. * @param node The node to check. * @return <code>true</code> if the node is the right class, |