throws ServletException, IOException {
try {
///< 读取、解析设备列表
String xmlPath = ConfigureProperties.getInstance().getMediaServerPath();
///< 解析xml
Document doc = XmlManager.parse(xmlPath); //相对路径
Element element = doc.getDocumentElement(); //获得spots根节点
List<Spot> spots = null;
spots = SpotsParser.parser(element); //解析spots根节点,返回解析列表
List<OnlineDevice> lsonline = displaySpotsOnline(spots);
///< 发送在线设备到前台
java.lang.reflect.Type type =
new com.google.gson.reflect.TypeToken<List<OnlineDevice>>(){}.getType();
gson = new Gson();
String json = gson.toJson(lsonline, type);
resp.setCharacterEncoding("UTF-8");
resp.getWriter().write(json);
resp.getWriter().flush();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public List<OnlineDevice> displaySpotsOnline(List<Spot> ls){
int len = ls.size();
Spot spot =null;
List<OnlineDevice> lsOnDe=new ArrayList<OnlineDevice>();
for(int i =0;i<len;i++){
spot = ls.get(i);
Integer spotOnline=spot.getState();
if (1==spotOnline){
OnlineDevice onDe= new OnlineDevice();
onDe.setLson(spotOnline);
onDe.setNameon(spot.getName());
onDe.setUrl(spot.getUrl());
//此处的id必须从url中截取出来
Long spotId = Long.parseLong(onDe.getUrl().substring(0, onDe.getUrl().indexOf("@")));
onDe.setId(spotId);
String onLineId = spotId.toString();
List<SpotsPublish> spotsPublishList = SpotsPublish.getInstance().readPublishState();
String tempPublishState = "0";
for(int j=0; j<spotsPublishList.size(); j++ ){
///注意一下此处的向量能当成二维向量来使,因为此处比较相同的spotid需要传出的是他的发布状态publishState
String tempId = spotsPublishList.get(j).getStrId();
if(tempId.equalsIgnoreCase(onLineId)){
tempPublishState = spotsPublishList.get(j).getStrPublishState();
break;
}
}
onDe.setOnPublish(tempPublishState);
lsOnDe.add(onDe);
}
}
return lsOnDe;
}