[Htmlparser-cvs] htmlparser/src/org/htmlparser/tags CompositeTag.java,1.74,1.75 FrameSetTag.java,1.3
Brought to you by:
derrickoswald
From: <der...@pr...> - 2004-01-27 09:45:01
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26191/tags Modified Files: CompositeTag.java FrameSetTag.java ImageTag.java Log Message: Fix bug #883664 toUpperCase on tag names and attributes depends on locale Added locale information to all relevant toUpperCase() calls, with an English locale for tag names and attribute names, or developers choice of locale for methods that do uppercase conversion as part of their algorithms. Index: CompositeTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/CompositeTag.java,v retrieving revision 1.74 retrieving revision 1.75 diff -C2 -d -r1.74 -r1.75 *** CompositeTag.java 24 Jan 2004 23:57:52 -0000 1.74 --- CompositeTag.java 25 Jan 2004 21:33:11 -0000 1.75 *************** *** 27,30 **** --- 27,32 ---- package org.htmlparser.tags; + import java.util.Locale; + import org.htmlparser.Node; import org.htmlparser.NodeFilter; *************** *** 186,216 **** /** ! * Searches for any node whose text representation contains the search ! * string. Collects all such nodes in a NodeList. ! * e.g. if you wish to find any textareas in a form tag containing "hello ! * world", the code would be : * <code> ! * NodeList nodeList = formTag.searchFor("Hello World"); * </code> ! * @param searchString search criterion ! * @param caseSensitive specify whether this search should be case ! * sensitive ! * @return NodeList Collection of nodes whose string contents or ! * representation have the searchString in them */ ! public NodeList searchFor(String searchString, boolean caseSensitive) { ! NodeList foundList = new NodeList(); Node node; ! if (!caseSensitive) searchString = searchString.toUpperCase(); ! for (SimpleNodeIterator e = children();e.hasMoreNodes();) { ! node = e.nextNode(); ! String nodeTextString = node.toPlainTextString(); ! if (!caseSensitive) nodeTextString=nodeTextString.toUpperCase(); ! if (nodeTextString.indexOf(searchString)!=-1) { ! foundList.add(node); ! } } ! return foundList; } --- 188,266 ---- /** ! * Searches for all nodes whose text representation contains the search string. ! * Collects all nodes containing the search string into a NodeList. ! * This search is <b>case-insensitive</b> and the search string and the ! * node text are converted to uppercase using an English locale. ! * For example, if you wish to find any textareas in a form tag containing ! * "hello world", the code would be: * <code> ! * NodeList nodeList = formTag.searchFor("Hello World"); * </code> ! * @param searchString Search criterion. ! * @return A collection of nodes whose string contents or ! * representation have the <code>searchString</code> in them. */ + public NodeList searchFor (String searchString) + { + return (searchFor (searchString, false)); + } ! /** ! * Searches for all nodes whose text representation contains the search string. ! * Collects all nodes containing the search string into a NodeList. ! * For example, if you wish to find any textareas in a form tag containing ! * "hello world", the code would be: ! * <code> ! * NodeList nodeList = formTag.searchFor("Hello World"); ! * </code> ! * @param searchString Search criterion. ! * @param caseSensitive If <code>true</code> this search should be case ! * sensitive. Otherwise, the search string and the node text are converted ! * to uppercase using an English locale. ! * @return A collection of nodes whose string contents or ! * representation have the <code>searchString</code> in them. ! */ ! public NodeList searchFor (String searchString, boolean caseSensitive) ! { ! return (searchFor (searchString, caseSensitive, Locale.ENGLISH)); ! } ! ! /** ! * Searches for all nodes whose text representation contains the search string. ! * Collects all nodes containing the search string into a NodeList. ! * For example, if you wish to find any textareas in a form tag containing ! * "hello world", the code would be: ! * <code> ! * NodeList nodeList = formTag.searchFor("Hello World"); ! * </code> ! * @param searchString Search criterion. ! * @param caseSensitive If <code>true</code> this search should be case ! * sensitive. Otherwise, the search string and the node text are converted ! * to uppercase using the locale provided. ! * @parem locale The locale for uppercase conversion. ! * @return A collection of nodes whose string contents or ! * representation have the <code>searchString</code> in them. ! */ ! public NodeList searchFor (String searchString, boolean caseSensitive, Locale locale) ! { Node node; ! String text; ! NodeList ret; ! ! ret = new NodeList (); ! ! if (!caseSensitive) ! searchString = searchString.toUpperCase (locale); ! for (SimpleNodeIterator e = children (); e.hasMoreNodes (); ) ! { ! node = e.nextNode (); ! text = node.toPlainTextString (); ! if (!caseSensitive) ! text = text.toUpperCase (locale); ! if (-1 != text.indexOf (searchString)) ! ret.add (node); } ! ! return (ret); } *************** *** 231,258 **** /** ! * Searches for any node whose text representation contains the search ! * string. Collects all such nodes in a NodeList. ! * e.g. if you wish to find any textareas in a form tag containing "hello ! * world", the code would be : ! * <code> ! * NodeList nodeList = formTag.searchFor("Hello World"); ! * </code> ! * This search is <b>case-insensitive</b>. ! * @param searchString search criterion ! * @return NodeList Collection of nodes whose string contents or ! * representation have the searchString in them */ ! public NodeList searchFor(String searchString) { ! return searchFor(searchString, false); } /** ! * Returns the node number of the string node containing the ! * given text. This can be useful to index into the composite tag ! * and get other children. ! * @param text ! * @return int */ ! public int findPositionOf(String text) { Node node; --- 281,307 ---- /** ! * Returns the node number of the first node containing the given text. ! * This can be useful to index into the composite tag and get other children. ! * Text is compared without case sensitivity and conversion to uppercase ! * uses an English locale. ! * @param text The text to search for. ! * @return int The node index in the children list of the node containing ! * the text or -1 if not found. */ ! public int findPositionOf (String text) ! { ! return (findPositionOf (text, Locale.ENGLISH)); } /** ! * Returns the node number of the first node containing the given text. ! * This can be useful to index into the composite tag and get other children. ! * Text is compared without case sensitivity and conversion to uppercase ! * uses the supplied locale. ! * @param text The text to search for. ! * @return int The node index in the children list of the node containing ! * the text or -1 if not found. */ ! public int findPositionOf (String text, Locale locale) { Node node; *************** *** 260,268 **** loc = 0; ! text = text.toUpperCase (); for (SimpleNodeIterator e = children (); e.hasMoreNodes (); ) { node = e.nextNode (); ! if (-1 != node.toPlainTextString ().toUpperCase ().indexOf (text)) return loc; loc++; --- 309,317 ---- loc = 0; ! text = text.toUpperCase (locale); for (SimpleNodeIterator e = children (); e.hasMoreNodes (); ) { node = e.nextNode (); ! if (-1 != node.toPlainTextString ().toUpperCase (locale).indexOf (text)) return loc; loc++; Index: FrameSetTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/FrameSetTag.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** FrameSetTag.java 2 Jan 2004 16:24:54 -0000 1.35 --- FrameSetTag.java 25 Jan 2004 21:33:12 -0000 1.36 *************** *** 27,30 **** --- 27,32 ---- package org.htmlparser.tags; + import java.util.Locale; + import org.htmlparser.Node; import org.htmlparser.util.NodeList; *************** *** 90,119 **** /** * Gets a frame by name. * @param name The name of the frame to retrieve. * @return The specified frame or <code>null</code> if it wasn't found. */ ! public FrameTag getFrame(String name) { - boolean found; Node node; ! FrameTag frameTag; ! found = false; ! name = name.toUpperCase (); ! frameTag = null; ! for (SimpleNodeIterator e=getFrames().elements();e.hasMoreNodes() && !found;) { node = e.nextNode(); if (node instanceof FrameTag) { ! frameTag = (FrameTag)node; ! if (frameTag.getFrameName().toUpperCase().equals(name)) ! found = true; } } ! if (found) ! return (frameTag); ! else ! return (null); } --- 92,133 ---- /** * Gets a frame by name. + * Names are checked without case sensitivity and conversion to uppercase + * is performed with an English locale. * @param name The name of the frame to retrieve. * @return The specified frame or <code>null</code> if it wasn't found. */ ! public FrameTag getFrame (String name) ! { ! return (getFrame (name, Locale.ENGLISH)); ! } ! ! /** ! * Gets a frame by name. ! * Names are checked without case sensitivity and conversion to uppercase ! * is performed with the locale provided. ! * @param name The name of the frame to retrieve. ! * @param locale The locale to use when converting to uppercase. ! * @return The specified frame or <code>null</code> if it wasn't found. ! */ ! public FrameTag getFrame (String name, Locale locale) { Node node; ! FrameTag ret; ! ! ret = null; ! name = name.toUpperCase (locale); ! for (SimpleNodeIterator e = getFrames ().elements (); e.hasMoreNodes () && (null == ret); ) { node = e.nextNode(); if (node instanceof FrameTag) { ! ret = (FrameTag)node; ! if (!ret.getFrameName ().toUpperCase (locale).equals (name)) ! ret = null; } } ! ! return (ret); } Index: ImageTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/ImageTag.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** ImageTag.java 14 Jan 2004 02:53:46 -0000 1.41 --- ImageTag.java 25 Jan 2004 21:33:12 -0000 1.42 *************** *** 27,31 **** --- 27,33 ---- package org.htmlparser.tags; + import java.util.Locale; import java.util.Vector; + import org.htmlparser.lexer.nodes.Attribute; import org.htmlparser.util.ParserUtils; *************** *** 107,111 **** if (null != string) { ! name = string.toUpperCase (); if (name.equals ("SRC")) { --- 109,113 ---- if (null != string) { ! name = string.toUpperCase (Locale.ENGLISH); if (name.equals ("SRC")) { |