84 lines
1.8 KiB
Java
84 lines
1.8 KiB
Java
package com.tenwa.sdk.utils;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
import java.util.Properties;
|
|
|
|
import org.xml.sax.Attributes;
|
|
import org.xml.sax.SAXException;
|
|
import org.xml.sax.helpers.DefaultHandler;
|
|
|
|
|
|
/**
|
|
*
|
|
* ÕÐÐÐXML±¨ÎĽâÎöÀà
|
|
*
|
|
*/
|
|
@SuppressWarnings("rawtypes")
|
|
public class SaxHandler extends DefaultHandler {
|
|
int layer=0;
|
|
String curSectionName;
|
|
String curKey;
|
|
String curValue;
|
|
XmlPacket pktData;
|
|
Map mpRecord;
|
|
|
|
public SaxHandler(XmlPacket data){
|
|
curSectionName = "";
|
|
curKey = "";
|
|
curValue = "";
|
|
pktData = data;
|
|
mpRecord = new Properties();
|
|
}
|
|
|
|
public void startElement(String uri, String localName, String qName,
|
|
Attributes attributes) throws SAXException {
|
|
layer++;
|
|
if(layer==2){
|
|
curSectionName = qName;
|
|
}else if(layer==3){
|
|
curKey = qName;
|
|
}
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
public void endElement(String uri, String localName, String qName)
|
|
throws SAXException {
|
|
if(layer==2){
|
|
pktData.putProperty(curSectionName, mpRecord);
|
|
mpRecord = new Properties();
|
|
}else if(layer==3){
|
|
mpRecord.put(curKey, curValue);
|
|
if(curSectionName.equals("INFO")){
|
|
if(curKey.equals("FUNNAM")){
|
|
pktData.setFUNNAM(curValue);
|
|
}else if(curKey.equals("LGNNAM")){
|
|
pktData.setLGNNAM(curValue);
|
|
}else if(curKey.equals("RETCOD")){
|
|
pktData.setRETCOD(curValue);
|
|
}else if(curKey.equals("ERRMSG")){
|
|
pktData.setERRMSG(curValue);
|
|
}else if(curKey.equals("DATTYP")){
|
|
pktData.setDATTYP(curValue);
|
|
}
|
|
}
|
|
}
|
|
curValue = "";
|
|
layer--;
|
|
}
|
|
|
|
@SuppressWarnings("unlikely-arg-type")
|
|
public void characters(char[] ch, int start, int length)
|
|
throws SAXException {
|
|
if(layer==3){
|
|
String value = new String(ch, start, length);
|
|
if(ch.equals("\n")){
|
|
curValue += "\r\n";
|
|
}else{
|
|
curValue += value;
|
|
}
|
|
}
|
|
}
|
|
}
|