[Htmlparser-cvs] htmlparser/src/org/htmlparser/filters HasParentFilter.java,NONE,1.1 IsEqualFilter.j
Brought to you by:
derrickoswald
From: <der...@pr...> - 2004-01-27 14:31:36
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23128/filters Modified Files: HasChildFilter.java Added Files: HasParentFilter.java IsEqualFilter.java Log Message: Fix bug #882940 empty applet tag contents causes NullPointerException Also found and fixed other similar problems where getChildren() could return null. Then changed table row and column handling to handle rows and columns embedded within other tags. --- NEW FILE: HasParentFilter.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/filters/HasParentFilter.java,v $ // $Author: derrickoswald $ // $Date: 2004/01/24 23:57:49 $ // $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 org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.tags.Tag; import org.htmlparser.util.NodeList; /** * This class accepts all tags that have a parent acceptable to the filter. */ public class HasParentFilter implements NodeFilter { /** * The filter to apply to children. */ public NodeFilter mFilter; /** * Creates a new instance of HasParentFilter that accepts tags with parent acceptable to the filter. * @param filter The filter to apply to the parent. */ public HasParentFilter (NodeFilter filter) { mFilter = filter; } /** * Accept tags with parent acceptable to the filter. * @param node The node to check. */ public boolean accept (Node node) { Node parent; NodeList children; boolean ret; ret = false; parent = node.getParent (); if (null != parent) ret = mFilter.accept (parent); return (ret); } } --- NEW FILE: IsEqualFilter.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/filters/IsEqualFilter.java,v $ // $Author: derrickoswald $ // $Date: 2004/01/24 23:57:50 $ // $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 org.htmlparser.Node; import org.htmlparser.NodeFilter; /** * This class accepts only one specific node. */ public class IsEqualFilter implements NodeFilter { /** * The node to match. */ public Node mNode; /** * Creates a new instance of an IsEqualFilter that accepts only the node provided. * @param node The node to match. */ public IsEqualFilter (Node node) { mNode = node; } /** * Accept the node. * @param node The node to check. * @return <code>false</code> unless <code>node</code> is the one and only. */ public boolean accept (Node node) { return (mNode == node); } } Index: HasChildFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/HasChildFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** HasChildFilter.java 8 Nov 2003 21:30:58 -0000 1.1 --- HasChildFilter.java 24 Jan 2004 23:57:48 -0000 1.2 *************** *** 69,78 **** tag = (CompositeTag)node; children = tag.getChildren (); ! for (int i = 0; i < children.size (); i++) ! if (mFilter.accept (children.elementAt (i))) ! { ! ret = true; ! break; ! } } --- 69,79 ---- tag = (CompositeTag)node; children = tag.getChildren (); ! if (null != children) ! for (int i = 0; i < children.size (); i++) ! if (mFilter.accept (children.elementAt (i))) ! { ! ret = true; ! break; ! } } |