📄 perform.java
字号:
package com.talkweb.micp.icpl.business;
import java.io.*;
import java.util.*;
import com.talkweb.micp.icpl.systool.*;
import org.kxml.kdom.Element;
import javax.microedition.lcdui.Display;
import com.talkweb.micp.icsp.parse.PackageParse;
public class Perform {
private Display _display = null;
private ProgressUI _progress = null;
private Hashtable[] smilData = null ;
public Perform(Display display){
_display = display;
_progress = new ProgressUI("联网等待");
_progress.init();
_display.setCurrent(_progress);
}
/**
* 根据类型和ID得到解析后的数据
* @param sType String 类型(0表根目录,1表故事,其他表场景)
* @param sId String 所对应资源的src
* @throws Exception 例外
* @return Hashtable 解析后的数据
*/
public Hashtable getParseCartoomData(String sType , String sId) throws Exception {
Hashtable parsedCartoomData = new Hashtable(3); // 解析完的数据
if (sType.equals("0") || sType.equals("1")){ // 如果是目录
try{
parsedCartoomData.put("LABEL", new Hashtable());
parsedCartoomData.put("REGION", new Vector());
parsedCartoomData.put("SELECT", getCartoomDirInfo(sType,sId));
}catch (Exception ex){
System.out.println(ex);
}
}else{ // 如果为关联场景
getStream(sId);
parsedCartoomData = PackageParse.getCartoomData(smilData,getRelationScene(sId)) ;
}
return parsedCartoomData ;
}
/**
* 得到场景目录信息
* @param sType String 类型
* @param sId String id
* @throws Exception 例外
* @return Vector 目录信息
*/
private Vector getCartoomDirInfo(String sType, String sId) throws Exception {
Dictionary dic = new Dictionary("GetNodeInfo");
dic.setValueByName("type", sType);
dic.setValueByName("id", sId);
ServiceDisp servDisp = new ServiceDisp(dic, Systool.conUrl);
dic = servDisp.call();
int len = dic.getCountByName("ret");
Vector vt = new Vector(len);
for (int x = 0; x < len; ++x) {
Hashtable hsEle = (Hashtable)dic.getValueByName("ret", x) ;
String[] strDir = new String[4] ;
strDir[0] = hsEle.get("RETID").toString();
strDir[1] = hsEle.get("RETNAME").toString();
strDir[2] = hsEle.get("RETTYPE").toString();
strDir[3] = hsEle.get("FIRSTPIC").toString();
vt.addElement(strDir);
}
dic.destory();
dic = null;
return vt;
}
/**
* 得到资源数据流
* @param sId String 资源src
* @throws Exception 例外
*/
private void getStream(String sId) throws
Exception {
getStream(sId,this._progress);
}
/**
* 得到资源数据流
* @param sId String 资源src
* @param progress ProgressUI
* @throws Exception 例外
*/
private void getStream(String sId, ProgressUI progress) throws
Exception {
String sData = "SCENEID=" + sId.trim();
Hashtable ht = Systool.getInStream(Systool.binUrl, sData);
InputStream is = (InputStream) ht.get("stream");
smilData = Systool.decodeStream(is, progress,
((Integer) ht.get("length")).
intValue());
is.close();
is = null;
ht = null;
}
/**
* 得到相关联的场景
* @param id String 资源src
* @throws Exception 例外
* @return Vector 相关联的场景
*/
private Vector getRelationScene(String id) throws Exception {
KXmlTool kt = new KXmlTool(getXMLData(id));
Vector vt = kt.getAllElementByName("OPTION");
Vector vecReturn = new Vector();
for (int i = 0; i < vt.size(); ++i) {
String[] strDir = new String[4] ;
Element ele = (Element) vt.elementAt(i);
Hashtable htAttr = kt.getElementAttr(ele);
strDir[0] = htAttr.get("id").toString();
strDir[1] = htAttr.get("text").toString();
vecReturn.addElement(strDir);
}
return vecReturn;
}
/**
* 得到SELECT数据
* @param id String 资源src
* @throws Exception 例外
* @return byte[] select位数据
*/
private byte[] getXMLData(String id) throws
Exception {
for (int data = 0; data < smilData.length; data++) {
Hashtable dataEle = smilData[data];
String type = (String) dataEle.get("TYPE"); // 数据的类型
if (type.equals("XML")) {
return (byte[]) dataEle.get("STREAM_BYTE") ;
}
}
return null ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -