HtmlParser--TagFindingVisitor源文件
发布日期:2021-10-17 16:08:13 浏览次数:1 分类:技术文章

本文共 3091 字,大约阅读时间需要 10 分钟。

// $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/visitors/TagFindingVisitor.java,v 1.2 2004/02/11 02:16:59 woolfel Exp $

/*
* ====================================================================
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// The developers of JMeter and Apache are greatful to the developers
// of HTMLParser for giving Apache Software Foundation a non-exclusive
// license. The performance benefits of HTMLParser are clear and the
// users of JMeter will benefit from the hard work the HTMLParser
// team. For detailed information about HTMLParser, the project is
// hosted on sourceforge at http://htmlparser.sourceforge.net/.
//
// HTMLParser was originally created by Somik Raha in 2000. Since then
// a healthy community of users has formed and helped refine the
// design so that it is able to tackle the difficult task of parsing
// dirty HTML. Derrick Oswald is the current lead developer and was kind
// enough to assist JMeter.
//
// contributed by Joshua Kerievsky
package org.htmlparser.visitors;
import org.htmlparser.Node;
import org.htmlparser.tags.EndTag;
import org.htmlparser.tags.Tag;
import org.htmlparser.util.NodeList;
public class TagFindingVisitor extends NodeVisitor
{
    private String[] tagsToBeFound;
    private int count[];
    private int endTagCount[];
    private NodeList[] tags;
    private NodeList[] endTags;
    private boolean endTagCheck;
    public TagFindingVisitor(String[] tagsToBeFound)
    {
        this(tagsToBeFound, false);
    }
    public TagFindingVisitor(String[] tagsToBeFound, boolean endTagCheck)
    {
        this.tagsToBeFound = tagsToBeFound;
        this.tags = new NodeList[tagsToBeFound.length];
        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;
    }
    public int getTagCount(int index)
    {
        return count[index];
    }
    public void visitTag(Tag tag)
    {
        for (int i = 0; i < tagsToBeFound.length; i++)
            if (tag.getTagName().equalsIgnoreCase(tagsToBeFound[i]))
            {
                count[i]++;
                tags[i].add(tag);
            }
    }
    public Node[] getTags(int index)
    {
        return tags[index].toNodeArray();
    }
    public void visitEndTag(EndTag endTag)
    {
        if (!endTagCheck)
            return;
        for (int i = 0; i < tagsToBeFound.length; i++)
            if (endTag.getTagName().equalsIgnoreCase(tagsToBeFound[i]))
            {
                endTagCount[i]++;
                endTags[i].add(endTag);
            }
    }
    public int getEndTagCount(int index)
    {
        return endTagCount[index];
    }
}

转载地址:https://blog.csdn.net/thamsyangsw/article/details/4422985 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:HtmlParser--TextExtractingVisitor
下一篇:htmlParser收集记录

发表评论

最新留言

不错!
[***.144.177.141]2024年03月02日 21时02分58秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

java reduce.mdn_reduce高级用法 2021-06-24
java shape用法_Java PShape.scale方法代码示例 2021-06-24
java字符串三目_java字符串连接运算符和三目运算符 2021-06-24
java 堆内存 非堆内存_JVM 堆内存和非堆内存 2021-06-24
Java新手写什么demo_通过入门demo简单了解netty使用方法 2021-06-24
java国际化bundle_java语言国际化--ResouceBundle、struts 2021-06-24
java图片延迟加载_jQuery实现图片延迟加载 2021-06-24
java开发加入购物车功能_java web开发——购物车功能实现 2021-06-24
Java虚拟机不能满足_深入理解Java虚拟机--读书笔记1/3 2021-06-24
python 协程 asyncio_python – asyncio.as_completed是否会产生期货或协同程序? 2021-06-24
java设定xml文件的encoding_配置web-xml解决中文乱码问题,及各种乱码问题集结 2021-06-24
hanlp java api_java分词工具hanlp介绍 2021-06-24
nginx php 源码安装,Nginx1.12.2加php7.2.0的编译安装 2021-06-24
php 删除字节,php – 删除无效/不完整的多字节字符 2021-06-24
php 实现版本号对比,如何在PHP中实现比较版本号 2021-06-24
php sql 给数据库追加内容,php如何向数据库中的某串数据后追加内容【急】 2021-06-24
php微信小程序获取用户信息,微信小程序授权获取用户详细信息openid的实例详解... 2021-06-24
Java三元运算和if,Java三元运算符与<JDK8兼容性中的if / else 2021-06-24
graphql-php enum,php – 如何在不写长查询的情况下查询所有的GraphQL类型字段? 2021-06-24
php date 函数用法,php中date()日期时间函数使用方法 2021-06-24