Welcome![Sign In][Sign Up]
Location:
Search - catch

Search list

[ActiveX/DCOM/ATLAtlDebugHeap_demo.zip

Description: 使用ATL跟踪内存错误的例子(如MFC里的try..catch)
Platform: | Size: 18583 | Author: | Hits:

[Internet-Network用Java编写HTML文件分析程序

Description:

Java编写HTML文件分析程序

 一、概述

    

    Web服务器的核心是对Html文件中的各标记(Tag)作出正确的分析,一种编程语言的解释程序也是对源文件中的保留字进行分析再做解释的。实际应用中,我们也经常会碰到需要对某一特定类型文件进行要害字分析的情况,比如,需要将某个HTML文件下载并同时下载与之相关的.gif.class等文件,此时就要求对HTML文件中的标记进行分离,找出所需的文件名及目录。在Java出现以前,类似工作需要对文件中的每个字符进行分析,从中找出所需部分,不仅编程量大,且易出错。笔者在近期的项目中利用Java的输入流类StreamTokenizer进行HTML文件的分析,效果较好。在此,我们要实现从已知的Web页面下载HTML文件,对其进行分析后,下载该页面中包含的HTML文件(假如在Frame中)、图像文件和ClassJava Applet)文件。

    

    二、StreamTokenizer

    

    StreamTokenizer即令牌化输入流的作用是将一个输入流中变成令牌流。令牌流中的令牌实体有三类:单词(即多字符令牌)、单字符令牌和空白(包括JavaC/C++中的说明语句)。

    

    StreamTokenizer类的构造器为: StreamTokenizer(InputStream in)

    

    该类有一些公有实例变量:ttypesvalnval ,分别表示令牌类型、当前字符串值和当前数字值。当我们需要取得令牌(即HTML中的标记)之间的字符时,应访问变量sval。而读向下一个令牌的方法是调用nextToken()。方法nextToken()的返回值是int型,共有四种可能的返回:

    

    StreamTokenizer.TT_NUMBER: 表示读到的令牌是数字,数字的值是double型,可以从实例变量nval中读取。

    

    StreamTokenizer.TT_Word: 表示读到的令牌是非数字的单词(其他字符也在其中),单词可以从实例变量sval中读取。

    

    StreamTokenizer.TT_EOL: 表示读到的令牌是行结束符。

    

    假如已读到流的尽头,则nextToken()返回TT_EOF

    

    开始调用nextToken()之前,要设置输入流的语法表,以便使分析器辨识不同的字符。WhitespaceChars(int low, int hi)方法定义没有意义的字符的范围。WordChars(int low, int hi)方法定义构造单词的字符范围。

    

    三、程序实现

    

    1HtmlTokenizer类的实现

    

    对某个令牌流进行分析之前,首先应对该令牌流的语法表进行设置,在本例中,即是让程序分出哪个单词是HTML的标记。下面给出针对我们需要的HTML标记的令牌流类定义,它是StreamTokenizer的子类:

    

    

    import java.io.*;

    import java.lang.String;

    class HtmlTokenizer extends

    StreamTokenizer {

    //定义各标记,这里的标记仅是本例中必须的,

    可根据需要自行扩充

     static int HTML_TEXT=-1;

     static int HTML_UNKNOWN=-2;

     static int HTML_EOF=-3;

     static int HTML_IMAGE=-4;

     static int HTML_FRAME=-5;

     static int HTML_BACKGROUND=-6;

     static int HTML_APPLET=-7;

    

    boolean outsideTag=true; //判定是否在标记之中

    

     //构造器,定义该令牌流的语法表。

     public HtmlTokenizer(BufferedReader r) {

    super(r);

    this.resetSyntax(); //重置语法表

    this.wordChars(0,255); //令牌范围为全部字符

    this.ordinaryChar('< '); //HTML标记两边的分割符

    this.ordinaryChar('>');

     } //end of constrUCtor

    

     public int nextHtml(){

    int token; //令牌

    try{

    switch(token=this.nextToken()){

    case StreamTokenizer.TT_EOF:

    //假如已读到流的尽头,则返回TT_EOF

    return HTML_EOF;

    case '< ': //进入标记字段

    outsideTag=false;

    return nextHtml();

    case '>': //出标记字段

    outsideTag=true;

    return nextHtml();

    case StreamTokenizer.TT_WORD:

    //若当前令牌为单词,判定是哪个标记

    if (allWhite(sval))

     return nextHtml(); //过滤其中空格

    else if(sval.toUpperCase().indexOf("FRAME")

    !=-1 && !outsideTag) //标记FRAME

     return HTML_FRAME;

    else if(sval.toUpperCase().indexOf("IMG")

    !=-1 && !outsideTag) //标记IMG

     return HTML_IMAGE;

    else if(sval.toUpperCase().indexOf("BACKGROUND")

    !=-1 && !outsideTag) //标记BACKGROUND

     return HTML_BACKGROUND;

    else if(sval.toUpperCase().indexOf("APPLET")

    !=-1 && !outsideTag) //标记APPLET

     return HTML_APPLET;

    default:

    System.out.println ("Unknown tag: "+token);

    return HTML_UNKNOWN;

     } //end of case

    }catch(IOException e){

    System.out.println("Error:"+e.getMessage());}

    return HTML_UNKNOWN;

     } //end of nextHtml

    

    protected boolean allWhite(String s){//过滤所有空格

    //实现略

     }// end of allWhite

    

    } //end of class

    

    以上方法在近期项目中测试通过,操作系统为Windows NT4,编程工具使用Inprise Jbuilder3


Platform: | Size: 1066 | Author: tiberxu | Hits:

[GUI DevelopTextTip

Description: 用VC写了一个CMFECToolTip类来实现浮动的鼠标提示功能,它能捕捉鼠标信息,当鼠标在设定的控件上停留时会显示彩色文本。-VC was a CMFECToolTip categories to achieve the floating mouse suggest function, it can catch mice information, when the mouse in the control set to stay on the text color will be displayed.
Platform: | Size: 38953 | Author: 郭经飞 | Hits:

[ICQ-IM-Chatqq密码大盗

Description: 这是一个捕捉qq密码的软件.它有vc开发而成, 分客户端和服务端构成.-This a catch qq password software. Vc it was developed, sub-client and server-side form.
Platform: | Size: 142253 | Author: 许益欢 | Hits:

[Windows Developftpprotocol_client

Description: 在学习FTP协议偶有感悟,于是想起了写一篇文章来总结一下自己学习的东西-I suddenly catch something when I study the FTP protocol. Therefore I want to write something to summarize my learnings.
Platform: | Size: 97007 | Author: szh | Hits:

[OtherMOCATCH

Description: mocatch -- Catch mouse button presses and releases.
Platform: | Size: 3031 | Author: 余华 | Hits:

[GUI DevelopMonitorDemo_src

Description: 模拟一个电视机,很漂亮的界面。非非非常 的漂亮漂亮-An simulator of TV sets with a beautiful interface,really catch your eye!
Platform: | Size: 57176 | Author: 李真如 | Hits:

[Other resourcezuigansuanfa

Description: 用于多个离散点拟合光滑曲线的,优化了追赶法,这个例子适用于闭合和不闭合两种情况。当时由于工程情况,写的急,代码不好看,但是很好用。为了方便传递参数,我做了一个链表,用时候根据自己情况可以修改,核心算法不动即可。-point for a number of discrete smooth curve fitting, and optimized to catch up with the law applicable to this case is not closed and the closure of two. At that time, because the situation, was the most aggressive, the code does not look good, but good use. To facilitate the transmission parameters, I have done a linked list, when used according to its own circumstances can change, the core algorithm can be fixed.
Platform: | Size: 2966 | Author: qiao | Hits:

[Windows DevelopWin32病毒简单快速传染型

Description: 截获你的应用程序,调用的,任何输入函数.rar-Catch your application, and invoke any input function.
Platform: | Size: 7822 | Author: 111 | Hits:

[Game Hook CrackHappyBall

Description: 以前写的一个台球程序外挂,现可实现桌面球的捕捉、定位、画线,支持快键。-previously written a billiards external procedures can now achieve desktop catch the ball, positioning, line drawing, support fast keys.
Platform: | Size: 31915 | Author: 吴剑 | Hits:

[Windows DevelopQQSniffer

Description: qq抓包软件, 可以捕获局域网中的QQ数据包。本程序使用C++开发。 欢迎大家指教-qq capturing Packet software, which you can catch the QQ LAN data packets. The programs use C + + development. You are welcome to enlighten
Platform: | Size: 27398 | Author: 地方 | Hits:

[Game ProgramCatchCreature

Description: “抓住它”小遊戲,a applet that plays a game called Catch the Crearure. have the crature appear at a ramdom lacation for a random durarion. the goal is to catch the creature by pressing the moouse button while the mouce pointer is on the creature-"seize it" small game, a applet that plays a game called Catch the Crearure. Have the crature appear at a ramdom lacation for a random durarion. The goal is to catch the creature by pressing the moouse mouce button while the pointer is on the creature
Platform: | Size: 43417 | Author: 何璟雯 | Hits:

[CSharpTry-Catch-Finally

Description: 帮助大家理解try catch的功能,很实用的小工具。-the program can help us to learn try catch .this is a useful tool
Platform: | Size: 14336 | Author: 丁伟业 | Hits:

[Delphi/CppBuilderCatch-the-eggs

Description: A simple game entitled catch the eggs using delphi-A simple game entitled catch the eggs using delphi
Platform: | Size: 927744 | Author: an | Hits:

[JSP/Javacatch-animal

Description: 一个扑捉动物的游戏程序,动物先随机出现在任何位置并维持一段随机的时间后消失,又以同样的方式出现在另一个随机位置上。游戏的目标是,当鼠标指在表示动物的图片上时点击鼠标捕捉动物。定义一个方法检测点击鼠标的位置是否与动物当前位置一致。最终显示捕捉到动物的次数。-A game of catch animals, animals first appear in any position and maintain disappears after a random time, and in the same way in another random position. The goal of the game is, when the mouse to point to in said animal pictures on the click of a mouse capture animals. Define a method to detect the location of the mouse click is consistent with its current location. Eventually the number of captured animals.
Platform: | Size: 2048 | Author: | Hits:

[Other GamesBeach-to-catch-crabs

Description: 线程和鼠标以及键盘事件的监听与处理是Java桌面应用程序中必须熟练掌握的关键技术。本程序使用线程和鼠标事件监听器开发一个捉螃蟹的程序,程序启动后会有一个线程控制螃蟹随机出现在沙滩的某个小洞里,鼠标点击某个螃蟹,它会流泪(因为知道自己要被抓了),而鼠标也会变成拾取物品的动作-Threads and monitor and handle mouse and keyboard events is a key technology Java desktop applications must be familiar of. This program uses threads and mouse event listeners catch crabs develop a program, the program will start a thread control random crab at the beach a little hole, a mouse click on a crab, it will cry (because they know they have to He was arrested), and the mouse will pick up items into action
Platform: | Size: 684032 | Author: 黄道 | Hits:

[CADCATCH-COOR

Description: 用鼠标左键点击选取,提取cad坐标,并输出到相应的文件中-catch CAD coordinate
Platform: | Size: 2048 | Author: qaquanxu | Hits:

[e-languageCatch--8853ASPxjkgcv906544VxWorksZI

Description: 这个源码Catch 8853ASPxjkgcv906544VxWorksZI是不错的,功能也很好,用来学习还是值得-The source of Catch- 8853 aspxjkgcv906544vxworkszi is good, function also is very good, used to is worth learning
Platform: | Size: 75776 | Author: ylf-331070 | Hits:

[Internet-Networkdstamace-Java-catch

Description: 用java读取ODBC数据库中的表,并捕获异常,输出表中的数据-With Java read ODBC tables, and catch exceptions, output the data in the table
Platform: | Size: 24576 | Author: mvleo | Hits:

[catch

Description: Catch unitest framework
Platform: | Size: 77824 | Author: rankg200 | Hits:
« 1 2 34 5 6 7 8 9 10 ... 50 »

CodeBus www.codebus.net