Package org.htmlparser.util

Examples of org.htmlparser.util.NodeList


     * Set the enclosed <code>PARAM<code> children.
     * @param newObjectParams The new parameters.
     */
    public void setObjectParams (Hashtable newObjectParams)
    {
        NodeList kids;
        Node node;
        Tag tag;
        String paramName;
        String paramValue;
        Vector attributes;
        TextNode string;
       
        kids = getChildren ();
        if (null == kids)
            kids = new NodeList ();
        else
            // erase objectParams from kids
            for (int i = 0; i < kids.size (); )
            {
                node = kids.elementAt (i);
                if (node instanceof Tag)
                    if (((Tag)node).getTagName ().equals ("PARAM"))
                    {
                        kids.remove (i);
                        // remove whitespace too
                        if (i < kids.size ())
                        {
                            node = kids.elementAt (i);
                            if (node instanceof TextNode)
                            {
                                string = (TextNode)node;
                                if (0 == string.getText ().trim ().length ())
                                    kids.remove (i);
                            }
                        }
                    }
                    else
                        i++;
                else
                    i++;
            }
       
        // add newObjectParams to kids
        for (Enumeration e = newObjectParams.keys (); e.hasMoreElements (); )
        {
            attributes = new Vector (); // should the tag copy the attributes?
            paramName = (String)e.nextElement ();
            paramValue = (String)newObjectParams.get (paramName);
            attributes.addElement (new Attribute ("PARAM", null));
            attributes.addElement (new Attribute (" "));
            attributes.addElement (new Attribute ("VALUE", paramValue, '"'));
            attributes.addElement (new Attribute (" "));
            attributes.addElement (new Attribute ("NAME", paramName.toUpperCase (), '"'));
            tag = new TagNode (null, 0, 0, attributes);
            kids.add (tag);
        }
       
        //set kids as new children
        setChildren (kids);
    }
View Full Code Here


        if (endTagCheck) {
            endTags = new NodeList[tagsToBeFound.length];
            endTagCount = new int[tagsToBeFound.length];
        }
        for (int i=0;i<tagsToBeFound.length;i++) {
            tags[i] = new NodeList();
            if (endTagCheck)
                endTags[i] = new NodeList();
        }
        this.count = new int[tagsToBeFound.length];
        this.endTagCheck = endTagCheck;
    }
View Full Code Here

     * Get the row tags within this table.
     * @return The rows directly contained by this table.
     */
    public TableRow[] getRows ()
    {
        NodeList kids;
        NodeClassFilter cls;
        HasParentFilter recursion;
        NodeFilter filter;
        TableRow[] ret;

        kids = getChildren ();
        if (null != kids)
        {
            cls = new NodeClassFilter (TableTag.class);
            recursion = new HasParentFilter (null);
            filter = new OrFilter (
                        new AndFilter (
                            cls,
                            new IsEqualFilter (this)),
                        new AndFilter ( // recurse up the parent chain
                            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
                new AndFilter (
                    new NodeClassFilter (TableRow.class),
                    filter), true);
            ret = new TableRow[kids.size ()];
            kids.copyToNodeArray (ret);
        }
        else
            ret = new TableRow[0];
       
        return (ret);
View Full Code Here

        SimpleNodeIterator ret;

        if (null != getChildren ())
            ret = getChildren ().elements ();
        else
            ret = (new NodeList ()).elements ();

        return (ret);
    }
View Full Code Here

     * @return An iterator over the children.
     */
    public SimpleNodeIterator elements()
    {
        return (
            (null == getChildren ()) ? new NodeList ().elements () :
            getChildren ().elements ());
    }
View Full Code Here

     */
    public NodeList searchFor (String searchString, boolean caseSensitive, Locale locale)
    {
        Node node;
        String text;
        NodeList ret;
       
        ret = new NodeList ();

        if (!caseSensitive)
            searchString = searchString.toUpperCase (locale);
        for (SimpleNodeIterator e = children (); e.hasMoreNodes (); )
        {
            node = e.nextNode ();
            text = node.toPlainTextString ();
            if (!caseSensitive)
                text = text.toUpperCase (locale);
            if (-1 != text.indexOf (searchString))
                ret.add (node);
        }

        return (ret);
    }
View Full Code Here

     * @param recursive If true, recursively search through the children.
     * @return A list of children found.
     */
    public NodeList searchFor (Class classType, boolean recursive)
    {
        NodeList children;
        NodeList ret;

        children = getChildren ();
        if (null == children)
            ret = new NodeList ();
        else
            ret = children.extractAllNodesThatMatch (
                new NodeClassFilter (classType), recursive);

        return (ret);
View Full Code Here

     * Return the number of child nodes in this tag.
     * @return The child node count.
     */
    public int getChildCount()
    {
        NodeList children;
       
        children = getChildren ();

        return ((null == children) ? 0 : children.size ());
    }
View Full Code Here

     * further navigation is possible.
     * @param searchText The text to search for.
     * @return The list of text nodes (recursively) found.
     */
    public Text[] digupStringNode(String searchText) {
        NodeList nodeList = searchFor(searchText);
        NodeList stringNodes = new NodeList();
        for (int i=0;i<nodeList.size();i++) {
            Node node = nodeList.elementAt(i);
            if (node instanceof Text) {
                stringNodes.add(node);
            } else {
                if (node instanceof CompositeTag) {
                    CompositeTag ctag = (CompositeTag)node;
                    Text[] nodes = ctag.digupStringNode(searchText);
                    for (int j=0;j<nodes.length;j++)
                        stringNodes.add(nodes[j]);
                }
            }
        }
        Text[] stringNode = new Text[stringNodes.size()];
        for (int i=0;i<stringNode.length;i++) {
            stringNode[i] = (Text)stringNodes.elementAt(i);
        }
        return stringNode;
    }
View Full Code Here

      NodeFilter filter = new OrFilter( new NodeFilter[] {
          new TagNameFilter("A"),
          new TagNameFilter("META")
          }
      );
      NodeList list = par.parse( filter );
      System.out.println("Url: " + _url.toString() + " found " + list.size() + " items.");
      LinkTag lt = null;
      for (SimpleNodeIterator e = list.elements (); e.hasMoreNodes (); ) {
        Node n = e.nextNode();
        if (n.getClass() == LinkTag.class ) {
          lt = (LinkTag)n;
          if ( FileTypes.isAllowedFileType(lt.getLink())) {
            String url = par.getLexer().getPage().getAbsoluteURL(lt.getLink());
View Full Code Here

TOP

Related Classes of org.htmlparser.util.NodeList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.