check.java
来自「这是一个汉诺塔程序」· Java 代码 · 共 76 行
JAVA
76 行
/**
@ author LightingMan
*/
import javax.swing.text.html.*;
import java.util.*;
import javax.swing.text.*;
import java.io.*;
import javax.swing.*;
/**
*
* This class will deal with all the tags and attributes
* to check weather they are legal
*
*/
class Check{
HTML.Tag tag;
HTML.Attribute attrib;
ArrayList<HTML.Attribute> attributes;
StringTokenizer stk;
/**
* The default constrator
*
*/
public Check(){
}
/**
*
* @param line The String line to be check weather there is any error
* @param lineNumber At whice line is the tag
*/
public Check(String line,JTextArea jta,int lineNumber){
//this();
String tmp;
boolean p=true;
line=dealTheString(line);
stk=new StringTokenizer(line);
tmp=stk.nextToken().toLowerCase();
tag=HTML.getTag(tmp);
if (tag==null) {
new MyException("Unknow Tag Exception:"+tmp,jta,lineNumber);
p=false;
}
else
attributes=TagAndAttributes.getAttribute(tag);
if (p)
while(stk.hasMoreTokens()){
tmp=stk.nextToken().toLowerCase();
attrib=HTML.getAttributeKey(tmp);
if (attrib==null) new MyException("Unknow attribute '"+tmp+"' to the tag:<"+tag+">",jta,lineNumber);
else
if (!attributes.contains(attrib))
new MyException("Attribute '"+attrib+"' does not match the tag! <"+tag+">",jta,lineNumber);
if (stk.hasMoreTokens())tmp=stk.nextToken();
else
if(attrib!=null&&(!tmp.equals("="))){
new MyException("The symbol \"=\" should take after the attrib: "+attrib,jta,lineNumber);
}
if (stk.hasMoreTokens())tmp=stk.nextToken();
else
if(attrib!=null)
new MyException("The Attribute "+attrib+" should have a value!",jta,lineNumber);
}
}
private String dealTheString(String s){
String tmp;
tmp=s.replaceAll("="," = ");
return tmp;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?