htmlparser-cvs Mailing List for HTML Parser (Page 10)
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...> - 2005-02-13 20:43:22
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/layouts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12396/src/org/htmlparser/parserapplications/filterbuilder/layouts Added Files: NullLayoutManager.java VerticalLayoutManager.java Log Message: FilterBuilder --- NEW FILE: NullLayoutManager.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/layouts/NullLayoutManager.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:13 $ // $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.parserapplications.filterbuilder.layouts; import java.awt.*; import java.io.*; /** * A layout manager that doesn't move things around. * Attempts to set the bounds of components to accomodate them * but doesn't move them. */ public class NullLayoutManager implements LayoutManager2, Serializable { /** * Constructs a NullLayoutManager object. */ public NullLayoutManager () { } /** * Calculates the minimum size dimensions for the specified * panel given the components in the specified parent container. * @param target The component to be laid out. * @see #preferredLayoutSize */ public Dimension minimumLayoutSize (Container target) { return (preferredLayoutSize (target)); } /** * Calculates the preferred size dimensions for the specified * panel given the components in the specified parent container. * @param target The component to be laid out. * @see #minimumLayoutSize */ public Dimension preferredLayoutSize (Container target) { int count; Container parent; Component component; Point point; Dimension dimension; Insets insets; Dimension ret; synchronized (target.getTreeLock ()) { count = target.getComponentCount (); if (0 == count) { // be the same size unless we have a parent ret = target.getSize (); parent = target.getParent (); if (null != parent) { insets = parent.getInsets (); ret = parent.getSize (); ret.setSize ( ret.width - insets.left - insets.right, ret.height - insets.top - insets.bottom); } } else { ret = new Dimension (0, 0); for (int i = 0 ; i < count ; i++) { component = target.getComponent (i); if (component.isVisible ()) { point = component.getLocation (); dimension = component.getPreferredSize(); ret.width = Math.max (ret.width, point.x + dimension.width); ret.height = Math.max (ret.height, point.y + dimension.height); } } insets = target.getInsets (); ret.width += insets.left + insets.right; ret.height += insets.top + insets.bottom; } } return (ret); } /** * Returns the maximum size of this component. * @param target The component to be laid out. * @see java.awt.Component#getMinimumSize * @see java.awt.Component#getPreferredSize * @see java.awt.LayoutManager */ public Dimension maximumLayoutSize (Container target) { return (preferredLayoutSize (target)); } // // LayoutManager Interface // /** * Adds the specified component with the specified name to * the layout. * @param name the component name * @param comp the component to be added */ public void addLayoutComponent (String name, Component comp) { } /** * Removes the specified component from the layout. * @param comp the component ot be removed */ public void removeLayoutComponent (Component comp) { } /** * Lays out the container. * @param target The container which needs to be laid out. */ public void layoutContainer (Container target) { int count; Component component; Dimension dimension; synchronized (target.getTreeLock ()) { count = target.getComponentCount (); for (int i = 0 ; i < count ; i++) { component = target.getComponent (i); if (component.isVisible ()) { dimension = component.getPreferredSize(); component.setSize (dimension.width, dimension.height); } } } } // // LayoutManager2 Interface // /** * Adds the specified component to the layout, using the specified * constraint object. * @param comp the component to be added * @param constraints where/how the component is added to the layout. */ public void addLayoutComponent (Component comp, Object constraints) { } /** * Returns the alignment along the x axis. This specifies how * the component would like to be aligned relative to other * components. The value should be a number between 0 and 1 * where 0 represents alignment along the origin, 1 is aligned * the furthest away from the origin, 0.5 is centered, etc. * @param target The target container. */ public float getLayoutAlignmentX (Container target) { return (0.0f); } /** * Returns the alignment along the y axis. This specifies how * the component would like to be aligned relative to other * components. The value should be a number between 0 and 1 * where 0 represents alignment along the origin, 1 is aligned * the furthest away from the origin, 0.5 is centered, etc. * @param target The target container. */ public float getLayoutAlignmentY (Container target) { return (0.0f); } /** * Invalidates the layout, indicating that if the layout manager * has cached information it should be discarded. * @param target The target container. */ public void invalidateLayout (Container target) { } } --- NEW FILE: VerticalLayoutManager.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/layouts/VerticalLayoutManager.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:13 $ // $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.parserapplications.filterbuilder.layouts; import java.awt.*; import java.io.*; /** * A layout manager like a vertical FlowLayout. * Stacks components vertically like GridLayout(0,1) but doesn't * resize each component equally. More like a vertical FlowLayout * but doesn't snake columns or align things. */ public class VerticalLayoutManager implements LayoutManager2, Serializable { /** * Constructs a VerticalLayoutManager object. */ public VerticalLayoutManager () { } /** * Calculates the minimum size dimensions for the specified * panel given the components in the specified parent container. * @param target The component to be laid out. * @see #preferredLayoutSize */ public Dimension minimumLayoutSize (Container target) { return (preferredLayoutSize (target)); } /** * Calculates the preferred size dimensions for the specified * panel given the components in the specified parent container. * @param target The component to be laid out. * @see #minimumLayoutSize */ public Dimension preferredLayoutSize (Container target) { int count; Component component; Dimension dimension; Insets insets; Dimension ret; synchronized (target.getTreeLock ()) { // get the the total height and maximum width component ret = new Dimension (0, 0); count = target.getComponentCount (); for (int i = 0 ; i < count ; i++) { component = target.getComponent (i); if (component.isVisible ()) { dimension = component.getPreferredSize (); ret.width = Math.max (ret.width, dimension.width); ret.height += dimension.height; } } insets = target.getInsets (); ret.width += insets.left + insets.right; ret.height += insets.top + insets.bottom; } return (ret); } /** * Returns the maximum size of this component. * @param target The component to be laid out. * @see java.awt.Component#getMinimumSize * @see java.awt.Component#getPreferredSize * @see java.awt.LayoutManager */ public Dimension maximumLayoutSize (Container target) { return (preferredLayoutSize (target)); } // // LayoutManager Interface // /** * Adds the specified component with the specified name to * the layout. * @param name the component name * @param comp the component to be added */ public void addLayoutComponent (String name, Component comp) { } /** * Removes the specified component from the layout. * @param comp the component ot be removed */ public void removeLayoutComponent (Component comp) { } /** * Lays out the container. * @param target The container which needs to be laid out. */ public void layoutContainer (Container target) { Insets insets; int x; int y; int count; int width; Component component; Dimension dimension; synchronized (target.getTreeLock ()) { insets = target.getInsets (); x = insets.left; y = insets.top; count = target.getComponentCount (); width = 0; for (int i = 0 ; i < count ; i++) { component = target.getComponent (i); if (component.isVisible ()) { dimension = component.getPreferredSize (); width = Math.max (width, dimension.width); component.setSize (dimension.width, dimension.height); component.setLocation (x, y); y += dimension.height; } } // now set them all to the same width for (int i = 0 ; i < count ; i++) { component = target.getComponent (i); if (component.isVisible ()) { dimension = component.getSize (); dimension.width = width; component.setSize (dimension.width, dimension.height); } } } } // // LayoutManager2 Interface // /** * Adds the specified component to the layout, using the specified * constraint object. * @param comp the component to be added * @param constraints where/how the component is added to the layout. */ public void addLayoutComponent (Component comp, Object constraints) { } /** * Returns the alignment along the x axis. This specifies how * the component would like to be aligned relative to other * components. The value should be a number between 0 and 1 * where 0 represents alignment along the origin, 1 is aligned * the furthest away from the origin, 0.5 is centered, etc. * @param target The target container. */ public float getLayoutAlignmentX (Container target) { return (0.0f); } /** * Returns the alignment along the y axis. This specifies how * the component would like to be aligned relative to other * components. The value should be a number between 0 and 1 * where 0 represents alignment along the origin, 1 is aligned * the furthest away from the origin, 0.5 is centered, etc. * @param target The target container. */ public float getLayoutAlignmentY (Container target) { return (0.0f); } /** * Invalidates the layout, indicating that if the layout manager * has cached information it should be discarded. * @param target The target container. */ public void invalidateLayout (Container target) { } } |
From: Derrick O. <der...@us...> - 2005-02-13 20:43:21
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/images/.xvpics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12396/src/org/htmlparser/parserapplications/filterbuilder/images/.xvpics Added Files: delete.gif cut.gif copy.gif Log Message: FilterBuilder --- NEW FILE: cut.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: copy.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: delete.gif --- (This appears to be a binary file; contents omitted.) |
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12396/src/org/htmlparser/parserapplications/filterbuilder Added Files: SubFilterList.java HtmlTreeCellRenderer.java Filter.java HtmlTreeModel.java FilterBuilder.java Log Message: FilterBuilder --- NEW FILE: SubFilterList.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/SubFilterList.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder; import java.awt.*; import javax.swing.*; import javax.swing.border.*; import org.htmlparser.NodeFilter; import org.htmlparser.parserapplications.filterbuilder.layouts.VerticalLayoutManager; public class SubFilterList extends JPanel { protected int mExtra = 25; // for now protected Component mSpacer; protected Filter mHome; protected String mTitle; protected int mMax; /** * Creates a container panel. * Set the panel minimum size to the same width as the container * but with a bit of extra length. * @param home The filter we belong to. * @param title The border title. * @param max The maximum number of filters in the list (0 for no limit). */ public SubFilterList (Filter home, String title, int max) { mHome = home; mTitle = title; mMax = max; // not quite: // new BoxLayout (this, BoxLayout.Y_AXIS)); setLayout (new VerticalLayoutManager ()); addSpacer (); setSelected (false); } /** * Set the 'selected look' for the component. * @param selected If <code>true</code>, 'select' this component, * otherwise 'deselect' it. */ public void setSelected (boolean selected) { if (selected) setBorder ( new CompoundBorder ( new TitledBorder ( null, mTitle, TitledBorder.LEFT, TitledBorder.TOP), new CompoundBorder ( new LineBorder (Color.green, 2), new EmptyBorder (1, 1, 1, 1)))); else setBorder ( new CompoundBorder ( new TitledBorder ( null, mTitle, TitledBorder.LEFT, TitledBorder.TOP), new EmptyBorder (3,3,3,3))); } protected void addSpacer () { Dimension dimension; Insets insets; // set the command area size by adding a rigid area dimension = mHome.getSize (); insets = mHome.getInsets (); // todo: this should resize with the container dimension.setSize (dimension.width - insets.left - insets.right, mExtra); mSpacer = Box.createRigidArea (dimension); add (mSpacer); } protected void removeSpacer () { remove (mSpacer); mSpacer = null; } /** * Get the components in which to drop commands. * @return The component to act as a drop target. */ public Component[] getDropTargets () { return (new Component[] { this }); } /** * Add a filter to the container contents. * @param filter The command to add to the container. */ public void addFilter (Filter filter) { int count; count = getComponentCount (); if (null != mSpacer) count--; // insert before the spacer addFilter (filter, count); } /** * Add a filter to the container at a specific position. * @param filter The filter to add to the container. * @param index The index at which to add it. */ public void addFilter (Filter filter, int index) { NodeFilter[] before; NodeFilter[] after; int offset; add (filter, index); before = mHome.getSubNodeFilters (); after = new NodeFilter[before.length + 1]; offset = 0; for (int i = 0; i < after.length; i++) after[i] = (i == index) ? filter : before[offset++]; mHome.setSubNodeFilters (after); if ((null != mSpacer) && (0 != mMax) && (after.length >= mMax)) removeSpacer (); } /** * Remove a filter from the container. * @param filter The filter to remove from the container. */ public void removeFilter (Filter filter) { Filter[] filters; int index; filters = getFilters (); index = -1; for (int i = 0; ((-1 == index) && (i < filters.length)); i++) if (filter == filters[i]) index = i; if (-1 != index) removeFilter (index); } /** * Remove a filter from the container. * @param filter The filter to remove from the container. */ public void removeFilter (int index) { NodeFilter[] before; NodeFilter[] after; int offset; remove (index); before = mHome.getSubNodeFilters (); if (0 != before.length) { after = new NodeFilter[before.length - 1]; offset = 0; for (int i = 0; i < before.length; i++) if (i != index) after[offset++] = before[i]; mHome.setSubNodeFilters (after); if ((null == mSpacer) && (0 != mMax) && (after.length < mMax)) addSpacer (); } } /** * Return the list of filters in this container. * @return The list of contained filters. */ public Filter[] getFilters () { NodeFilter[] list; Filter[] ret; list = mHome.getSubNodeFilters (); ret = new Filter[list.length]; System.arraycopy (list, 0, ret, 0, list.length); return (ret); } public boolean canAccept () { int count; boolean ret; if (0 == mMax) ret = true; else { count = getComponentCount (); if (null != mSpacer) count--; ret = count < mMax; } return (ret); } /** * Get the bytes for this command as a String. * @param indent The number of spaces to indent a block. * @param level The current indentation level. * The first non-whitespace character should be at * indented <code>indent</code> * <code>level</code> spaces. * @return The string representing this command. */ public String toString (int indent, int level) { Filter[] filters; StringBuffer ret; ret = new StringBuffer (); filters = getFilters (); for (int i = 0; i < filters.length; i++) { ret.append (filters[i].toString ()); if (i + 1 != filters.length) ret.append ("\n"); } return (ret.toString ()); } } --- NEW FILE: HtmlTreeCellRenderer.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/HtmlTreeCellRenderer.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder; import java.awt.Component; import java.util.Vector; import javax.swing.JTree; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreeCellRenderer; import org.htmlparser.Attribute; import org.htmlparser.Node; import org.htmlparser.lexer.Cursor; import org.htmlparser.nodes.TagNode; import org.htmlparser.nodes.TextNode; import org.htmlparser.util.ParserException; import org.htmlparser.util.Translate; /** * @author derrick * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class HtmlTreeCellRenderer extends DefaultTreeCellRenderer implements TreeCellRenderer { public HtmlTreeCellRenderer () { setLeafIcon (null); setClosedIcon (null); setOpenIcon (null); } /** * Render the tag as HTML. * This is different from the tag's normal toHtml() method in that it * doesn't process children or end tags, just the initial tag, and * it also wraps the tag in something a label would expect. * @see org.htmlparser.Node#toHtml() */ public String toHtml (TagNode tag) { int length; int size; Vector attributes; Attribute attribute; String s; boolean children; StringBuffer ret; length = 2; attributes = tag.getAttributesEx (); size = attributes.size (); for (int i = 0; i < size; i++) { attribute = (Attribute)attributes.elementAt (i); length += attribute.getLength (); } ret = new StringBuffer (length); ret.append ("<"); for (int i = 0; i < size; i++) { attribute = (Attribute)attributes.elementAt (i); attribute.toString (ret); } ret.append (">"); s = Translate.encode (ret.toString ()); children = null != tag.getChildren (); ret = new StringBuffer (s.length () + 13 + (children ? 16 : 0)); ret.append ("<html>"); if (children) ret.append ("<font color=\"blue\">"); ret.append (s); if (children) ret.append ("</font>"); ret.append ("</html>"); return (ret.toString ()); } /** * Express this string node as a printable string * This is suitable for display in a debugger or output to a printout. * Control characters are replaced by their equivalent escape * sequence and contents is truncated to 80 characters. * @return A string representation of the string node. */ public String toText (TextNode node) { int startpos; int endpos; String s; char c; StringBuffer ret; startpos = node.getStartPosition (); endpos = node.getEndPosition (); ret = new StringBuffer (endpos - startpos + 20); s = node.toHtml (); for (int i = 0; i < s.length (); i++) { c = s.charAt (i); switch (c) { case '\t': ret.append ("\\t"); break; case '\n': ret.append ("\\n"); break; case '\r': ret.append ("\\r"); break; default: ret.append (c); } if (77 <= ret.length ()) { ret.append ("..."); break; } } return (ret.toString ()); } /** * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean) */ public Component getTreeCellRendererComponent (JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { Node node; super.getTreeCellRendererComponent (tree, value, selected, expanded, leaf, row, hasFocus); node = (Node)value; if (node instanceof TagNode) setText (toHtml ((TagNode)node)); else if (node instanceof TextNode) setText (toText ((TextNode)node)); else setText (node.toHtml ()); return (this); } } --- NEW FILE: Filter.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/Filter.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder; import java.awt.*; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Hashtable; import java.util.Vector; import javax.swing.*; import javax.swing.border.*; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.parserapplications.filterbuilder.layouts.VerticalLayoutManager; /** * Base class for all filters. * Provides common functionality applicable to all filters. */ public abstract class Filter extends JComponent implements NodeFilter { /** * Create a new filter from the class name. * @param class_name The class to instatiate. * @return The constructed filter object. */ public static Filter instantiate (String class_name) { Filter ret; ret = null; try { Class cls = Class.forName (class_name); ret = (Filter)cls.newInstance (); mWrappers.put (ret.getNodeFilter ().getClass ().getName (), class_name); } catch (ClassNotFoundException cnfe) { System.out.println ("can't find class " + class_name); } catch (InstantiationException ie) { System.out.println ("can't instantiate class " + class_name); } catch (IllegalAccessException ie) { System.out.println ("class " + class_name + " has no public constructor"); } catch (ClassCastException cce) { System.out.println ("class " + class_name + " is not a Filter"); } return (ret); } /** * Map from cilter class to wrapper. * Populated as part of each wrapper being loaded. */ protected static Hashtable mWrappers = new Hashtable (); /** * Create a filter. * Set up the default display. * Only a border with the label of the filter name, * returned by <code>getDescription()</code>, * and an icon, returned by <code>getIcon()</code>. */ public Filter () { JLabel label; Dimension dimension; Insets insets; setToolTipText (getDescription ()); // none of these quite does it: // new BoxLayout (this, BoxLayout.Y_AXIS)); // new GridLayout (0, 1)); setLayout (new VerticalLayoutManager ()); setSelected (false); label = new JLabel (getDescription (), getIcon (), SwingConstants.LEFT); label.setBackground (Color.green); label.setAlignmentX (Component.LEFT_ALIGNMENT); label.setHorizontalAlignment (SwingConstants.LEFT); add (label); dimension = label.getMaximumSize (); insets = getInsets (); dimension.setSize (dimension.width + insets.left + insets.right, dimension.height + insets.top + insets.bottom); setSize (dimension); } /** * Get the name of the filter. * @return A descriptive name for the filter. */ public abstract String getDescription (); /** * Get the underlying node filter object. * @return The node filter object suitable for serialization. */ public abstract NodeFilter getNodeFilter (); /** * Assign the underlying node filter for this wrapper. * @param filter The filter to wrap. * @param context The parser to use for conditioning this filter. * Some filters need contextual information to provide to the user, * i.e. for tag names or attribute names or values, * so the Parser context is provided. */ public abstract void setNodeFilter (NodeFilter filter, Parser context); /** * Get the underlying node filter's subordinate filters. * @return The node filter object's contained filters. */ public abstract NodeFilter[] getSubNodeFilters (); /** * Assign the underlying node filter's subordinate filters. * @param filters The filters to insert into the underlying node filter. */ public abstract void setSubNodeFilters (NodeFilter[] filters); /** * Convert this filter into Java code. * Output whatever text necessary and return the variable name. * @param out The output buffer. * @param context Three integers as follows: * <li>indent level - the number of spaces to insert at the beginning of each line</li> * <li>filter number - the next available filter number</li> * <li>filter array number - the next available array of filters number</li> * @return The variable name to use when referencing this filter (usually "filter" + context[1]++) */ public abstract String toJavaCode (StringBuffer out, int[] context); /** * Get the icon for the filter. * Loads the resource specified by * <code>getIconSpec()</code> as an icon. * @return The icon or null if it was not found. */ public Icon getIcon () { ImageIcon ret; ret = null; try { ret = new ImageIcon (getClass ().getResource (getIconSpec ())); } catch (NullPointerException npe) { System.err.println ("can't find icon " + getIconSpec ()); } return (ret); } /** * Get the resource name for the icon. * @return The icon resource specification. */ public abstract String getIconSpec (); // // Component overrides // /** * Returns a string representation of this component and its values. * @return A string representation of this component. */ public String toString () { return (getDescription () + " [" + this.getClass ().getName () + "]"); } // // utilities // public static byte[] pickle (Object object) throws IOException { ByteArrayOutputStream bos; ObjectOutputStream oos; byte[] ret; bos = new ByteArrayOutputStream (); oos = new ObjectOutputStream (bos); oos.writeObject (object); oos.close (); ret = bos.toByteArray (); return (ret); } public static Object unpickle (byte[] data) throws IOException, ClassNotFoundException { ByteArrayInputStream bis; ObjectInputStream ois; Object ret; bis = new ByteArrayInputStream (data); ois = new ObjectInputStream (bis); ret = ois.readObject (); ois.close (); return (ret); } public static String serialize (byte[] data) { String string; StringBuffer ret; ret = new StringBuffer (data.length * 2); for (int i = 0; i < data.length; i++) { string = Integer.toString (0xff & data[i], 16); if (string.length () < 2) ret.append ("0"); ret.append (string); } return (ret.toString ()); } public static byte[] deserialize (String string) { byte[] ret; ret = new byte[string.length () / 2]; for (int i = 0; i < string.length (); i += 2) ret[i/2] = (byte)Integer.parseInt (string.substring (i, i + 2), 16); // todo: hopelessly inefficient return (ret); } /** * Returns a string serialization of the filters. * @return A string representation of the filters. */ public static String deconstitute (Filter[] filters) throws IOException { StringBuffer ret; ret = new StringBuffer (1024); for (int i = 0; i < filters.length; i++) { ret.append ("["); ret.append (serialize (pickle (filters[i].getNodeFilter ()))); ret.append ("]"); } return (ret.toString ()); } /** * Returns the filters represented by the string. * @param string The string with serialized node filters. * @return The filters gleaned from the string. */ public static Filter[] reconstitute (String string, Parser context) { Filter[] ret; Vector vector; int index; String code; Object object; Filter filter; vector = new Vector (); try { while (string.startsWith ("[")) { index = string.indexOf (']'); if (-1 != index) { code = string.substring (1, index); string = string.substring (index + 1); object = unpickle (deserialize (code)); if (object instanceof NodeFilter) { filter = wrap ((NodeFilter)object, context); if (null != filter) vector.addElement (filter); } else break; } else break; } } catch (Exception e) { e.printStackTrace (); } ret = new Filter[vector.size ()]; vector.copyInto (ret); return (ret); } /** * Get the enclosed sub filter list if any. * Todo: rationalize with FilterBuilder's method(s) of the same name. * @param component The component that's supposedly enclosing the list. * @return The enclosed component or <code>null</code> otherwise. */ protected static SubFilterList getEnclosed (Component component) { Component[] list; if (component instanceof Container) { list = ((Container)component).getComponents (); for (int i = 0; i < list.length; i++) if (list[i] instanceof SubFilterList) return ((SubFilterList)list[i]); } return (null); } /** * Returns a wrapped filter. * @param filter A filter to be wrapped by GUI components. * @param context The context within which to wrap the object. * Some wrappers need context to set up useful choices for the user. * @return The filter to wrap. */ public static Filter wrap (NodeFilter filter, Parser context) { String class_name; NodeFilter[] filters; SubFilterList list; Filter ret; ret = null; class_name = filter.getClass ().getName (); class_name = (String)mWrappers.get (class_name); if (null != class_name) { try { ret = Filter.instantiate (class_name); ret.setNodeFilter (filter, context); // recurse into subfilters filters = ret.getSubNodeFilters (); if (0 != filters.length) { list = getEnclosed (ret); if (null != list) { ret.setSubNodeFilters (new NodeFilter[0]); // clean out the unwrapped filters for (int i = 0; i < filters.length; i++) list.addFilter (wrap (filters[i], context)); } else throw new IllegalStateException ("filter can't have subnodes without a SubFilterList on the wrapper"); } } catch (Exception e) { e.printStackTrace (); } } else System.out.println (class_name + " is not registered for wrapping."); return (ret); } /** * Set the 'selected look' for the component. * @param selected If <code>true</code>, 'select' this component, * otherwise 'deselect' it. */ public void setSelected (boolean selected) { if (selected) setBorder ( new CompoundBorder ( new EtchedBorder (), new CompoundBorder ( new LineBorder(Color.blue, 2), new EmptyBorder (1, 1, 1, 1)))); else setBorder ( new CompoundBorder ( new EtchedBorder (), new EmptyBorder (3,3,3,3))); } /** * Set the expanded state for the component. * This sets invisible all but the JLabel component in the * comand component. * @param expanded If <code>true</code>, 'expand' this component, * otherwise 'collapse' it. */ public void setExpanded (boolean expanded) { Component[] components; components = getComponents (); for (int i = 0; i < components.length; i++) if (!(components[i] instanceof JLabel)) components[i].setVisible (expanded); } public static void spaces (StringBuffer out, int count) { for (int i = 0; i < count; i++) out.append (' '); } public static void newline (StringBuffer out) { out.append ('\n'); } } --- NEW FILE: HtmlTreeModel.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/HtmlTreeModel.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder; import java.util.Vector; import javax.swing.tree.*; import javax.swing.event.*; import org.htmlparser.Node; import org.htmlparser.tags.Html; import org.htmlparser.util.NodeList; /** * Each leaf is a TreeItem or something that does toString(). */ public class HtmlTreeModel implements TreeModel { protected Vector mTreeListeners; protected Node mRoot; public HtmlTreeModel (NodeList root) { mTreeListeners = new Vector (); // for simplicity we encapsulate the nodelist in a Html tag mRoot = new Html (); mRoot.setChildren (root); } // // TreeModel interface // // Adds a listener for the TreeModelEvent posted after the tree changes. public void addTreeModelListener (TreeModelListener l) { synchronized (mTreeListeners) { if (!mTreeListeners.contains(l)) mTreeListeners.addElement(l); } } // Removes a listener previously added with addTreeModelListener(). public void removeTreeModelListener(TreeModelListener l) { synchronized (mTreeListeners) { mTreeListeners.removeElement (l); } } // Returns the child of parent at index index in the parent's child array. public Object getChild (Object parent, int index) { Node node; NodeList list; Object ret; node = (Node)parent; list = node.getChildren (); if (null == list) throw new IllegalArgumentException ("invalid parent for getChild()"); else ret = list.elementAt (index); return (ret); } // Returns the number of children of parent. public int getChildCount (Object parent) { Node node; NodeList list; int ret; ret = 0; node = (Node)parent; list = node.getChildren (); if (null != list) ret = list.size (); return (ret); } // Returns the index of child in parent. public int getIndexOfChild (Object parent, Object child) { Node node; NodeList list; int count; int ret; ret = -1; node = (Node)parent; list = node.getChildren (); if (null != list) { count = list.size (); for (int i = 0; i < count; i++) if (child == list.elementAt (i)) { ret = i; break; } } else throw new IllegalArgumentException ("invalid parent for getIndexOfChild()"); if (0 > ret) throw new IllegalArgumentException ("child not found in getIndexOfChild()"); return (ret); } // Returns the root of the tree. public Object getRoot () { return (mRoot); } // Returns true if node is a leaf. public boolean isLeaf (Object node) { NodeList list; boolean ret; list = ((Node)node).getChildren (); if (null == list) ret = true; else ret = 0 == list.size (); return (ret); } // Messaged when the user has altered the value for the item identified by path to newValue. public void valueForPathChanged (TreePath path, Object newValue) { TreeModelEvent event; Vector v; event = new TreeModelEvent (this, path); synchronized (mTreeListeners) { v = (Vector)mTreeListeners.clone (); } for (int i = 0; i < v.size (); i++) { TreeModelListener listener = (TreeModelListener)v.elementAt (i); listener.treeStructureChanged (event); } } } --- NEW FILE: FilterBuilder.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/FilterBuilder.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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 [...2371 lines suppressed...] // { // javax.swing.UIManager.setLookAndFeel (javax.swing.UIManager.getSystemLookAndFeelClassName ()); // } // catch (Exception e) // { // } // create a new instance of our application's frame, and make it visible FilterBuilder builder = new FilterBuilder (); builder.setVisible (true); } catch (Throwable t) { t.printStackTrace (); // ensure the application exits with an error condition System.exit (1); } } } |
From: Derrick O. <der...@us...> - 2005-02-13 20:43:21
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/images/.xvpics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12396/src/org/htmlparser/parserapplications/filterbuilder/wrappers/images/.xvpics Added Files: HasChildFilter.gif NodeClassFilter.gif AndFilter.gif HasParentFilter.gif RegexFilter.gif StringFilter2.gif HasSiblingFilter.gif OrFilter.gif TagNameFilter.gif HasAttributeFilter.gif NotFilter.gif StringFilter.gif Log Message: FilterBuilder --- NEW FILE: NotFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: RegexFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: StringFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: HasAttributeFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: StringFilter2.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: HasSiblingFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: OrFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: HasChildFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: AndFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: NodeClassFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: HasParentFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: TagNameFilter.gif --- (This appears to be a binary file; contents omitted.) |
From: Derrick O. <der...@us...> - 2005-02-13 20:43:21
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12396/src/org/htmlparser/parserapplications/filterbuilder/wrappers Added Files: AndFilterWrapper.java OrFilterWrapper.java NotFilterWrapper.java HasAttributeFilterWrapper.java NodeClassFilterWrapper.java HasParentFilterWrapper.java TagNameFilterWrapper.java RegexFilterWrapper.java StringFilterWrapper.java HasChildFilterWrapper.java HasSiblingFilterWrapper.java Log Message: FilterBuilder --- NEW FILE: HasParentFilterWrapper.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/HasParentFilterWrapper.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder.wrappers; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JCheckBox; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.filters.HasParentFilter; import org.htmlparser.parserapplications.filterbuilder.Filter; import org.htmlparser.parserapplications.filterbuilder.SubFilterList; /** * Wrapper for HasParentFilters. */ public class HasParentFilterWrapper extends Filter implements ActionListener { /** * The underlying filter. */ protected HasParentFilter mFilter; /** * The check box for recursion. */ protected JCheckBox mRecursive; /** * The drop target container. */ protected SubFilterList mContainer; /** * Create a wrapper over a new HasParentFilter. */ public HasParentFilterWrapper () { mFilter = new HasParentFilter (); // add the recursive flag mRecursive = new JCheckBox ("Recursive"); add (mRecursive); mRecursive.addActionListener (this); mRecursive.setSelected (mFilter.getRecursive ()); // add the subfilter container mContainer = new SubFilterList (this, "Parent Filter", 1); add (mContainer); } // // Filter overrides and concrete implementations // public String getDescription () { return ("Has Parent"); } public String getIconSpec () { return ("images/HasParentFilter.gif"); } public NodeFilter getNodeFilter () { NodeFilter filter; HasParentFilter ret; ret = new HasParentFilter (); ret.setRecursive (mFilter.getRecursive ()); filter = mFilter.getParentFilter (); if (null != filter) ret.setParentFilter (((Filter)filter).getNodeFilter ()); return (ret); } public void setNodeFilter (NodeFilter filter, Parser context) { mFilter = (HasParentFilter)filter; mRecursive.setSelected (mFilter.getRecursive ()); } public NodeFilter[] getSubNodeFilters () { NodeFilter filter; NodeFilter[] ret; filter = mFilter.getParentFilter (); if (null != filter) ret = new NodeFilter[] { filter }; else ret = new NodeFilter[0]; return (ret); } public void setSubNodeFilters (NodeFilter[] filters) { if (0 != filters.length) mFilter.setParentFilter (filters[0]); else mFilter.setParentFilter (null); } public String toJavaCode (StringBuffer out, int[] context) { String name; String ret; if (null != mFilter.getParentFilter ()) name = ((Filter)mFilter.getParentFilter ()).toJavaCode (out, context); else name = null; ret = "filter" + context[1]++; spaces (out, context[0]); out.append ("HasParentFilter "); out.append (ret); out.append (" = new HasParentFilter ();"); newline (out); spaces (out, context[0]); out.append (ret); out.append (".setRecursive ("); out.append (mFilter.getRecursive () ? "true" : "false"); out.append (");"); newline (out); if (null != name) { spaces (out, context[0]); out.append (ret); out.append (".setParentFilter ("); out.append (name); out.append (");"); newline (out); } return (ret); } // // NodeFilter interface // public boolean accept (Node node) { return (mFilter.accept (node)); } // // ActionListener interface // /** * Invoked when an action occurs on the check box. */ public void actionPerformed (ActionEvent event) { Object source; boolean recursive; source = event.getSource (); if (source == mRecursive) { recursive = mRecursive.isSelected (); mFilter.setRecursive (recursive); } } } --- NEW FILE: NotFilterWrapper.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/NotFilterWrapper.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder.wrappers; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.filters.NotFilter; import org.htmlparser.parserapplications.filterbuilder.Filter; import org.htmlparser.parserapplications.filterbuilder.SubFilterList; /** * Wrapper for NotFilters. */ public class NotFilterWrapper extends Filter { /** * The drop target container. */ protected SubFilterList mContainer; /** * The underlying filter. */ protected NotFilter mFilter; /** * Create a wrapper over a new NotFilter. */ public NotFilterWrapper () { mFilter = new NotFilter (); // add the subfilter container mContainer = new SubFilterList (this, "Predicate", 1); add (mContainer); } // // Filter overrides and concrete implementations // public String getDescription () { return ("Not"); } public String getIconSpec () { return ("images/NotFilter.gif"); } public NodeFilter getNodeFilter () { NodeFilter predicate; NotFilter ret; ret = new NotFilter (); predicate = mFilter.getPredicate (); if (null != predicate) ret.setPredicate (((Filter)predicate).getNodeFilter ()); return (ret); } public void setNodeFilter (NodeFilter filter, Parser context) { mFilter = (NotFilter)filter; } public NodeFilter[] getSubNodeFilters () { NodeFilter predicate; NodeFilter[] ret; predicate = mFilter.getPredicate (); if (null != predicate) ret = new NodeFilter[] { predicate }; else ret = new NodeFilter[0]; return (ret); } public void setSubNodeFilters (NodeFilter[] filters) { if (0 != filters.length) mFilter.setPredicate (filters[0]); else mFilter.setPredicate (null); } public String toJavaCode (StringBuffer out, int[] context) { String name; String ret; if (null != mFilter.getPredicate ()) name = ((Filter)mFilter.getPredicate ()).toJavaCode (out, context); else name = null; ret = "filter" + context[1]++; spaces (out, context[0]); out.append ("NotFilter "); out.append (ret); out.append (" = new NotFilter ();"); newline (out); if (null != name) { spaces (out, context[0]); out.append (ret); out.append (".setPredicate ("); out.append (name); out.append (");"); newline (out); } return (ret); } // // NodeFilter interface // public boolean accept (Node node) { return (mFilter.accept (node)); } } --- NEW FILE: StringFilterWrapper.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/StringFilterWrapper.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder.wrappers; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Locale; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JTextArea; import javax.swing.border.BevelBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.filters.StringFilter; import org.htmlparser.parserapplications.filterbuilder.Filter; /** * Wrapper for StringFilters. */ public class StringFilterWrapper extends Filter implements ActionListener, DocumentListener, Runnable { /** * The underlying filter. */ protected StringFilter mFilter; /** * Text to check for. */ protected JTextArea mPattern; /** * The check box for case sensitivity. */ protected JCheckBox mCaseSensitivity; /** * Combo box for locale. */ protected JComboBox mLocale; /** * Cached locales. */ protected static Locale[] mLocales = null; /** * Create a wrapper over a new StringFilter. */ public StringFilterWrapper () { Thread thread; mFilter = new StringFilter (); mFilter.setCaseSensitive (true); // add the text pattern mPattern = new JTextArea (2, 20); mPattern.setBorder (new BevelBorder (BevelBorder.LOWERED)); add (mPattern); mPattern.getDocument ().addDocumentListener (this); mPattern.setText (mFilter.getPattern ()); // add the case sensitivity flag mCaseSensitivity = new JCheckBox ("Case Sensitive"); add (mCaseSensitivity); mCaseSensitivity.addActionListener (this); mCaseSensitivity.setSelected (mFilter.getCaseSensitive ()); // add the locales choice mLocale = new JComboBox (); synchronized (mLocale) { mLocale.addItem (mFilter.getLocale ().getDisplayName ()); thread = new Thread (this); thread.setName ("locale_getter"); thread.setPriority (Thread.MIN_PRIORITY); thread.run (); } add (mLocale); mLocale.addActionListener (this); mLocale.setSelectedIndex (0); mLocale.setVisible (!mFilter.getCaseSensitive ()); } // // Filter overrides and concrete implementations // public String getDescription () { return ("Nodes containing string"); } public String getIconSpec () { return ("images/StringFilter.gif"); } public NodeFilter getNodeFilter () { StringFilter ret; ret = new StringFilter (); ret.setCaseSensitive (mFilter.getCaseSensitive ()); ret.setLocale (mFilter .getLocale ()); ret.setPattern (mFilter.getPattern ()); return (ret); } public void setNodeFilter (NodeFilter filter, Parser context) { mFilter = (StringFilter)filter; mPattern.setText (mFilter.getPattern ()); mCaseSensitivity.setSelected (mFilter.getCaseSensitive ()); mLocale.setVisible (!mFilter.getCaseSensitive ()); mLocale.setSelectedItem (mFilter.getLocale ().getDisplayName ()); } public NodeFilter[] getSubNodeFilters () { return (new NodeFilter[0]); } public void setSubNodeFilters (NodeFilter[] filters) { // should we complain? } public String toJavaCode (StringBuffer out, int[] context) { String ret; ret = "filter" + context[1]++; spaces (out, context[0]); out.append ("StringFilter "); out.append (ret); out.append (" = new StringFilter ();"); newline (out); spaces (out, context[0]); out.append (ret); out.append (".setCaseSensitive ("); out.append (mFilter.getCaseSensitive () ? "true" : "false"); out.append (");"); newline (out); spaces (out, context[0]); out.append (ret); out.append (".setLocale (new java.util.Locale (\""); out.append (mFilter .getLocale ().getLanguage ()); out.append ("\", \""); out.append (mFilter .getLocale ().getCountry ()); out.append ("\", \""); out.append (mFilter .getLocale ().getVariant ()); out.append ("\"));"); newline (out); spaces (out, context[0]); out.append (ret); out.append (".setPattern (\""); out.append (mFilter.getPattern ()); out.append ("\");"); newline (out); return (ret); } // // NodeFilter interface // public boolean accept (Node node) { return (mFilter.accept (node)); } // // ActionListener interface // /** * Invoked when an action occurs on the combo box. */ public void actionPerformed (ActionEvent event) { Object source; boolean sensitive; Object[] selection; String locale; source = event.getSource (); if (source == mCaseSensitivity) { sensitive = mCaseSensitivity.isSelected (); mFilter.setCaseSensitive (sensitive); mLocale.setVisible (!sensitive); mLocale.setSelectedItem (mFilter.getLocale ().getDisplayName ()); } else if (source == mLocale) { synchronized (mLocale) { selection = mLocale.getSelectedObjects (); if ((null != selection) && (0 != selection.length)) { locale = (String)selection[0]; for (int i = 0; i < mLocales.length; i++) if (locale.equals (mLocales[i].getDisplayName ())) mFilter.setLocale (mLocales[i]); } } } } // // Runnable interface // public void run() { String locale; synchronized (mLocale) { mLocales = Locale.getAvailableLocales (); locale = mFilter.getLocale ().getDisplayName (); for (int i = 0; i < mLocales.length; i++) if (!locale.equals (mLocales[i].getDisplayName ())) mLocale.addItem (mLocales[i].getDisplayName ()); mLocale.invalidate (); } } // // DocumentListener interface // public void insertUpdate (DocumentEvent e) { Document doc; doc = e.getDocument (); try { mFilter.setPattern (doc.getText (0, doc.getLength ())); } catch (BadLocationException ble) { ble.printStackTrace (); } } public void removeUpdate (DocumentEvent e) { Document doc; doc = e.getDocument (); try { mFilter.setPattern (doc.getText (0, doc.getLength ())); } catch (BadLocationException ble) { ble.printStackTrace (); } } public void changedUpdate (DocumentEvent e) { // plain text components don't fire these events } } --- NEW FILE: HasChildFilterWrapper.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/HasChildFilterWrapper.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder.wrappers; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JCheckBox; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.filters.HasChildFilter; import org.htmlparser.parserapplications.filterbuilder.Filter; import org.htmlparser.parserapplications.filterbuilder.SubFilterList; /** * Wrapper for HasChildFilters. */ public class HasChildFilterWrapper extends Filter implements ActionListener { /** * The underlying filter. */ protected HasChildFilter mFilter; /** * The check box for recursion. */ protected JCheckBox mRecursive; /** * The drop target container. */ protected SubFilterList mContainer; /** * Create a wrapper over a new HasChildFilter. */ public HasChildFilterWrapper () { mFilter = new HasChildFilter (); // add the recursive flag mRecursive = new JCheckBox ("Recursive"); add (mRecursive); mRecursive.addActionListener (this); mRecursive.setSelected (mFilter.getRecursive ()); // add the subfilter container mContainer = new SubFilterList (this, "Child Filter", 1); add (mContainer); } // // Filter overrides and concrete implementations // public String getDescription () { return ("Has Child"); } public String getIconSpec () { return ("images/HasChildFilter.gif"); } public NodeFilter getNodeFilter () { NodeFilter filter; HasChildFilter ret; ret = new HasChildFilter (); ret.setRecursive (mFilter.getRecursive ()); filter = mFilter.getChildFilter (); if (null != filter) ret.setChildFilter (((Filter)filter).getNodeFilter ()); return (ret); } public void setNodeFilter (NodeFilter filter, Parser context) { mFilter = (HasChildFilter)filter; mRecursive.setSelected (mFilter.getRecursive ()); } public NodeFilter[] getSubNodeFilters () { NodeFilter filter; NodeFilter[] ret; filter = mFilter.getChildFilter (); if (null != filter) ret = new NodeFilter[] { filter }; else ret = new NodeFilter[0]; return (ret); } public void setSubNodeFilters (NodeFilter[] filters) { if (0 != filters.length) mFilter.setChildFilter (filters[0]); else mFilter.setChildFilter (null); } public String toJavaCode (StringBuffer out, int[] context) { String name; String ret; if (null != mFilter.getChildFilter ()) name = ((Filter)mFilter.getChildFilter ()).toJavaCode (out, context); else name = null; ret = "filter" + context[1]++; spaces (out, context[0]); out.append ("HasChildFilter "); out.append (ret); out.append (" = new HasChildFilter ();"); newline (out); spaces (out, context[0]); out.append (ret); out.append (".setRecursive ("); out.append (mFilter.getRecursive () ? "true" : "false"); out.append (");"); newline (out); if (null != name) { spaces (out, context[0]); out.append (ret); out.append (".setChildFilter ("); out.append (name); out.append (");"); newline (out); } return (ret); } // // NodeFilter interface // public boolean accept (Node node) { return (mFilter.accept (node)); } // // ActionListener interface // /** * Invoked when an action occurs on the check box. */ public void actionPerformed (ActionEvent event) { Object source; boolean recursive; source = event.getSource (); if (source == mRecursive) { recursive = mRecursive.isSelected (); mFilter.setRecursive (recursive); } } } --- NEW FILE: AndFilterWrapper.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/AndFilterWrapper.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder.wrappers; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.filters.AndFilter; import org.htmlparser.parserapplications.filterbuilder.Filter; import org.htmlparser.parserapplications.filterbuilder.SubFilterList; /** * Wrapper for AndFilters. */ public class AndFilterWrapper extends Filter { /** * The drop target container. */ protected SubFilterList mContainer; /** * The underlying filter. */ protected AndFilter mFilter; /** * Create a wrapper over a new AndFilter. */ public AndFilterWrapper () { mFilter = new AndFilter (); // add the subfilter container mContainer = new SubFilterList (this, "Predicates", 0); add (mContainer); } // // Filter overrides and concrete implementations // public String getDescription () { return ("And"); } public String getIconSpec () { return ("images/AndFilter.gif"); } public NodeFilter getNodeFilter () { NodeFilter[] predicates; NodeFilter[] temp; AndFilter ret; ret = new AndFilter (); predicates = mFilter.getPredicates (); temp = new NodeFilter[predicates.length]; for (int i = 0; i < predicates.length; i++) temp[i] = ((Filter)predicates[i]).getNodeFilter (); ret.setPredicates (temp); return (ret); } public void setNodeFilter (NodeFilter filter, Parser context) { mFilter = (AndFilter)filter; } public NodeFilter[] getSubNodeFilters () { return (mFilter.getPredicates ()); } public void setSubNodeFilters (NodeFilter[] filters) { mFilter.setPredicates (filters); } public String toJavaCode (StringBuffer out, int[] context) { String array; NodeFilter[] predicates; String[] names; String ret; predicates = mFilter.getPredicates (); array = null; // stoopid Java compiler if (0 != predicates.length) { names = new String[predicates.length]; for (int i = 0; i < predicates.length; i++) { names[i] = ((Filter)predicates[i]).toJavaCode (out, context); } array = "array" + context[2]++; spaces (out, context[0]); out.append ("NodeFilter[] "); out.append (array); out.append (" = new NodeFilter["); out.append (predicates.length); out.append ("];"); newline (out); for (int i = 0; i < predicates.length; i++) { spaces (out, context[0]); out.append (array); out.append ("["); out.append (i); out.append ("] = "); out.append (names[i]); out.append (";"); newline (out); } } ret = "filter" + context[1]++; spaces (out, context[0]); out.append ("AndFilter "); out.append (ret); out.append (" = new AndFilter ();"); newline (out); if (0 != predicates.length) { spaces (out, context[0]); out.append (ret); out.append (".setPredicates ("); out.append (array); out.append (");"); newline (out); } return (ret); } // // NodeFilter interface // public boolean accept (Node node) { return (mFilter.accept (node)); } } --- NEW FILE: HasSiblingFilterWrapper.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/HasSiblingFilterWrapper.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder.wrappers; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.filters.HasSiblingFilter; import org.htmlparser.parserapplications.filterbuilder.Filter; import org.htmlparser.parserapplications.filterbuilder.SubFilterList; /** * Wrapper for HasSiblingFilters. */ public class HasSiblingFilterWrapper extends Filter implements ActionListener { /** * The underlying filter. */ protected HasSiblingFilter mFilter; /** * The drop target container. */ protected SubFilterList mContainer; /** * Create a wrapper over a new HasParentFilter. */ public HasSiblingFilterWrapper () { mFilter = new HasSiblingFilter (); // add the subfilter container mContainer = new SubFilterList (this, "Sibling Filter", 1); add (mContainer); } // // Filter overrides and concrete implementations // public String getDescription () { return ("Has Sibling"); } public String getIconSpec () { return ("images/HasSiblingFilter.gif"); } public NodeFilter getNodeFilter () { NodeFilter filter; HasSiblingFilter ret; ret = new HasSiblingFilter (); filter = mFilter.getSiblingFilter (); if (null != filter) ret.setSiblingFilter (((Filter)filter).getNodeFilter ()); return (ret); } public void setNodeFilter (NodeFilter filter, Parser context) { mFilter = (HasSiblingFilter)filter; } public NodeFilter[] getSubNodeFilters () { NodeFilter filter; NodeFilter[] ret; filter = mFilter.getSiblingFilter (); if (null != filter) ret = new NodeFilter[] { filter }; else ret = new NodeFilter[0]; return (ret); } public void setSubNodeFilters (NodeFilter[] filters) { if (0 != filters.length) mFilter.setSiblingFilter (filters[0]); else mFilter.setSiblingFilter (null); } public String toJavaCode (StringBuffer out, int[] context) { String name; String ret; if (null != mFilter.getSiblingFilter ()) name = ((Filter)mFilter.getSiblingFilter ()).toJavaCode (out, context); else name = null; ret = "filter" + context[1]++; spaces (out, context[0]); out.append ("HasSiblingFilter "); out.append (ret); out.append (" = new HasSiblingFilter ();"); newline (out); if (null != name) { spaces (out, context[0]); out.append (ret); out.append (".setSiblingFilter ("); out.append (name); out.append (");"); newline (out); } return (ret); } // // NodeFilter interface // public boolean accept (Node node) { return (mFilter.accept (node)); } // // ActionListener interface // /** * Invoked when an action occurs. */ public void actionPerformed (ActionEvent event) { } } --- NEW FILE: TagNameFilterWrapper.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/TagNameFilterWrapper.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder.wrappers; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import javax.swing.JComboBox; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.Tag; import org.htmlparser.filters.TagNameFilter; import org.htmlparser.parserapplications.filterbuilder.Filter; import org.htmlparser.tags.CompositeTag; import org.htmlparser.util.NodeIterator; import org.htmlparser.util.NodeList; import org.htmlparser.util.ParserException; /** * Wrapper for TagNameFilters. */ public class TagNameFilterWrapper extends Filter implements ActionListener { /** * The underlying filter. */ protected TagNameFilter mFilter; /** * Combo box for tag name. */ protected JComboBox mName; /** * Create a wrapper over a new TagNameFilter. */ public TagNameFilterWrapper () { mFilter = new TagNameFilter (); // add the tag name choice mName = new JComboBox (); mName.setEditable (true); add (mName); mName.addItem (mFilter.getName ()); mName.addActionListener (this); } // // Filter overrides and concrete implementations // public String getDescription () { return ("Tag named"); } public String getIconSpec () { return ("images/TagNameFilter.gif"); } public NodeFilter getNodeFilter () { TagNameFilter ret; ret = new TagNameFilter (); ret.setName (mFilter.getName ()); return (ret); } public void setNodeFilter (NodeFilter filter, Parser context) { Set set; mFilter = (TagNameFilter)filter; set = new HashSet (); context.reset (); try { for (NodeIterator iterator = context.elements (); iterator.hasMoreNodes (); ) addName (set, iterator.nextNode ()); } catch (ParserException pe) { // oh well, we tried } for (Iterator iterator = set.iterator (); iterator.hasNext (); ) mName.addItem (iterator.next ()); mName.setSelectedItem (mFilter.getName ()); } public NodeFilter[] getSubNodeFilters () { return (new NodeFilter[0]); } public void setSubNodeFilters (NodeFilter[] filters) { // should we complain? } public String toJavaCode (StringBuffer out, int[] context) { String ret; ret = "filter" + context[1]++; spaces (out, context[0]); out.append ("TagNameFilter "); out.append (ret); out.append (" = new TagNameFilter ();"); newline (out); spaces (out, context[0]); out.append (ret); out.append (".setName (\""); out.append (mFilter.getName ()); out.append ("\");"); newline (out); return (ret); } protected void addName (Set set, Node node) { NodeList children; if (node instanceof Tag) { set.add (((Tag)node).getTagName ()); if (node instanceof CompositeTag) { children = ((CompositeTag)node).getChildren (); if (null != children) for (int i = 0; i < children.size (); i++) addName (set, children.elementAt (i)); } } } // // NodeFilter interface // public boolean accept (Node node) { return (mFilter.accept (node)); } // // ActionListener interface // /** * Invoked when an action occurs on the combo box. */ public void actionPerformed (ActionEvent event) { Object source; Object[] selection; source = event.getSource (); if (source == mName) { selection = mName.getSelectedObjects (); if ((null != selection) && (0 != selection.length)) mFilter.setName ((String)selection[0]); } } } --- NEW FILE: NodeClassFilterWrapper.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/NodeClassFilterWrapper.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder.wrappers; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Iterator; import java.util.Set; import javax.swing.JComboBox; //import javax.swing.event.DocumentEvent; //import javax.swing.event.DocumentListener; //import javax.swing.text.BadLocationException; //import javax.swing.text.Document; import org.htmlparser.Node; import org.htmlparser.NodeFactory; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; import org.htmlparser.Tag; import org.htmlparser.filters.NodeClassFilter; import org.htmlparser.parserapplications.filterbuilder.Filter; /** * Wrapper for NodeClassFilters. */ public class NodeClassFilterWrapper extends Filter implements ActionListener // , // DocumentListener { /** * The underlying filter. */ protected NodeClassFilter mFilter; /** * Combo box for strategy. */ protected JComboBox mClass; /** * Create a wrapper over a new NodeClassFilter. */ public NodeClassFilterWrapper () { mFilter = new NodeClassFilter (); // add the strategy choice mClass = new JComboBox (); mClass.addItem (""); add (mClass); mClass.addActionListener (this); } // // Filter overrides and concrete implementations // public String getDescription () { return ("Nodes of class"); } public String getIconSpec () { return ("images/NodeClassFilter.gif"); } public NodeFilter getNodeFilter () { NodeClassFilter ret; ret = new NodeClassFilter (); ret.setMatchClass (mFilter.getMatchClass ()); return (ret); } public void setNodeFilter (NodeFilter filter, Parser context) { NodeFactory factory; PrototypicalNodeFactory proto; Set names; String name; Tag tag; mFilter = (NodeClassFilter)filter; factory = context.getNodeFactory (); if (factory instanceof PrototypicalNodeFactory) { proto = (PrototypicalNodeFactory)factory; // iterate over the classes names = proto.getTagNames (); for (Iterator iterator = names.iterator (); iterator.hasNext (); ) { name = (String)iterator.next (); tag = proto.get (name); mClass.addItem (tag.getClass ().getName ()); } } mClass.setSelectedItem (mFilter.getMatchClass ().getName ()); } public NodeFilter[] getSubNodeFilters () { return (new NodeFilter[0]); } public void setSubNodeFilters (NodeFilter[] filters) { // should we complain? } public String toJavaCode (StringBuffer out, int[] context) { String ret; ret = "filter" + context[1]++; spaces (out, context[0]); out.append ("NodeClassFilter "); out.append (ret); out.append (" = new NodeClassFilter ();"); newline (out); spaces (out, context[0]); out.append ("try { "); out.append (ret); out.append (".setMatchClass (Class.forName (\""); out.append (mFilter.getMatchClass ().getName ()); out.append ("\")); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace (); }"); newline (out); return (ret); } // // NodeFilter interface // public boolean accept (Node node) { return (mFilter.accept (node)); } // // ActionListener interface // /** * Invoked when an action occurs on the combo box. */ public void actionPerformed (ActionEvent event) { Object source; source = event.getSource (); if (source == mClass) try { mFilter.setMatchClass (Class.forName ((String)mClass.getSelectedItem ())); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace (); } } // // // // DocumentListener interface // // // // public void insertUpdate (DocumentEvent e) // { // Document doc; // // doc = e.getDocument (); // try // { // mFilter.setPattern (doc.getText (0, doc.getLength ())); // } // catch (BadLocationException ble) // { // ble.printStackTrace (); // } // } // // public void removeUpdate (DocumentEvent e) // { // Document doc; // // doc = e.getDocument (); // try // { // mFilter.setPattern (doc.getText (0, doc.getLength ())); // } // catch (BadLocationException ble) // { // ble.printStackTrace (); // } // } // // public void changedUpdate (DocumentEvent e) // { // // plain text components don't fire these events // } } --- NEW FILE: HasAttributeFilterWrapper.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/HasAttributeFilterWrapper.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder.wrappers; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.Vector; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JTextArea; import javax.swing.border.BevelBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import org.htmlparser.Attribute; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.Tag; import org.htmlparser.filters.HasAttributeFilter; import org.htmlparser.parserapplications.filterbuilder.Filter; import org.htmlparser.tags.CompositeTag; import org.htmlparser.util.NodeIterator; import org.htmlparser.util.NodeList; import org.htmlparser.util.ParserException; /** * Wrapper for HasAttributeFilters. */ public class HasAttributeFilterWrapper extends Filter implements ActionListener, DocumentListener { /** * The underlying filter. */ protected HasAttributeFilter mFilter; /** * Combo box for attribute name. */ protected JComboBox mAttributeName; /** * The check box for has value. */ protected JCheckBox mValued; /** * Value to check for. */ protected JTextArea mAttributeValue; /** * Create a wrapper over a new HasAttributeFilter. */ public HasAttributeFilterWrapper () { String value; mFilter = new HasAttributeFilter (); // add the attribute name choice mAttributeName = new JComboBox (); mAttributeName.setEditable (true); add (mAttributeName); mAttributeName.addItem (mFilter.getAttributeName ()); mAttributeName.addActionListener (this); // add the valued flag value = mFilter.getAttributeValue (); mValued = new JCheckBox ("Has Value"); add (mValued); mValued.setSelected (null != value); mValued.addActionListener (this); // add the value pattern mAttributeValue = new JTextArea (2, 20); mAttributeValue.setBorder (new BevelBorder (BevelBorder.LOWERED)); add (mAttributeValue); if (null != value) mAttributeValue.setText (value); else mAttributeValue.setVisible (false); mAttributeValue.getDocument ().addDocumentListener (this); } // // local methods // protected void addAttributes (Set set, Node node) { Vector attributes; Attribute attribute; String name; NodeList children; if (node instanceof Tag) { attributes = ((Tag)node).getAttributesEx (); for (int i = 1; i < attributes.size (); i++) { attribute = (Attribute)attributes.elementAt (i); name = attribute.getName (); if (null != name) set.add (name); } if (node instanceof CompositeTag) { children = ((CompositeTag)node).getChildren (); if (null != children) for (int i = 0; i < children.size (); i++) addAttributes (set, children.elementAt (i)); } } } protected void addAttributeValues (Set set, Node node) { Vector attributes; Attribute attribute; String value; NodeList children; if (node instanceof Tag) { attributes = ((Tag)node).getAttributesEx (); for (int i = 1; i < attributes.size (); i++) { attribute = (Attribute)attributes.elementAt (i); if (null != attribute.getName ()) { value = attribute.getValue (); if (null != value) set.add (value); } } if (node instanceof CompositeTag) { children = ((CompositeTag)node).getChildren (); if (null != children) for (int i = 0; i < children.size (); i++) addAttributeValues (set, children.elementAt (i)); } } } // // Filter overrides and concrete implementations // public String getDescription () { return ("Has attribute"); } public String getIconSpec () { return ("images/HasAttributeFilter.gif"); } public NodeFilter getNodeFilter () { HasAttributeFilter ret; ret = new HasAttributeFilter (); ret.setAttributeName (mFilter.getAttributeName ()); ret.setAttributeValue (mFilter.getAttributeValue ()); return (ret); } public void setNodeFilter (NodeFilter filter, Parser context) { Set set; String name; String value; mFilter = (HasAttributeFilter)filter; set = new HashSet (); context.reset (); try { for (NodeIterator iterator = context.elements (); iterator.hasMoreNodes (); ) addAttributes (set, iterator.nextNode ()); } catch (ParserException pe) { // oh well, we tried } for (Iterator iterator = set.iterator (); iterator.hasNext (); ) mAttributeName.addItem (iterator.next ()); name = mFilter.getAttributeName (); if (!name.equals ("")) mAttributeName.setSelectedItem (name); value = mFilter.getAttributeValue (); if (null != value) { mValued.setSelected (true); mAttributeValue.setVisible (true); mAttributeValue.setText (value); } else { mValued.setSelected (false); mAttributeValue.setVisible (false); } } public NodeFilter[] getSubNodeFilters () { return (new NodeFilter[0]); } public void setSubNodeFilters (NodeFilter[] filters) { // should we complain? } public String toJavaCode (StringBuffer out, int[] context) { String ret; ret = "filter" + context[1]++; spaces (out, context[0]); out.append ("HasAttributeFilter "); out.append (ret); out.append (" = new HasAttributeFilter ();"); newline (out); spaces (out, context[0]); out.append (ret); out.append (".setAttributeName (\""); out.append (mFilter.getAttributeName ()); out.append ("\");"); newline (out); if (null != mFilter.getAttributeValue ()) { spaces (out, context[0]); out.append (ret); out.append (".setAttributeValue (\""); out.append (mFilter.getAttributeValue ()); out.append ("\");"); newline (out); } return (ret); } // // NodeFilter interface // public boolean accept (Node node) { return (mFilter.accept (node)); } // // ActionListener interface // /** * Invoked when an action occurs on the combo box. */ public void actionPerformed (ActionEvent event) { Object source; Object[] selection; boolean valued; source = event.getSource (); if (source == mAttributeName) { selection = mAttributeName.getSelectedObjects (); if ((null != selection) && (0 != selection.length)) mFilter.setAttributeName ((String)selection[0]); } else if (source == mValued) { valued = mValued.isSelected (); if (valued) { mFilter.setAttributeValue (mAttributeValue.getText ()); mAttributeValue.setVisible (true); } else { mAttributeValue.setVisible (false); mAttributeValue.setText (""); mFilter.setAttributeValue (null); } } } // // DocumentListener interface // public void insertUpdate (DocumentEvent e) { Document doc; doc = e.getDocument (); try { mFilter.setAttributeValue (doc.getText (0, doc.getLength ())); } catch (BadLocationException ble) { ble.printStackTrace (); } } public void removeUpdate (DocumentEvent e) { Document doc; doc = e.getDocument (); try { mFilter.setAttributeValue (doc.getText (0, doc.getLength ())); } catch (BadLocationException ble) { ble.printStackTrace (); } } public void changedUpdate (DocumentEvent e) { // plain text components don't fire these events } } --- NEW FILE: RegexFilterWrapper.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/RegexFilterWrapper.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:43:06 $ // $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.parserapplications.filterbuilder.wrappers; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JComboBox; import javax.swing.JTextArea; import javax.swing.border.BevelBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.filters.RegexFilter; import org.htmlparser.parserapplications.filterbuilder.Filter; /** * Wrapper for RegexFilters. */ public class RegexFilterWrapper extends Filter implements ActionListener, DocumentListener { /** * Mapping for RegexFilter constants to strings. */ public static Object[][] mMap; static { mMap = new Object[3][]; mMap[0] = new Object[2]; mMap[0][0] = "MATCH"; mMap[0][1] = new Integer (RegexFilter.MATCH); mMap[1] = new Object[2]; mMap[1][0] = "LOOKINGAT"; mMap[1][1] = new Integer (RegexFilter.LOOKINGAT); mMap[2] = new Object[2]; mMap[2][0] = "FIND"; mMap[2][1] = new Integer (RegexFilter.FIND); } /** * The underlying filter. */ protected RegexFilter mFilter; /** * Text to check for */ protected JTextArea mPattern; /** * Combo box for strategy. */ protected JComboBox mStrategy; /** * Create a wrapper over a new RegexFilter. */ public RegexFilterWrapper () { mFilter = new RegexFilter (); // add the text pattern mPattern = new JTextArea (2, 20); mPattern.setBorder (new BevelBorder (BevelBorder.LOWERED)); add (mPattern); mPattern.getDocument ().addDocumentListener (this); mPattern.setText (mFilter.getPattern ()); // add the strategy choice mStrategy = new JComboBox (); mStrategy.addItem ("MATCH"); mStrategy.addItem ("LOOKINGAT"); mStrategy.addItem ("FIND"); add (mStrategy); mStrategy.addActionListener (this); mStrategy.setSelectedIndex (strategyToIndex (mFilter.getStrategy ())); } // // Filter overrides and concrete implementations // public String getDescription () { return ("Nodes containing regex"); } public String getIconSpec () { return ("images/RegexFilter.gif"); } public NodeFilter getNodeFilter () { RegexFilter ret; ret = new RegexFilter (); ret.setStrategy (mFilter.getStrategy ()); ret.setPattern (mFilter.getPattern ()); return (ret); } public void setNodeFilter (NodeFilter filter, Parser context) { mFilter = (RegexFilter)filter; mPattern.setText (mFilter.getPattern ()); mStrategy.setSelectedIndex (strategyToIndex (mFilter.getStrategy ())); } public NodeFilter[] getSubNodeFilters () { return (new NodeFilter[0]); } public void setSubNodeFilters (NodeFilter[] filters) { // should we complain? } public String toJavaCode (StringBuffer out, int[] context) { String ret; ret = "filter" + context[1]++; spaces (out, context[0]); out.append ("RegexFilter "); out.append (ret); out.append (" = new RegexFilter ();"); newline (out); spaces (out, context[0]); out.append (ret); out.append (".setStrategy (RegexFilter."); out.append (strategyToString (mFilter.getStrategy ())); out.append (");"); newline (out); spaces (out, context[0]); out.append (ret); out.append (".setPattern (\""); out.append (mFilter.getPattern ()); out.append ("\");"); newline (out); return (ret); } public String strategyToString (int strategy) { for (int i =0; i < mMap.length; i++) if (strategy == ((Integer)mMap[i][1]).intValue ()) return ((String)mMap[i][0]); throw new IllegalArgumentException ("unknown strategy constant - " + strategy); } public int stringToStrategy (String strategy) { for (int i =0; i < mMap.length; i++) if (strategy.equalsIgn... [truncated message content] |
From: Derrick O. <der...@us...> - 2005-02-13 20:43:20
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/images In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12396/src/org/htmlparser/parserapplications/filterbuilder/wrappers/images Added Files: HasChildFilter.gif RegexFilter.gif HasParentFilter.gif HasSiblingFilter.gif TagNameFilter.gif NodeClassFilter.gif OrFilter.gif AndFilter.gif HasAttributeFilter.gif NotFilter.gif StringFilter.gif Log Message: FilterBuilder --- NEW FILE: NotFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: RegexFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: StringFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: HasAttributeFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: HasSiblingFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: OrFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: HasChildFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: AndFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: NodeClassFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: HasParentFilter.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: TagNameFilter.gif --- (This appears to be a binary file; contents omitted.) |
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/images In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12396/src/org/htmlparser/parserapplications/filterbuilder/images Added Files: delete.gif about.gif new.gif open.gif paste.gif copy.gif save.gif cut.gif Log Message: FilterBuilder --- NEW FILE: copy.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: new.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: save.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: paste.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: cut.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: open.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: about.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: delete.gif --- (This appears to be a binary file; contents omitted.) |
From: Derrick O. <der...@us...> - 2005-02-13 20:36:44
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8914/src/org/htmlparser/filters Modified Files: HasChildFilter.java NodeClassFilter.java RegexFilter.java NotFilter.java TagNameFilter.java AndFilter.java HasAttributeFilter.java OrFilter.java HasParentFilter.java StringFilter.java Added Files: HasSiblingFilter.java Log Message: FilterBuilder Index: AndFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/AndFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AndFilter.java 8 Nov 2003 21:30:58 -0000 1.1 --- AndFilter.java 13 Feb 2005 20:36:00 -0000 1.2 *************** *** 31,50 **** /** ! * This class accepts all nodes matching both filters (AND operation). */ ! public class AndFilter implements NodeFilter { /** ! * The left hand side. */ ! protected NodeFilter mLeft; /** ! * The right hand side. */ ! protected NodeFilter mRight; /** ! * Creates a new instance of AndFilter that accepts nodes acceptable to both filters. * @param left One filter. * @param right The other filter. --- 31,58 ---- /** ! * Accepts nodes matching all of it's predicate filters (AND operation). */ ! public class AndFilter ! implements ! NodeFilter { /** ! * The predicates that are to be and'ed together; */ ! protected NodeFilter[] mPredicates; /** ! * Creates a new instance of an AndFilter. ! * With no predicates, this would always answer <code>true</code> ! * to {@link #accept}. ! * @see #setPredicates */ ! public AndFilter () ! { ! setPredicates (null); ! } /** ! * Creates a new instance of an AndFilter that accepts nodes acceptable to both filters. * @param left One filter. * @param right The other filter. *************** *** 52,66 **** public AndFilter (NodeFilter left, NodeFilter right) { ! mLeft = left; ! mRight = right; } /** ! * Accept nodes that are acceptable to both filters. * @param node The node to check. */ public boolean accept (Node node) { ! return (mLeft.accept (node) && mRight.accept (node)); } } --- 60,110 ---- public AndFilter (NodeFilter left, NodeFilter right) { ! NodeFilter[] predicates; ! ! predicates = new NodeFilter[2]; ! predicates[0] = left; ! predicates[1] = right; ! setPredicates (predicates); } /** ! * Get the predicates used by this AndFilter. ! * @return The predicates currently in use. ! */ ! public NodeFilter[] getPredicates () ! { ! return (mPredicates); ! } ! ! /** ! * Set the predicates for this AndFilter. ! * @param predicates The list of predidcates to use in {@link #accept}. ! */ ! public void setPredicates (NodeFilter[] predicates) ! { ! if (null == predicates) ! predicates = new NodeFilter[0]; ! mPredicates = predicates; ! } ! ! // ! // NodeFilter interface ! // ! ! /** ! * Accept nodes that are acceptable to all of it's predicate filters. * @param node The node to check. */ public boolean accept (Node node) { ! boolean ret; ! ! ret = true; ! ! for (int i = 0; ret && (i < mPredicates.length); i++) ! if (!mPredicates[i].accept (node)) ! ret = false; ! ! return (ret); } } Index: StringFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/StringFilter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** StringFilter.java 24 May 2004 16:18:13 -0000 1.4 --- StringFilter.java 13 Feb 2005 20:36:00 -0000 1.5 *************** *** 35,40 **** /** * This class accepts all string nodes containing the given string. */ ! public class StringFilter implements NodeFilter { /** --- 35,45 ---- /** * This class accepts all string nodes containing the given string. + * This is a fairly simplistic filter, so for more sophisticated + * string matching, for example newline and whitespace handling, + * use a {@link RegexFilter} instead. */ ! public class StringFilter ! implements ! NodeFilter { /** *************** *** 44,59 **** /** * Case sensitive toggle. */ protected boolean mCaseSensitive; /** ! * The locale to use converting to uppercase in the case insensitive searches. */ protected Locale mLocale; /** ! * Creates a new instance of StringFilter that accepts string nodes containing a certain string. ! * The comparison is case insensitive. * @param pattern The pattern to search for. */ --- 49,78 ---- /** + * The string to really search for (converted to uppercase if necessary). + */ + protected String mUpperPattern; + + /** * Case sensitive toggle. + * If <code>true</code> strings are compared with case sensitivity. */ protected boolean mCaseSensitive; /** ! * The locale to use converting to uppercase in case insensitive searches. */ protected Locale mLocale; /** ! * Creates a new instance of StringFilter that accepts all string nodes. ! */ ! public StringFilter () ! { ! this ("", false); ! } ! ! /** ! * Creates a new instance of a StringFilter that accepts string nodes containing a certain string. ! * The comparison is case insensitive, with conversions done using the default <code>Locale</code>. * @param pattern The pattern to search for. */ *************** *** 64,71 **** /** ! * Creates a new instance of StringFilter that accepts string nodes containing a certain string. * @param pattern The pattern to search for. * @param case_sensitive If <code>true</code>, comparisons are performed ! * respecting case. */ public StringFilter (String pattern, boolean case_sensitive) --- 83,90 ---- /** ! * Creates a new instance of a StringFilter that accepts string nodes containing a certain string. * @param pattern The pattern to search for. * @param case_sensitive If <code>true</code>, comparisons are performed ! * respecting case, with conversions done using the default <code>Locale</code>. */ public StringFilter (String pattern, boolean case_sensitive) *************** *** 75,98 **** /** ! * Creates a new instance of StringFilter that accepts string nodes containing a certain string. * @param pattern The pattern to search for. * @param case_sensitive If <code>true</code>, comparisons are performed * respecting case. */ public StringFilter (String pattern, boolean case_sensitive, Locale locale) { mCaseSensitive = case_sensitive; ! if (mCaseSensitive) ! mPattern = pattern; else ! { ! mLocale = (null == locale) ? Locale.ENGLISH : locale; ! mPattern = pattern.toUpperCase (mLocale); ! } } /** * Accept string nodes that contain the string. * @param node The node to check. */ public boolean accept (Node node) --- 94,194 ---- /** ! * Creates a new instance of a StringFilter that accepts string nodes containing a certain string. * @param pattern The pattern to search for. * @param case_sensitive If <code>true</code>, comparisons are performed * respecting case. + * @param locale The locale to use when converting to uppercase. + * If <code>null</code>, the default <code>Locale</code> is used. */ public StringFilter (String pattern, boolean case_sensitive, Locale locale) { + mPattern = pattern; mCaseSensitive = case_sensitive; ! mLocale = (null == locale) ? Locale.getDefault () : locale; ! setUpperPattern (); ! } ! ! // ! // protected methods ! // ! ! /** ! * Set the real (upper case) comparison string. ! */ ! protected void setUpperPattern () ! { ! if (getCaseSensitive ()) ! mUpperPattern = getPattern (); else ! mUpperPattern = getPattern ().toUpperCase (getLocale ()); ! } ! ! /** ! * Get the case sensitivity. ! * @return Returns the case sensitivity. ! */ ! public boolean getCaseSensitive () ! { ! return (mCaseSensitive); ! } ! ! /** ! * Set case sensitivity on or off. ! * @param sensitive If <code>false</code> searches for the ! * string are case insensitive. ! */ ! public void setCaseSensitive (boolean sensitive) ! { ! mCaseSensitive = sensitive; ! setUpperPattern (); ! } ! ! /** ! * Get the locale for uppercase conversion. ! * @return Returns the locale. ! */ ! public Locale getLocale () ! { ! return (mLocale); ! } ! ! /** ! * Set the locale for uppercase conversion. ! * @param locale The locale to set. ! */ ! public void setLocale (Locale locale) ! { ! mLocale = locale; ! setUpperPattern (); ! } ! ! /** ! * Get the search pattern. ! * @return Returns the pattern. ! */ ! public String getPattern () ! { ! return (mPattern); ! } ! ! /** ! * Set the search pattern. ! * @param pattern The pattern to set. ! */ ! public void setPattern (String pattern) ! { ! mPattern = pattern; ! setUpperPattern (); } + // + // NodeFilter interface + // + /** * Accept string nodes that contain the string. * @param node The node to check. + * @return <code>true</code> if <code>node</code> is a {@link Text} node + * and contains the pattern string, <code>false</code> otherwise. */ public boolean accept (Node node) *************** *** 105,111 **** { string = ((Text)node).getText (); ! if (!mCaseSensitive) ! string = string.toUpperCase (mLocale); ! ret = -1 != string.indexOf (mPattern); } --- 201,207 ---- { string = ((Text)node).getText (); ! if (!getCaseSensitive ()) ! string = string.toUpperCase (getLocale ()); ! ret = (-1 != string.indexOf (mUpperPattern)); } Index: RegexFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/RegexFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RegexFilter.java 24 May 2004 19:36:26 -0000 1.1 --- RegexFilter.java 13 Feb 2005 20:36:00 -0000 1.2 *************** *** 83,86 **** --- 83,91 ---- /** + * The regular expression to search for. + */ + protected String mPatternString; + + /** * The compiled regular expression to search for. */ *************** *** 95,98 **** --- 100,112 ---- /** * Creates a new instance of RegexFilter that accepts string nodes matching + * the regular expression ".*" using the FIND strategy. + */ + public RegexFilter () + { + this (".*", FIND); + } + + /** + * 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. *************** *** 116,120 **** --- 130,171 ---- public RegexFilter (String pattern, int strategy) { + setPattern (pattern); + setStrategy (strategy); + } + + /** + * Get the search pattern. + * @return Returns the pattern. + */ + public String getPattern () + { + return (mPatternString); + } + + /** + * Set the search pattern. + * @param pattern The pattern to set. + */ + public void setPattern (String pattern) + { + mPatternString = pattern; mPattern = Pattern.compile (pattern); + } + + /** + * Get the search strategy. + * @return Returns the strategy. + */ + public int getStrategy () + { + return (mStrategy); + } + + /** + * Set the search pattern. + * @param strategy The strategy to use. One of MATCH, LOOKINGAT or FIND. + */ + public void setStrategy (int strategy) + { mStrategy = strategy; } Index: HasParentFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/HasParentFilter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** HasParentFilter.java 31 Jul 2004 16:42:34 -0000 1.5 --- HasParentFilter.java 13 Feb 2005 20:36:00 -0000 1.6 *************** *** 29,54 **** import org.htmlparser.Node; import org.htmlparser.NodeFilter; /** * This class accepts all tags that have a parent acceptable to another filter. */ ! public class HasParentFilter implements NodeFilter { /** * The filter to apply to the parent. */ ! 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. */ --- 29,130 ---- import org.htmlparser.Node; import org.htmlparser.NodeFilter; + import org.htmlparser.Tag; /** * This class accepts all tags that have a parent acceptable to another filter. + * It can be set to operate recursively, that is perform a scan up the node + * heirarchy looking for any ancestor that matches the predicate filter. + * End tags are not considered to be children of any tag. */ ! public class HasParentFilter ! implements ! NodeFilter { /** * The filter to apply to the parent. */ ! public NodeFilter mParentFilter; /** ! * Performs a recursive search up the node heirarchy if <code>true</code>. ! */ ! public boolean mRecursive; ! ! /** ! * Creates a new instance of HasParentFilter. ! * With no parent filter, this would always return <code>false</code> ! * from {@link #accept}. ! */ ! public HasParentFilter () ! { ! this (null); ! } ! ! /** ! * Creates a new instance of HasParentFilter that accepts nodes with direct parent acceptable to the filter. * @param filter The filter to apply to the parent. */ public HasParentFilter (NodeFilter filter) { ! this (filter, false); ! } ! ! /** ! * Creates a new instance of HasParentFilter that accepts nodes with a parent acceptable to the filter. ! * @param filter The filter to apply to the parent. ! * @param recursive If <code>true</code>, any enclosing node acceptable ! * to the given filter causes the node being tested to be accepted ! * (i.e. a recursive scan through the parent nodes up the node ! * heirarchy is performed). ! */ ! public HasParentFilter (NodeFilter filter, boolean recursive) ! { ! setParentFilter (filter); ! setRecursive (recursive); ! } ! ! /** ! * Get the filter used by this HasParentFilter. ! * @return The filter to apply to parents. ! */ ! public NodeFilter getParentFilter () ! { ! return (mParentFilter); ! } ! ! /** ! * Set the filter for this HasParentFilter. ! * @param filter The filter to apply to parents in {@link #accept}. ! */ ! public void setParentFilter (NodeFilter filter) ! { ! mParentFilter = filter; ! } ! ! /** ! * Get the recusion setting for the filter. ! * @return Returns <code>true</code> if the filter is recursive ! * up the node heirarchy. ! */ ! public boolean getRecursive () ! { ! return mRecursive; ! } ! ! /** ! * Sets whether the filter is recursive or not. ! * @param recursive The recursion setting for the filter. ! */ ! public void setRecursive (boolean recursive) ! { ! mRecursive = recursive; } /** * Accept tags with parent acceptable to the filter. + * If recursion is enabled, each parent in turn up to + * the topmost enclosing node is checked. + * Recursion only proceeds while no parent satisfies the + * filter. * @param node The node to check. */ *************** *** 59,65 **** ret = false; ! parent = node.getParent (); ! if (null != parent) ! ret = mFilter.accept (parent); return (ret); --- 135,148 ---- ret = false; ! if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) ! { ! parent = node.getParent (); ! if ((null != parent) && (null != getParentFilter ())) ! { ! ret = getParentFilter ().accept (parent); ! if (!ret && getRecursive ()) ! ret = accept (parent); ! } ! } return (ret); Index: NotFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/NotFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NotFilter.java 8 Nov 2003 21:30:58 -0000 1.1 --- NotFilter.java 13 Feb 2005 20:36:00 -0000 1.2 *************** *** 31,35 **** /** ! * This class accepts all nodes not acceptable to the filter. */ public class NotFilter implements NodeFilter --- 31,35 ---- /** ! * Accepts all nodes not acceptable to it's predicate filter. */ public class NotFilter implements NodeFilter *************** *** 38,59 **** * The filter to gainsay. */ ! protected NodeFilter mFilter; /** ! * Creates a new instance of NotFilter that accepts nodes not acceptable to the filter. ! * @param filter The filter to consult. */ ! public NotFilter (NodeFilter filter) { ! mFilter = filter; } /** ! * Accept nodes that are not acceptable to the filter. * @param node The node to check. */ public boolean accept (Node node) { ! return (!mFilter.accept (node)); } } --- 38,92 ---- * The filter to gainsay. */ ! protected NodeFilter mPredicate; /** ! * Creates a new instance of a NotFilter. ! * With no predicates, this would always return <code>false</code> ! * from {@link #accept}. ! * @see #setPredicates */ ! public NotFilter () { ! setPredicate (null); } /** ! * Creates a new instance of NotFilter that accepts nodes not acceptable to the predicate filter. ! * @param predicate The filter to consult. ! */ ! public NotFilter (NodeFilter predicate) ! { ! setPredicate (predicate); ! } ! ! /** ! * Get the predicate used by this NotFilter. ! * @return The predicate currently in use. ! */ ! public NodeFilter getPredicate () ! { ! return (mPredicate); ! } ! ! /** ! * Set the predicate for this NotFilter. ! * @param predicate The predidcate to use in {@link #accept}. ! */ ! public void setPredicate (NodeFilter predicate) ! { ! mPredicate = predicate; ! } ! ! // ! // NodeFilter interface ! // ! ! /** ! * Accept nodes that are not acceptable to the predicate filter. * @param node The node to check. */ public boolean accept (Node node) { ! return ((null != mPredicate) && !mPredicate.accept (node)); } } Index: OrFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/OrFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OrFilter.java 8 Nov 2003 21:30:58 -0000 1.1 --- OrFilter.java 13 Feb 2005 20:36:00 -0000 1.2 *************** *** 31,50 **** /** ! * This class accepts all nodes matching either filter (OR operation). */ public class OrFilter implements NodeFilter { /** ! * The left hand side. */ ! protected NodeFilter mLeft; /** ! * The right hand side. */ ! protected NodeFilter mRight; /** ! * Creates a new instance of OrFilter that accepts nodes acceptable to either filter. * @param left One filter. * @param right The other filter. --- 31,56 ---- /** ! * Accepts nodes matching any of it's predicates filters (OR operation). */ public class OrFilter implements NodeFilter { /** ! * The predicates that are to be or'ed together; */ ! protected NodeFilter[] mPredicates; /** ! * Creates a new instance of an OrFilter. ! * With no predicates, this would always answer <code>false</code> ! * to {@link #accept}. ! * @see #setPredicates */ ! public OrFilter () ! { ! setPredicates (null); ! } /** ! * Creates a new instance of an OrFilter that accepts nodes acceptable to either filter. * @param left One filter. * @param right The other filter. *************** *** 52,66 **** public OrFilter (NodeFilter left, NodeFilter right) { ! mLeft = left; ! mRight = right; } /** ! * Accept nodes that are acceptable to either filter. * @param node The node to check. */ public boolean accept (Node node) { ! return (mLeft.accept (node) || mRight.accept (node)); } } --- 58,108 ---- public OrFilter (NodeFilter left, NodeFilter right) { ! NodeFilter[] predicates; ! ! predicates = new NodeFilter[2]; ! predicates[0] = left; ! predicates[1] = right; ! setPredicates (predicates); } /** ! * Get the predicates used by this OrFilter. ! * @return The predicates currently in use. ! */ ! public NodeFilter[] getPredicates () ! { ! return (mPredicates); ! } ! ! /** ! * Set the predicates for this OrFilter. ! * @param predicates The list of predidcates to use in {@link #accept}. ! */ ! public void setPredicates (NodeFilter[] predicates) ! { ! if (null == predicates) ! predicates = new NodeFilter[0]; ! mPredicates = predicates; ! } ! ! // ! // NodeFilter interface ! // ! ! /** ! * Accept nodes that are acceptable to any of it's predicate filters. * @param node The node to check. */ public boolean accept (Node node) { ! boolean ret; ! ! ret = false; ! ! for (int i = 0; !ret && (i < mPredicates.length); i++) ! if (mPredicates[i].accept (node)) ! ret = true; ! ! return (ret); } } Index: HasChildFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/HasChildFilter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HasChildFilter.java 24 Jan 2004 23:57:48 -0000 1.2 --- HasChildFilter.java 13 Feb 2005 20:36:00 -0000 1.3 *************** *** 35,55 **** * This class accepts all tags that have a child acceptable to the filter. */ ! public class HasChildFilter implements NodeFilter { /** * The filter to apply to children. */ ! protected NodeFilter mFilter; /** ! * Creates a new instance of HasChildFilter that accepts tags with children acceptable to the filter. ! * Similar to asking for the parent of a node returned by the given ! * filter, but where multiple children may be acceptable, this class ! * will only accept the parent once. ! * @param filter The filter to apply to children. */ public HasChildFilter (NodeFilter filter) { ! mFilter = filter; } --- 35,121 ---- * This class accepts all tags that have a child acceptable to the filter. */ ! public class HasChildFilter ! implements ! NodeFilter { /** * The filter to apply to children. */ ! protected NodeFilter mChildFilter; /** ! * Performs a recursive search down the node heirarchy if <code>true</code>. ! */ ! public boolean mRecursive; ! ! /** ! * Creates a new instance of a HasChildFilter. ! * With no child filter, this would always return <code>false</code> ! * from {@link #accept}. ! */ ! public HasChildFilter () ! { ! this (null); ! } ! ! /** ! * Creates a new instance of HasChildFilter that accepts nodes with a direct child acceptable to the filter. ! * @param filter The filter to apply to the children. */ public HasChildFilter (NodeFilter filter) { ! this (filter, false); ! } ! ! /** ! * Creates a new instance of HasChildFilter that accepts nodes with a child acceptable to the filter. ! * Of necessity, this applies only to composite tags, i.e. those that can ! * contain other nodes, for example <HTML></HTML>. ! * @param filter The filter to apply to children. ! * @param recursive If <code>true</code>, any enclosed node acceptable ! * to the given filter causes the node being tested to be accepted ! * (i.e. a recursive scan through the child nodes down the node ! * heirarchy is performed). ! */ ! public HasChildFilter (NodeFilter filter, boolean recursive) ! { ! setChildFilter (filter); ! setRecursive (recursive); } ! ! /** ! * Get the filter used by this HasParentFilter. ! * @return The filter to apply to parents. ! */ ! public NodeFilter getChildFilter () ! { ! return (mChildFilter); ! } ! ! /** ! * Set the filter for this HasParentFilter. ! * @param filter The filter to apply to parents in {@link #accept}. ! */ ! public void setChildFilter (NodeFilter filter) ! { ! mChildFilter = filter; ! } ! ! /** ! * Get the recusion setting for the filter. ! * @return Returns <code>true</code> if the filter is recursive ! * up the node heirarchy. ! */ ! public boolean getRecursive () ! { ! return mRecursive; ! } ! ! /** ! * Sets whether the filter is recursive or not. ! * @param recursive The recursion setting for the filter. ! */ ! public void setRecursive (boolean recursive) ! { ! mRecursive = recursive; } *************** *** 70,79 **** children = tag.getChildren (); if (null != children) ! for (int i = 0; i < children.size (); i++) ! if (mFilter.accept (children.elementAt (i))) ! { ret = true; ! break; ! } } --- 136,149 ---- children = tag.getChildren (); if (null != children) ! { ! for (int i = 0; !ret && i < children.size (); i++) ! if (getChildFilter ().accept (children.elementAt (i))) ret = true; ! // do recursion after all children checked to get breadth first traversal ! if (!ret && getRecursive ()) ! for (int i = 0; !ret && i < children.size (); i++) ! if (accept (children.elementAt (i))) ! ret = true; ! } } --- NEW FILE: HasSiblingFilter.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2005 Derrick Oswald // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/HasSiblingFilter.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:36:00 $ // $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.Tag; import org.htmlparser.util.NodeList; /** * This class accepts all tags that have a sibling acceptable to another filter. * End tags are not considered to be siblings of any tag. */ public class HasSiblingFilter implements NodeFilter { /** * The filter to apply to the sibling. */ public NodeFilter mSiblingFilter; /** * Creates a new instance of HasSiblingFilter. * With no sibling filter, this would always return <code>false</code> * from {@link #accept}. */ public HasSiblingFilter () { this (null); } /** * Creates a new instance of HasSiblingFilter that accepts nodes with sibling acceptable to the filter. * @param filter The filter to apply to the sibling. */ public HasSiblingFilter (NodeFilter filter) { setSiblingFilter (filter); } /** * Get the filter used by this HasSiblingFilter. * @return The filter to apply to siblings. */ public NodeFilter getSiblingFilter () { return (mSiblingFilter); } /** * Set the filter for this HasSiblingFilter. * @param filter The filter to apply to siblings in {@link #accept}. */ public void setSiblingFilter (NodeFilter filter) { mSiblingFilter = filter; } /** * Accept tags with a sibling acceptable to the filter. * @param node The node to check. */ public boolean accept (Node node) { Node parent; NodeList siblings; int count; boolean ret; ret = false; if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) { parent = node.getParent (); if (null != parent) { siblings = parent.getChildren (); if (null != siblings) { count = siblings.size (); for (int i = 0; !ret && (i < count); i++) if (getSiblingFilter ().accept (siblings.elementAt (i))) ret = true; } else System.out.println("gotcha"); } } return (ret); } } Index: TagNameFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/TagNameFilter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TagNameFilter.java 24 May 2004 16:18:13 -0000 1.3 --- TagNameFilter.java 13 Feb 2005 20:36:00 -0000 1.4 *************** *** 46,49 **** --- 46,59 ---- /** + * Creates a new instance of TagNameFilter. + * With no name, this would always return <code>false</code> + * from {@link #accept}. + */ + public TagNameFilter () + { + this (""); + } + + /** * Creates a new instance of TagNameFilter that accepts tags with the given name. * @param name The tag name to match. *************** *** 55,58 **** --- 65,86 ---- /** + * Get the tag name. + * @return Returns the name of acceptable tags. + */ + public String getName () + { + return (mName); + } + + /** + * Set the tag name. + * @param name The name of the tag to accept. + */ + public void setName (String name) + { + mName = name; + } + + /** * Accept nodes that are tags and have a matching tag name. * This discards non-tag nodes and end tags. Index: HasAttributeFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/HasAttributeFilter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** HasAttributeFilter.java 24 May 2004 16:18:13 -0000 1.4 --- HasAttributeFilter.java 13 Feb 2005 20:36:00 -0000 1.5 *************** *** 50,53 **** --- 50,63 ---- /** + * Creates a new instance of HasAttributeFilter. + * With no attribute name, this would always return <code>false</code> + * from {@link #accept}. + */ + public HasAttributeFilter () + { + this ("", null); + } + + /** * Creates a new instance of HasAttributeFilter that accepts tags with the given attribute. * @param attribute The attribute to search for. *************** *** 70,73 **** --- 80,120 ---- /** + * Get the attribute name. + * @return Returns the name of the attribute that is acceptable. + */ + public String getAttributeName () + { + return (mAttribute); + } + + /** + * Set the attribute name. + * @param name The name of the attribute to accept. + */ + public void setAttributeName (String name) + { + mAttribute = name; + } + + /** + * Get the attribute value. + * @return Returns the value of the attribute that is acceptable. + */ + public String getAttributeValue () + { + return (mValue); + } + + /** + * Set the attribute value. + * @param value The value of the attribute to accept. + * If <code>null</code>, any tag with the attribute, no matter it's value is acceptable. + */ + public void setAttributeValue (String value) + { + mValue = value; + } + + /** * Accept tags with a certain attribute. * @param node The node to check. Index: NodeClassFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/NodeClassFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NodeClassFilter.java 8 Nov 2003 21:30:58 -0000 1.1 --- NodeClassFilter.java 13 Feb 2005 20:36:00 -0000 1.2 *************** *** 41,44 **** --- 41,52 ---- /** + * Creates a new instance of NodeClassFilter that accepts tags of the Html (top level) class. + */ + public NodeClassFilter () + { + this (org.htmlparser.tags.Html.class); + } + + /** * Creates a new instance of NodeClassFilter that accepts tags of the given class. * @param cls The cls to match. *************** *** 50,53 **** --- 58,79 ---- /** + * Get the class to match. + * @return Returns the class. + */ + public Class getMatchClass () + { + return (mClass); + } + + /** + * Set the class to match. + * @param cls The node class to match. + */ + public void setMatchClass (Class cls) + { + mClass = cls; + } + + /** * Accept nodes that are assignable from the class provided in the constructor. * @param node The node to check. *************** *** 55,59 **** public boolean accept (Node node) { ! return (mClass.isAssignableFrom (node.getClass ())); } } --- 81,85 ---- public boolean accept (Node node) { ! return ((null != mClass) && mClass.isAssignableFrom (node.getClass ())); } } |
From: Derrick O. <der...@us...> - 2005-02-13 20:36:40
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8914/src/org/htmlparser/tags Modified Files: TableTag.java TableRow.java Log Message: FilterBuilder Index: TableRow.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/TableRow.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** TableRow.java 24 Jan 2004 23:57:52 -0000 1.40 --- TableRow.java 13 Feb 2005 20:36:00 -0000 1.41 *************** *** 108,112 **** new NotFilter (cls), // but not past the first row recursion)); ! recursion.mFilter = filter; kids = kids.extractAllNodesThatMatch ( // it's a column, and has this row as it's enclosing row --- 108,112 ---- new NotFilter (cls), // but not past the first row recursion)); ! recursion.setParentFilter (filter); kids = kids.extractAllNodesThatMatch ( // it's a column, and has this row as it's enclosing row *************** *** 155,159 **** new NotFilter (cls), // but not past the first row recursion)); ! recursion.mFilter = filter; kids = kids.extractAllNodesThatMatch ( // it's a header, and has this row as it's enclosing row --- 155,159 ---- new NotFilter (cls), // but not past the first row recursion)); ! recursion.setParentFilter (filter); kids = kids.extractAllNodesThatMatch ( // it's a header, and has this row as it's enclosing row Index: TableTag.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/TableTag.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** TableTag.java 24 Jan 2004 23:58:04 -0000 1.39 --- TableTag.java 13 Feb 2005 20:36:00 -0000 1.40 *************** *** 100,104 **** new NotFilter (cls), // but not past the first table recursion)); ! recursion.mFilter = filter; kids = kids.extractAllNodesThatMatch ( // it's a row, and has this table as it's enclosing table --- 100,104 ---- new NotFilter (cls), // but not past the first table recursion)); ! recursion.setParentFilter (filter); kids = kids.extractAllNodesThatMatch ( // it's a row, and has this table as it's enclosing table |
From: Derrick O. <der...@us...> - 2005-02-13 20:36:40
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexerapplications/thumbelina In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8914/src/org/htmlparser/lexerapplications/thumbelina Modified Files: Thumbelina.java Log Message: FilterBuilder Index: Thumbelina.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexerapplications/thumbelina/Thumbelina.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Thumbelina.java 31 Jul 2004 16:42:30 -0000 1.6 --- Thumbelina.java 13 Feb 2005 20:36:00 -0000 1.7 *************** *** 1297,1301 **** version = System.getProperty ("java.version"); ! if (version.startsWith ("1.4")) frame = new ThumbelinaFrame (url); else --- 1297,1301 ---- version = System.getProperty ("java.version"); ! if (version.startsWith ("1.4") || version.startsWith ("1.5")) frame = new ThumbelinaFrame (url); else *************** *** 1453,1456 **** --- 1453,1459 ---- * * $Log$ + * Revision 1.7 2005/02/13 20:36:00 derrickoswald + * FilterBuilder + * * Revision 1.6 2004/07/31 16:42:30 derrickoswald * Remove unused variables and other fixes exposed by turning on compiler warnings. |
From: Derrick O. <der...@us...> - 2005-02-13 20:36:16
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/beans In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8914/src/org/htmlparser/beans Modified Files: BeanyBaby.java Added Files: FilterBean.java Log Message: FilterBuilder --- NEW FILE: FilterBean.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/beans/FilterBean.java,v $ // $Author: derrickoswald $ // $Date: 2005/02/13 20:36:03 $ // $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.beans; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.Serializable; import java.net.URLConnection; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.util.NodeList; import org.htmlparser.util.ParserException; import org.htmlparser.util.EncodingChangeException; /** * Extract nodes from a URL using a filter. * FilterBean fb = new FilterBean ("http://cbc.ca"); * fb.setFilters (new NodeFilter[] { new TagNameFilter ("META") }); * fb.setURL ("http://cbc.ca"); * System.out.println (fb.getNodes ().toHtml ()); */ public class FilterBean implements Serializable { /** * Property name in event where the URL contents changes. */ public static final String PROP_NODES_PROPERTY = "nodes"; /** * Property name in event where the URL contents changes. */ public static final String PROP_TEXT_PROPERTY = "text"; /** * Property name in event where the URL changes. */ public static final String PROP_URL_PROPERTY = "URL"; /** * Property name in event where the connection changes. */ public static final String PROP_CONNECTION_PROPERTY = "connection"; /** * Bound property support. */ protected PropertyChangeSupport mPropertySupport; /** * The parser used to filter. */ protected Parser mParser; /** * The filter set. */ protected NodeFilter[] mFilters; /** * The nodes extracted from the URL. */ protected NodeList mNodes; /** * Create a FilterBean object. */ public FilterBean () { mPropertySupport = new PropertyChangeSupport (this); mParser = new Parser (); mFilters = null; mNodes = null; } // // internals // /** * Assign the <code>Nodes</code> property, firing the property change. * @param nodes The new value of the <code>Nodes</code> property. */ protected void updateNodes (NodeList nodes) { NodeList oldValue; String oldText; String newText; if ((null == mNodes) || !mNodes.equals (nodes)) { oldValue = mNodes; if (null != oldValue) oldText = getText (); else oldText = ""; if (null == oldText) oldText = ""; mNodes = nodes; if (null != mNodes) // TODO: fix this null problem if StringBean finds no nodes newText = getText (); else newText = ""; if (null == newText) newText = ""; mPropertySupport.firePropertyChange (PROP_NODES_PROPERTY, oldValue, nodes); if (!newText.equals (oldText)) mPropertySupport.firePropertyChange (PROP_TEXT_PROPERTY, oldText, newText); } } /** * Apply each of the filters. * The first filter is applied to the parser. * Subsequent filters are applied to the output of the prior filter. * @return A list of nodes passed through all filters. * @throws ParserException If an encoding change occurs or there is some other problem. */ protected NodeList applyFilters () throws ParserException { NodeList ret; ret = new NodeList (); if (null != getFilters ()) for (int i = 0; i < getFilters ().length; i++) if (0 == i) ret = mParser.parse (getFilters ()[0]); else ret = ret.extractAllNodesThatMatch (getFilters ()[i]); return (ret); } /** * Fetch the URL contents and filter it. * Only do work if there is a valid parser with it's URL set. */ protected void setNodes () { NodeList list; if (null != getURL ()) try { list = applyFilters (); updateNodes (list); } catch (EncodingChangeException ece) { try { // try again with the encoding now in force mParser.reset (); list = applyFilters (); updateNodes (list); } catch (ParserException pe) { updateNodes (new NodeList ()); } } catch (ParserException pe) { updateNodes (new NodeList ()); } } // // Property change support. // /** * Add a PropertyChangeListener to the listener list. * The listener is registered for all properties. * @param listener The PropertyChangeListener to be added. */ public void addPropertyChangeListener (PropertyChangeListener listener) { mPropertySupport.addPropertyChangeListener (listener); } /** * Remove a PropertyChangeListener from the listener list. * This removes a PropertyChangeListener that was registered for all properties. * @param listener The PropertyChangeListener to be removed. */ public void removePropertyChangeListener (PropertyChangeListener listener) { mPropertySupport.removePropertyChangeListener (listener); } // // Properties // /** * Return the nodes of the URL matching the filter. * This is the primary output of the bean. * @return The nodes from the URL matching the current filter. */ public NodeList getNodes () { if (null == mNodes) setNodes (); return (mNodes); } /** * Get the current URL. * @return The URL from which text has been extracted, or <code>null</code> * if this property has not been set yet. */ public String getURL () { return ((null != mParser) ? mParser.getURL () : null); } /** * Set the URL to extract strings from. * The text from the URL will be fetched, which may be expensive, so this * property should be set last. * @param url The URL that text should be fetched from. */ public void setURL (String url) { String old; URLConnection conn; old = getURL (); conn = getConnection (); if (((null == old) && (null != url)) || ((null != old) && !old.equals (url))) { try { if (null == mParser) mParser = new Parser (url); else mParser.setURL (url); mPropertySupport.firePropertyChange (PROP_URL_PROPERTY, old, getURL ()); mPropertySupport.firePropertyChange (PROP_CONNECTION_PROPERTY, conn, mParser.getConnection ()); setNodes (); } catch (ParserException pe) { updateNodes (new NodeList ()); } } } /** * Get the current connection. * @return The connection that the parser has or <code>null</code> if it * hasn't been set or the parser hasn't been constructed yet. */ public URLConnection getConnection () { return ((null != mParser) ? mParser.getConnection () : null); } /** * Set the parser's connection. * The text from the URL will be fetched, which may be expensive, so this * property should be set last. * @param connection New value of property Connection. */ public void setConnection (URLConnection connection) { String url; URLConnection conn; url = getURL (); conn = getConnection (); if (((null == conn) && (null != connection)) || ((null != conn) && !conn.equals (connection))) { try { if (null == mParser) mParser = new Parser (connection); else mParser.setConnection (connection); mPropertySupport.firePropertyChange (PROP_URL_PROPERTY, url, getURL ()); mPropertySupport.firePropertyChange (PROP_CONNECTION_PROPERTY, conn, mParser.getConnection ()); setNodes (); } catch (ParserException pe) { updateNodes (new NodeList ()); } } } /** * Get the current filter set. * @return The current filters. */ public NodeFilter[] getFilters () { return (mFilters); } /** * Set the filters for the bean. * If the parser has been set, it is reset and * the nodes are refetched with the new filters. * @param filters The filter set to use. */ public void setFilters (NodeFilter[] filters) { mFilters = filters; if (null != getParser ()) { getParser ().reset (); setNodes (); } } /** * Get the parser used to fetch nodes. * @return The parser used by the bean. */ public Parser getParser () { return (mParser); } /** * Set the parser for the bean. * The parser is used immediately to fetch the nodes, * which for a null filter means all the nodes * @param parser The parser to use. */ public void setParser (Parser parser) { mParser = parser; if (null != getFilters ()) setNodes (); } /** * Convenience method to apply a {@link StringBean} to the results of filtering. * This may yield duplicate or multiple text elements if the node list contains nodes from * two or more levels in the same nested tag heirarchy, but if the node list * contains only one tag, it provides access to the text within the node. * @return The textual contents of the nodes that pass through the filter set, * as collected by the StringBean. */ public String getText () { NodeList list; StringBean sb; String ret; list = getNodes (); if (0 != list.size ()) { sb = new StringBean (); for (int i = 0; i < list.size (); i++) list.elementAt (i).accept (sb); ret = sb.getStrings (); } else ret = ""; return (ret); } /** * Unit test. * @param args Pass arg[0] as the URL to process, * and optionally a node name for filtering. */ public static void main (String[] args) { if (0 >= args.length) System.out.println ("Usage: java -classpath htmlparser.jar org.htmlparser.beans.FilterBean <http://whatever_url> [node name]"); else { FilterBean fb = new FilterBean (); if (1 < args.length) fb.setFilters (new NodeFilter[] { new org.htmlparser.filters.TagNameFilter (args[1]) }); fb.setURL (args[0]); //System.out.println (fb.getNodes ().toHtml ()); System.out.println (fb.getText ()); } } } Index: BeanyBaby.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/beans/BeanyBaby.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** BeanyBaby.java 2 Jan 2004 16:24:53 -0000 1.21 --- BeanyBaby.java 13 Feb 2005 20:36:03 -0000 1.22 *************** *** 61,67 **** // shenanigans to get the splitter bar at the midpoint ! show (); mSplitPane.setDividerLocation(0.5); ! hide (); // set up twinning --- 61,67 ---- // shenanigans to get the splitter bar at the midpoint ! setVisible (true); mSplitPane.setDividerLocation(0.5); ! setVisible (false); // set up twinning *************** *** 368,372 **** { BeanyBaby bb = new BeanyBaby (); ! bb.show (); bb.setURL ("http://www.slashdot.org"); } --- 368,372 ---- { BeanyBaby bb = new BeanyBaby (); ! bb.setVisible (true); bb.setURL ("http://www.slashdot.org"); } |
From: Derrick O. <der...@us...> - 2005-02-13 20:36:16
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8914/src/org/htmlparser/util Modified Files: NodeList.java Log Message: FilterBuilder Index: NodeList.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/NodeList.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** NodeList.java 31 Jul 2004 16:42:33 -0000 1.56 --- NodeList.java 13 Feb 2005 20:36:03 -0000 1.57 *************** *** 151,155 **** } ! public String asHtml() { StringBuffer buff = new StringBuffer(); for (int i=0;i<size;i++) --- 151,170 ---- } ! /** ! * Convert this nodelist into the equivalent HTML. ! * @deprecated Use {@link #toHtml}. ! * @return The contents of the list as HTML text. ! */ ! public String asHtml() ! { ! return (toHtml ()); ! } ! ! /** ! * Convert this nodelist into the equivalent HTML. ! * @return The contents of the list as HTML text. ! */ ! public String toHtml() ! { StringBuffer buff = new StringBuffer(); for (int i=0;i<size;i++) *************** *** 175,183 **** } ! public String toString() { StringBuffer text = new StringBuffer(); for (int i=0;i<size;i++) ! text.append(nodeData[i].toPlainTextString()); ! return text.toString(); } --- 190,204 ---- } ! /** ! * Return the contents of the list as a string. ! * Suitable for debugging. ! * @return A string representation of the list. ! */ ! public String toString() ! { StringBuffer text = new StringBuffer(); for (int i=0;i<size;i++) ! text.append (nodeData[i]); ! return (text.toString ()); } |
From: Derrick O. <der...@us...> - 2005-02-13 20:36:16
|
Update of /cvsroot/htmlparser/htmlparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8914 Modified Files: build.xml Log Message: FilterBuilder Index: build.xml =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/build.xml,v retrieving revision 1.73 retrieving revision 1.74 diff -C2 -d -r1.73 -r1.74 *** build.xml 6 Sep 2004 17:19:14 -0000 1.73 --- build.xml 13 Feb 2005 20:36:03 -0000 1.74 *************** *** 334,338 **** update="true"> <include name="org/htmlparser/lexerapplications/thumbelina/**/*.class"/> - <zipfileset src="${lib}/htmllexer.jar" includes="**/*.class"/> <manifest> <attribute name="Main-Class" value="org.htmlparser.lexerapplications.thumbelina.Thumbelina"/> --- 334,337 ---- *************** *** 341,344 **** --- 340,362 ---- </target> + <!-- Create the FilterBuilder jar --> + <target name="filterbuilder" depends="JDK1.4,jarparser" description="create filterbuilder.jar" if="JDK1.4"> + <!-- Create the lib directory --> + <mkdir dir="${lib}"/> + <javac compiler="javac1.4" srcdir="${src}" debug="on" classpath="src:${lib}/htmlparser.jar" source="1.3"> + <include name="org/htmlparser/parserapplications/filterbuilder/**/*.java"/> + </javac> + <jar jarfile="${lib}/filterbuilder.jar" + basedir="${src}" + defaultexcludes="no" + update="true"> + <include name="org/htmlparser/parserapplications/filterbuilder/**/*.class"/> + <include name="org/htmlparser/parserapplications/filterbuilder/**/*.gif"/> + <manifest> + <attribute name="Main-Class" value="org.htmlparser.parserapplications.filterbuilder.FilterBuilder"/> + </manifest> + </jar> + </target> + <!-- Run the unit tests --> <target name="test" depends="jar" description="run the JUnit tests"> |
From: Derrick O. <der...@us...> - 2005-02-13 20:36:11
|
Update of /cvsroot/htmlparser/htmlparser/bin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8914/bin Modified Files: thumbelina.bat thumbelina Added Files: filterbuilder filterbuilder.bat Log Message: FilterBuilder Index: thumbelina =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/bin/thumbelina,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** thumbelina 28 Jul 2004 11:38:08 -0000 1.2 --- thumbelina 13 Feb 2005 20:36:02 -0000 1.3 *************** *** 54,57 **** HTMLPARSER_LIB="${HTMLPARSER_HOME}/lib" ! "$JAVACMD" -Xmx256M -classpath "${HTMLPARSER_LIB}/thumbelina.jar" org.htmlparser.lexerapplications.thumbelina.Thumbelina "$@" --- 54,57 ---- HTMLPARSER_LIB="${HTMLPARSER_HOME}/lib" ! "$JAVACMD" -Xmx256M -classpath "${HTMLPARSER_LIB}/thumbelina.jar:${HTMLPARSER_LIB}/htmllexer.jar" org.htmlparser.lexerapplications.thumbelina.Thumbelina "$@" --- NEW FILE: filterbuilder --- #! /bin/sh if [ -z "$HTMLPARSER_HOME" ] ; then ## resolve links - $0 may be a link to the home PRG="$0" progname=`basename "$0"` saveddir=`pwd` # need this for relative symlinks dirname_prg=`dirname "$PRG"` cd "$dirname_prg" while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done HTMLPARSER_HOME=`dirname "$PRG"`/.. cd "$saveddir" # make it fully qualified HTMLPARSER_HOME=`cd "$HTMLPARSER_HOME" && pwd` fi if [ -z "$JAVACMD" ] ; then if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi else JAVACMD=`which java 2> /dev/null ` if [ -z "$JAVACMD" ] ; then JAVACMD=java fi fi fi if [ ! -x "$JAVACMD" ] ; then echo "Error: JAVA_HOME is not defined correctly." echo " We cannot execute $JAVACMD" exit 1 fi HTMLPARSER_LIB="${HTMLPARSER_HOME}/lib" "$JAVACMD" -Xmx256M -classpath "${HTMLPARSER_LIB}/filterbuilder.jar:${HTMLPARSER_LIB}/htmlparser.jar" org.htmlparser.parserapplications.filterbuilder.FilterBuilder "$@" --- NEW FILE: filterbuilder.bat --- java -Xmx256M -classpath ..\lib\filterbuilder.jar;..\lib\htmlparser.jar org.htmlparser.parserapplications.filterbuilder.FilterBuilder Index: thumbelina.bat =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/bin/thumbelina.bat,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** thumbelina.bat 28 Jul 2004 11:38:08 -0000 1.2 --- thumbelina.bat 13 Feb 2005 20:36:02 -0000 1.3 *************** *** 1 **** ! java -Xmx256M -classpath ..\lib\thumbelina.jar org.htmlparser.lexerapplications.thumbelina.Thumbelina %1 %2 --- 1 ---- ! java -Xmx256M -classpath ..\lib\thumbelina.jar;..\lib\htmllexer.jar org.htmlparser.lexerapplications.thumbelina.Thumbelina %1 %2 |
From: Derrick O. <der...@us...> - 2005-02-13 20:36:11
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/visitorsTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8914/src/org/htmlparser/tests/visitorsTests Modified Files: HtmlPageTest.java Log Message: FilterBuilder Index: HtmlPageTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/visitorsTests/HtmlPageTest.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** HtmlPageTest.java 24 May 2004 16:18:34 -0000 1.19 --- HtmlPageTest.java 13 Feb 2005 20:36:02 -0000 1.20 *************** *** 108,112 **** NodeList bodyNodes = page.getBody(); assertEquals("number of nodes in body",2,bodyNodes.size()); ! assertXmlEquals("body html", guts, bodyNodes.asHtml()); TableTag tables [] = page.getTables(); assertEquals("number of tables",1,tables.length); --- 108,112 ---- NodeList bodyNodes = page.getBody(); assertEquals("number of nodes in body",2,bodyNodes.size()); ! assertXmlEquals("body html", guts, bodyNodes.toHtml()); TableTag tables [] = page.getTables(); assertEquals("number of tables",1,tables.length); |
From: Derrick O. <der...@us...> - 2005-02-13 20:36:10
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8914/src/org/htmlparser/tests Modified Files: ParserTest.java Log Message: FilterBuilder Index: ParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/ParserTest.java,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** ParserTest.java 6 Sep 2004 17:13:08 -0000 1.63 --- ParserTest.java 13 Feb 2005 20:36:02 -0000 1.64 *************** *** 35,39 **** import java.net.HttpURLConnection; import java.net.URL; - import java.net.URLConnection; import java.util.Locale; --- 35,38 ---- *************** *** 47,52 **** import org.htmlparser.filters.TagNameFilter; import org.htmlparser.lexer.InputStreamSource; - import org.htmlparser.lexer.Lexer; - import org.htmlparser.lexer.Page; import org.htmlparser.tags.BodyTag; import org.htmlparser.tags.ImageTag; --- 46,49 ---- |
From: Derrick O. <der...@us...> - 2005-02-13 20:36:10
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8914/src/org/htmlparser Modified Files: NodeFilter.java Parser.java Log Message: FilterBuilder Index: Parser.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/Parser.java,v retrieving revision 1.99 retrieving revision 1.100 diff -C2 -d -r1.99 -r1.100 *** Parser.java 2 Sep 2004 02:28:08 -0000 1.99 --- Parser.java 13 Feb 2005 20:36:01 -0000 1.100 *************** *** 494,518 **** * Parse the given resource, using the filter provided. * @param filter The filter to apply to the parsed nodes. */ ! public void parse (NodeFilter filter) throws ParserException { NodeIterator e; Node node; ! NodeList list; ! list = new NodeList (); for (e = elements (); e.hasMoreNodes (); ) { node = e.nextNode (); if (null != filter) ! { ! node.collectInto (list, filter); ! for (int i = 0; i < list.size (); i++) ! System.out.println (list.elementAt (i)); ! list.removeAll (); ! } else ! System.out.println (node); } } --- 494,517 ---- * Parse the given resource, using the filter provided. * @param filter The filter to apply to the parsed nodes. + * @return The list of matching nodes (for a <code>null</code> + * filter this is all the top level nodes). */ ! public NodeList parse (NodeFilter filter) throws ParserException { NodeIterator e; Node node; ! NodeList ret; ! ret = new NodeList (); for (e = elements (); e.hasMoreNodes (); ) { node = e.nextNode (); if (null != filter) ! node.collectInto (ret, filter); else ! ret.add (node); } + + return (ret); } *************** *** 643,647 **** } parser.setURL (args[0]); ! parser.parse (filter); } catch (ParserException e) --- 642,646 ---- } parser.setURL (args[0]); ! System.out.println (parser.parse (filter)); } catch (ParserException e) Index: NodeFilter.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/NodeFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NodeFilter.java 8 Nov 2003 21:30:56 -0000 1.1 --- NodeFilter.java 13 Feb 2005 20:36:01 -0000 1.2 *************** *** 27,34 **** --- 27,39 ---- package org.htmlparser; + import java.io.Serializable; + /** * Implement this interface to select particular nodes. */ public interface NodeFilter + extends + Serializable, + Cloneable { /** |
From: Derrick O. <der...@us...> - 2005-02-13 19:39:51
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/images In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15462/src/org/htmlparser/parserapplications/filterbuilder/wrappers/images Log Message: Directory /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/images added to the repository |
From: Derrick O. <der...@us...> - 2005-02-13 19:39:51
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15462/src/org/htmlparser/parserapplications/filterbuilder/wrappers Log Message: Directory /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers added to the repository |
From: Derrick O. <der...@us...> - 2005-02-13 19:39:51
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/layouts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15462/src/org/htmlparser/parserapplications/filterbuilder/layouts Log Message: Directory /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/layouts added to the repository |
From: Derrick O. <der...@us...> - 2005-02-13 19:39:50
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15462/src/org/htmlparser/parserapplications/filterbuilder Log Message: Directory /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder added to the repository |
From: Derrick O. <der...@us...> - 2005-02-13 19:39:50
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/images In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15462/src/org/htmlparser/parserapplications/filterbuilder/images Log Message: Directory /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/images added to the repository |
From: Derrick O. <der...@us...> - 2005-02-13 19:39:50
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/images/.xvpics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15462/src/org/htmlparser/parserapplications/filterbuilder/wrappers/images/.xvpics Log Message: Directory /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/images/.xvpics added to the repository |
From: Derrick O. <der...@us...> - 2005-02-13 19:39:50
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/images/.xvpics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15462/src/org/htmlparser/parserapplications/filterbuilder/images/.xvpics Log Message: Directory /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/images/.xvpics added to the repository |
From: Derrick O. <der...@us...> - 2005-01-10 00:43:34
|
Update of /cvsroot/htmlparser/htmlparser/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30634/docs Modified Files: samples.html Log Message: Fix link to StringExtractor. Index: samples.html =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/docs/samples.html,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** samples.html 4 Jan 2004 03:23:08 -0000 1.1 --- samples.html 10 Jan 2005 00:43:24 -0000 1.2 *************** *** 57,61 **** <td> <i>Extract text from a web page.</i><br> ! <a href="../javadoc/org/htmlparser/parserapplications/LinkExtractor.html" target="_parent">org.htmlparser.parserapplications.StringExtractor</a> <pre> <code>bin/stringextractor http://website_url [-links]</code> --- 57,61 ---- <td> <i>Extract text from a web page.</i><br> ! <a href="../javadoc/org/htmlparser/parserapplications/StringExtractor.html" target="_parent">org.htmlparser.parserapplications.StringExtractor</a> <pre> <code>bin/stringextractor http://website_url [-links]</code> |