htmlparser-cvs Mailing List for HTML Parser (Page 17)
Brought to you by:
derrickoswald
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(141) |
Jun
(108) |
Jul
(66) |
Aug
(127) |
Sep
(155) |
Oct
(149) |
Nov
(72) |
Dec
(72) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(100) |
Feb
(36) |
Mar
(21) |
Apr
(3) |
May
(87) |
Jun
(28) |
Jul
(84) |
Aug
(5) |
Sep
(14) |
Oct
|
Nov
|
Dec
|
2005 |
Jan
(1) |
Feb
(39) |
Mar
(26) |
Apr
(38) |
May
(14) |
Jun
(10) |
Jul
|
Aug
|
Sep
(13) |
Oct
(8) |
Nov
(10) |
Dec
|
2006 |
Jan
|
Feb
(1) |
Mar
(17) |
Apr
(20) |
May
(28) |
Jun
(24) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Derrick O. <der...@us...> - 2004-05-30 01:27:55
|
Update of /cvsroot/htmlparser/htmlparser/docs/wiki In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19191/wiki Log Message: Directory /cvsroot/htmlparser/htmlparser/docs/wiki added to the repository |
From: Derrick O. <der...@us...> - 2004-05-29 20:40:22
|
Update of /cvsroot/htmlparser/htmlparser/resources In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4693/resources Added Files: license.txt Log Message: Add LGPL license.txt to the distribution. --- NEW FILE: license.txt --- GNU Lesser General Public License Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. one line to give the library's name and an idea of what it does. Copyright (C) year name of author This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. signature of Ty Coon, 1 April 1990 Ty Coon, President of Vice That's all there is to it! |
From: Derrick O. <der...@us...> - 2004-05-29 20:40:22
|
Update of /cvsroot/htmlparser/htmlparser/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4693/docs Modified Files: release.txt Log Message: Add LGPL license.txt to the distribution. Index: release.txt =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/docs/release.txt,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** release.txt 22 May 2004 12:08:59 -0000 1.59 --- release.txt 29 May 2004 20:40:11 -0000 1.60 *************** *** 4,9 **** Contents of the distribution ---------------------------- ! (i) binary jar files - htmlparser.jar and lexer.jar (in lib directory) ! (ii) source code - src.zip Also contains necessary resources, and build file. Unzip this --- 4,12 ---- Contents of the distribution ---------------------------- ! (i) jar files - lib directory ! HTML Parser jars: htmlparser.jar, lexer.jar and thumbelina.jar. ! Also thirdparty jar files checkstyle-all-3.1.jar, commons-logging.jar, ! fit.jar and junit.jar. ! (ii) source code - src.zip Also contains necessary resources, and build file. Unzip this *************** *** 11,21 **** You would need Jakarta Ant installed. ! (iii) documentation - docs directory (includes javadoc) Point your browser at index.html in the docs directory. (iv) executing scripts - bin directory ! Batch files assume that java 1.2 (or upwards) is visible in your path. ! (v) this file Changes since Version 1.4 --- 14,27 ---- You would need Jakarta Ant installed. ! (iii) documentation - docs directory (includes javadocs) Point your browser at index.html in the docs directory. (iv) executing scripts - bin directory ! Batch/script files assume that Java is visible in your path. ! Most require Java 1.2 (or upwards), except for lexer. ! (v) license.txt (GNU Lesser General Public License) ! ! (vi) this file, release.txt Changes since Version 1.4 |
From: Derrick O. <der...@us...> - 2004-05-29 20:40:20
|
Update of /cvsroot/htmlparser/htmlparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4693 Modified Files: build.xml Log Message: Add LGPL license.txt to the distribution. Index: build.xml =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/build.xml,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** build.xml 29 May 2004 19:51:47 -0000 1.66 --- build.xml 29 May 2004 20:40:10 -0000 1.67 *************** *** 225,232 **** </target> ! <!-- Create the distribution of htmlparser.jar and htmllexer.jar --> <target name="jar" depends="jarlexer,jarparser" description="create htmlparser.jar and htmllexer.jar"/> ! <!-- Create the distribution of htmllexer.jar --> <target name="jarlexer" depends="compilelexer" description="create htmllexer.jar"> <mkdir dir="${lib}"/> --- 225,232 ---- </target> ! <!-- Create the htmlparser.jar and htmllexer.jar --> <target name="jar" depends="jarlexer,jarparser" description="create htmlparser.jar and htmllexer.jar"/> ! <!-- Create htmllexer.jar --> <target name="jarlexer" depends="compilelexer" description="create htmllexer.jar"> <mkdir dir="${lib}"/> *************** *** 257,261 **** </target> ! <!-- Create the distribution of htmlparser.jar --> <target name="jarparser" depends="compileparser" description="create htmlparser.jar"> <mkdir dir="${lib}"/> --- 257,261 ---- </target> ! <!-- Create htmlparser.jar --> <target name="jarparser" depends="compileparser" description="create htmlparser.jar"> <mkdir dir="${lib}"/> *************** *** 287,291 **** <!-- Create the Thumbelina jar --> <target name="thumbelina" depends="JDK1.4,jarlexer" description="create thumbelina.jar" if="JDK1.4"> ! <!-- Create the distribution directory --> <mkdir dir="${lib}"/> <javac compiler="javac1.4" srcdir="${src}" debug="on" classpath="src:${lib}/htmllexer.jar"> --- 287,291 ---- <!-- Create the Thumbelina jar --> <target name="thumbelina" depends="JDK1.4,jarlexer" description="create thumbelina.jar" if="JDK1.4"> ! <!-- Create the lib directory --> <mkdir dir="${lib}"/> <javac compiler="javac1.4" srcdir="${src}" debug="on" classpath="src:${lib}/htmllexer.jar"> *************** *** 364,368 **** <link href="http://java.sun.com/j2se/1.4.2/docs/api/"/> </javadoc> ! <copy file="resources/inherit.gif" tofile="${docs}/javadoc/resources/inherit.gif" overwrite="true"/> <delete file="${resources}/HtmlTaglet.class"/> </target> --- 364,368 ---- <link href="http://java.sun.com/j2se/1.4.2/docs/api/"/> </javadoc> ! <copy file="${resources}/inherit.gif" tofile="${docs}/javadoc/resources/inherit.gif" overwrite="true"/> <delete file="${resources}/HtmlTaglet.class"/> </target> *************** *** 371,376 **** </target> ! <!-- Package the release --> ! <target name="package" depends="release,sources" description="glom the release and source files into the distribution zip file"> <mkdir dir="${distribution}"/> --- 371,386 ---- </target> ! <!-- Prepare the sources zip, allowing folks to build the code --> ! <target name="sources" description="create the source zip"> ! <zip destfile="src.zip" defaultexcludes="no"> ! <zipfileset dir="${src}" prefix="${src}" includes="**/*.java **/*.html **/*.gif **/*.form **/*.properties"/> ! <zipfileset dir="." includes="build.xml"/> ! <zipfileset dir="${resources}" prefix="${resources}" excludes="cvs2cl.pl"/> ! <zipfileset dir="${resources}" prefix="${resources}" includes="cvs2cl.pl" filemode="755"/> ! </zip> ! </target> ! ! <!-- Perform the htmlparser integration --> ! <target name="htmlparser" depends="release,sources" description="glom the release and source files into the distribution zip file"> <mkdir dir="${distribution}"/> *************** *** 384,400 **** <!-- Copy the release notes as readme.txt in the base release directory --> <zipfileset dir="${docs}" includes="release.txt" fullpath="htmlparser${versionQualifier}/readme.txt"/> </zip> </target> - <!-- Prepare the sources zip, allowing folks to build the code --> - <target name="sources" description="create the source zip"> - <zip destfile="src.zip" defaultexcludes="no"> - <zipfileset dir="${src}" prefix="${src}" includes="**/*.java **/*.html **/*.gif **/*.form **/*.properties"/> - <zipfileset dir="." includes="build.xml"/> - <zipfileset dir="${resources}" prefix="${resources}" excludes="cvs2cl.pl"/> - <zipfileset dir="${resources}" prefix="${resources}" includes="cvs2cl.pl" filemode="755"/> - </zip> - </target> - <target name="clean" description="cleanup"> <!-- delete the src.zip, classes and javadocs leave the jars --> --- 394,402 ---- <!-- Copy the release notes as readme.txt in the base release directory --> <zipfileset dir="${docs}" includes="release.txt" fullpath="htmlparser${versionQualifier}/readme.txt"/> + <!-- Copy the LGPL license.txt to the base release directory --> + <zipfileset dir="${resources}" includes="license.txt" fullpath="htmlparser${versionQualifier}/license.txt"/> </zip> </target> <target name="clean" description="cleanup"> <!-- delete the src.zip, classes and javadocs leave the jars --> *************** *** 406,412 **** </target> - <!-- Perform the htmlparser integration --> - <target name="htmlparser" depends="package,clean" description="same as package plus cleanup"> - </target> - </project> --- 408,410 ---- |
From: Derrick O. <der...@us...> - 2004-05-29 19:51:59
|
Update of /cvsroot/htmlparser/htmlparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29369 Modified Files: build.xml Log Message: Fix javadoc inheritance white background GIF. Index: build.xml =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/build.xml,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** build.xml 24 May 2004 16:18:10 -0000 1.65 --- build.xml 29 May 2004 19:51:47 -0000 1.66 *************** *** 364,367 **** --- 364,368 ---- <link href="http://java.sun.com/j2se/1.4.2/docs/api/"/> </javadoc> + <copy file="resources/inherit.gif" tofile="${docs}/javadoc/resources/inherit.gif" overwrite="true"/> <delete file="${resources}/HtmlTaglet.class"/> </target> |
From: Derrick O. <der...@us...> - 2004-05-29 19:51:59
|
Update of /cvsroot/htmlparser/htmlparser/resources In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29369/resources Added Files: inherit.gif Log Message: Fix javadoc inheritance white background GIF. --- NEW FILE: inherit.gif --- (This appears to be a binary file; contents omitted.) |
From: Derrick O. <der...@us...> - 2004-05-24 19:36:37
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv582/filters Added Files: RegexFilter.java Log Message: Add regular expression filter. --- NEW FILE: RegexFilter.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2003 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/RegexFilter.java,v $ // $Author: derrickoswald $ // $Date: 2004/05/24 19:36:26 $ // $Revision: 1.1 $ // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // package org.htmlparser.filters; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Text; /** * This filter accepts all string nodes matching a regular expression. * Because this searches {@link org.htmlparser.Text Text} nodes. it is * only useful for finding small fragments of text, where it is * unlikely to be broken up by a tag. To find large fragments of text * you should convert the page to plain text with something like the * {@link org.htmlparser.beans.StringBean StringBean} and then apply * the regular expression. * <p> * For example, to look for dates use: * <pre> * (19|20)\d\d([- \\/.](0[1-9]|1[012])[- \\/.](0[1-9]|[12][0-9]|3[01]))? * </pre> * as in: * <pre> * Parser parser = new Parser ("http://cbc.ca"); * RegexFilter filter = new RegexFilter ("(19|20)\\d\\d([- \\\\/.](0[1-9]|1[012])[- \\\\/.](0[1-9]|[12][0-9]|3[01]))?"); * NodeIterator iterator = parser.extractAllNodesThatMatch (filter).elements (); * </pre> * which matches a date in yyyy-mm-dd format between 1900-01-01 and 2099-12-31, * with a choice of five separators, dash, space, either slash or a period. * The year is matched by (19|20)\d\d which uses alternation to allow the * either 19 or 20 as the first two digits. The round brackets are mandatory. * 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. * The day and month are optional, but must occur together because of the ()? * bracketing after the year. */ public class RegexFilter implements NodeFilter { /** * Use match() matching strategy. */ public static final int MATCH = 1; /** * Use lookingAt() match strategy. */ public static final int LOOKINGAT = 2; /** * Use find() match strategy. */ public static final int FIND = 3; /** * The compiled regular expression to search for. */ protected Pattern mPattern; /** * The match strategy. * @see #RegexFilter(String, int) */ protected int mStrategy; /** * Creates a new instance of RegexFilter that accepts string nodes matching * a regular expression using the FIND strategy. * @param pattern The pattern to search for. */ public RegexFilter (String pattern) { this (pattern, FIND); } /** * Creates a new instance of RegexFilter that accepts string nodes matching * a regular expression. * @param pattern The pattern to search for. * @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> */ public RegexFilter (String pattern, int strategy) { mPattern = Pattern.compile (pattern); mStrategy = strategy; } /** * Accept string nodes that match the regular expression. * @param node The node to check. */ public boolean accept (Node node) { String string; Matcher matcher; boolean ret; ret = false; if (node instanceof Text) { string = ((Text)node).getText (); matcher = mPattern.matcher (string); switch (mStrategy) { case MATCH: ret = matcher.matches (); break; case LOOKINGAT: ret = matcher.lookingAt (); break; case FIND: ret = matcher.find (); break; } } return (ret); } } |
From: Derrick O. <der...@us...> - 2004-05-24 19:36:34
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/filterTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv582/tests/filterTests Modified Files: FilterTest.java Log Message: Add regular expression filter. Index: FilterTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/filterTests/FilterTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FilterTest.java 24 May 2004 16:18:31 -0000 1.5 --- FilterTest.java 24 May 2004 19:36:23 -0000 1.6 *************** *** 35,38 **** --- 35,39 ---- import org.htmlparser.filters.NotFilter; import org.htmlparser.filters.OrFilter; + import org.htmlparser.filters.RegexFilter; import org.htmlparser.filters.StringFilter; import org.htmlparser.filters.TagNameFilter; *************** *** 271,274 **** --- 272,333 ---- assertEquals ("wrong count", 2, count); } + + /** + * Test regular expression matching: + */ + public void testRegularExpression () throws Exception + { + String target = + "\n" + + "\n" + + "Most recently, in the Western Conference final, the Flames knocked off \n" + + "the San Jose Sharks, the Pacific Division champions, to become the first \n" + + "Canadian team to reach the Stanley Cup Championship series since 1994."; + + String html = + "<html><head><title>CBC Sports Online: NHL Playoffs</title></head>" + + "<body><h1>CBC SPORTS ONLINE</h1>\n" + + "The Calgary Flames have already defeated three NHL division winners \n" + + "during their improbable playoff run. If they are to hoist the Stanley \n" + + "Cup they'll have to go through one more. <p><table ALIGN=\"Right\" width=196 CELLPADDING=0 cellspacing=0 hspace=4> <tr><td><img src=\"/gfx/topstory/sports/iginla_j0524.jpg\" width=194 height=194 hspace=3 border=1><br>\n" + + "\n" + + "<font SIZE=\"1\" FACE=\"verdana,arial\">\n" + + "Jarome Iginla skates during the Flames' practice on Monday. Calgary takes on the Tampa Bay Lightning in the Stanley Cup finals beginning Tuesday night in Tampa\n" + + "</font></td></tr></table>\n" + + "\n" + + "\n" + + "In the post-season's first round, the Flames defeated the Vancouver \n" + + "Canucks, the Northwest Division winners, in seven tough games. <p>\n" + + "\n" + + "In Round 2 it was the Detroit Red Wings, who not only won the Central \n" + + "Division, but also boasted the NHL's best overall record during the \n" + + "regular season, who fell to the Flames. <p>" + + target + + "<p>\n" + + "\n" + + "Up next for the Flames is the Tampa Bay Lighting -- the runaway winners \n" + + "of the NHL's Southeast Division and the Eastern Conference's best team \n" + + "during the regular season. <p>\n" + + "\n" + + "The Lighting advanced by beating the Philadelphia Flyers in the Eastern \n" + + "Conference final. <p>\n" + + "</body></html>\n"; + Lexer lexer; + Parser parser; + RegexFilter filter; + NodeIterator iterator; + int count; + + lexer = new Lexer (html); + parser = new Parser (lexer); + filter = new RegexFilter ("(19|20)\\d\\d([- \\\\/.](0[1-9]|1[012])[- \\\\/.](0[1-9]|[12][0-9]|3[01]))?"); + count = 0; + for (iterator = parser.extractAllNodesThatMatch (filter).elements (); iterator.hasMoreNodes ();) + { + assertEquals ("text wrong", target, iterator.nextNode ().toHtml ()); + count++; + } + assertEquals ("wrong count", 1, count); + } } |
From: Derrick O. <der...@us...> - 2004-05-24 16:31:31
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21785/tests/lexerTests Modified Files: AttributeTests.java Log Message: Fix some files misplaced in last refactoring submission. Index: AttributeTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/AttributeTests.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** AttributeTests.java 24 May 2004 16:18:31 -0000 1.14 --- AttributeTests.java 24 May 2004 16:31:22 -0000 1.15 *************** *** 33,37 **** import org.htmlparser.Attribute; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.lexer.nodes.PageAttribute; import org.htmlparser.tags.ImageTag; import org.htmlparser.tags.Tag; --- 33,37 ---- import org.htmlparser.Attribute; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.lexer.PageAttribute; import org.htmlparser.tags.ImageTag; import org.htmlparser.tags.Tag; |
From: Derrick O. <der...@us...> - 2004-05-24 16:31:31
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/scanners In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21785/scanners Modified Files: package.html Log Message: Fix some files misplaced in last refactoring submission. Index: package.html =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/scanners/package.html,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** package.html 2 Jan 2004 19:32:04 -0000 1.21 --- package.html 24 May 2004 16:31:22 -0000 1.22 *************** *** 34,38 **** org.htmlparser.lexer.Lexer lexer} package convert byte streams to characters and characters to nodes (via the {@link ! org.htmlparser.lexer.nodes.NodeFactory NodeFactory}). In the case of tags, the scanners in this package can then complete the tag or override the current tag and return an augmented tag. The existing implementation of the {@link --- 34,38 ---- org.htmlparser.lexer.Lexer lexer} package convert byte streams to characters and characters to nodes (via the {@link ! org.htmlparser.NodeFactory NodeFactory}). In the case of tags, the scanners in this package can then complete the tag or override the current tag and return an augmented tag. The existing implementation of the {@link |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:17
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/utilTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/tests/utilTests Modified Files: CharacterTranslationTest.java HTMLParserUtilsTest.java NodeListTest.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: CharacterTranslationTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/utilTests/CharacterTranslationTest.java,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** CharacterTranslationTest.java 9 Feb 2004 02:09:44 -0000 1.42 --- CharacterTranslationTest.java 24 May 2004 16:18:34 -0000 1.43 *************** *** 45,50 **** import org.htmlparser.Node; import org.htmlparser.Parser; ! import org.htmlparser.RemarkNode; ! import org.htmlparser.StringNode; import org.htmlparser.tags.LinkTag; import org.htmlparser.tags.Tag; --- 45,50 ---- import org.htmlparser.Node; import org.htmlparser.Parser; ! import org.htmlparser.Remark; ! import org.htmlparser.Text; import org.htmlparser.tags.LinkTag; import org.htmlparser.tags.Tag; *************** *** 251,259 **** NodeList children; ! if (node instanceof StringNode) { // Node is a plain string ! // Cast it to an HTMLStringNode ! StringNode stringNode = (StringNode)node; // Retrieve the data from the object buffer.append (stringNode.getText ()); --- 251,259 ---- NodeList children; ! if (node instanceof Text) { // Node is a plain string ! // Cast it to an HTMLText ! Text stringNode = (Text)node; // Retrieve the data from the object buffer.append (stringNode.getText ()); *************** *** 280,284 **** } } ! else if (node instanceof RemarkNode) { } --- 280,284 ---- } } ! else if (node instanceof Remark) { } Index: HTMLParserUtilsTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/utilTests/HTMLParserUtilsTest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** HTMLParserUtilsTest.java 12 May 2004 14:14:32 -0000 1.16 --- HTMLParserUtilsTest.java 24 May 2004 16:18:34 -0000 1.17 *************** *** 220,228 **** catch (Exception e) { ! assertStringEquals( ! "modified text", ! "error msg", ! e.getMessage() ! ); } } --- 220,227 ---- catch (Exception e) { ! String msg = e.getMessage (); ! if (null == msg) ! msg = e.getClass ().getName (); ! fail (msg); } } *************** *** 279,287 **** catch (Exception e) { ! assertStringEquals( ! "modified text", ! "error msg", ! e.getMessage() ! ); } } --- 278,285 ---- catch (Exception e) { ! String msg = e.getMessage (); ! if (null == msg) ! msg = e.getClass ().getName (); ! fail (msg); } } *************** *** 338,346 **** catch (Exception e) { ! assertStringEquals( ! "modified text", ! "error msg", ! e.getMessage() ! ); } } --- 336,343 ---- catch (Exception e) { ! String msg = e.getMessage (); ! if (null == msg) ! msg = e.getClass ().getName (); ! fail (msg); } } *************** *** 392,400 **** catch (Exception e) { ! assertStringEquals( ! "modified text", ! "error msg", ! e.getMessage() ! ); } } --- 389,396 ---- catch (Exception e) { ! String msg = e.getMessage (); ! if (null == msg) ! msg = e.getClass ().getName (); ! fail (msg); } } Index: NodeListTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/utilTests/NodeListTest.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** NodeListTest.java 24 May 2004 00:38:19 -0000 1.26 --- NodeListTest.java 24 May 2004 16:18:34 -0000 1.27 *************** *** 27,32 **** package org.htmlparser.tests.utilTests; - import org.htmlparser.AbstractNode; import org.htmlparser.Node; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.NodeList; --- 27,32 ---- package org.htmlparser.tests.utilTests; import org.htmlparser.Node; + import org.htmlparser.nodes.AbstractNode; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.NodeList; *************** *** 110,114 **** public void testElements() throws Exception { createTestDataAndPutInVector(11); ! Node [] resultNodes = new AbstractNode[11]; int i = 0; for (SimpleNodeIterator e = nodeList.elements();e.hasMoreNodes();) { --- 110,114 ---- public void testElements() throws Exception { createTestDataAndPutInVector(11); ! Node [] resultNodes = new Node[11]; int i = 0; for (SimpleNodeIterator e = nodeList.elements();e.hasMoreNodes();) { *************** *** 141,145 **** private void createTestDataAndPutInVector(int nodeCount) { ! testNodes = new AbstractNode[nodeCount]; for (int i=0;i<nodeCount;i++) { testNodes[i]= createHTMLNodeObject(); --- 141,145 ---- private void createTestDataAndPutInVector(int nodeCount) { ! testNodes = new Node[nodeCount]; for (int i=0;i<nodeCount;i++) { testNodes[i]= createHTMLNodeObject(); |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:17
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/tests/tagTests Modified Files: BulletListTagTest.java CompositeTagTest.java FormTagTest.java ImageTagTest.java LinkTagTest.java OptionTagTest.java StyleTagTest.java TagTest.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: StyleTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/StyleTagTest.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** StyleTagTest.java 29 Feb 2004 14:16:27 -0000 1.36 --- StyleTagTest.java 24 May 2004 16:18:33 -0000 1.37 *************** *** 28,32 **** import org.htmlparser.Parser; ! import org.htmlparser.StringNode; import org.htmlparser.tags.HeadTag; import org.htmlparser.tags.Html; --- 28,32 ---- import org.htmlparser.Parser; ! import org.htmlparser.Text; import org.htmlparser.tags.HeadTag; import org.htmlparser.tags.Html; *************** *** 150,154 **** "</style>"; StyleTag tag; ! StringNode string; createParser (html); --- 150,154 ---- "</style>"; StyleTag tag; ! Text string; createParser (html); *************** *** 157,162 **** tag = (StyleTag)node[0]; assertTrue ("STYLE tag should have one child", 1 == tag.getChildCount ()); ! assertTrue ("Child should be a StringNode", tag.getChild (0) instanceof StringNode); ! string = (StringNode)tag.getChild (0); assertStringEquals ("Style text incorrect", style, string.toHtml ()); } --- 157,162 ---- tag = (StyleTag)node[0]; assertTrue ("STYLE tag should have one child", 1 == tag.getChildCount ()); ! assertTrue ("Child should be a StringNode", tag.getChild (0) instanceof Text); ! string = (Text)tag.getChild (0); assertStringEquals ("Style text incorrect", style, string.toHtml ()); } Index: FormTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/FormTagTest.java,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** FormTagTest.java 2 Jan 2004 16:24:57 -0000 1.43 --- FormTagTest.java 24 May 2004 16:18:33 -0000 1.44 *************** *** 27,36 **** package org.htmlparser.tests.tagTests; - import org.htmlparser.AbstractNode; import org.htmlparser.Node; import org.htmlparser.Parser; - import org.htmlparser.StringNode; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.RemarkNode; import org.htmlparser.filters.NodeClassFilter; import org.htmlparser.tags.BodyTag; --- 27,35 ---- package org.htmlparser.tests.tagTests; import org.htmlparser.Node; import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.Remark; ! import org.htmlparser.Text; import org.htmlparser.filters.NodeClassFilter; import org.htmlparser.tags.BodyTag; *************** *** 223,227 **** assertTrue("Should be a HTMLFormTag",node[0] instanceof FormTag); NodeList remarkNodes = new NodeList (); ! NodeClassFilter filter = new NodeClassFilter (RemarkNode.class); for (NodeIterator e = ((FormTag)node[0]).children (); e.hasMoreNodes ();) e.nextNode ().collectInto (remarkNodes, filter); --- 222,226 ---- assertTrue("Should be a HTMLFormTag",node[0] instanceof FormTag); NodeList remarkNodes = new NodeList (); ! NodeClassFilter filter = new NodeClassFilter (Remark.class); for (NodeIterator e = ((FormTag)node[0]).children (); e.hasMoreNodes ();) e.nextNode ().collectInto (remarkNodes, filter); *************** *** 242,251 **** assertTrue("Should be a HTMLFormTag",node[0] instanceof FormTag); FormTag formTag = (FormTag)node[0]; ! RemarkNode [] remarkNode = new RemarkNode[10]; int i = 0; for (NodeIterator e=formTag.children();e.hasMoreNodes();) { Node formNode = (Node)e.nextNode(); ! if (formNode instanceof RemarkNode) { ! remarkNode[i++] = (RemarkNode)formNode; } } --- 241,250 ---- assertTrue("Should be a HTMLFormTag",node[0] instanceof FormTag); FormTag formTag = (FormTag)node[0]; ! Remark [] remarkNode = new Remark[10]; int i = 0; for (NodeIterator e=formTag.children();e.hasMoreNodes();) { Node formNode = (Node)e.nextNode(); ! if (formNode instanceof Remark) { ! remarkNode[i++] = (Remark)formNode; } } *************** *** 324,328 **** parser.setNodeFactory (factory); i = 0; ! nodes = new AbstractNode[50]; for (NodeIterator e = parser.elements(); e.hasMoreNodes();) nodes[i++] = e.nextNode(); --- 323,327 ---- parser.setNodeFactory (factory); i = 0; ! nodes = new Node[50]; for (NodeIterator e = parser.elements(); e.hasMoreNodes();) nodes[i++] = e.nextNode(); *************** *** 377,382 **** assertEquals("Number of nodes found",1,nodes.length); ! assertType("search result node",StringNode.class,nodes[0]); ! StringNode stringNode = (StringNode)nodes[0]; assertEquals("Expected contents of string node","User Name",stringNode.getText()); } --- 376,381 ---- assertEquals("Number of nodes found",1,nodes.length); ! assertType("search result node",Text.class,nodes[0]); ! Text stringNode = (Text)nodes[0]; assertEquals("Expected contents of string node","User Name",stringNode.getText()); } Index: LinkTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/LinkTagTest.java,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** LinkTagTest.java 14 Jan 2004 02:53:47 -0000 1.46 --- LinkTagTest.java 24 May 2004 16:18:33 -0000 1.47 *************** *** 27,36 **** package org.htmlparser.tests.tagTests; - import org.htmlparser.AbstractNode; import org.htmlparser.Node; - import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.StringNode; import org.htmlparser.tags.HeadTag; import org.htmlparser.tags.Html; --- 27,34 ---- package org.htmlparser.tests.tagTests; import org.htmlparser.Node; import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.Text; import org.htmlparser.tags.HeadTag; import org.htmlparser.tags.Html; *************** *** 391,398 **** // The first node should be a Tag assertTrue("First node should be a Tag",node[0] instanceof Tag); ! // The second node should be a HTMLStringNode ! assertTrue("Second node should be a StringNode",node[1] instanceof StringNode); ! StringNode stringNode = (StringNode)node[1]; ! assertEquals("Text of the StringNode","Site Comments?",stringNode.getText()); assertTrue("Third node should be a tag",node[2] instanceof Tag); assertTrue("Fourth node should be a link",node[3] instanceof LinkTag); --- 389,396 ---- // The first node should be a Tag assertTrue("First node should be a Tag",node[0] instanceof Tag); ! // The second node should be a Text ! assertTrue("Second node should be a Text",node[1] instanceof Text); ! Text stringNode = (Text)node[1]; ! assertEquals("Text of the Text","Site Comments?",stringNode.getText()); assertTrue("Third node should be a tag",node[2] instanceof Tag); assertTrue("Fourth node should be a link",node[3] instanceof LinkTag); *************** *** 510,515 **** assertStringEquals("Link URL of link tag",exp,linkTag.getLink()); assertEquals("Link Text of link tag"," Journalism 3.0",linkTag.getLinkText()); ! assertTrue("Eight node should be a string node",node[7] instanceof StringNode); ! StringNode stringNode = (StringNode)node[7]; assertEquals("String node contents"," by Rajesh Jain",stringNode.getText()); } --- 508,513 ---- assertStringEquals("Link URL of link tag",exp,linkTag.getLink()); assertEquals("Link Text of link tag"," Journalism 3.0",linkTag.getLinkText()); ! assertTrue("Eight node should be a string node",node[7] instanceof Text); ! Text stringNode = (Text)node[7]; assertEquals("String node contents"," by Rajesh Jain",stringNode.getText()); } *************** *** 556,560 **** LinkTag linkTag = (LinkTag)node[0]; // Get the link data and cross-check ! Node [] dataNode= new AbstractNode[10]; int i = 0; for (SimpleNodeIterator e = linkTag.children();e.hasMoreNodes();) --- 554,558 ---- LinkTag linkTag = (LinkTag)node[0]; // Get the link data and cross-check ! Node [] dataNode= new Node[10]; int i = 0; for (SimpleNodeIterator e = linkTag.children();e.hasMoreNodes();) *************** *** 564,573 **** assertEquals("Number of data nodes",new Integer(2),new Integer(i)); assertTrue("First data node should be an Image Node",dataNode[0] instanceof ImageTag); ! assertTrue("Second data node shouls be a String Node",dataNode[1] instanceof StringNode); // Check the contents of each data node ImageTag imageTag = (ImageTag)dataNode[0]; assertEquals("Image URL","http://www.yahoo.com/abcd.jpg",imageTag.getImageURL()); ! StringNode stringNode = (StringNode)dataNode[1]; assertEquals("String Contents","Hello World",stringNode.getText()); } --- 562,571 ---- assertEquals("Number of data nodes",new Integer(2),new Integer(i)); assertTrue("First data node should be an Image Node",dataNode[0] instanceof ImageTag); ! assertTrue("Second data node shouls be a String Node",dataNode[1] instanceof Text); // Check the contents of each data node ImageTag imageTag = (ImageTag)dataNode[0]; assertEquals("Image URL","http://www.yahoo.com/abcd.jpg",imageTag.getImageURL()); ! Text stringNode = (Text)dataNode[1]; assertEquals("String Contents","Hello World",stringNode.getText()); } *************** *** 588,594 **** assertEquals("Tag Contents",html,tag.toHtml()); assertEquals("Node 0 should have one child", 1, tag.getChildren ().size ()); ! assertTrue("The child should be a string node", tag.getChildren ().elementAt (0) instanceof StringNode); ! StringNode stringNode = (StringNode)tag.getChildren ().elementAt (0); ! assertEquals("StringNode Contents","Revision",stringNode.getText()); } --- 586,592 ---- assertEquals("Tag Contents",html,tag.toHtml()); assertEquals("Node 0 should have one child", 1, tag.getChildren ().size ()); ! assertTrue("The child should be a string node", tag.getChildren ().elementAt (0) instanceof Text); ! Text stringNode = (Text)tag.getChildren ().elementAt (0); ! assertEquals("Text Contents","Revision",stringNode.getText()); } *************** *** 628,632 **** assertEquals("Link URL","http://transfer.go.com/cgi/atransfer.pl?goto=http://www.signs.movies.com&name=114332&srvc=nws&context=283&guid=4AD5723D-C802-4310-A388-0B24E1A79689",linkTag.getLink()); assertEquals("Link Text","",linkTag.getLinkText()); ! Node [] containedNodes = new AbstractNode[10]; int i=0; for (SimpleNodeIterator e = linkTag.children();e.hasMoreNodes();) { --- 626,630 ---- assertEquals("Link URL","http://transfer.go.com/cgi/atransfer.pl?goto=http://www.signs.movies.com&name=114332&srvc=nws&context=283&guid=4AD5723D-C802-4310-A388-0B24E1A79689",linkTag.getLink()); assertEquals("Link Text","",linkTag.getLinkText()); ! Node [] containedNodes = new Node[10]; int i=0; for (SimpleNodeIterator e = linkTag.children();e.hasMoreNodes();) { *************** *** 776,780 **** // Get the image tag from the link ! Node insideNodes [] = new AbstractNode[10]; int j =0 ; for (SimpleNodeIterator e = linkTag.children();e.hasMoreNodes();) { --- 774,778 ---- // Get the image tag from the link ! Node insideNodes [] = new Node[10]; int j =0 ; for (SimpleNodeIterator e = linkTag.children();e.hasMoreNodes();) { Index: OptionTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/OptionTagTest.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** OptionTagTest.java 2 Jan 2004 16:24:57 -0000 1.41 --- OptionTagTest.java 24 May 2004 16:18:33 -0000 1.42 *************** *** 27,31 **** package org.htmlparser.tests.tagTests; ! import org.htmlparser.StringNode; import org.htmlparser.tags.OptionTag; import org.htmlparser.tests.ParserTestCase; --- 27,31 ---- package org.htmlparser.tests.tagTests; ! import org.htmlparser.Text; import org.htmlparser.tags.OptionTag; import org.htmlparser.tests.ParserTestCase; *************** *** 156,160 **** for (int j = 0; j < 10; j++) { ! if (node[j] instanceof StringNode) continue; assertTrue("Node " + j + " should be Option Tag",node[j] instanceof OptionTag); --- 156,160 ---- for (int j = 0; j < 10; j++) { ! if (node[j] instanceof Text) continue; assertTrue("Node " + j + " should be Option Tag",node[j] instanceof OptionTag); Index: ImageTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/ImageTagTest.java,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** ImageTagTest.java 14 Jan 2004 02:53:47 -0000 1.42 --- ImageTagTest.java 24 May 2004 16:18:33 -0000 1.43 *************** *** 27,31 **** package org.htmlparser.tests.tagTests; - import org.htmlparser.AbstractNode; import org.htmlparser.Node; import org.htmlparser.Parser; --- 27,30 ---- *************** *** 288,292 **** createParser("<small><a href=s/5926>Air</a>, <a href=s/5927>Hotel</a>, <a href=s/5928>Vacations</a>, <a href=s/5929>Cruises</a></small></td><td align=center><a href=\"http://rd.yahoo.com/M=218794.2020165.3500581.220161/D=yahoo_top/S=2716149:NP/A=1041273/?http://adfarm.mediaplex.com/ad/ck/990-1736-1039-211\" target=\"_top\"><img width=230 height=33 src=\"http://us.a1.yimg.com/us.yimg.com/a/co/columbiahouse/4for49Freesh_230x33_redx2.gif\" alt=\"\" border=0></a></td><td nowrap align=center width=215>Find your match on<br><a href=s/2734><b>Yahoo! Personals</b></a></td></tr><tr><td colspan=3 align=center><input size=30 name=p>\n"+ "<input type=submit value=Search> <a href=r/so>advanced search</a></td></tr></table><table border=0 cellspacing=0 cellpadding=3 width=640><tr><td nowrap align=center><table border=0 cellspacing=0 cellpadding=0><tr><td><a href=s/5948><img src=\"http://us.i1.yimg.com/us.yimg.com/i/ligans/klgs/eet.gif\" width=20 height=20 border=0></a></td><td> <a href=s/1048><b>Yahooligans!</b></a> - <a href=s/5282>Eet & Ern</a>, <a href=s/5283>Games</a>, <a href=s/5284>Science</a>, <a href=s/5285>Sports</a>, <a href=s/5286>Movies</a>, <a href=s/1048>more</a> </td><td><a href=s/5948><img src=\"http://us.i1.yimg.com/us.yimg.com/i/ligans/klgs/ern.gif\" width=20 height=20 border=0></a></td></tr></table></td></tr><tr><td nowrap align=center><small><b>Shop</b> \n","http://www.yahoo.com"); ! Node [] node = new AbstractNode[10]; parser.setNodeFactory (new PrototypicalNodeFactory (new ImageTag ())); int i = 0; --- 287,291 ---- createParser("<small><a href=s/5926>Air</a>, <a href=s/5927>Hotel</a>, <a href=s/5928>Vacations</a>, <a href=s/5929>Cruises</a></small></td><td align=center><a href=\"http://rd.yahoo.com/M=218794.2020165.3500581.220161/D=yahoo_top/S=2716149:NP/A=1041273/?http://adfarm.mediaplex.com/ad/ck/990-1736-1039-211\" target=\"_top\"><img width=230 height=33 src=\"http://us.a1.yimg.com/us.yimg.com/a/co/columbiahouse/4for49Freesh_230x33_redx2.gif\" alt=\"\" border=0></a></td><td nowrap align=center width=215>Find your match on<br><a href=s/2734><b>Yahoo! Personals</b></a></td></tr><tr><td colspan=3 align=center><input size=30 name=p>\n"+ "<input type=submit value=Search> <a href=r/so>advanced search</a></td></tr></table><table border=0 cellspacing=0 cellpadding=3 width=640><tr><td nowrap align=center><table border=0 cellspacing=0 cellpadding=0><tr><td><a href=s/5948><img src=\"http://us.i1.yimg.com/us.yimg.com/i/ligans/klgs/eet.gif\" width=20 height=20 border=0></a></td><td> <a href=s/1048><b>Yahooligans!</b></a> - <a href=s/5282>Eet & Ern</a>, <a href=s/5283>Games</a>, <a href=s/5284>Science</a>, <a href=s/5285>Sports</a>, <a href=s/5286>Movies</a>, <a href=s/1048>more</a> </td><td><a href=s/5948><img src=\"http://us.i1.yimg.com/us.yimg.com/i/ligans/klgs/ern.gif\" width=20 height=20 border=0></a></td></tr></table></td></tr><tr><td nowrap align=center><small><b>Shop</b> \n","http://www.yahoo.com"); ! Node [] node = new Node[10]; parser.setNodeFactory (new PrototypicalNodeFactory (new ImageTag ())); int i = 0; Index: BulletListTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/BulletListTagTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BulletListTagTest.java 24 Jan 2004 23:58:06 -0000 1.2 --- BulletListTagTest.java 24 May 2004 16:18:33 -0000 1.3 *************** *** 29,33 **** import org.htmlparser.Node; import org.htmlparser.tests.ParserTestCase; ! import org.htmlparser.StringNode; import org.htmlparser.tags.Bullet; import org.htmlparser.tags.BulletList; --- 29,33 ---- import org.htmlparser.Node; import org.htmlparser.tests.ParserTestCase; ! import org.htmlparser.Text; import org.htmlparser.tags.Bullet; import org.htmlparser.tags.BulletList; *************** *** 80,84 **** assertType( "first child in bullet", ! StringNode.class, firstNodeInFirstBullet ); --- 80,84 ---- assertType( "first child in bullet", ! Text.class, firstNodeInFirstBullet ); Index: CompositeTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/CompositeTagTest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** CompositeTagTest.java 2 Jan 2004 16:24:57 -0000 1.16 --- CompositeTagTest.java 24 May 2004 16:18:33 -0000 1.17 *************** *** 28,32 **** import org.htmlparser.Node; ! import org.htmlparser.StringNode; import org.htmlparser.tags.CompositeTag; import org.htmlparser.tags.TableColumn; --- 28,32 ---- import org.htmlparser.Node; ! import org.htmlparser.Text; import org.htmlparser.tags.CompositeTag; import org.htmlparser.tags.TableColumn; *************** *** 62,66 **** parseAndAssertNodeCount(1); TableTag tableTag = (TableTag)node[0]; ! StringNode [] stringNode = tableTag.digupStringNode("Hello World"); --- 62,66 ---- parseAndAssertNodeCount(1); TableTag tableTag = (TableTag)node[0]; ! Text[] stringNode = tableTag.digupStringNode("Hello World"); *************** *** 93,97 **** parseAndAssertNodeCount(1); TableTag tableTag = (TableTag)node[0]; ! StringNode [] stringNode = tableTag.digupStringNode("Hello World"); --- 93,97 ---- parseAndAssertNodeCount(1); TableTag tableTag = (TableTag)node[0]; ! Text [] stringNode = tableTag.digupStringNode("Hello World"); Index: TagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/TagTest.java,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** TagTest.java 9 Feb 2004 02:09:44 -0000 1.57 --- TagTest.java 24 May 2004 16:18:33 -0000 1.58 *************** *** 32,36 **** import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.StringNode; import org.htmlparser.tags.BodyTag; import org.htmlparser.tags.Div; --- 32,36 ---- import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.Text; import org.htmlparser.tags.BodyTag; import org.htmlparser.tags.Div; *************** *** 154,158 **** Tag tag; Tag etag; ! StringNode snode; Node node=null; String lin1 = "<A href=\"http://www.iki.fi/kaila\" myParameter yourParameter=\"Kaarle Kaaila\">Kaarle's homepage</A><p>Paragraph</p>"; --- 154,158 ---- Tag tag; Tag etag; ! Text snode; Node node=null; String lin1 = "<A href=\"http://www.iki.fi/kaila\" myParameter yourParameter=\"Kaarle Kaaila\">Kaarle's homepage</A><p>Paragraph</p>"; *************** *** 182,186 **** if ( en.hasMoreNodes()) { node = en.nextNode(); ! snode = (StringNode)node; assertEquals("Value of element","Kaarle's homepage",snode.getText()); } --- 182,186 ---- if ( en.hasMoreNodes()) { node = en.nextNode(); ! snode = (Text)node; assertEquals("Value of element","Kaarle's homepage",snode.getText()); } *************** *** 201,205 **** if (en.hasMoreNodes()) { node = en.nextNode(); ! snode = (StringNode)node; assertEquals("paragraph contents","Paragraph",snode.getText()); } --- 201,205 ---- if (en.hasMoreNodes()) { node = en.nextNode(); ! snode = (Text)node; assertEquals("paragraph contents","Paragraph",snode.getText()); } *************** *** 224,228 **** Tag tag; Tag etag; ! StringNode snode; Node node=null; String lin1 = "<G href=\"http://www.iki.fi/kaila\" myParameter yourParameter=\"Kaila\">Kaarle's homepage</G><p>Paragraph</p>"; --- 224,228 ---- Tag tag; Tag etag; ! Text snode; Node node=null; String lin1 = "<G href=\"http://www.iki.fi/kaila\" myParameter yourParameter=\"Kaila\">Kaarle's homepage</G><p>Paragraph</p>"; *************** *** 250,254 **** if (en.hasMoreNodes()) { node = en.nextNode(); ! snode = (StringNode)node; assertEquals("The text of the element",snode.getText(),"Kaarle's homepage"); } --- 250,254 ---- if (en.hasMoreNodes()) { node = en.nextNode(); ! snode = (Text)node; assertEquals("The text of the element",snode.getText(),"Kaarle's homepage"); } *************** *** 268,272 **** if (en.hasMoreNodes()) { node = en.nextNode(); ! snode = (StringNode)node; assertEquals("Verify the paragraph text","Paragraph", snode.getText()); } --- 268,272 ---- if (en.hasMoreNodes()) { node = en.nextNode(); ! snode = (Text)node; assertEquals("Verify the paragraph text","Paragraph", snode.getText()); } *************** *** 292,296 **** Tag tag; Tag etag; ! StringNode snode; Node node=null; String lin1 = "<A yourParameter = \"Kaarle\">Kaarle's homepage</A>"; --- 292,296 ---- Tag tag; Tag etag; ! Text snode; Node node=null; String lin1 = "<A yourParameter = \"Kaarle\">Kaarle's homepage</A>"; *************** *** 316,320 **** if ( en.hasMoreNodes()) { node = en.nextNode(); ! snode = (StringNode)node; assertEquals("Value of element","Kaarle's homepage",snode.getText()); } --- 316,320 ---- if ( en.hasMoreNodes()) { node = en.nextNode(); ! snode = (Text)node; assertEquals("Value of element","Kaarle's homepage",snode.getText()); } *************** *** 516,521 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(5); ! assertTrue("Third node should be a string node",node[2] instanceof StringNode); ! StringNode stringNode = (StringNode)node[2]; assertEquals("Third node has incorrect text","<>text",stringNode.getText()); } --- 516,521 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(5); ! assertTrue("Third node should be a string node",node[2] instanceof Text); ! Text stringNode = (Text)node[2]; assertEquals("Third node has incorrect text","<>text",stringNode.getText()); } *************** *** 529,534 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(5); ! assertTrue("Third node should be a string node",node[2] instanceof StringNode); ! StringNode stringNode = (StringNode)node[2]; assertEquals("Third node has incorrect text","text<>",stringNode.getText()); } --- 529,534 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(5); ! assertTrue("Third node should be a string node",node[2] instanceof Text); ! Text stringNode = (Text)node[2]; assertEquals("Third node has incorrect text","text<>",stringNode.getText()); } *************** *** 547,552 **** BodyTag body = (BodyTag)html.getChild(0); assertTrue("BODY node should have one child",1 == body.getChildCount ()); ! assertTrue("Only node should be a string node",body.getChild(0) instanceof StringNode); ! StringNode stringNode = (StringNode)body.getChild(0); assertEquals("Third node has incorrect text","text<>text",stringNode.getText()); } --- 547,552 ---- BodyTag body = (BodyTag)html.getChild(0); assertTrue("BODY node should have one child",1 == body.getChildCount ()); ! assertTrue("Only node should be a string node",body.getChild(0) instanceof Text); ! Text stringNode = (Text)body.getChild(0); assertEquals("Third node has incorrect text","text<>text",stringNode.getText()); } *************** *** 566,571 **** BodyTag body = (BodyTag)html.getChild(0); assertTrue("BODY node should have one child",1 == body.getChildCount ()); ! assertTrue("Only node should be a string node",body.getChild(0) instanceof StringNode); ! StringNode stringNode = (StringNode)body.getChild(0); String actual = stringNode.getText(); assertEquals("Third node has incorrect text","text\n<>text",actual); --- 566,571 ---- BodyTag body = (BodyTag)html.getChild(0); assertTrue("BODY node should have one child",1 == body.getChildCount ()); ! assertTrue("Only node should be a string node",body.getChild(0) instanceof Text); ! Text stringNode = (Text)body.getChild(0); String actual = stringNode.getText(); assertEquals("Third node has incorrect text","text\n<>text",actual); *************** *** 586,591 **** BodyTag body = (BodyTag)html.getChild(0); assertTrue("BODY node should have one child",1 == body.getChildCount ()); ! assertTrue("Only node should be a string node",body.getChild(0) instanceof StringNode); ! StringNode stringNode = (StringNode)body.getChild(0); String actual = stringNode.getText(); assertEquals("Third node has incorrect text","text<\n>text",actual); --- 586,591 ---- BodyTag body = (BodyTag)html.getChild(0); assertTrue("BODY node should have one child",1 == body.getChildCount ()); ! assertTrue("Only node should be a string node",body.getChild(0) instanceof Text); ! Text stringNode = (Text)body.getChild(0); String actual = stringNode.getText(); assertEquals("Third node has incorrect text","text<\n>text",actual); *************** *** 606,611 **** BodyTag body = (BodyTag)html.getChild(0); assertTrue("BODY node should have one child",1 == body.getChildCount ()); ! assertTrue("Only node should be a string node",body.getChild(0) instanceof StringNode); ! StringNode stringNode = (StringNode)body.getChild(0); String actual = stringNode.getText(); assertEquals("Third node has incorrect text","text<>\ntext",actual); --- 606,611 ---- BodyTag body = (BodyTag)html.getChild(0); assertTrue("BODY node should have one child",1 == body.getChildCount ()); ! assertTrue("Only node should be a string node",body.getChild(0) instanceof Text); ! Text stringNode = (Text)body.getChild(0); String actual = stringNode.getText(); assertEquals("Third node has incorrect text","text<>\ntext",actual); *************** *** 648,652 **** assertStringEquals("Expected HTML","John Doe",htmlTag.getLabel()); ! ((org.htmlparser.StringNode)((org.htmlparser.tags.CompositeTag)htmlTag).getChild(0)).setText("Jane Doe"); expectedHTML = "<LABEL ID=\"JohnDoe\">Jane Doe</LABEL>"; assertStringEquals("Expected HTML",expectedHTML,htmlTag.toHtml()); --- 648,652 ---- assertStringEquals("Expected HTML","John Doe",htmlTag.getLabel()); ! ((org.htmlparser.Text)((org.htmlparser.tags.CompositeTag)htmlTag).getChild(0)).setText("Jane Doe"); expectedHTML = "<LABEL ID=\"JohnDoe\">Jane Doe</LABEL>"; assertStringEquals("Expected HTML",expectedHTML,htmlTag.toHtml()); |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:17
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/util Modified Files: ParserUtils.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: ParserUtils.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/ParserUtils.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** ParserUtils.java 12 May 2004 14:16:08 -0000 1.40 --- ParserUtils.java 24 May 2004 16:18:35 -0000 1.41 *************** *** 39,44 **** import org.htmlparser.lexer.Page; import org.htmlparser.lexer.Source; - import org.htmlparser.lexer.nodes.TagNode; import org.htmlparser.tags.CompositeTag; import org.htmlparser.util.NodeList; import org.htmlparser.util.ParserException; --- 39,44 ---- import org.htmlparser.lexer.Page; import org.htmlparser.lexer.Source; import org.htmlparser.tags.CompositeTag; + import org.htmlparser.tags.Tag; import org.htmlparser.util.NodeList; import org.htmlparser.util.ParserException; *************** *** 719,723 **** { CompositeTag beginTag = (CompositeTag)links.elementAt(j); ! TagNode endTag = beginTag.getEndTag(); // positions of begin and end tags --- 719,723 ---- { CompositeTag beginTag = (CompositeTag)links.elementAt(j); ! Tag endTag = (Tag)beginTag.getEndTag(); // positions of begin and end tags *************** *** 844,848 **** { CompositeTag beginTag = (CompositeTag)links.elementAt(j); ! TagNode endTag = beginTag.getEndTag(); // positions of begin and end tags --- 844,848 ---- { CompositeTag beginTag = (CompositeTag)links.elementAt(j); ! Tag endTag = (Tag)beginTag.getEndTag(); // positions of begin and end tags *************** *** 948,952 **** { CompositeTag beginTag = (CompositeTag)links.elementAt(j); ! TagNode endTag = beginTag.getEndTag(); // positions of begin and end tags --- 948,952 ---- { CompositeTag beginTag = (CompositeTag)links.elementAt(j); ! Tag endTag = (Tag)beginTag.getEndTag(); // positions of begin and end tags *************** *** 1047,1051 **** { CompositeTag beginTag = (CompositeTag)links.elementAt(j); ! TagNode endTag = beginTag.getEndTag(); // positions of begin and end tags --- 1047,1051 ---- { CompositeTag beginTag = (CompositeTag)links.elementAt(j); ! Tag endTag = (Tag)beginTag.getEndTag(); // positions of begin and end tags *************** *** 1124,1128 **** { CompositeTag jStartTag = (CompositeTag)links.elementAt(j); ! TagNode jEndTag = jStartTag.getEndTag(); int jStartTagBegin = jStartTag.getTagBegin(); int jEndTagEnd = jEndTag.getTagEnd(); --- 1124,1128 ---- { CompositeTag jStartTag = (CompositeTag)links.elementAt(j); ! Tag jEndTag = (Tag)jStartTag.getEndTag(); int jStartTagBegin = jStartTag.getTagBegin(); int jEndTagEnd = jEndTag.getTagEnd(); *************** *** 1130,1134 **** { CompositeTag kStartTag = (CompositeTag)links.elementAt(k); ! TagNode kEndTag = kStartTag.getEndTag(); int kStartTagBegin = kStartTag.getTagBegin(); int kEndTagEnd = kEndTag.getTagEnd(); --- 1130,1134 ---- { CompositeTag kStartTag = (CompositeTag)links.elementAt(k); ! Tag kEndTag = (Tag)kStartTag.getEndTag(); int kStartTagBegin = kStartTag.getTagBegin(); int kEndTagEnd = kEndTag.getTagEnd(); *************** *** 1164,1168 **** { CompositeTag jStartTag = (CompositeTag)links.elementAt(j); ! TagNode jEndTag = jStartTag.getEndTag(); int jStartTagBegin = jStartTag.getTagBegin(); int jEndTagEnd = jEndTag.getTagEnd(); --- 1164,1168 ---- { CompositeTag jStartTag = (CompositeTag)links.elementAt(j); ! Tag jEndTag = (Tag)jStartTag.getEndTag(); int jStartTagBegin = jStartTag.getTagBegin(); int jEndTagEnd = jEndTag.getTagEnd(); *************** *** 1170,1174 **** { CompositeTag kStartTag = (CompositeTag)links.elementAt(k); ! TagNode kEndTag = kStartTag.getEndTag(); int kStartTagBegin = kStartTag.getTagBegin(); int kEndTagEnd = kEndTag.getTagEnd(); --- 1170,1174 ---- { CompositeTag kStartTag = (CompositeTag)links.elementAt(k); ! Tag kEndTag = (Tag)kStartTag.getEndTag(); int kStartTagBegin = kStartTag.getTagBegin(); int kEndTagEnd = kEndTag.getTagEnd(); |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:17
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/tests/scannersTests Modified Files: CompositeTagScannerTest.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: CompositeTagScannerTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests/CompositeTagScannerTest.java,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** CompositeTagScannerTest.java 14 Jan 2004 02:53:47 -0000 1.59 --- CompositeTagScannerTest.java 24 May 2004 16:18:33 -0000 1.60 *************** *** 27,34 **** package org.htmlparser.tests.scannersTests; - import org.htmlparser.AbstractNode; import org.htmlparser.Node; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.StringNode; import org.htmlparser.scanners.CompositeTagScanner; import org.htmlparser.tags.CompositeTag; --- 27,34 ---- package org.htmlparser.tests.scannersTests; import org.htmlparser.Node; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.Text; ! import org.htmlparser.nodes.AbstractNode; import org.htmlparser.scanners.CompositeTagScanner; import org.htmlparser.tags.CompositeTag; *************** *** 116,120 **** assertEquals("ending line position",0,customTag.getEndingLineNumber()); Node child = customTag.childAt(0); ! assertType("child",StringNode.class,child); assertStringEquals("child text","Hello",child.toPlainTextString()); } --- 116,120 ---- assertEquals("ending line position",0,customTag.getEndingLineNumber()); Node child = customTag.childAt(0); ! assertType("child",Text.class,child); assertStringEquals("child text","Hello",child.toPlainTextString()); } *************** *** 235,240 **** assertEquals("another tag children count",1,anotherTag.getChildCount()); node = anotherTag.childAt(0); ! assertType("nested child",StringNode.class,node); ! StringNode text = (StringNode)node; assertEquals("text","Hello",text.toPlainTextString()); } --- 235,240 ---- assertEquals("another tag children count",1,anotherTag.getChildCount()); node = anotherTag.childAt(0); ! assertType("nested child",Text.class,node); ! Text text = (Text)node; assertEquals("text","Hello",text.toPlainTextString()); } *************** *** 269,274 **** assertEquals("another tag children count",1,anotherTag.getChildCount()); node = anotherTag.childAt(0); ! assertType("nested child",StringNode.class,node); ! StringNode text = (StringNode)node; assertEquals("text","Hello",text.toPlainTextString()); } --- 269,274 ---- assertEquals("another tag children count",1,anotherTag.getChildCount()); node = anotherTag.childAt(0); ! assertType("nested child",Text.class,node); ! Text text = (Text)node; assertEquals("text","Hello",text.toPlainTextString()); } *************** *** 416,420 **** AnotherTag anotherTag = (AnotherTag)customTag.childAt(0); assertEquals("anotherTag child count",1,anotherTag.getChildCount()); ! StringNode stringNode = (StringNode)anotherTag.childAt(0); assertStringEquals("anotherTag child text","something",stringNode.toPlainTextString()); assertStringEquals( --- 416,420 ---- AnotherTag anotherTag = (AnotherTag)customTag.childAt(0); assertEquals("anotherTag child count",1,anotherTag.getChildCount()); ! Text stringNode = (Text)anotherTag.childAt(0); assertStringEquals("anotherTag child text","something",stringNode.toPlainTextString()); assertStringEquals( *************** *** 532,536 **** Node firstChild = customTag.childAt(0); ! assertType("firstChild",StringNode.class,firstChild); Node parent = firstChild.getParent(); assertNotNull("first child parent should not be null",parent); --- 532,536 ---- Node firstChild = customTag.childAt(0); ! assertType("firstChild",Text.class,firstChild); Node parent = firstChild.getParent(); assertNotNull("first child parent should not be null",parent); |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:16
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/parserHelperTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/tests/parserHelperTests Modified Files: RemarkNodeParserTest.java StringParserTest.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: RemarkNodeParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/parserHelperTests/RemarkNodeParserTest.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** RemarkNodeParserTest.java 2 Jan 2004 16:24:56 -0000 1.44 --- RemarkNodeParserTest.java 24 May 2004 16:18:32 -0000 1.45 *************** *** 29,34 **** import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.RemarkNode; ! import org.htmlparser.StringNode; import org.htmlparser.tags.Tag; import org.htmlparser.tests.ParserTestCase; --- 29,34 ---- import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.Remark; ! import org.htmlparser.Text; import org.htmlparser.tags.Tag; import org.htmlparser.tests.ParserTestCase; *************** *** 39,46 **** static { ! System.setProperty ("org.htmlparser.tests.parserHelperTests.RemarkNodeParserTest", "RemarkNodeParserTest"); } ! public RemarkNodeParserTest(String name) { super(name); } --- 39,46 ---- static { ! System.setProperty ("org.htmlparser.tests.parserHelperTests.RemarkParserTest", "RemarkParserTest"); } ! public RemarkNodeParserTest (String name) { super(name); } *************** *** 61,65 **** * This bug was reported by Serge Kruppa (2002-Feb-08). */ ! public void testRemarkNodeBug() throws ParserException { createParser( --- 61,65 ---- * This bug was reported by Serge Kruppa (2002-Feb-08). */ ! public void testRemarkBug() throws ParserException { createParser( *************** *** 76,87 **** Parser.setLineSeparator("\r\n"); parseAndAssertNodeCount(15); ! // The first node should be a HTMLRemarkNode ! assertTrue("First node should be a RemarkNode",node[0] instanceof RemarkNode); ! RemarkNode remarkNode = (RemarkNode)node[0]; ! assertEquals("Text of the remarkNode #1"," saved from url=(0022)http://internet.e-mail ",remarkNode.getText()); ! // The tenth node should be a HTMLRemarkNode ! assertTrue("Tenth node should be a RemarkNode",node[9] instanceof RemarkNode); ! remarkNode = (RemarkNode)node[9]; ! assertEquals("Text of the remarkNode #10","\n Whats gonna happen now ?\n",remarkNode.getText()); } --- 76,87 ---- Parser.setLineSeparator("\r\n"); parseAndAssertNodeCount(15); ! // The first node should be a Remark ! assertTrue("First node should be a Remark",node[0] instanceof Remark); ! Remark Remark = (Remark)node[0]; ! assertEquals("Text of the Remark #1"," saved from url=(0022)http://internet.e-mail ",Remark.getText()); ! // The tenth node should be a Remark ! assertTrue("Tenth node should be a Remark",node[9] instanceof Remark); ! Remark = (Remark)node[9]; ! assertEquals("Text of the Remark #10","\n Whats gonna happen now ?\n",Remark.getText()); } *************** *** 100,111 **** Parser.setLineSeparator("\r\n"); parseAndAssertNodeCount(15); ! // The first node should be a HTMLRemarkNode ! assertTrue("First node should be a RemarkNode",node[0] instanceof RemarkNode); ! RemarkNode remarkNode = (RemarkNode)node[0]; ! assertEquals("Plain Text of the remarkNode #1"," saved from url=(0022)http://internet.e-mail ",remarkNode.toPlainTextString()); ! // The tenth node should be a HTMLRemarkNode ! assertTrue("Tenth node should be a RemarkNode",node[9] instanceof RemarkNode); ! remarkNode = (RemarkNode)node[9]; ! assertEquals("Plain Text of the remarkNode #10","\n Whats gonna happen now ?\n",remarkNode.getText()); } --- 100,111 ---- Parser.setLineSeparator("\r\n"); parseAndAssertNodeCount(15); ! // The first node should be a Remark ! assertTrue("First node should be a Remark",node[0] instanceof Remark); ! Remark Remark = (Remark)node[0]; ! assertEquals("Plain Text of the Remark #1"," saved from url=(0022)http://internet.e-mail ",Remark.toPlainTextString()); ! // The tenth node should be a Remark ! assertTrue("Tenth node should be a Remark",node[9] instanceof Remark); ! Remark = (Remark)node[9]; ! assertEquals("Plain Text of the Remark #10","\n Whats gonna happen now ?\n",Remark.getText()); } *************** *** 125,145 **** Parser.setLineSeparator("\r\n"); parseAndAssertNodeCount(15); ! // The first node should be a HTMLRemarkNode ! assertTrue("First node should be a RemarkNode",node[0] instanceof RemarkNode); ! RemarkNode remarkNode = (RemarkNode)node[0]; ! assertStringEquals("Raw String of the remarkNode #1","<!-- saved from url=(0022)http://internet.e-mail -->",remarkNode.toHtml()); ! // The tenth node should be a HTMLRemarkNode ! assertTrue("Tenth node should be a RemarkNode",node[9] instanceof RemarkNode); ! remarkNode = (RemarkNode)node[9]; ! assertStringEquals("Raw String of the remarkNode #6","<!--\n Whats gonna happen now ?\n-->",remarkNode.toHtml()); } ! public void testNonRemarkNode() throws ParserException { createParser(" <![endif]>"); parseAndAssertNodeCount(2); ! // The first node should be a HTMLRemarkNode ! assertTrue("First node should be a string node",node[0] instanceof StringNode); assertTrue("Second node should be a Tag",node[1] instanceof Tag); ! StringNode stringNode = (StringNode)node[0]; Tag tag = (Tag)node[1]; assertEquals("Text contents"," ",stringNode.getText()); --- 125,145 ---- Parser.setLineSeparator("\r\n"); parseAndAssertNodeCount(15); ! // The first node should be a Remark ! assertTrue("First node should be a Remark",node[0] instanceof Remark); ! Remark Remark = (Remark)node[0]; ! assertStringEquals("Raw String of the Remark #1","<!-- saved from url=(0022)http://internet.e-mail -->",Remark.toHtml()); ! // The tenth node should be a Remark ! assertTrue("Tenth node should be a Remark",node[9] instanceof Remark); ! Remark = (Remark)node[9]; ! assertStringEquals("Raw String of the Remark #6","<!--\n Whats gonna happen now ?\n-->",Remark.toHtml()); } ! public void testNonRemark() throws ParserException { createParser(" <![endif]>"); parseAndAssertNodeCount(2); ! // The first node should be a Remark ! assertTrue("First node should be a string node",node[0] instanceof Text); assertTrue("Second node should be a Tag",node[1] instanceof Tag); ! Text stringNode = (Text)node[0]; Tag tag = (Tag)node[1]; assertEquals("Text contents"," ",stringNode.getText()); *************** *** 154,158 **** * the state */ ! public void testRemarkNodeWithBlankLine() throws ParserException { createParser("<!--\n"+ "\n"+ --- 154,158 ---- * the state */ ! public void testRemarkWithBlankLine() throws ParserException { createParser("<!--\n"+ "\n"+ *************** *** 161,167 **** Parser.setLineSeparator("\r\n"); parseAndAssertNodeCount(1); ! assertTrue("Node should be a HTMLRemarkNode",node[0] instanceof RemarkNode); ! RemarkNode remarkNode = (RemarkNode)node[0]; ! assertEquals("Expected contents","\n\n",remarkNode.getText()); } --- 161,167 ---- Parser.setLineSeparator("\r\n"); parseAndAssertNodeCount(1); ! assertTrue("Node should be a Remark",node[0] instanceof Remark); ! Remark Remark = (Remark)node[0]; ! assertEquals("Expected contents","\n\n",Remark.getText()); } *************** *** 172,182 **** * If it is a comment with nothing in it, parser crashes */ ! public void testRemarkNodeWithNothing() throws ParserException { createParser("<!-->"); parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); ! assertTrue("Node should be a RemarkNode",node[0] instanceof RemarkNode); ! RemarkNode remarkNode = (RemarkNode)node[0]; ! assertEquals("Expected contents","",remarkNode.getText()); } --- 172,182 ---- * If it is a comment with nothing in it, parser crashes */ ! public void testRemarkWithNothing() throws ParserException { createParser("<!-->"); parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); ! assertTrue("Node should be a Remark",node[0] instanceof Remark); ! Remark Remark = (Remark)node[0]; ! assertEquals("Expected contents","",Remark.getText()); } *************** *** 188,192 **** * it doesent get parsed correctly */ ! public void testTagWithinRemarkNode() throws ParserException { createParser("<!-- \n"+ "<A>\n"+ --- 188,192 ---- * it doesent get parsed correctly */ ! public void testTagWithinRemark() throws ParserException { createParser("<!-- \n"+ "<A>\n"+ *************** *** 195,201 **** Parser.setLineSeparator("\n"); parseAndAssertNodeCount(1); ! assertTrue("Node should be a HTMLRemarkNode",node[0] instanceof RemarkNode); ! RemarkNode remarkNode = (RemarkNode)node[0]; ! assertStringEquals("Expected contents"," \n<A>\nbcd ",remarkNode.getText()); } --- 195,201 ---- Parser.setLineSeparator("\n"); parseAndAssertNodeCount(1); ! assertTrue("Node should be a Remark",node[0] instanceof Remark); ! Remark Remark = (Remark)node[0]; ! assertStringEquals("Expected contents"," \n<A>\nbcd ",Remark.getText()); } *************** *** 207,211 **** * -<br> * ssd --><br> ! * This is not supposed to be a remarknode */ public void testInvalidTag() throws ParserException { --- 207,211 ---- * -<br> * ssd --><br> ! * This is not supposed to be a Remark */ public void testInvalidTag() throws ParserException { *************** *** 234,240 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); ! assertTrue("Node should be a HTMLRemarkNode but was "+node[0],node[0] instanceof RemarkNode); ! RemarkNode remarkNode = (RemarkNode)node[0]; ! assertEquals("Remark Node contents"," -- ",remarkNode.getText()); } --- 234,240 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); ! assertTrue("Node should be a Remark but was "+node[0],node[0] instanceof Remark); ! Remark Remark = (Remark)node[0]; ! assertEquals("Remark Node contents"," -- ",Remark.getText()); } *************** *** 281,287 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(18); ! assertTrue("Node should be a RemarkNode but was "+node[12],node[12] instanceof RemarkNode); ! RemarkNode remarkNode = (RemarkNode)node[12]; ! assertEquals("Remark Node contents"," Id: html-sgml.sgm,v 1.5 1995/05/26 21:29:50 connolly Exp ",remarkNode.getText()); } --- 281,287 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(18); ! assertTrue("Node should be a Remark but was "+node[12],node[12] instanceof Remark); ! Remark Remark = (Remark)node[12]; ! assertEquals("Remark Node contents"," Id: html-sgml.sgm,v 1.5 1995/05/26 21:29:50 connolly Exp ",Remark.getText()); } *************** *** 305,311 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(18); ! assertTrue("Node should be a RemarkNode but was "+node[12],node[12] instanceof RemarkNode); ! RemarkNode remarkNode = (RemarkNode)node[12]; ! assertEquals("Remark Node contents"," another -- -- comment ",remarkNode.getText()); } --- 305,311 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(18); ! assertTrue("Node should be a Remark but was "+node[12],node[12] instanceof Remark); ! Remark Remark = (Remark)node[12]; ! assertEquals("Remark Node contents"," another -- -- comment ",Remark.getText()); } *************** *** 329,335 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(18); ! assertTrue("Node should be a RemarkNode but was "+node[12],node[12] instanceof RemarkNode); ! RemarkNode remarkNode = (RemarkNode)node[12]; ! assertEquals("Remark Node contents","",remarkNode.getText()); } --- 329,335 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(18); ! assertTrue("Node should be a Remark but was "+node[12],node[12] instanceof Remark); ! Remark Remark = (Remark)node[12]; ! assertEquals("Remark Node contents","",Remark.getText()); } *************** *** 355,361 **** // ); // parseAndAssertNodeCount(10); ! // assertTrue("Node should not be a HTMLRemarkNode",!(node[7] instanceof HTMLRemarkNode)); ! // assertTrue("Node should be a HTMLStringNode but was "+node[7],node[7].getType()==HTMLStringNode.TYPE); ! // HTMLStringNode stringNode = (HTMLStringNode)node[7]; // assertEquals("String Node contents","<!- not a comment, just regular old data characters ->\n",stringNode.getText()); // } --- 355,361 ---- // ); // parseAndAssertNodeCount(10); ! // assertTrue("Node should not be a Remark",!(node[7] instanceof Remark)); ! // assertTrue("Node should be a HTMLText but was "+node[7],node[7].getType()==HTMLText.TYPE); ! // HTMLText stringNode = (HTMLText)node[7]; // assertEquals("String Node contents","<!- not a comment, just regular old data characters ->\n",stringNode.getText()); // } *************** *** 381,385 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount (18); ! assertTrue("Node should be a RemarkNode but was " + node[12], node[12] instanceof RemarkNode); assertStringEquals ("remark text", "<!-- foobar --!>", node[12].toHtml ()); } --- 381,385 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount (18); ! assertTrue("Node should be a Remark but was " + node[12], node[12] instanceof Remark); assertStringEquals ("remark text", "<!-- foobar --!>", node[12].toHtml ()); } Index: StringParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/parserHelperTests/StringParserTest.java,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** StringParserTest.java 22 May 2004 03:57:30 -0000 1.47 --- StringParserTest.java 24 May 2004 16:18:32 -0000 1.48 *************** *** 29,34 **** import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.RemarkNode; ! import org.htmlparser.StringNode; import org.htmlparser.tags.HeadTag; import org.htmlparser.tags.Html; --- 29,34 ---- import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.Remark; ! import org.htmlparser.Text; import org.htmlparser.tags.HeadTag; import org.htmlparser.tags.Html; *************** *** 57,68 **** * Creation date: (6/17/2001 4:01:06 PM) */ ! public void testStringNodeBug1() throws ParserException { createParser("<HTML><HEAD><TITLE>Google</TITLE>"); parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(5); ! // The fourth node should be a StringNode- with the text - Google ! assertTrue("Fourth node should be a StringNode",node[3] instanceof StringNode); ! StringNode stringNode = (StringNode)node[3]; ! assertEquals("Text of the StringNode","Google",stringNode.getText()); } --- 57,68 ---- * Creation date: (6/17/2001 4:01:06 PM) */ ! public void testTextBug1() throws ParserException { createParser("<HTML><HEAD><TITLE>Google</TITLE>"); parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(5); ! // The fourth node should be a Text- with the text - Google ! assertTrue("Fourth node should be a Text",node[3] instanceof Text); ! Text stringNode = (Text)node[3]; ! assertEquals("Text of the Text","Google",stringNode.getText()); } *************** *** 75,79 **** * Creation date: (8/2/2001 2:07:32 AM) */ ! public void testStringNodeBug2() throws ParserException { // Register the link scanner --- 75,79 ---- * Creation date: (8/2/2001 2:07:32 AM) */ ! public void testTextBug2() throws ParserException { // Register the link scanner *************** *** 82,89 **** Parser.setLineSeparator("\r\n"); parseAndAssertNodeCount(3); ! // The first node should be a StringNode- with the text - view these documents, you must have ! assertTrue("First node should be a StringNode",node[0] instanceof StringNode); ! StringNode stringNode = (StringNode)node[0]; ! assertEquals("Text of the StringNode","view these documents, you must have ",stringNode.getText()); assertTrue("Second node should be a link node",node[1] instanceof LinkTag); LinkTag linkNode = (LinkTag)node[1]; --- 82,89 ---- Parser.setLineSeparator("\r\n"); parseAndAssertNodeCount(3); ! // The first node should be a Text- with the text - view these documents, you must have ! assertTrue("First node should be a Text",node[0] instanceof Text); ! Text stringNode = (Text)node[0]; ! assertEquals("Text of the Text","view these documents, you must have ",stringNode.getText()); assertTrue("Second node should be a link node",node[1] instanceof LinkTag); LinkTag linkNode = (LinkTag)node[1]; *************** *** 91,96 **** assertEquals("Link text is","Adobe \nAcrobat Reader",linkNode.getLinkText()); ! assertTrue("Third node should be a string node",node[2] instanceof StringNode); ! StringNode stringNode2 = (StringNode)node[2]; assertEquals("Contents of third node"," installed on your computer.",stringNode2.getText()); } --- 91,96 ---- assertEquals("Link text is","Adobe \nAcrobat Reader",linkNode.getLinkText()); ! assertTrue("Third node should be a string node",node[2] instanceof Text); ! Text stringNode2 = (Text)node[2]; assertEquals("Contents of third node"," installed on your computer.",stringNode2.getText()); } *************** *** 102,106 **** * The string node is not correctly identified */ ! public void testTagCharsInStringNode() throws ParserException { createParser("<a href=\"http://asgard.ch\">[> ASGARD <]</a>"); parseAndAssertNodeCount(1); --- 102,106 ---- * The string node is not correctly identified */ ! public void testTagCharsInText() throws ParserException { createParser("<a href=\"http://asgard.ch\">[> ASGARD <]</a>"); parseAndAssertNodeCount(1); *************** *** 115,123 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(10); ! assertTrue("Fourth Node identified must be a string node",node[3] instanceof StringNode); ! StringNode stringNode = (StringNode)node[3]; assertEquals("First String Node","This is the Title",stringNode.toPlainTextString()); ! assertTrue("Eighth Node identified must be a string node",node[7] instanceof StringNode); ! stringNode = (StringNode)node[7]; assertEquals("Second string node","Hello World, this is the HTML Parser",stringNode.toPlainTextString()); } --- 115,123 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(10); ! assertTrue("Fourth Node identified must be a string node",node[3] instanceof Text); ! Text stringNode = (Text)node[3]; assertEquals("First String Node","This is the Title",stringNode.toPlainTextString()); ! assertTrue("Eighth Node identified must be a string node",node[7] instanceof Text); ! stringNode = (Text)node[7]; assertEquals("Second string node","Hello World, this is the HTML Parser",stringNode.toPlainTextString()); } *************** *** 127,135 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(10); ! assertTrue("Fourth Node identified must be a string node",node[3] instanceof StringNode); ! StringNode stringNode = (StringNode)node[3]; assertEquals("First String Node","This is the Title",stringNode.toHtml()); ! assertTrue("Eighth Node identified must be a string node",node[7] instanceof StringNode); ! stringNode = (StringNode)node[7]; assertEquals("Second string node","Hello World, this is the HTML Parser",stringNode.toHtml()); } --- 127,135 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(10); ! assertTrue("Fourth Node identified must be a string node",node[3] instanceof Text); ! Text stringNode = (Text)node[3]; assertEquals("First String Node","This is the Title",stringNode.toHtml()); ! assertTrue("Eighth Node identified must be a string node",node[7] instanceof Text); ! stringNode = (Text)node[7]; assertEquals("Second string node","Hello World, this is the HTML Parser",stringNode.toHtml()); } *************** *** 143,147 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(4); ! assertTrue("Third Node identified must be a string node",node[2] instanceof StringNode); } --- 143,147 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(4); ! assertTrue("Third Node identified must be a string node",node[2] instanceof Text); } *************** *** 156,167 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(3); ! assertTrue("First node should be StringNode",node[0] instanceof StringNode); ! assertTrue("Second node should be RemarkNode",node[1] instanceof RemarkNode); ! assertTrue("Third node should be StringNode",node[2] instanceof StringNode); ! StringNode stringNode = (StringNode)node[0]; assertEquals("First String node contents","Before Comment ",stringNode.getText()); ! StringNode stringNode2 = (StringNode)node[2]; assertEquals("Second String node contents"," After Comment",stringNode2.getText()); ! RemarkNode remarkNode = (RemarkNode)node[1]; assertEquals("Remark Node contents"," Comment ",remarkNode.getText()); --- 156,167 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(3); ! assertTrue("First node should be Text",node[0] instanceof Text); ! assertTrue("Second node should be Remark",node[1] instanceof Remark); ! assertTrue("Third node should be Text",node[2] instanceof Text); ! Text stringNode = (Text)node[0]; assertEquals("First String node contents","Before Comment ",stringNode.getText()); ! Text stringNode2 = (Text)node[2]; assertEquals("Second String node contents"," After Comment",stringNode2.getText()); ! Remark remarkNode = (Remark)node[1]; assertEquals("Remark Node contents"," Comment ",remarkNode.getText()); *************** *** 170,174 **** /** * Based on a bug report submitted by Cedric Rosa, if the last line contains a single character, ! * StringNode does not return the string node correctly. */ public void testLastLineWithOneChar() throws ParserException { --- 170,174 ---- /** * Based on a bug report submitted by Cedric Rosa, if the last line contains a single character, ! * Text does not return the string node correctly. */ public void testLastLineWithOneChar() throws ParserException { *************** *** 176,181 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); ! assertTrue("First node should be StringNode",node[0] instanceof StringNode); ! StringNode stringNode = (StringNode)node[0]; assertEquals("First String node contents","a",stringNode.getText()); } --- 176,181 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); ! assertTrue("First node should be Text",node[0] instanceof Text); ! Text stringNode = (Text)node[0]; assertEquals("First String node contents","a",stringNode.getText()); } *************** *** 186,191 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); ! assertTrue("First node should be StringNode",node[0] instanceof StringNode); ! StringNode stringNode = (StringNode)node[0]; assertStringEquals("First String node contents",text,stringNode.getText()); } --- 186,191 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); ! assertTrue("First node should be Text",node[0] instanceof Text); ! Text stringNode = (Text)node[0]; assertStringEquals("First String node contents",text,stringNode.getText()); } *************** *** 238,243 **** parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); ! assertType("first node",StringNode.class,node[0]); ! StringNode stringNode = (StringNode)node[0]; assertStringEquals("text",text,stringNode.toPlainTextString()); } --- 238,243 ---- parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); ! assertType("first node",Text.class,node[0]); ! Text stringNode = (Text)node[0]; assertStringEquals("text",text,stringNode.toPlainTextString()); } |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:16
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/tags Modified Files: AppletTag.java CompositeTag.java ImageTag.java MetaTag.java Tag.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: ImageTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/ImageTag.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** ImageTag.java 24 May 2004 00:38:17 -0000 1.45 --- ImageTag.java 24 May 2004 16:18:30 -0000 1.46 *************** *** 30,34 **** import java.util.Vector; ! import org.htmlparser.lexer.nodes.Attribute; import org.htmlparser.util.ParserUtils; import org.htmlparser.visitors.NodeVisitor; --- 30,34 ---- import java.util.Vector; ! import org.htmlparser.Attribute; import org.htmlparser.util.ParserUtils; import org.htmlparser.visitors.NodeVisitor; *************** *** 37,41 **** * Identifies an image tag. */ ! public class ImageTag extends Tag { /** --- 37,43 ---- * Identifies an image tag. */ ! public class ImageTag ! extends ! Tag { /** Index: MetaTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/MetaTag.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** MetaTag.java 2 Jan 2004 16:24:55 -0000 1.35 --- MetaTag.java 24 May 2004 16:18:30 -0000 1.36 *************** *** 27,31 **** package org.htmlparser.tags; ! import org.htmlparser.lexer.nodes.Attribute; import org.htmlparser.util.ParserException; --- 27,31 ---- package org.htmlparser.tags; ! import org.htmlparser.Attribute; import org.htmlparser.util.ParserException; *************** *** 33,37 **** * A Meta Tag */ ! public class MetaTag extends Tag { /** --- 33,39 ---- * A Meta Tag */ ! public class MetaTag ! extends ! Tag { /** Index: AppletTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/AppletTag.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** AppletTag.java 24 Jan 2004 23:57:52 -0000 1.39 --- AppletTag.java 24 May 2004 16:18:30 -0000 1.40 *************** *** 31,37 **** import java.util.Vector; import org.htmlparser.Node; ! import org.htmlparser.StringNode; ! import org.htmlparser.lexer.nodes.Attribute; import org.htmlparser.util.NodeList; import org.htmlparser.util.SimpleNodeIterator; --- 31,37 ---- import java.util.Vector; + import org.htmlparser.Attribute; import org.htmlparser.Node; ! import org.htmlparser.Text; import org.htmlparser.util.NodeList; import org.htmlparser.util.SimpleNodeIterator; *************** *** 42,46 **** * archive and parameters. */ ! public class AppletTag extends CompositeTag { /** --- 42,48 ---- * archive and parameters. */ ! public class AppletTag ! extends ! CompositeTag { /** *************** *** 193,197 **** String paramValue; Vector attributes; ! StringNode string; kids = getChildren (); --- 195,199 ---- String paramValue; Vector attributes; ! Text string; kids = getChildren (); *************** *** 211,217 **** { node = kids.elementAt (i); ! if (node instanceof StringNode) { ! string = (StringNode)node; if (0 == string.getText ().trim ().length ()) kids.remove (i); --- 213,219 ---- { node = kids.elementAt (i); ! if (node instanceof Text) { ! string = (Text)node; if (0 == string.getText ().trim ().length ()) kids.remove (i); Index: CompositeTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/CompositeTag.java,v retrieving revision 1.76 retrieving revision 1.77 diff -C2 -d -r1.76 -r1.77 *** CompositeTag.java 29 Feb 2004 15:09:57 -0000 1.76 --- CompositeTag.java 24 May 2004 16:18:30 -0000 1.77 *************** *** 31,37 **** import org.htmlparser.Node; import org.htmlparser.NodeFilter; ! import org.htmlparser.StringNode; ! import org.htmlparser.AbstractNode; ! import org.htmlparser.lexer.nodes.TagNode; import org.htmlparser.scanners.CompositeTagScanner; import org.htmlparser.util.NodeList; --- 31,37 ---- import org.htmlparser.Node; import org.htmlparser.NodeFilter; ! import org.htmlparser.Text; ! import org.htmlparser.nodes.AbstractNode; ! import org.htmlparser.nodes.TagNode; import org.htmlparser.scanners.CompositeTagScanner; import org.htmlparser.util.NodeList; *************** *** 476,496 **** /** ! * Finds a string node, however embedded it might be, and returns ! * it. The string node will retain links to its parents, so * further navigation is possible. * @param searchText ! * @return The list of string nodes (recursively) found. */ ! public StringNode [] digupStringNode(String searchText) { NodeList nodeList = searchFor(searchText); NodeList stringNodes = new NodeList(); for (int i=0;i<nodeList.size();i++) { Node node = nodeList.elementAt(i); ! if (node instanceof StringNode) { stringNodes.add(node); } else { if (node instanceof CompositeTag) { CompositeTag ctag = (CompositeTag)node; ! StringNode [] nodes = ctag.digupStringNode(searchText); for (int j=0;j<nodes.length;j++) stringNodes.add(nodes[j]); --- 476,496 ---- /** ! * Finds a text node, however embedded it might be, and returns ! * it. The text node will retain links to its parents, so * further navigation is possible. * @param searchText ! * @return The list of text nodes (recursively) found. */ ! public Text[] digupStringNode(String searchText) { NodeList nodeList = searchFor(searchText); NodeList stringNodes = new NodeList(); for (int i=0;i<nodeList.size();i++) { Node node = nodeList.elementAt(i); ! if (node instanceof Text) { stringNodes.add(node); } else { if (node instanceof CompositeTag) { CompositeTag ctag = (CompositeTag)node; ! Text[] nodes = ctag.digupStringNode(searchText); for (int j=0;j<nodes.length;j++) stringNodes.add(nodes[j]); *************** *** 498,504 **** } } ! StringNode [] stringNode = new StringNode[stringNodes.size()]; for (int i=0;i<stringNode.length;i++) { ! stringNode[i] = (StringNode)stringNodes.elementAt(i); } return stringNode; --- 498,504 ---- } } ! Text[] stringNode = new Text[stringNodes.size()]; for (int i=0;i<stringNode.length;i++) { ! stringNode[i] = (Text)stringNodes.elementAt(i); } return stringNode; Index: Tag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/Tag.java,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** Tag.java 24 May 2004 00:38:18 -0000 1.63 --- Tag.java 24 May 2004 16:18:30 -0000 1.64 *************** *** 30,36 **** import org.htmlparser.lexer.Page; ! import org.htmlparser.lexer.nodes.TagNode; import org.htmlparser.scanners.TagScanner; - import org.htmlparser.visitors.NodeVisitor; /** --- 30,35 ---- import org.htmlparser.lexer.Page; ! import org.htmlparser.nodes.TagNode; import org.htmlparser.scanners.TagScanner; /** *************** *** 40,44 **** * lexer which has nodes). */ ! public class Tag extends TagNode implements Cloneable { /** --- 39,47 ---- * lexer which has nodes). */ ! public class Tag ! extends ! TagNode ! implements ! Cloneable { /** |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:16
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/scanners In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/scanners Modified Files: CompositeTagScanner.java ScriptScanner.java StyleScanner.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: StyleScanner.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/scanners/StyleScanner.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** StyleScanner.java 29 Feb 2004 14:16:27 -0000 1.33 --- StyleScanner.java 24 May 2004 16:18:30 -0000 1.34 *************** *** 30,39 **** import org.htmlparser.Node; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.RemarkNode; ! import org.htmlparser.StringNode; import org.htmlparser.lexer.Cursor; import org.htmlparser.lexer.Lexer; - import org.htmlparser.lexer.nodes.NodeFactory; import org.htmlparser.tags.CompositeTag; import org.htmlparser.tags.Tag; --- 30,39 ---- import org.htmlparser.Node; + import org.htmlparser.NodeFactory; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.Remark; ! import org.htmlparser.Text; import org.htmlparser.lexer.Cursor; import org.htmlparser.lexer.Lexer; import org.htmlparser.tags.CompositeTag; import org.htmlparser.tags.Tag; *************** *** 70,74 **** boolean done; int position; ! StringNode last; Tag end; NodeFactory factory; --- 70,74 ---- boolean done; int position; ! Text last; Tag end; NodeFactory factory; *************** *** 108,115 **** last.setEndPosition (node.elementEnd ()); else ! // TODO: need to remove this cast ! last = (StringNode)factory.createStringNode (lexer.getPage (), node.elementBegin (), node.elementEnd ()); } ! else if (node instanceof RemarkNode) { if (null != last) --- 108,114 ---- last.setEndPosition (node.elementEnd ()); else ! last = factory.createStringNode (lexer.getPage (), node.elementBegin (), node.elementEnd ()); } ! else if (node instanceof Remark) { if (null != last) *************** *** 117,132 **** else { ! // TODO: need to remove this cast ! // last = (StringNode)factory.createStringNode (lexer, node.elementBegin (), node.elementEnd ()); ! last = (StringNode)factory.createStringNode (lexer.getPage (), node.elementBegin (), node.elementEnd ()); } } ! else // StringNode { if (null != last) last.setEndPosition (node.getEndPosition ()); else ! // TODO: need to remove this cast ! last = (StringNode)node; } --- 116,129 ---- else { ! // last = factory.createStringNode (lexer, node.elementBegin (), node.elementEnd ()); ! last = factory.createStringNode (lexer.getPage (), node.elementBegin (), node.elementEnd ()); } } ! else // Text { if (null != last) last.setEndPosition (node.getEndPosition ()); else ! last = (Text)node; } *************** *** 136,141 **** // build new string tag if required if (null == last) ! // TODO: need to remove this cast ! last = (StringNode)factory.createStringNode (lexer.getPage (), position, position); // build new end tag if required if (null == end) --- 133,137 ---- // build new string tag if required if (null == last) ! last = factory.createStringNode (lexer.getPage (), position, position); // build new end tag if required if (null == end) Index: CompositeTagScanner.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/scanners/CompositeTagScanner.java,v retrieving revision 1.85 retrieving revision 1.86 diff -C2 -d -r1.85 -r1.86 *** CompositeTagScanner.java 14 Jan 2004 02:53:46 -0000 1.85 --- CompositeTagScanner.java 24 May 2004 16:18:20 -0000 1.86 *************** *** 29,36 **** import java.util.Vector; import org.htmlparser.Node; import org.htmlparser.lexer.Lexer; import org.htmlparser.lexer.Page; - import org.htmlparser.lexer.nodes.Attribute; import org.htmlparser.scanners.Scanner; import org.htmlparser.tags.CompositeTag; --- 29,36 ---- import java.util.Vector; + import org.htmlparser.Attribute; import org.htmlparser.Node; import org.htmlparser.lexer.Lexer; import org.htmlparser.lexer.Page; import org.htmlparser.scanners.Scanner; import org.htmlparser.tags.CompositeTag; Index: ScriptScanner.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/scanners/ScriptScanner.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** ScriptScanner.java 28 Feb 2004 15:52:43 -0000 1.56 --- ScriptScanner.java 24 May 2004 16:18:30 -0000 1.57 *************** *** 30,39 **** import org.htmlparser.Node; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.RemarkNode; ! import org.htmlparser.StringNode; import org.htmlparser.lexer.Cursor; import org.htmlparser.lexer.Lexer; - import org.htmlparser.lexer.nodes.NodeFactory; import org.htmlparser.scanners.ScriptDecoder; import org.htmlparser.tags.CompositeTag; --- 30,39 ---- import org.htmlparser.Node; + import org.htmlparser.NodeFactory; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.Remark; ! import org.htmlparser.Text; import org.htmlparser.lexer.Cursor; import org.htmlparser.lexer.Lexer; import org.htmlparser.scanners.ScriptDecoder; import org.htmlparser.tags.CompositeTag; *************** *** 75,79 **** boolean done; int position; ! StringNode last; Tag end; NodeFactory factory; --- 75,79 ---- boolean done; int position; ! Text last; Tag end; NodeFactory factory; *************** *** 94,98 **** String code = ScriptDecoder.Decode (lexer.getPage (), lexer.getCursor ()); ((ScriptTag)tag).setScriptCode (code); ! last = (StringNode)factory.createStringNode (lexer.getPage (), start, lexer.getPosition ()); } } --- 94,98 ---- String code = ScriptDecoder.Decode (lexer.getPage (), lexer.getCursor ()); ((ScriptTag)tag).setScriptCode (code); ! last = factory.createStringNode (lexer.getPage (), start, lexer.getPosition ()); } } *************** *** 126,133 **** last.setEndPosition (node.elementEnd ()); else ! // TODO: need to remove this cast ! last = (StringNode)factory.createStringNode (lexer.getPage (), node.elementBegin (), node.elementEnd ()); } ! else if (node instanceof RemarkNode) { if (null != last) --- 126,132 ---- last.setEndPosition (node.elementEnd ()); else ! last = factory.createStringNode (lexer.getPage (), node.elementBegin (), node.elementEnd ()); } ! else if (node instanceof Remark) { if (null != last) *************** *** 135,150 **** else { ! // TODO: need to remove this cast ! // last = (StringNode)factory.createStringNode (lexer, node.elementBegin (), node.elementEnd ()); ! last = (StringNode)factory.createStringNode (lexer.getPage (), node.elementBegin (), node.elementEnd ()); } } ! else // StringNode { if (null != last) last.setEndPosition (node.getEndPosition ()); else ! // TODO: need to remove this cast ! last = (StringNode)node; } --- 134,147 ---- else { ! // last = factory.createStringNode (lexer, node.elementBegin (), node.elementEnd ()); ! last = factory.createStringNode (lexer.getPage (), node.elementBegin (), node.elementEnd ()); } } ! else // Text { if (null != last) last.setEndPosition (node.getEndPosition ()); else ! last = (Text)node; } *************** *** 154,159 **** // build new string tag if required if (null == last) ! // TODO: need to remove this cast ! last = (StringNode)factory.createStringNode (lexer.getPage (), position, position); // build new end tag if required if (null == end) --- 151,155 ---- // build new string tag if required if (null == last) ! last = factory.createStringNode (lexer.getPage (), position, position); // build new end tag if required if (null == end) |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:16
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/tests Modified Files: ParserTest.java ParserTestCase.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: ParserTestCase.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/ParserTestCase.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** ParserTestCase.java 28 Feb 2004 15:52:43 -0000 1.45 --- ParserTestCase.java 24 May 2004 16:18:30 -0000 1.46 *************** *** 33,40 **** import junit.framework.TestCase; - import org.htmlparser.AbstractNode; import org.htmlparser.Node; import org.htmlparser.Parser; ! import org.htmlparser.StringNode; import org.htmlparser.lexer.Lexer; import org.htmlparser.lexer.Page; --- 33,39 ---- import junit.framework.TestCase; import org.htmlparser.Node; import org.htmlparser.Parser; ! import org.htmlparser.Text; import org.htmlparser.lexer.Lexer; import org.htmlparser.lexer.Page; *************** *** 68,72 **** mLexer = new Lexer (new Page (inputHTML)); parser = new Parser(mLexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET)); ! node = new AbstractNode[40]; } --- 67,71 ---- mLexer = new Lexer (new Page (inputHTML)); parser = new Parser(mLexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET)); ! node = new Node[40]; } *************** *** 75,79 **** Lexer lexer = new Lexer (inputHTML); parser = new Parser (lexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET)); ! node = new AbstractNode[numNodes]; } --- 74,78 ---- Lexer lexer = new Lexer (inputHTML); parser = new Parser (lexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET)); ! node = new Node[numNodes]; } *************** *** 82,86 **** lexer.getPage ().setUrl (url); parser = new Parser (lexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET)); ! node = new AbstractNode[40]; } --- 81,85 ---- lexer.getPage ().setUrl (url); parser = new Parser (lexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET)); ! node = new Node[40]; } *************** *** 89,93 **** lexer.getPage ().setUrl (url); parser = new Parser (lexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET)); ! node = new AbstractNode[numNodes]; } --- 88,92 ---- lexer.getPage ().setUrl (url); parser = new Parser (lexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET)); ! node = new Node[numNodes]; } *************** *** 271,275 **** do { nextNode = nodeIterator.nextNode(); ! if (nextNode instanceof StringNode) { text = nextNode.toPlainTextString().trim(); } else text = null; --- 270,274 ---- do { nextNode = nodeIterator.nextNode(); ! if (nextNode instanceof Text) { text = nextNode.toPlainTextString().trim(); } else text = null; *************** *** 426,439 **** Object object) { ! ! String expectedTypeName = expectedType.getName(); ! String actualTypeName = object.getClass().getName(); ! if (!actualTypeName.equals(expectedTypeName)) ! fail( ! message+" should have been of type\n"+ ! expectedTypeName+ ! " but was of type \n"+ ! actualTypeName+"\n and is :"+((Node)object).toHtml() ! ); } --- 425,442 ---- Object object) { ! if (!expectedType.isAssignableFrom (object.getClass ())) ! { ! String expectedTypeName = expectedType.getName (); ! String actualTypeName = object.getClass ().getName (); ! if (!actualTypeName.equals (expectedTypeName)) ! fail( ! message + " should have been of type "+ ! expectedTypeName ! + " but was of type " ! + actualTypeName ! + " and is:" ! + ((Node)object).toHtml() ! ); ! } } Index: ParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/ParserTest.java,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** ParserTest.java 18 Mar 2004 04:04:08 -0000 1.58 --- ParserTest.java 24 May 2004 16:18:30 -0000 1.59 *************** *** 38,47 **** import java.util.Locale; - import org.htmlparser.AbstractNode; import org.htmlparser.Node; import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.RemarkNode; ! import org.htmlparser.StringNode; import org.htmlparser.filters.NodeClassFilter; import org.htmlparser.filters.TagNameFilter; --- 38,46 ---- import java.util.Locale; import org.htmlparser.Node; import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; ! import org.htmlparser.Remark; ! import org.htmlparser.Text; import org.htmlparser.filters.NodeClassFilter; import org.htmlparser.filters.TagNameFilter; *************** *** 103,107 **** } ! Node [] node = new AbstractNode[500]; int i = 0; for (NodeIterator e = parser.elements();e.hasMoreNodes();) --- 102,106 ---- } ! Node[] node = new Node[500]; int i = 0; for (NodeIterator e = parser.elements();e.hasMoreNodes();) *************** *** 230,234 **** NodeIterator enumeration; Node node; ! StringNode string; try --- 229,233 ---- NodeIterator enumeration; Node node; ! Text string; try *************** *** 313,319 **** { node = enumeration.nextNode (); ! if (node instanceof StringNode) { ! string = (StringNode)node; if (-1 != string.getText ().indexOf (postal_code)) pass = true; --- 312,318 ---- { node = enumeration.nextNode (); ! if (node instanceof Text) { ! string = (Text)node; if (-1 != string.getText ().indexOf (postal_code)) pass = true; *************** *** 356,360 **** parser = new Parser (file.getAbsolutePath (), new DefaultParserFeedback(DefaultParserFeedback.QUIET)); parser.setNodeFactory (new PrototypicalNodeFactory (true)); ! nodes = new AbstractNode[30]; i = 0; for (enumeration = parser.elements (); enumeration.hasMoreNodes ();) --- 355,359 ---- parser = new Parser (file.getAbsolutePath (), new DefaultParserFeedback(DefaultParserFeedback.QUIET)); parser.setNodeFactory (new PrototypicalNodeFactory (true)); ! nodes = new Node[30]; i = 0; for (enumeration = parser.elements (); enumeration.hasMoreNodes ();) *************** *** 437,441 **** parser.setNodeFactory (new PrototypicalNodeFactory (new MetaTag ())); i = 0; ! nodes = new AbstractNode[30]; for (NodeIterator e = parser.elements(); e.hasMoreNodes();) nodes[i++] = e.nextNode(); --- 436,440 ---- parser.setNodeFactory (new PrototypicalNodeFactory (new MetaTag ())); i = 0; ! nodes = new Node[30]; for (NodeIterator e = parser.elements(); e.hasMoreNodes();) nodes[i++] = e.nextNode(); *************** *** 577,581 **** parser = new Parser(url); parser.setNodeFactory (new PrototypicalNodeFactory (true)); ! Node node [] = new AbstractNode[30]; int i = 0; for (NodeIterator e = parser.elements();e.hasMoreNodes();) { --- 576,580 ---- parser = new Parser(url); parser.setNodeFactory (new PrototypicalNodeFactory (true)); ! Node node [] = new Node[30]; int i = 0; for (NodeIterator e = parser.elements();e.hasMoreNodes();) { *************** *** 905,909 **** assertStringEquals ("html wrong", html, node[0].toHtml ()); assertTrue ("wrong number of children", 1 == node[0].getChildren ().size ()); ! assertTrue ("string node expected", node[0].getChildren ().elementAt (0) instanceof StringNode); txt = node[0].getChildren ().elementAt (0); assertStringEquals ("string html wrong", text, txt.toHtml ()); --- 904,908 ---- assertStringEquals ("html wrong", html, node[0].toHtml ()); assertTrue ("wrong number of children", 1 == node[0].getChildren ().size ()); ! assertTrue ("string node expected", node[0].getChildren ().elementAt (0) instanceof Text); txt = node[0].getChildren ().elementAt (0); assertStringEquals ("string html wrong", text, txt.toHtml ()); *************** *** 940,944 **** assertStringEquals ("html wrong", html, node[0].toHtml ()); assertTrue ("wrong number of children", 1 == node[0].getChildren ().size ()); ! assertTrue ("remark node expected", node[0].getChildren ().elementAt (0) instanceof RemarkNode); rem = node[0].getChildren ().elementAt (0); assertStringEquals ("remark html wrong", remark, rem.toHtml ()); --- 939,943 ---- assertStringEquals ("html wrong", html, node[0].toHtml ()); assertTrue ("wrong number of children", 1 == node[0].getChildren ().size ()); ! assertTrue ("remark node expected", node[0].getChildren ().elementAt (0) instanceof Remark); rem = node[0].getChildren ().elementAt (0); assertStringEquals ("remark html wrong", remark, rem.toHtml ()); |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:15
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/tests/lexerTests Modified Files: AttributeTests.java KitTest.java LexerTests.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: AttributeTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/AttributeTests.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** AttributeTests.java 14 Mar 2004 15:42:37 -0000 1.13 --- AttributeTests.java 24 May 2004 16:18:31 -0000 1.14 *************** *** 31,36 **** import org.htmlparser.Node; import org.htmlparser.PrototypicalNodeFactory; - import org.htmlparser.lexer.nodes.Attribute; import org.htmlparser.lexer.nodes.PageAttribute; import org.htmlparser.tags.ImageTag; --- 31,36 ---- import org.htmlparser.Node; + import org.htmlparser.Attribute; import org.htmlparser.PrototypicalNodeFactory; import org.htmlparser.lexer.nodes.PageAttribute; import org.htmlparser.tags.ImageTag; Index: LexerTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/LexerTests.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** LexerTests.java 24 May 2004 00:38:18 -0000 1.20 --- LexerTests.java 24 May 2004 16:18:31 -0000 1.21 *************** *** 33,41 **** import org.htmlparser.Node; import org.htmlparser.Parser; import org.htmlparser.lexer.Lexer; - import org.htmlparser.RemarkNode; - import org.htmlparser.StringNode; - import org.htmlparser.lexer.nodes.TagNode; - import org.htmlparser.tags.Tag; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.NodeIterator; --- 33,40 ---- import org.htmlparser.Node; import org.htmlparser.Parser; + import org.htmlparser.Remark; + import org.htmlparser.Tag; + import org.htmlparser.Text; import org.htmlparser.lexer.Lexer; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.NodeIterator; *************** *** 66,75 **** String reference; Lexer lexer; ! StringNode node; reference = "Hello world"; lexer = new Lexer (reference); ! node = (StringNode)lexer.nextNode (); ! assertEquals ("StringNode contents wrong", reference, node.getText ()); } --- 65,74 ---- String reference; Lexer lexer; ! Text node; reference = "Hello world"; lexer = new Lexer (reference); ! node = (Text)lexer.nextNode (); ! assertEquals ("Text contents wrong", reference, node.getText ()); } *************** *** 81,90 **** String reference; Lexer lexer; ! StringNode node; reference = "Hello\nworld"; lexer = new Lexer (reference); ! node = (StringNode)lexer.nextNode (); ! assertEquals ("StringNode contents wrong", reference, node.getText ()); } --- 80,89 ---- String reference; Lexer lexer; ! Text node; reference = "Hello\nworld"; lexer = new Lexer (reference); ! node = (Text)lexer.nextNode (); ! assertEquals ("Text contents wrong", reference, node.getText ()); } *************** *** 96,109 **** String reference; Lexer lexer; ! StringNode node; reference = "Hello\r\nworld"; lexer = new Lexer (reference); ! node = (StringNode)lexer.nextNode (); ! assertEquals ("StringNode contents wrong", reference, node.getText ()); reference = "Hello\rworld"; lexer = new Lexer (reference); ! node = (StringNode)lexer.nextNode (); ! assertEquals ("StringNode contents wrong", reference, node.getText ()); } --- 95,108 ---- String reference; Lexer lexer; ! Text node; reference = "Hello\r\nworld"; lexer = new Lexer (reference); ! node = (Text)lexer.nextNode (); ! assertEquals ("Text contents wrong", reference, node.getText ()); reference = "Hello\rworld"; lexer = new Lexer (reference); ! node = (Text)lexer.nextNode (); ! assertEquals ("Text contents wrong", reference, node.getText ()); } *************** *** 115,132 **** String reference; Lexer lexer; ! StringNode node; reference = "Hello world\n"; lexer = new Lexer (reference); ! node = (StringNode)lexer.nextNode (); ! assertEquals ("StringNode contents wrong", reference, node.getText ()); reference = "Hello world\r"; lexer = new Lexer (reference); ! node = (StringNode)lexer.nextNode (); ! assertEquals ("StringNode contents wrong", reference, node.getText ()); reference = "Hello world\r\n"; lexer = new Lexer (reference); ! node = (StringNode)lexer.nextNode (); ! assertEquals ("StringNode contents wrong", reference, node.getText ()); } --- 114,131 ---- String reference; Lexer lexer; ! Text node; reference = "Hello world\n"; lexer = new Lexer (reference); ! node = (Text)lexer.nextNode (); ! assertEquals ("Text contents wrong", reference, node.getText ()); reference = "Hello world\r"; lexer = new Lexer (reference); ! node = (Text)lexer.nextNode (); ! assertEquals ("Text contents wrong", reference, node.getText ()); reference = "Hello world\r\n"; lexer = new Lexer (reference); ! node = (Text)lexer.nextNode (); ! assertEquals ("Text contents wrong", reference, node.getText ()); } *************** *** 152,156 **** }; Lexer lexer; ! StringNode node; for (int i = 0; i < references.length; i++) --- 151,155 ---- }; Lexer lexer; ! Text node; for (int i = 0; i < references.length; i++) *************** *** 159,164 **** { lexer = new Lexer (references[i] + suffixes[j]); ! node = (StringNode)lexer.nextNode (); ! assertEquals ("StringNode contents wrong", references[i], node.getText ()); } } --- 158,163 ---- { lexer = new Lexer (references[i] + suffixes[j]); ! node = (Text)lexer.nextNode (); ! assertEquals ("Text contents wrong", references[i], node.getText ()); } } *************** *** 173,181 **** String suffix; Lexer lexer; ! TagNode node; reference = "<head>"; lexer = new Lexer (reference); ! node = (TagNode)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); --- 172,180 ---- String suffix; Lexer lexer; ! Node node; reference = "<head>"; lexer = new Lexer (reference); ! node = lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); *************** *** 183,189 **** suffix = "<body>"; lexer = new Lexer (reference + suffix); ! node = (TagNode)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); ! node = (TagNode)lexer.nextNode (); assertEquals ("Tag contents wrong", suffix, node.toHtml ()); } --- 182,188 ---- suffix = "<body>"; lexer = new Lexer (reference + suffix); ! node = lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); ! node = lexer.nextNode (); assertEquals ("Tag contents wrong", suffix, node.toHtml ()); } *************** *** 196,204 **** String reference; Lexer lexer; ! TagNode node; reference = "<head lang='en_US' dir=ltr\nprofile=\"http://htmlparser.sourceforge.org/dictionary.html\">"; lexer = new Lexer (reference); ! node = (TagNode)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); } --- 195,203 ---- String reference; Lexer lexer; ! Node node; reference = "<head lang='en_US' dir=ltr\nprofile=\"http://htmlparser.sourceforge.org/dictionary.html\">"; lexer = new Lexer (reference); ! node = lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); } *************** *** 207,230 **** * Test operation with comments. */ ! public void testRemarkNode () throws ParserException { String reference; Lexer lexer; ! RemarkNode node; String suffix; reference = "<!-- This is a comment -->"; lexer = new Lexer (reference); ! node = (RemarkNode)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); reference = "<!-- This is a comment -- >"; lexer = new Lexer (reference); ! node = (RemarkNode)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); reference = "<!-- This is a\nmultiline comment -->"; lexer = new Lexer (reference); ! node = (RemarkNode)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); --- 206,229 ---- * Test operation with comments. */ ! public void testRemark () throws ParserException { String reference; Lexer lexer; ! Remark node; String suffix; reference = "<!-- This is a comment -->"; lexer = new Lexer (reference); ! node = (Remark)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); reference = "<!-- This is a comment -- >"; lexer = new Lexer (reference); ! node = (Remark)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); reference = "<!-- This is a\nmultiline comment -->"; lexer = new Lexer (reference); ! node = (Remark)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); *************** *** 232,246 **** reference = "<!-- This is a comment -->"; lexer = new Lexer (reference + suffix); ! node = (RemarkNode)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); reference = "<!-- This is a comment -- >"; lexer = new Lexer (reference + suffix); ! node = (RemarkNode)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); reference = "<!-- This is a\nmultiline comment -->"; lexer = new Lexer (reference + suffix); ! node = (RemarkNode)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); } --- 231,245 ---- reference = "<!-- This is a comment -->"; lexer = new Lexer (reference + suffix); ! node = (Remark)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); reference = "<!-- This is a comment -- >"; lexer = new Lexer (reference + suffix); ! node = (Remark)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); reference = "<!-- This is a\nmultiline comment -->"; lexer = new Lexer (reference + suffix); ! node = (Remark)lexer.nextNode (); assertEquals ("Tag contents wrong", reference, node.toHtml ()); } Index: KitTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/KitTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** KitTest.java 14 Jan 2004 02:53:47 -0000 1.6 --- KitTest.java 24 May 2004 16:18:31 -0000 1.7 *************** *** 37,46 **** import javax.swing.text.html.HTMLEditorKit.Parser; import javax.swing.text.html.HTMLEditorKit.ParserCallback; import org.htmlparser.Node; import org.htmlparser.lexer.Cursor; import org.htmlparser.lexer.Lexer; - import org.htmlparser.AbstractNode; - import org.htmlparser.lexer.nodes.Attribute; - import org.htmlparser.lexer.nodes.TagNode; import org.htmlparser.util.ParserException; import org.htmlparser.util.Translate; --- 37,47 ---- import javax.swing.text.html.HTMLEditorKit.Parser; import javax.swing.text.html.HTMLEditorKit.ParserCallback; + + import org.htmlparser.Attribute; import org.htmlparser.Node; + import org.htmlparser.Tag; + import org.htmlparser.nodes.AbstractNode; import org.htmlparser.lexer.Cursor; import org.htmlparser.lexer.Lexer; import org.htmlparser.util.ParserException; import org.htmlparser.util.Translate; *************** *** 266,272 **** { node = (Node)mNodes.elementAt (i); ! if (node instanceof TagNode) { ! ours = ((Attribute)(((TagNode)node).getAttributesEx ().elementAt (0))).getName (); if (match (theirs, ours)) { --- 267,273 ---- { node = (Node)mNodes.elementAt (i); ! if (node instanceof Tag) { ! ours = ((Attribute)(((Tag)node).getAttributesEx ().elementAt (0))).getName (); if (match (theirs, ours)) { *************** *** 331,337 **** { node = (Node)mNodes.elementAt (i); ! if (node instanceof TagNode) { ! ours = ((Attribute)(((TagNode)node).getAttributesEx ().elementAt (0))).getName ().substring (1); if (match (theirs, ours)) { --- 332,338 ---- { node = (Node)mNodes.elementAt (i); ! if (node instanceof Tag) { ! ours = ((Attribute)(((Tag)node).getAttributesEx ().elementAt (0))).getName ().substring (1); if (match (theirs, ours)) { *************** *** 397,403 **** { node = (Node)mNodes.elementAt (i); ! if (node instanceof TagNode) { ! ours = ((Attribute)(((TagNode)node).getAttributesEx ().elementAt (0))).getName (); if (match (theirs, ours)) { --- 398,404 ---- { node = (Node)mNodes.elementAt (i); ! if (node instanceof Tag) { ! ours = ((Attribute)(((Tag)node).getAttributesEx ().elementAt (0))).getName (); if (match (theirs, ours)) { *************** *** 604,607 **** --- 605,615 ---- * * $Log$ + * Revision 1.7 2004/05/24 16:18:31 derrickoswald + * Part three of a multiphase refactoring. + * The three node types are now fronted by interfaces (program to the interface paradigm) + * with concrete implementations in the new htmlparser.nodes package. Classes from the + * lexer.nodes package are moved to this package, and obvious references to the concrete + * classes that got broken by this have been changed to use the interfaces where possible. + * * Revision 1.6 2004/01/14 02:53:47 derrickoswald * *** empty log message *** |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:14
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/filterTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/tests/filterTests Modified Files: FilterTest.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: FilterTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/filterTests/FilterTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FilterTest.java 24 May 2004 00:38:18 -0000 1.4 --- FilterTest.java 24 May 2004 16:18:31 -0000 1.5 *************** *** 38,43 **** import org.htmlparser.filters.TagNameFilter; import org.htmlparser.lexer.Lexer; ! import org.htmlparser.StringNode; ! import org.htmlparser.lexer.nodes.TagNode; import org.htmlparser.tags.BodyTag; import org.htmlparser.tags.LinkTag; --- 38,42 ---- import org.htmlparser.filters.TagNameFilter; import org.htmlparser.lexer.Lexer; ! import org.htmlparser.Text; import org.htmlparser.tags.BodyTag; import org.htmlparser.tags.LinkTag; *************** *** 80,84 **** BodyTag body = (BodyTag)list.elementAt (0); assertEquals ("only one child", 1, body.getChildCount ()); ! assertSuperType ("should be StringNode", StringNode.class, body.getChildren ().elementAt (0)); assertStringEquals("html", guts, body.toHtml ()); } --- 79,83 ---- BodyTag body = (BodyTag)list.elementAt (0); assertEquals ("only one child", 1, body.getChildCount ()); ! assertSuperType ("should be Text", Text.class, body.getChildren ().elementAt (0)); assertStringEquals("html", guts, body.toHtml ()); } *************** *** 99,104 **** list = parser.extractAllNodesThatMatch (new TagNameFilter ("booty")); assertEquals ("only one element", 1, list.size ()); ! assertSuperType ("should be Tag", TagNode.class, list.elementAt (0)); ! assertStringEquals("name", "BOOTY", ((TagNode)list.elementAt (0)).getTagName ()); } --- 98,103 ---- list = parser.extractAllNodesThatMatch (new TagNameFilter ("booty")); assertEquals ("only one element", 1, list.size ()); ! assertSuperType ("should be Tag", Tag.class, list.elementAt (0)); ! assertStringEquals("name", "BOOTY", ((Tag)(list.elementAt (0))).getTagName ()); } *************** *** 117,122 **** list = parser.extractAllNodesThatMatch (new StringFilter ("Time")); assertEquals ("only one element", 1, list.size ()); ! assertSuperType ("should be String", StringNode.class, list.elementAt (0)); ! assertStringEquals("name", "time", ((StringNode)list.elementAt (0)).getText ()); // test case sensitivity list = parser.extractAllNodesThatMatch (new StringFilter ("Time", true)); --- 116,121 ---- list = parser.extractAllNodesThatMatch (new StringFilter ("Time")); assertEquals ("only one element", 1, list.size ()); ! assertSuperType ("should be String", Text.class, list.elementAt (0)); ! assertStringEquals("name", "time", ((Text)list.elementAt (0)).getText ()); // test case sensitivity list = parser.extractAllNodesThatMatch (new StringFilter ("Time", true)); *************** *** 141,146 **** LinkTag link = (LinkTag)list.elementAt (0); assertEquals ("three children", 3, link.getChildCount ()); ! assertSuperType ("should be TagNode", TagNode.class, link.getChildren ().elementAt (0)); ! TagNode tag = (TagNode)link.getChildren ().elementAt (0); assertStringEquals("name", "B", tag.getTagName ()); } --- 140,145 ---- LinkTag link = (LinkTag)list.elementAt (0); assertEquals ("three children", 3, link.getChildCount ()); ! assertSuperType ("should be TagNode", Tag.class, link.getChildren ().elementAt (0)); ! Tag tag = (Tag)link.getChildren ().elementAt (0); assertStringEquals("name", "B", tag.getTagName ()); } |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:07
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodeDecorators In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/nodeDecorators Modified Files: AbstractNodeDecorator.java DecodingNode.java EscapeCharacterRemovingNode.java NonBreakingSpaceConvertingNode.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: NonBreakingSpaceConvertingNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodeDecorators/NonBreakingSpaceConvertingNode.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** NonBreakingSpaceConvertingNode.java 2 Jan 2004 16:24:54 -0000 1.13 --- NonBreakingSpaceConvertingNode.java 24 May 2004 16:18:18 -0000 1.14 *************** *** 27,34 **** package org.htmlparser.nodeDecorators; ! import org.htmlparser.Node; public class NonBreakingSpaceConvertingNode extends AbstractNodeDecorator { ! public NonBreakingSpaceConvertingNode(Node newDelegate) { super(newDelegate); } --- 27,34 ---- package org.htmlparser.nodeDecorators; ! import org.htmlparser.Text; public class NonBreakingSpaceConvertingNode extends AbstractNodeDecorator { ! public NonBreakingSpaceConvertingNode(Text newDelegate) { super(newDelegate); } Index: DecodingNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodeDecorators/DecodingNode.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** DecodingNode.java 2 Jan 2004 16:24:54 -0000 1.15 --- DecodingNode.java 24 May 2004 16:18:18 -0000 1.16 *************** *** 27,35 **** package org.htmlparser.nodeDecorators; ! import org.htmlparser.Node; import org.htmlparser.util.Translate; public class DecodingNode extends AbstractNodeDecorator { ! public DecodingNode(Node node) { super(node); } --- 27,35 ---- package org.htmlparser.nodeDecorators; ! import org.htmlparser.Text; import org.htmlparser.util.Translate; public class DecodingNode extends AbstractNodeDecorator { ! public DecodingNode(Text node) { super(node); } Index: AbstractNodeDecorator.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodeDecorators/AbstractNodeDecorator.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** AbstractNodeDecorator.java 24 May 2004 00:38:17 -0000 1.19 --- AbstractNodeDecorator.java 24 May 2004 16:18:18 -0000 1.20 *************** *** 28,31 **** --- 28,32 ---- import org.htmlparser.Node; + import org.htmlparser.Text; import org.htmlparser.NodeFilter; import org.htmlparser.util.NodeList; *************** *** 33,40 **** import org.htmlparser.visitors.NodeVisitor; ! public abstract class AbstractNodeDecorator implements Node { ! protected Node delegate; ! protected AbstractNodeDecorator(Node delegate) { this.delegate = delegate; } --- 34,43 ---- import org.htmlparser.visitors.NodeVisitor; ! public abstract class AbstractNodeDecorator implements Text ! { ! protected Text delegate; ! protected AbstractNodeDecorator(Text delegate) ! { this.delegate = delegate; } Index: EscapeCharacterRemovingNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodeDecorators/EscapeCharacterRemovingNode.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** EscapeCharacterRemovingNode.java 2 Jan 2004 16:24:54 -0000 1.13 --- EscapeCharacterRemovingNode.java 24 May 2004 16:18:18 -0000 1.14 *************** *** 27,35 **** package org.htmlparser.nodeDecorators; ! import org.htmlparser.Node; import org.htmlparser.util.ParserUtils; public class EscapeCharacterRemovingNode extends AbstractNodeDecorator { ! public EscapeCharacterRemovingNode(Node newDelegate) { super(newDelegate); } --- 27,35 ---- package org.htmlparser.nodeDecorators; ! import org.htmlparser.Text; import org.htmlparser.util.ParserUtils; public class EscapeCharacterRemovingNode extends AbstractNodeDecorator { ! public EscapeCharacterRemovingNode(Text newDelegate) { super(newDelegate); } |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:07
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/lexer Modified Files: Lexer.java Added Files: PageAttribute.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. --- NEW FILE: PageAttribute.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2004 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/PageAttribute.java,v $ // $Author: derrickoswald $ // $Date: 2004/05/24 16:18:16 $ // $Revision: 1.1 $ // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // package org.htmlparser.lexer; import org.htmlparser.Attribute; import org.htmlparser.lexer.Page; /** * An attribute within a tag on a page. * This attribute is similar to Attribute but 'lazy loaded' from the * <code>Page</code> by providing the page and cursor offsets * into the page for the name and value. This is done for speed, since * if the name and value are not needed we can avoid the cost and memory * overhead of creating the strings. * <p> * Thus the property getters, defer to the base class unless the property * is null, in which case an attempt is made to read it from the underlying * page. Optimizations in the predicates and length calculation defer the * actual instantiation of strings until absolutely needed. */ public class PageAttribute extends Attribute { /** * The page this attribute is extracted from. */ protected Page mPage; /** * The starting offset of the name within the page. * If negative, the name is considered <code>null</code>. */ protected int mNameStart; /** * The ending offset of the name within the page. */ protected int mNameEnd; /** * The starting offset of the value within the page. * If negative, the value is considered <code>null</code>. */ protected int mValueStart; /** * The ending offset of the name within the page. */ protected int mValueEnd; /** * Create an attribute. * @param page The page containing the attribute. * @param name_start The starting offset of the name within the page. * If this is negative, the name is considered null. * @param name_end The ending offset of the name within the page. * @param value_start he starting offset of the value within the page. * If this is negative, the value is considered null. * @param value_end The ending offset of the value within the page. * @param quote The quote, if any, surrounding the value of the attribute, * (i.e. ' or "), or zero if none. */ public PageAttribute (Page page, int name_start, int name_end, int value_start, int value_end, char quote) { mPage = page; mNameStart = name_start; mNameEnd = name_end; mValueStart = value_start; mValueEnd = value_end; setName (null); setAssignment (null); setValue (null); setQuote (quote); } // // provide same constructors as super class // private void init () { mPage = null; mNameStart = -1; mNameEnd = -1; mValueStart = -1; mValueEnd = -1; } /** * Create an attribute with the name, assignment string, value and quote given. * If the quote value is zero, assigns the value using {@link #setRawValue} * which sets the quote character to a proper value if necessary. * @param name The name of this attribute. * @param assignment The assignment string of this attribute. * @param value The value of this attribute. * @param quote The quote around the value of this attribute. */ public PageAttribute (String name, String assignment, String value, char quote) { super (name, assignment, value, quote); init (); } /** * Create an attribute with the name, value and quote given. * Uses an equals sign as the assignment string if the value is not * <code>null</code>, and calls {@link #setRawValue} to get the * correct quoting if <code>quote</code> is zero. * @param name The name of this attribute. * @param value The value of this attribute. * @param quote The quote around the value of this attribute. */ public PageAttribute (String name, String value, char quote) { super (name, value, quote); init (); } /** * Create a whitespace attribute with the value given. * @param value The value of this attribute. * @exception IllegalArgumentException if the value contains other than * whitespace. To set a real value use {@link Attribute#Attribute(String)}. */ public PageAttribute (String value) { super (value); init (); } /** * Create an attribute with the name and value given. * Uses an equals sign as the assignment string if the value is not * <code>null</code>, and calls {@link #setRawValue} to get the * correct quoting. * @param name The name of this attribute. * @param value The value of this attribute. */ public PageAttribute (String name, String value) { super (name, value); init (); } /** * Create an attribute with the name, assignment string and value given. * Calls {@link #setRawValue} to get the correct quoting. * @param name The name of this attribute. * @param assignment The assignment string of this attribute. * @param value The value of this attribute. */ public PageAttribute (String name, String assignment, String value) { super (name, assignment, value); init (); } /** * Create an empty attribute. * This will provide "" from the {@link #toString} and * {@link #toString(StringBuffer)} methods. */ public PageAttribute () { super (); init (); } /** * Get the name of this attribute. * The part before the equals sign, or the contents of the * stand-alone attribute. * @return The name, or <code>null</code> if it's just a whitepace * 'attribute'. */ public String getName () { String ret; ret = super.getName (); if (null == ret) { if ((null != mPage) && (0 <= mNameStart)) { ret = mPage.getText (mNameStart, mNameEnd); setName (ret); // cache the value } } return (ret); } /** * Get the name of this attribute. * @param buffer The buffer to place the name in. * @see #getName() */ public void getName (StringBuffer buffer) { String name; name = super.getName (); if (null == name) { if ((null != mPage) && (0 <= mNameStart)) mPage.getText (buffer, mNameStart, mNameEnd); } else buffer.append (name); } /** * Get the assignment string of this attribute. * This is usually just an equals sign, but in poorly formed attributes it * can include whitespace on either or both sides of an equals sign. * @return The assignment string. */ public String getAssignment () { String ret; ret = super.getAssignment (); if (null == ret) { if ((null != mPage) && (0 <= mNameEnd) && (0 <= mValueStart)) { ret = mPage.getText (mNameEnd, mValueStart); // remove a possible quote included in the assignment // since mValueStart points at the real start of the value if (ret.endsWith ("\"") || ret.endsWith ("'")) ret = ret.substring (0, ret.length () - 1); setAssignment (ret); // cache the value } } return (ret); } /** * Get the assignment string of this attribute. * @param buffer The buffer to place the assignment string in. * @see #getAssignment() */ public void getAssignment (StringBuffer buffer) { int length; char ch; String assignment; assignment = super.getAssignment (); if (null == assignment) { if ((null != mPage) && (0 <= mNameEnd) && (0 <= mValueStart)) { mPage.getText (buffer, mNameEnd, mValueStart); // remove a possible quote included in the assignment // since mValueStart points at the real start of the value length = buffer.length () - 1; ch = buffer.charAt (length); if (('\'' == ch) || ('"' == ch)) buffer.setLength (length); } } else buffer.append (assignment); } /** * Get the value of the attribute. * The part after the equals sign, or the text if it's just a whitepace * 'attribute'. * <em>NOTE:</em> This does not include any quotes that may have enclosed * the value when it was read. To get the un-stripped value use * {@link #getRawValue}. * @return The value, or <code>null</code> if it's a stand-alone or * empty attribute, or the text if it's just a whitepace 'attribute'. */ public String getValue () { String ret; ret = super.getValue (); if (null == ret) { if ((null != mPage) && (0 <= mValueEnd)) { ret = mPage.getText (mValueStart, mValueEnd); setValue (ret); // cache the value } } return (ret); } /** * Get the value of the attribute. * @param buffer The buffer to place the value in. * @see #getValue() */ public void getValue (StringBuffer buffer) { String value; value = super.getValue (); if (null == value) { if ((null != mPage) && (0 <= mValueEnd)) mPage.getText (buffer, mNameStart, mNameEnd); } else buffer.append (value); } /** * Get the raw value of the attribute. * The part after the equals sign, or the text if it's just a whitepace * 'attribute'. This includes the quotes around the value if any. * @return The value, or <code>null</code> if it's a stand-alone attribute, * or the text if it's just a whitepace 'attribute'. */ public String getRawValue () { char quote; StringBuffer buffer; String ret; ret = getValue (); if (null != ret && (0 != (quote = getQuote ()))) { buffer = new StringBuffer (ret.length() + 2); buffer.append (quote); buffer.append (ret); buffer.append (quote); ret = buffer.toString (); } return (ret); } /** * Get the raw value of the attribute. * The part after the equals sign, or the text if it's just a whitepace * 'attribute'. This includes the quotes around the value if any. * @return The value, or <code>null</code> if it's a stand-alone attribute, * or the text if it's just a whitepace 'attribute'. * @see #getRawValue() */ public void getRawValue (StringBuffer buffer) { char quote; if (null == mValue) { if (0 <= mValueEnd) { if (0 != (quote = getQuote ())) buffer.append (quote); if (mValueStart != mValueEnd) mPage.getText (buffer, mValueStart, mValueEnd); if (0 != quote) buffer.append (quote); } } else { if (0 != (quote = getQuote ())) buffer.append (quote); buffer.append (mValue); if (0 != quote) buffer.append (quote); } } /** * Get the page this attribute is anchored to, if any. * @return The page used to construct this attribute, or null if this * is just a regular attribute. */ public Page getPage () { return (mPage); } /** * Set the page this attribute is anchored to. * @param page The page to be used to construct this attribute. * Note: If you set this you probably also want to uncache the property * values by setting them to null. */ public void setPage (Page page) { mPage = page; } /** * Get the starting position of the attribute name. * @return The offset into the page at which the name begins. */ public int getNameStartPosition () { return (mNameStart); } /** * Set the starting position of the attribute name. * @param start The new offset into the page at which the name begins. */ public void setNameStartPosition (int start) { mNameStart = start; setName (null); // uncache value } /** * Get the ending position of the attribute name. * @return The offset into the page at which the name ends. */ public int getNameEndPosition () { return (mNameEnd); } /** * Set the ending position of the attribute name. * @param end The new offset into the page at which the name ends. */ public void setNameEndPosition (int end) { mNameEnd = end; setName (null); // uncache value setAssignment (null); // uncache value } /** * Get the starting position of the attribute value. * @return The offset into the page at which the value begins. */ public int getValueStartPosition () { return (mValueStart); } /** * Set the starting position of the attribute value. * @param start The new offset into the page at which the value begins. */ public void setValueStartPosition (int start) { mValueStart = start; setAssignment (null); // uncache value setValue (null); // uncache value } /** * Get the ending position of the attribute value. * @return The offset into the page at which the value ends. */ public int getValueEndPosition () { return (mValueEnd); } /** * Set the ending position of the attribute value. * @param end The new offset into the page at which the value ends. */ public void setValueEndPosition (int end) { mValueEnd = end; setValue (null); // uncache value } /** * Predicate to determine if this attribute is whitespace. * @return <code>true</code> if this attribute is whitespace, * <code>false</code> if it is a real attribute. */ public boolean isWhitespace () { return (((null == super.getName ()) && (null == mPage)) || ((null != mPage) && (0 > mNameStart))); } /** * Predicate to determine if this attribute has no equals sign (or value). * @return <code>true</code> if this attribute is a standalone attribute. * <code>false</code> if has an equals sign. */ public boolean isStandAlone () { return (!isWhitespace () // not whitespace && (null == super.getAssignment ()) // and no explicit assignment provided && !isValued () // and has no value && ((null == mPage) // and either its not coming from a page // or it is coming from a page and it doesn't have an assignment part || ((null != mPage) && (0 <= mNameEnd) && (0 > mValueStart)))); } /** * Predicate to determine if this attribute has an equals sign but no value. * @return <code>true</code> if this attribute is an empty attribute. * <code>false</code> if has an equals sign and a value. */ public boolean isEmpty () { return (!isWhitespace () // not whitespace && !isStandAlone () // and not standalone && (null == super.getValue ()) // and no explicit value provided && ((null == mPage) // and either its not coming from a page // or it is coming from a page and has no value || ((null != mPage) && (0 > mValueEnd)))); } /** * Predicate to determine if this attribute has a value. * @return <code>true</code> if this attribute has a value. * <code>false</code> if it is empty or standalone. */ public boolean isValued () { return ((null != super.getValue ()) // an explicit value provided // or it is coming from a page and has a non-empty value || ((null != mPage) && ((0 <= mValueStart) && (0 <= mValueEnd)) && (mValueStart != mValueEnd))); } /** * Get the length of the string value of this attribute. * @return The number of characters required to express this attribute. */ public int getLength () { String name; String assignment; String value; char quote; int ret; ret = 0; name = super.getName (); if (null != name) ret += name.length (); else if ((null != mPage) && (0 <= mNameStart) && (0 <= mNameEnd)) ret += mNameEnd - mNameStart; assignment = super.getAssignment (); if (null != assignment) ret += assignment.length (); else if ((null != mPage) && (0 <= mNameEnd) && (0 <= mValueStart)) ret += mValueStart - mNameEnd; value = super.getValue (); if (null != value) ret += value.length (); else if ((null != mPage) && (0 <= mValueStart) && (0 <= mValueEnd)) ret += mValueEnd - mValueStart; quote = getQuote (); if (0 != quote) ret += 2; return (ret); } } Index: Lexer.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/Lexer.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Lexer.java 24 May 2004 00:38:16 -0000 1.29 --- Lexer.java 24 May 2004 16:18:16 -0000 1.30 *************** *** 35,44 **** import org.htmlparser.Node; ! import org.htmlparser.AbstractNode; ! import org.htmlparser.lexer.nodes.PageAttribute; ! import org.htmlparser.lexer.nodes.NodeFactory; ! import org.htmlparser.RemarkNode; ! import org.htmlparser.StringNode; ! import org.htmlparser.lexer.nodes.TagNode; import org.htmlparser.util.ParserException; --- 35,45 ---- import org.htmlparser.Node; ! import org.htmlparser.NodeFactory; ! import org.htmlparser.Remark; ! import org.htmlparser.Text; ! import org.htmlparser.Tag; ! import org.htmlparser.nodes.RemarkNode; ! import org.htmlparser.nodes.TextNode; ! import org.htmlparser.nodes.TagNode; import org.htmlparser.util.ParserException; *************** *** 46,52 **** * This class parses the HTML stream into nodes. * There are three major types of nodes (lexemes): ! * <li>RemarkNode</li> ! * <li>StringNode</li> ! * <li>TagNode</li> * Each time <code>nextNode()</code> is called, another node is returned until * the stream is exhausted, and <code>null</code> is returned. --- 47,53 ---- * This class parses the HTML stream into nodes. * There are three major types of nodes (lexemes): ! * <li>Remark</li> ! * <li>Text</li> ! * <li>Tag</li> * Each time <code>nextNode()</code> is called, another node is returned until * the stream is exhausted, and <code>null</code> is returned. *************** *** 222,226 **** /** * Get the next node from the source. ! * @return A RemarkNode, StringNode or TagNode, or <code>null</code> if no * more lexemes are present. * @exception ParserException If there is a problem with the underlying page. --- 223,227 ---- /** * Get the next node from the source. ! * @return A Remark, Text or Tag, or <code>null</code> if no * more lexemes are present. * @exception ParserException If there is a problem with the underlying page. *************** *** 236,240 **** * Get the next node from the source. * @param quotesmart If <code>true</code>, strings ignore quoted contents. ! * @return A RemarkNode, StringNode or TagNode, or <code>null</code> if no * more lexemes are present. * @exception ParserException If there is a problem with the underlying page. --- 237,241 ---- * Get the next node from the source. * @param quotesmart If <code>true</code>, strings ignore quoted contents. ! * @return A Remark, Text or Tag, or <code>null</code> if no * more lexemes are present. * @exception ParserException If there is a problem with the underlying page. *************** *** 1080,1086 **** * @param end The ending positiong of the string. */ ! public Node createStringNode (Page page, int start, int end) { ! return (new StringNode (page, start, end)); } --- 1081,1087 ---- * @param end The ending positiong of the string. */ ! public Text createStringNode (Page page, int start, int end) { ! return (new TextNode (page, start, end)); } *************** *** 1091,1095 **** * @param end The ending positiong of the remark. */ ! public Node createRemarkNode (Page page, int start, int end) { return (new RemarkNode (page, start, end)); --- 1092,1096 ---- * @param end The ending positiong of the remark. */ ! public Remark createRemarkNode (Page page, int start, int end) { return (new RemarkNode (page, start, end)); *************** *** 1107,1111 **** * @param attributes The attributes contained in this tag. */ ! public Node createTagNode (Page page, int start, int end, Vector attributes) { return (new TagNode (page, start, end, attributes)); --- 1108,1112 ---- * @param attributes The attributes contained in this tag. */ ! public Tag createTagNode (Page page, int start, int end, Vector attributes) { return (new TagNode (page, start, end, attributes)); |
From: Derrick O. <der...@us...> - 2004-05-24 16:19:07
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexerapplications/thumbelina In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/lexerapplications/thumbelina Modified Files: Thumbelina.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: Thumbelina.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexerapplications/thumbelina/Thumbelina.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Thumbelina.java 16 May 2004 17:59:56 -0000 1.4 --- Thumbelina.java 24 May 2004 16:18:17 -0000 1.5 *************** *** 64,69 **** import org.htmlparser.Node; import org.htmlparser.lexer.Lexer; - import org.htmlparser.lexer.nodes.TagNode; import org.htmlparser.util.ParserException; --- 64,69 ---- import org.htmlparser.Node; + import org.htmlparser.Tag; import org.htmlparser.lexer.Lexer; import org.htmlparser.util.ParserException; *************** *** 769,776 **** boolean ina; // true when within a <A></A> pair Node node; ! TagNode tag; String name; ! TagNode startatag; ! TagNode imgtag; String href; String src; --- 769,776 ---- boolean ina; // true when within a <A></A> pair Node node; ! Tag tag; String name; ! Tag startatag; ! Tag imgtag; String href; String src; *************** *** 785,791 **** while (null != (node = lexer.nextNode ())) { ! if (node instanceof TagNode) { ! tag = (TagNode)node; name = tag.getTagName (); if ("A".equals (name)) --- 785,791 ---- while (null != (node = lexer.nextNode ())) { ! if (node instanceof Tag) { ! tag = (Tag)node; name = tag.getTagName (); if ("A".equals (name)) *************** *** 1454,1457 **** --- 1454,1464 ---- * * $Log$ + * Revision 1.5 2004/05/24 16:18:17 derrickoswald + * Part three of a multiphase refactoring. + * The three node types are now fronted by interfaces (program to the interface paradigm) + * with concrete implementations in the new htmlparser.nodes package. Classes from the + * lexer.nodes package are moved to this package, and obvious references to the concrete + * classes that got broken by this have been changed to use the interfaces where possible. + * * Revision 1.4 2004/05/16 17:59:56 derrickoswald * Alter bound property name constants to agree with section |
From: Derrick O. <der...@us...> - 2004-05-24 16:18:55
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser Modified Files: Parser.java PrototypicalNodeFactory.java StringNodeFactory.java Tag.java Added Files: Attribute.java NodeFactory.java Remark.java Text.java Removed Files: AbstractNode.java RemarkNode.java StringNode.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. --- StringNode.java DELETED --- --- NEW FILE: Remark.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2004 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/Remark.java,v $ // $Author: derrickoswald $ // $Date: 2004/05/24 16:18:12 $ // $Revision: 1.1 $ // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // package org.htmlparser; import org.htmlparser.Node; /** * This interface represents a comment in the HTML document. */ public interface Remark extends Node { /** * Returns the text contents of the comment tag. * @return The contents of the text inside the comment delimiters. */ public String getText(); /** * Sets the string contents of the node. * If the text has the remark delimiters (<!-- -->), these are stripped off. * @param text The new text for the node. */ public void setText (String text); // // Node interface // // public void accept (org.htmlparser.visitors.NodeVisitor visitor) // { // } // // public void collectInto (org.htmlparser.util.NodeList collectionList, NodeFilter filter) // { // } // // public int elementBegin () // { // } // // public int elementEnd () // { // } // // public org.htmlparser.util.NodeList getChildren () // { // } // // public int getEndPosition () // { // } // // public Node getParent () // { // } // // public int getStartPosition () // { // } // // public void setChildren (org.htmlparser.util.NodeList children) // { // } // // public void setEndPosition (int position) // { // } // // public void setParent (Node node) // { // } // // public void setStartPosition (int position) // { // } // // public String toHtml () // { // } // // public String toPlainTextString () // { // } } --- AbstractNode.java DELETED --- Index: Tag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/Tag.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Tag.java 22 May 2004 11:33:20 -0000 1.2 --- Tag.java 24 May 2004 16:18:12 -0000 1.3 *************** *** 28,32 **** import java.util.Vector; - import org.htmlparser.lexer.nodes.Attribute; /** --- 28,31 ---- --- NEW FILE: Text.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2004 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/Text.java,v $ // $Author: derrickoswald $ // $Date: 2004/05/24 16:18:12 $ // $Revision: 1.1 $ // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // package org.htmlparser; import org.htmlparser.Node; /** * This interface represents a piece of the content of the HTML document. */ public interface Text extends Node { /** * Accesses the textual contents of the node. * Returns the text of the node. */ public String getText (); /** * Sets the contents of the node. * @param text The new text for the node. */ public void setText (String text); // // Node interface // // public void accept (org.htmlparser.visitors.NodeVisitor visitor) // { // } // // public void collectInto (org.htmlparser.util.NodeList collectionList, NodeFilter filter) // { // } // // public void doSemanticAction () throws org.htmlparser.util.ParserException // { // } // // public int elementBegin () // { // } // // public int elementEnd () // { // } // // public org.htmlparser.util.NodeList getChildren () // { // } // // public int getEndPosition () // { // } // // public Node getParent () // { // } // // public int getStartPosition () // { // } // // public String getText () // { // } // // public void setChildren (org.htmlparser.util.NodeList children) // { // } // // public void setEndPosition (int position) // { // } // // public void setParent (Node node) // { // } // // public void setStartPosition (int position) // { // } // // public void setText (String text) // { // } // // public String toHtml () // { // } // // public String toPlainTextString () // { // } } --- RemarkNode.java DELETED --- Index: Parser.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/Parser.java,v retrieving revision 1.91 retrieving revision 1.92 diff -C2 -d -r1.91 -r1.92 *** Parser.java 22 May 2004 12:09:00 -0000 1.91 --- Parser.java 24 May 2004 16:18:12 -0000 1.92 *************** *** 41,45 **** import org.htmlparser.lexer.Lexer; import org.htmlparser.lexer.Page; - import org.htmlparser.lexer.nodes.NodeFactory; import org.htmlparser.util.DefaultParserFeedback; import org.htmlparser.util.IteratorImpl; --- 41,44 ---- --- NEW FILE: Attribute.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2004 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/Attribute.java,v $ // $Author: derrickoswald $ // $Date: 2004/05/24 16:18:12 $ // $Revision: 1.1 $ // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // package org.htmlparser; import java.io.Serializable; import org.htmlparser.lexer.Page; import org.htmlparser.util.Translate; /** * An attribute within a tag. * Holds the name, assignment string, value and quote character. * <p> * This class was made deliberately simple. Except for {@link #setRawValue RawValue}, * the properties are completely orthogonal, that is: each property is independant * of the others. This means you have enough rope here to hang yourself, and * it's very easy to create malformed HTML. Where it's obvious, warnings and * notes have been provided in the setters javadocs, but it is up to you -- the * programmer -- to ensure that the contents of the four fields will yield * valid HTML (if that's what you want). * <p> * Be especially mindful of quotes and assignment strings. These are handled * by the constructors where it's obvious, but in general, you need to set * them explicitly when building an attribute. For example to construct * the attribute <b><code>label="A multi word value."</code></b> you could use: * <pre> * attribute = new Attribute (); * attribute.setName ("label"); * attribute.setAssignment ("="); * attribute.setValue ("A multi word value."); * attribute.setQuote ('"'); * </pre> * or * <pre> * attribute = new Attribute (); * attribute.setName ("label"); * attribute.setAssignment ("="); * attribute.setRawValue ("A multi word value."); * </pre> * or * <pre> * attribute = new Attribute ("label", "A multi word value."); * </pre> * Note that the assignment value and quoting need to be set separately when * building the attribute from scratch using the properties. * <p> * <table width="100.0%" align="Center" border="1"> * <caption>Valid States for Attributes. * <tr> * <th align="Center">Description</th> * <th align="Center">toString()</th> * <th align="Center">Name</th> * <th align="Center">Assignment</th> * <th align="Center">Value</th> * <th align="Center">Quote</th> * </tr> * <tr> * <td align="Center">whitespace attribute</td> * <td align="Center">value</td> * <td align="Center"><code>null</code></td> * <td align="Center"><code>null</code></td> * <td align="Center">"value"</td> * <td align="Center"><code>0</code></td> * </tr> * <tr> * <td align="Center">standalone attribute</td> * <td align="Center">name</td> * <td align="Center">"name"</td> * <td align="Center"><code>null</code></td> * <td align="Center"><code>null</code></td> * <td align="Center"><code>0</code></td> * </tr> * <tr> * <td align="Center">empty attribute</td> * <td align="Center">name=</td> * <td align="Center">"name"</td> * <td align="Center">"="</td> * <td align="Center"><code>null</code></td> * <td align="Center"><code>0</code></td> * </tr> * <tr> * <td align="Center">empty single quoted attribute</td> * <td align="Center">name=''</td> * <td align="Center">"name"</td> * <td align="Center">"="</td> * <td align="Center"><code>null</code></td> * <td align="Center"><code>'</code></td> * </tr> * <tr> * <td align="Center">empty double quoted attribute</td> * <td align="Center">name=""</td> * <td align="Center">"name"</td> * <td align="Center">"="</td> * <td align="Center"><code>null</code></td> * <td align="Center"><code>"</code></td> * </tr> * <tr> * <td align="Center">naked attribute</td> * <td align="Center">name=value</td> * <td align="Center">"name"</td> * <td align="Center">"="</td> * <td align="Center">"value"</td> * <td align="Center"><code>0</code></td> * </tr> * <tr> * <td align="Center">single quoted attribute</td> * <td align="Center">name='value'</td> * <td align="Center">"name"</td> * <td align="Center">"="</td> * <td align="Center">"value"</td> * <td align="Center"><code>'</code></td> * </tr> * <tr> * <td align="Center">double quoted attribute</td> * <td align="Center">name="value"</td> * <td align="Center">"name"</td> * <td align="Center">"="</td> * <td align="Center">"value"</td> * <td align="Center"><code>"</code></td> * </tr> * </table> * <br>In words: * <br>If Name is null, and Assignment is null, and Quote is zero, it is whitepace and Value has the whitespace text -- value * <br>If Name is not null, and both Assignment and Value are null it's a standalone attribute -- name * <br>If Name is not null, and Assignment is an equals sign, and Quote is zero it's an empty attribute -- name= * <br>If Name is not null, and Assignment is an equals sign, and Value is "" or null, and Quote is ' it's an empty single quoted attribute -- name='' * <br>If Name is not null, and Assignment is an equals sign, and Value is "" or null, and Quote is " it's an empty double quoted attribute -- name="" * <br>If Name is not null, and Assignment is an equals sign, and Value is something, and Quote is zero it's a naked attribute -- name=value * <br>If Name is not null, and Assignment is an equals sign, and Value is something, and Quote is ' it's a single quoted attribute -- name='value' * <br>If Name is not null, and Assignment is an equals sign, and Value is something, and Quote is " it's a double quoted attribute -- name="value" * <br>All other states are invalid HTML. * <p> * From the <a href="http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2"> * HTML 4.01 Specification, W3C Recommendation 24 December 1999</a> * http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2:<p> * <cite> * 3.2.2 Attributes<p> * Elements may have associated properties, called attributes, which may * have values (by default, or set by authors or scripts). Attribute/value * pairs appear before the final ">" of an element's start tag. Any number * of (legal) attribute value pairs, separated by spaces, may appear in an * element's start tag. They may appear in any order.<p> * In this example, the id attribute is set for an H1 element: * <code> * <H1 id="section1"> * </code> * This is an identified heading thanks to the id attribute * <code> * </H1> * </code> * By default, SGML requires that all attribute values be delimited using * either double quotation marks (ASCII decimal 34) or single quotation * marks (ASCII decimal 39). Single quote marks can be included within the * attribute value when the value is delimited by double quote marks, and * vice versa. Authors may also use numeric character references to * represent double quotes (&#34;) and single quotes (&#39;). * For doublequotes authors can also use the character entity reference &quot;.<p> * In certain cases, authors may specify the value of an attribute without * any quotation marks. The attribute value may only contain letters * (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), * periods (ASCII decimal 46), underscores (ASCII decimal 95), * and colons (ASCII decimal 58). We recommend using quotation marks even * when it is possible to eliminate them.<p> * Attribute names are always case-insensitive.<p> * Attribute values are generally case-insensitive. The definition of each * attribute in the reference manual indicates whether its value is case-insensitive.<p> * All the attributes defined by this specification are listed in the attribute index.<p> * </cite> * <p> */ public class Attribute implements Serializable { /** * The name of this attribute. * The part before the equals sign, or the stand-alone attribute. * This will be <code>null</code> if the attribute is whitespace. */ protected String mName; /** * The assignment string of the attribute. * The equals sign. * This will be <code>null</code> if the attribute is a * stand-alone attribute. */ protected String mAssignment; /** * The value of the attribute. * The part after the equals sign. * This will be <code>null</code> if the attribute is an empty or * stand-alone attribute. */ protected String mValue; /** * The quote, if any, surrounding the value of the attribute, if any. * This will be zero if there are no quotes around the value. */ protected char mQuote; /** * Create an attribute with the name, assignment string, value and quote given. * If the quote value is zero, assigns the value using {@link #setRawValue} * which sets the quote character to a proper value if necessary. * @param name The name of this attribute. * @param assignment The assignment string of this attribute. * @param value The value of this attribute. * @param quote The quote around the value of this attribute. */ public Attribute (String name, String assignment, String value, char quote) { setName (name); setAssignment (assignment); if (0 == quote) setRawValue (value); else { setValue (value); setQuote (quote); } } /** * Create an attribute with the name, value and quote given. * Uses an equals sign as the assignment string if the value is not * <code>null</code>, and calls {@link #setRawValue} to get the * correct quoting if <code>quote</code> is zero. * @param name The name of this attribute. * @param value The value of this attribute. * @param quote The quote around the value of this attribute. */ public Attribute (String name, String value, char quote) { this (name, (null == value ? "" : "="), value, quote); } /** * Create a whitespace attribute with the value given. * @param value The value of this attribute. * @exception IllegalArgumentException if the value contains other than * whitespace. To set a real value use {@link #Attribute(String,String)}. */ public Attribute (String value) { if (0 != value.trim ().length ()) throw new IllegalArgumentException ("non whitespace value"); else { setName (null); setAssignment (null); setValue (value); setQuote ((char)0); } } /** * Create an attribute with the name and value given. * Uses an equals sign as the assignment string if the value is not * <code>null</code>, and calls {@link #setRawValue} to get the * correct quoting. * @param name The name of this attribute. * @param value The value of this attribute. */ public Attribute (String name, String value) { this (name, (null == value ? "" : "="), value, (char)0); } /** * Create an attribute with the name, assignment string and value given. * Calls {@link #setRawValue} to get the correct quoting. * @param name The name of this attribute. * @param assignment The assignment string of this attribute. * @param value The value of this attribute. */ public Attribute (String name, String assignment, String value) { this (name, assignment, value, (char)0); } /** * Create an empty attribute. * This will provide "" from the {@link #toString} and * {@link #toString(StringBuffer)} methods. */ public Attribute () { this (null, null, null, (char)0); } /** * Get the name of this attribute. * The part before the equals sign, or the contents of the * stand-alone attribute. * @return The name, or <code>null</code> if it's just a whitepace * 'attribute'. */ public String getName () { return (mName); } /** * Get the name of this attribute. * @param buffer The buffer to place the name in. * @see #getName() */ public void getName (StringBuffer buffer) { if (null != mName) buffer.append (mName); } /** * Set the name of this attribute. * Set the part before the equals sign, or the contents of the * stand-alone attribute. * <em>WARNING:</em> Setting this to <code>null</code> can result in * malformed HTML if the assignment string is not <code>null</code>. * @param name The new name. */ public void setName (String name) { mName = name; } /** * Get the assignment string of this attribute. * This is usually just an equals sign, but in poorly formed attributes it * can include whitespace on either or both sides of an equals sign. * @return The assignment string. */ public String getAssignment () { return (mAssignment); } /** * Get the assignment string of this attribute. * @param buffer The buffer to place the assignment string in. * @see #getAssignment() */ public void getAssignment (StringBuffer buffer) { if (null != mAssignment) buffer.append (mAssignment); } /** * Set the assignment string of this attribute. * <em>WARNING:</em> Setting this property to other than an equals sign * or <code>null</code> will result in malformed HTML. In the case of a * <code>null</code>, the {@link #setValue value} should also be set to * <code>null</code>. * @param assignment The new assignment string. */ public void setAssignment (String assignment) { mAssignment = assignment; } /** * Get the value of the attribute. * The part after the equals sign, or the text if it's just a whitepace * 'attribute'. * <em>NOTE:</em> This does not include any quotes that may have enclosed * the value when it was read. To get the un-stripped value use * {@link #getRawValue}. * @return The value, or <code>null</code> if it's a stand-alone or * empty attribute, or the text if it's just a whitepace 'attribute'. */ public String getValue () { return (mValue); } /** * Get the value of the attribute. * @param buffer The buffer to place the value in. * @see #getValue() */ public void getValue (StringBuffer buffer) { if (null != mValue) buffer.append (mValue); } /** * Set the value of the attribute. * The part after the equals sign, or the text if it's a whitepace * 'attribute'. * <em>WARNING:</em> Setting this property to a value that needs to be * quoted without also setting the quote character will result in malformed * HTML. * @param value The new value. */ public void setValue (String value) { mValue = value; } /** * Get the quote, if any, surrounding the value of the attribute, if any. * @return Either ' or " if the attribute value was quoted, or zero * if there are no quotes around it. */ public char getQuote () { return (mQuote); } /** * Get the quote, if any, surrounding the value of the attribute, if any. * @param buffer The buffer to place the quote in. * @see #getQuote() */ public void getQuote (StringBuffer buffer) { if (0 != mQuote) buffer.append (mQuote); } /** * Set the quote surrounding the value of the attribute. * <em>WARNING:</em> Setting this property to zero will result in malformed * HTML if the {@link #getValue value} needs to be quoted (i.e. contains * whitespace). * @param quote The new quote value. */ public void setQuote (char quote) { mQuote = quote; } /** * Get the raw value of the attribute. * The part after the equals sign, or the text if it's just a whitepace * 'attribute'. This includes the quotes around the value if any. * @return The value, or <code>null</code> if it's a stand-alone attribute, * or the text if it's just a whitepace 'attribute'. */ public String getRawValue () { char quote; StringBuffer buffer; String ret; if (isValued ()) { quote = getQuote (); if (0 != quote) { buffer = new StringBuffer (); // todo: can we get the value length? buffer.append (quote); getValue (buffer); buffer.append (quote); ret = buffer.toString (); } else ret = getValue (); } else ret = null; return (ret); } /** * Get the raw value of the attribute. * The part after the equals sign, or the text if it's just a whitepace * 'attribute'. This includes the quotes around the value if any. * @return The value, or <code>null</code> if it's a stand-alone attribute, * or the text if it's just a whitepace 'attribute'. * @see #getRawValue() */ public void getRawValue (StringBuffer buffer) { getQuote (buffer); getValue (buffer); getQuote (buffer); } /** * Set the value of the attribute and the quote character. * If the value is pure whitespace, assign it 'as is' and reset the * quote character. If not, check for leading and trailing double or * single quotes, and if found use this as the quote character and * the inner contents of <code>value</code> as the real value. * Otherwise, examine the string to determine if quotes are needed * and an appropriate quote character if so. This may involve changing * double quotes within the string to character references. * @param value The new value. */ public void setRawValue (String value) { char ch; boolean needed; boolean singleq; boolean doubleq; String ref; StringBuffer buffer; char quote; quote = 0; if ((null != value) && (0 != value.trim ().length ())) { if (value.startsWith ("'") && value.endsWith ("'") && (2 <= value.length ())) { quote = '\''; value = value.substring (1, value.length () - 1); } else if (value.startsWith ("\"") && value.endsWith ("\"") && (2 <= value.length ())) { quote = '"'; value = value.substring (1, value.length () - 1); } else { // first determine if there's whitespace in the value // and while we're at it find a suitable quote character needed = false; singleq = true; doubleq = true; for (int i = 0; i < value.length (); i++) { ch = value.charAt (i); if ('\'' == ch) { singleq = false; needed = true; } else if ('"' == ch) { doubleq = false; needed = true; } else if (!('-' == ch) && !('.' == ch) && !('_' == ch) && !(':' == ch) && !Character.isLetterOrDigit (ch)) { needed = true; } } // now apply quoting if (needed) { if (doubleq) quote = '"'; else if (singleq) quote = '\''; else { // uh-oh, we need to convert some quotes into character // references, so convert all double quotes into " quote = '"'; ref = """; // Translate.encode (quote); // JDK 1.4: value = value.replaceAll ("\"", ref); buffer = new StringBuffer (value.length() * 5); for (int i = 0; i < value.length (); i++) { ch = value.charAt (i); if (quote == ch) buffer.append (ref); else buffer.append (ch); } value = buffer.toString (); } } } } setValue (value); setQuote (quote); } /** * Predicate to determine if this attribute is whitespace. * @return <code>true</code> if this attribute is whitespace, * <code>false</code> if it is a real attribute. */ public boolean isWhitespace () { return (null == getName ()); } /** * Predicate to determine if this attribute has no equals sign (or value). * @return <code>true</code> if this attribute is a standalone attribute. * <code>false</code> if has an equals sign. */ public boolean isStandAlone () { return ((null != getName ()) && (null == getAssignment ())); } /** * Predicate to determine if this attribute has an equals sign but no value. * @return <code>true</code> if this attribute is an empty attribute. * <code>false</code> if has an equals sign and a value. */ public boolean isEmpty () { return ((null != getAssignment ()) && (null == getValue ())); } /** * Predicate to determine if this attribute has a value. * @return <code>true</code> if this attribute has a value. * <code>false</code> if it is empty or standalone. */ public boolean isValued () { return (null != getValue ()); } /** * Get the length of the string value of this attribute. * @return The number of characters required to express this attribute. */ public int getLength () { String name; String assignment; String value; char quote; int ret; ret = 0; name = getName (); if (null != name) ret += name.length (); assignment = getAssignment (); if (null != assignment) ret += assignment.length (); value = getValue (); if (null != value) ret += value.length (); quote = getQuote (); if (0 != quote) ret += 2; return (ret); } /** * Get a text representation of this attribute. * Suitable for insertion into a tag, the output is one of * the forms: * <code> * <pre> * value * name * name= * name=value * name='value' * name="value" * </pre> * </code> * @return A string that can be used within a tag. */ public String toString () { String name; String assignment; String value; char quote; int length; StringBuffer ret; // get the size to avoid extra StringBuffer allocations length = getLength (); ret = new StringBuffer (length); toString (ret); return (ret.toString ()); } /** * Get a text representation of this attribute. * @param buffer The accumulator for placing the text into. * @see #toString() */ public void toString (StringBuffer buffer) { getName (buffer); getAssignment (buffer); getRawValue (buffer); } } Index: StringNodeFactory.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/StringNodeFactory.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** StringNodeFactory.java 2 Jan 2004 16:24:52 -0000 1.11 --- StringNodeFactory.java 24 May 2004 16:18:12 -0000 1.12 *************** *** 76,82 **** * @param end The ending positiong of the string. */ ! public Node createStringNode (Page page, int start, int end) { ! Node ret; ret = super.createStringNode (page, start, end); --- 76,82 ---- * @param end The ending positiong of the string. */ ! public Text createStringNode (Page page, int start, int end) { ! Text ret; ret = super.createStringNode (page, start, end); --- NEW FILE: NodeFactory.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2003 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/NodeFactory.java,v $ // $Author: derrickoswald $ // $Date: 2004/05/24 16:18:12 $ // $Revision: 1.1 $ // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // package org.htmlparser; import java.util.Vector; import org.htmlparser.Remark; import org.htmlparser.Tag; import org.htmlparser.Text; import org.htmlparser.lexer.Page; import org.htmlparser.util.ParserException; /** * This interface defines the methods needed to create new nodes. * The factory is used when lexing to generate the nodes passed * back to the caller. */ public interface NodeFactory { /** * Create a new string node. * @param page The page the node is on. * @param start The beginning position of the string. * @param end The ending positiong of the string. */ public Text createStringNode (Page page, int start, int end) throws ParserException; /** * Create a new remark node. * @param page The page the node is on. * @param start The beginning position of the remark. * @param end The ending positiong of the remark. */ public Remark createRemarkNode (Page page, int start, int end) throws ParserException; /** * Create a new tag node. * Note that the attributes vector contains at least one element, * which is the tag name (standalone attribute) at position zero. * This can be used to decide which type of node to create, or * gate other processing that may be appropriate. * @param page The page the node is on. * @param start The beginning position of the tag. * @param end The ending positiong of the tag. * @param attributes The attributes contained in this tag. */ public Tag createTagNode (Page page, int start, int end, Vector attributes) throws ParserException; } Index: PrototypicalNodeFactory.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/PrototypicalNodeFactory.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PrototypicalNodeFactory.java 20 Mar 2004 17:03:53 -0000 1.6 --- PrototypicalNodeFactory.java 24 May 2004 16:18:12 -0000 1.7 *************** *** 33,39 **** import java.util.Vector; import org.htmlparser.lexer.Page; ! import org.htmlparser.lexer.nodes.Attribute; ! import org.htmlparser.lexer.nodes.NodeFactory; import org.htmlparser.tags.AppletTag; import org.htmlparser.tags.BaseHrefTag; --- 33,44 ---- import java.util.Vector; + import org.htmlparser.Attribute; + import org.htmlparser.NodeFactory; + import org.htmlparser.Remark; + import org.htmlparser.Tag; + import org.htmlparser.Text; import org.htmlparser.lexer.Page; ! import org.htmlparser.nodes.TextNode; ! import org.htmlparser.nodes.RemarkNode; import org.htmlparser.tags.AppletTag; import org.htmlparser.tags.BaseHrefTag; *************** *** 63,67 **** import org.htmlparser.tags.TableRow; import org.htmlparser.tags.TableTag; - import org.htmlparser.tags.Tag; import org.htmlparser.tags.TextareaTag; import org.htmlparser.tags.TitleTag; --- 68,71 ---- *************** *** 106,110 **** * Create a new factory with the given tag as the only one registered. */ ! public PrototypicalNodeFactory (Tag tag) { this (true); --- 110,114 ---- * Create a new factory with the given tag as the only one registered. */ ! public PrototypicalNodeFactory (org.htmlparser.tags.Tag tag) { this (true); *************** *** 115,119 **** * Create a new factory with the given tags registered. */ ! public PrototypicalNodeFactory (Tag[] tags) { this (true); --- 119,123 ---- * Create a new factory with the given tags registered. */ ! public PrototypicalNodeFactory (org.htmlparser.tags.Tag[] tags) { this (true); *************** *** 129,133 **** * or <code>null</code> if none. */ ! public Tag put (String id, Tag tag) { return ((Tag)mBlastocyst.put (id, tag)); --- 133,137 ---- * or <code>null</code> if none. */ ! public Tag put (String id, org.htmlparser.tags.Tag tag) { return ((Tag)mBlastocyst.put (id, tag)); *************** *** 139,145 **** * @return The tag registered under the id name or <code>null</code> if none. */ ! public Tag get (String id) { ! return ((Tag)mBlastocyst.get (id)); } --- 143,149 ---- * @return The tag registered under the id name or <code>null</code> if none. */ ! public org.htmlparser.tags.Tag get (String id) { ! return ((org.htmlparser.tags.Tag)mBlastocyst.get (id)); } *************** *** 149,155 **** * @return The tag that was registered with that id. */ ! public Tag remove (String id) { ! return ((Tag)mBlastocyst.remove (id)); } --- 153,159 ---- * @return The tag that was registered with that id. */ ! public org.htmlparser.tags.Tag remove (String id) { ! return ((org.htmlparser.tags.Tag)mBlastocyst.remove (id)); } *************** *** 163,167 **** ! public void registerTag (Tag tag) { String ids[]; --- 167,171 ---- ! public void registerTag (org.htmlparser.tags.Tag tag) { String ids[]; *************** *** 172,176 **** } ! public void unregisterTag (Tag tag) { String ids[]; --- 176,180 ---- } ! public void unregisterTag (org.htmlparser.tags.Tag tag) { String ids[]; *************** *** 226,236 **** * @param end The ending positiong of the string. */ ! public Node createStringNode (Page page, int start, int end) { ! Node ret; ! ! ret = new StringNode (page, start, end); ! ! return (ret); } --- 230,236 ---- * @param end The ending positiong of the string. */ ! public Text createStringNode (Page page, int start, int end) { ! return (new TextNode (page, start, end)); } *************** *** 241,245 **** * @param end The ending positiong of the remark. */ ! public Node createRemarkNode (Page page, int start, int end) { return (new RemarkNode (page, start, end)); --- 241,245 ---- * @param end The ending positiong of the remark. */ ! public Remark createRemarkNode (Page page, int start, int end) { return (new RemarkNode (page, start, end)); *************** *** 257,261 **** * @param attributes The attributes contained in this tag. */ ! public Node createTagNode (Page page, int start, int end, Vector attributes) throws ParserException --- 257,261 ---- * @param attributes The attributes contained in this tag. */ ! public Tag createTagNode (Page page, int start, int end, Vector attributes) throws ParserException *************** *** 263,268 **** Attribute attribute; String id; ! Tag prototype; ! Tag ret; ret = null; --- 263,268 ---- Attribute attribute; String id; ! org.htmlparser.tags.Tag prototype; ! org.htmlparser.tags.Tag ret; ret = null; *************** *** 281,288 **** if (id.endsWith ("/")) id = id.substring (0, id.length () - 1); ! prototype = (Tag)mBlastocyst.get (id); if (null != prototype) { ! ret = (Tag)prototype.clone (); ret.setPage (page); ret.setStartPosition (start); --- 281,288 ---- if (id.endsWith ("/")) id = id.substring (0, id.length () - 1); ! prototype = (org.htmlparser.tags.Tag)mBlastocyst.get (id); if (null != prototype) { ! ret = (org.htmlparser.tags.Tag)prototype.clone (); ret.setPage (page); ret.setStartPosition (start); *************** *** 299,303 **** } if (null == ret) ! ret = new Tag (page, start, end, attributes); return (ret); --- 299,303 ---- } if (null == ret) ! ret = new org.htmlparser.tags.Tag (page, start, end, attributes); return (ret); |
From: Derrick O. <der...@us...> - 2004-05-24 16:18:55
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19028/src/org/htmlparser/filters Modified Files: HasAttributeFilter.java StringFilter.java TagNameFilter.java Log Message: Part three of a multiphase refactoring. The three node types are now fronted by interfaces (program to the interface paradigm) with concrete implementations in the new htmlparser.nodes package. Classes from the lexer.nodes package are moved to this package, and obvious references to the concrete classes that got broken by this have been changed to use the interfaces where possible. Index: TagNameFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/TagNameFilter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TagNameFilter.java 25 Jan 2004 21:32:58 -0000 1.2 --- TagNameFilter.java 24 May 2004 16:18:13 -0000 1.3 *************** *** 31,35 **** import org.htmlparser.Node; import org.htmlparser.NodeFilter; ! import org.htmlparser.lexer.nodes.TagNode; /** --- 31,35 ---- import org.htmlparser.Node; import org.htmlparser.NodeFilter; ! import org.htmlparser.Tag; /** *************** *** 62,68 **** public boolean accept (Node node) { ! return ((node instanceof TagNode) && ! !((TagNode)node).isEndTag () && ! ((TagNode)node).getTagName ().equals (mName)); } } --- 62,68 ---- 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.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** HasAttributeFilter.java 25 Jan 2004 21:32:57 -0000 1.3 --- HasAttributeFilter.java 24 May 2004 16:18:13 -0000 1.4 *************** *** 29,36 **** import java.util.Locale; import org.htmlparser.Node; import org.htmlparser.NodeFilter; ! import org.htmlparser.lexer.nodes.Attribute; ! import org.htmlparser.lexer.nodes.TagNode; /** --- 29,36 ---- import java.util.Locale; + import org.htmlparser.Attribute; import org.htmlparser.Node; import org.htmlparser.NodeFilter; ! import org.htmlparser.Tag; /** *************** *** 75,86 **** public boolean accept (Node node) { ! TagNode tag; Attribute attribute; boolean ret; ret = false; ! if (node instanceof TagNode) { ! tag = (TagNode)node; attribute = tag.getAttributeEx (mAttribute); ret = null != attribute; --- 75,86 ---- public boolean accept (Node node) { ! Tag tag; Attribute attribute; boolean ret; ret = false; ! if (node instanceof Tag) { ! tag = (Tag)node; attribute = tag.getAttributeEx (mAttribute); ret = null != attribute; Index: StringFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/StringFilter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** StringFilter.java 24 May 2004 00:38:16 -0000 1.3 --- StringFilter.java 24 May 2004 16:18:13 -0000 1.4 *************** *** 31,35 **** import org.htmlparser.Node; import org.htmlparser.NodeFilter; ! import org.htmlparser.StringNode; /** --- 31,35 ---- import org.htmlparser.Node; import org.htmlparser.NodeFilter; ! import org.htmlparser.Text; /** *************** *** 102,108 **** ret = false; ! if (node instanceof StringNode) { ! string = ((StringNode)node).getText (); if (!mCaseSensitive) string = string.toUpperCase (mLocale); --- 102,108 ---- ret = false; ! if (node instanceof Text) { ! string = ((Text)node).getText (); if (!mCaseSensitive) string = string.toUpperCase (mLocale); |