📄 matchselectconfigparser.java
字号:
//匹配查询的xml配置解析器
package find;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.net.URL;
import java.io.File;
public class MatchSelectConfigParser extends DefaultHandler {
//private String currentSet;
//private String currentName;
private int step;
private StringBuffer currentValue = new StringBuffer();
private String sql;//sql语句
private String title;//页面标题
private String matchColumn;//匹配列
private String hide;//隐藏列
private String label;//标题名
private String column;//列名
private String back;//返回组件
public MatchSelectConfigParser(){
this.step = 1;
this.label = "";
this.column = "";
}
//get和set方法
public String getSql(){
return this.sql;
}
void setSql(String s){
this.sql = s;
}
public String getTitle(){
return this.title;
}
void setTitle(String s){
this.title = s;
}
public String getMatchColumn(){
return this.matchColumn;
}
void setMatchColumn(String s){
this.matchColumn = s;
}
public String getHide(){
return this.hide;
}
void setHide(String s){
this.hide = s;
}
public String[] getLabel(){
return this.label.split(";");
}
void setLabel(String s){
this.label = this.label+s+";";
}
public String[] getColumn(){
return this.column.split(";");
}
void setColumn(String s){
this.column = this.column+s+";";
}
public String getBack(){
return this.back;
}
void setBack(String s){
this.back = s;
}
//定义开始解析元素的方法. 这里是将<xxx>中的名称xxx提取出来.
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
currentValue.delete(0, currentValue.length());
if(qName.equals("标题名")) this.step = 5;
}
//这里是将<xxx></xxx>之间的值加入到currentValue
public void characters(char[] ch, int start, int length) throws SAXException {
currentValue.append(ch, start, length);
}
//在遇到</xxx>结束后,
public void endElement(String uri, String localName, String qName) throws SAXException {
switch(this.step){
case 1:
this.setSql(this.currentValue.toString().trim());
break;
case 2:
this.setTitle(this.currentValue.toString().trim());
break;
case 3:
this.setMatchColumn(this.currentValue.toString().trim());
break;
case 4:
this.setHide(this.currentValue.toString().trim());
break;
case 5:
this.setLabel(this.currentValue.toString().trim());
break;
case 6:
this.setColumn(this.currentValue.toString().trim());
break;
case 7:
break;
case 8:
this.setBack(this.currentValue.toString().trim());
break;
default:
;
}
this.step++;
//props.put(qName.toLowerCase(), currentValue.toString().trim());
}
public void parse(String filename) throws Exception {
SAXParserFactory factory = SAXParserFactory.newInstance();
//factory.setNamespaceAware(false);
//factory.setValidating(false);
SAXParser parser = factory.newSAXParser();
try{
parser.parse(new File(filename).toURL().toString(), this);
}finally{
factory=null;
parser=null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -