📄 myhtmlhrefhandler.java
字号:
// MyHtmlHrefHandler.java
// Written by Wei Sun @ 2006 Semester A; For Course CS5286
// This should always be used together with
// LinkExtractor.java
import java.util.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
public class MyHtmlHrefHandler extends HTMLEditorKit.ParserCallback {
public Set extLinks=new HashSet();
public Set localLinks=new HashSet();
public void reset(){
extLinks.clear();
localLinks.clear();
}
// This method is inherited from the super class
// HTMLEditorKit.ParserCallback
public void handleStartTag(
HTML.Tag tag, MutableAttributeSet attributes, int pos) {
//If the element is not a link, i.e.: Not <A HREF="...">...</A>
//Then ignore it
if(!(tag.equals(HTML.Tag.A))){
return;
}
// If the element is <A HREF="hello.html">Hello</a>
// Then link="hello.html"
String link=(String) attributes.getAttribute(HTML.Attribute.HREF);
if(link==null||link.length()==0)return;
if(link.length()>=4&&link.substring(0,4).equalsIgnoreCase("http")){
// An external link is like "http://www.google.com/"
extLinks.add(link);
}else{
// An internal link is like "/~cs5286/index.html"
localLinks.add(link);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -