Package org.htmlparser

Examples of org.htmlparser.NodeFilter


    }
   
    public void testTagsFilterMethods() {
        try
        {
            NodeFilter filter = new TagNameFilter ("DIV");
            String[] tmpSplitTags = ParserUtils.splitTags("Begin <DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter);
            assertStringEquals(
                "modified text",
                "Begin * ALL OK",
                new String(tmpSplitTags[0] + '*' + tmpSplitTags[1])
            );
            tmpSplitTags = ParserUtils.splitTags("Begin <DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, false, false);
            assertStringEquals(
                "modified text",
                "Begin *<DIV>  +12.5 </DIV>* ALL OK",
                new String(tmpSplitTags[0] + '*' + tmpSplitTags[1] + '*' + tmpSplitTags[2])
            );
            tmpSplitTags = ParserUtils.splitTags("Begin <DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, true, false);
            assertStringEquals(
                "modified text",
                "Begin *  +12.5 * ALL OK",
                new String(tmpSplitTags[0] + '*' + tmpSplitTags[1] + '*' + tmpSplitTags[2])
            );
            tmpSplitTags = ParserUtils.splitTags("Begin <DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, false, true);
            assertStringEquals(
                "modified text",
                "Begin * ALL OK",
                new String(tmpSplitTags[0] + '*' + tmpSplitTags[1])
            );
            assertStringEquals(
                "modified text",
                " ALL OK",
                ParserUtils.trimTags("<DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter)
            );
            assertStringEquals(
                "modified text",
                "<DIV>  +12.5 </DIV> ALL OK",
                ParserUtils.trimTags("<DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, false, false)
            );
            assertStringEquals(
                "modified text",
                "  +12.5  ALL OK",
                ParserUtils.trimTags("<DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, true, false)
            );
            assertStringEquals(
                "modified text",
                " ALL OK",
                ParserUtils.trimTags("<DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, false, true)
            );
            NodeFilter filterTableRow = new TagNameFilter("TR");
            NodeFilter filterTableColumn = new TagNameFilter("TD");
            OrFilter filterOr = new OrFilter(filterTableRow, filterTableColumn);
            assertStringEquals(
                "modified text",
                " ALL OK",
                ParserUtils.trimTags("<TR><TD>  +12.5 </TD></TR> ALL OK", filterOr)
View Full Code Here


    }
   
    public void testTagsClassMethods() {
        try
        {
            NodeFilter filter = new NodeClassFilter (Div.class);
            String[] tmpSplitTags = ParserUtils.splitTags("Begin <DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter);
            assertStringEquals(
                "modified text",
                "Begin * ALL OK",
                new String(tmpSplitTags[0] + '*' + tmpSplitTags[1])
            );
            tmpSplitTags = ParserUtils.splitTags("Begin <DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, false, false);
            assertStringEquals(
                "modified text",
                "Begin *<DIV>  +12.5 </DIV>* ALL OK",
                new String(tmpSplitTags[0] + '*' + tmpSplitTags[1] + '*' + tmpSplitTags[2])
            );
            tmpSplitTags = ParserUtils.splitTags("Begin <DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, true, false);
            assertStringEquals(
                "modified text",
                "Begin *  +12.5 * ALL OK",
                new String(tmpSplitTags[0] + '*' + tmpSplitTags[1] + '*' + tmpSplitTags[2])
            );
            tmpSplitTags = ParserUtils.splitTags("Begin <DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, false, true);
            assertStringEquals(
                "modified text",
                "Begin * ALL OK",
                new String(tmpSplitTags[0] + '*' + tmpSplitTags[1])
            );
            assertStringEquals(
                "modified text",
                " ALL OK",
                ParserUtils.trimTags("<DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter)
            );
            assertStringEquals(
                "modified text",
                "<DIV>  +12.5 </DIV> ALL OK",
                ParserUtils.trimTags("<DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, false, false)
            );
            assertStringEquals(
                "modified text",
                "  +12.5  ALL OK",
                ParserUtils.trimTags("<DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, true, false)
            );
            assertStringEquals(
                "modified text",
                " ALL OK",
                ParserUtils.trimTags("<DIV><DIV>  +12.5 </DIV></DIV> ALL OK", filter, false, true)
            );
            NodeFilter filterTableRow = new NodeClassFilter(TableRow.class);
            NodeFilter filterTableColumn = new NodeClassFilter(TableColumn.class);
            OrFilter filterOr = new OrFilter(filterTableRow, filterTableColumn);
            assertStringEquals(
                "modified text",
                " ALL OK",
                ParserUtils.trimTags("<TR><TD>  +12.5 </TD></TR> ALL OK", filterOr)
View Full Code Here

    }
   
    public void testTagsComplexMethods() {
        try
        {
            NodeFilter filterLink = new NodeClassFilter (LinkTag.class);
            NodeFilter filterDiv = new NodeClassFilter (Div.class);
            OrFilter filterLinkDiv = new OrFilter (filterLink, filterDiv);
            NodeFilter filterTable = new NodeClassFilter (TableColumn.class);
            OrFilter filter = new OrFilter (filterLinkDiv, filterTable);
            String[] tmpSplitTags = ParserUtils.splitTags("OutsideLeft<A>AInside</A><DIV><DIV>DivInside</DIV></DIV><TD>TableColoumnInside</TD>OutsideRight", filter);
            assertStringEquals(
                "modified text",
                "OutsideLeft*OutsideRight",
 
View Full Code Here

     * Get the underlying node filter object.
     * @return The node filter object suitable for serialization.
     */
    public NodeFilter getNodeFilter ()
    {
        NodeFilter filter;
        HasParentFilter ret;
       
        ret = new HasParentFilter ();

        ret.setRecursive (mFilter.getRecursive ());
View Full Code Here

     * Get the underlying node filter's subordinate filters.
     * @return The node filter object's contained filters.
     */
    public NodeFilter[] getSubNodeFilters ()
    {
        NodeFilter filter;
        NodeFilter[] ret;

        filter = mFilter.getParentFilter ();
        if (null != filter)
            ret = new NodeFilter[] { filter };
View Full Code Here

    public TableColumn[] getColumns ()
    {
        NodeList kids;
        NodeClassFilter cls;
        HasParentFilter recursion;
        NodeFilter filter;
        TableColumn[] ret;

        kids = getChildren ();
        if (null != kids)
        {
View Full Code Here

    public TableHeader[] getHeaders ()
    {
        NodeList kids;
        NodeClassFilter cls;
        HasParentFilter recursion;
        NodeFilter filter;
        TableHeader[] ret;

        kids = getChildren ();
        if (null != kids)
        {
View Full Code Here

    public TableRow[] getRows ()
    {
        NodeList kids;
        NodeClassFilter cls;
        HasParentFilter recursion;
        NodeFilter filter;
        TableRow[] ret;

        kids = getChildren ();
        if (null != kids)
        {
View Full Code Here

    String lines[] = priorToContent.split("\n");
    return lines.length;
  }

  public int countOfTagWithIdPrefix(String tag, String idPrefix) throws Exception {
    NodeFilter filter =
      new AndFilter(
        new TagNameFilter(tag),
        new HasAttributePrefixFilter("id", idPrefix));
    return getMatchingTags(filter).size();
  }
View Full Code Here

            new AndFilter(
                    new TagNameFilter(parentTag),
                    new HasAttributePrefixFilter("id", parentIdPrefix))
    );

    NodeFilter predicates[] = {
            new TagNameFilter(childTag),
            new HasAttributeFilter("class", tagClass)
    };
    NodeFilter filter = new AndFilter(predicates);
    NodeList matches = parents.extractAllNodesThatMatch(filter, true);
    return matches.size();
  }
View Full Code Here

TOP

Related Classes of org.htmlparser.NodeFilter

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.