KXmlParser


package com.lifecity.view;

import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import com.lifecity.bean.InClass;
import com.lifecity.common.CommandResources;
import com.lifecity.common.Constents;
import com.lifecity.control.GUIController;

/*******************************************************************************
*
******************************************************************************/
public class ClassListForm extends List implements CommandListener,Runnable {
private GUIController controller;
private Command commandOK; // 提交
private Command back; // 返回前一个页面
// 控制器
private String m_classId = "";
private InputStream iStrm;
private int eventType;
private KXmlParser parser = new KXmlParser();

public synchronized void setM_classId(String id) {
m_classId = id;
}
private String[] classId;
public final void run() {
HttpConnection http;
while (true) {
try {
http = (HttpConnection) Connector.open(Constents.URL_GETCLASS+ m_classId);
http.setRequestMethod(HttpConnection.GET);
if (http.getResponseCode() == HttpConnection.HTTP_OK) {
// 获得数据信息
int length = (int) http.getLength();
if (length > 0) {
iStrm = http.openInputStream();
this.parseXml();
}
break;
}
} catch (IOException exc) {
exc.printStackTrace();
// 告诉控制器,不能够发送短信
controller.setSendMMSException(exc.getMessage() + "/"
+ exc.getClass());
controller.handleEvent(GUIController.EventID.EVENT_ABOUT,
null);
break;
}
}
}
/**
* 解析xml Description:对传入的进行处理
*/
int k = 0;
public void parseXml() {
try {
parser.setInput(iStrm, "utf-8");
while (parser.next() > 1) {
eventType = parser.getEventType();
switch (eventType) {
case XmlPullParser.START_DOCUMENT:
break;
case XmlPullParser.END_DOCUMENT:
break;

case XmlPullParser.END_TAG:
break;
case XmlPullParser.START_TAG:
int size = parser.getAttributeCount();
if (size > 0) {
parser.getAttributeValue(0);
k++;
}
break;
case XmlPullParser.TEXT:
if (!parser.getText().trim().equals("")) {
this.append(parser.getText(), null);
}
break;
}
}

} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public ClassListForm(String title, GUIController control) {
super(title, List.IMPLICIT);
controller = control;
new Thread(this).start();
commandOK = new Command(String.valueOf(CommandResources
.getChars(CommandResources.TXT_C_OK)), 8, 10);
addCommand(commandOK);
back = new Command(String.valueOf(CommandResources
.getChars(CommandResources.TXT_C_BACK)), 8, 10);
addCommand(back);
setCommandListener(this);
}

/*
* 内部监听器,监听器监听所有Command事件,并把事件响应推出来让控制器处理
*/
public void commandAction(Command command, Displayable disp) {
if (command == commandOK || (command == List.SELECT_COMMAND)) {

System.out.println("Enter ClassListForm");
int ind = ((List) disp).getSelectedIndex();
String args[] = {""};
controller
.handleEvent(GUIController.EventID.EVENT_CLASS_BU_ACTION, args);
}
if (command == back) {
controller.handleEvent(GUIController.EventID.EVENT_MAIN_FORM, null);
}
}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值