package com.wasu.cs.protocol; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.json.JSONArray; import org.json.JSONObject; import com.wasu.cs.model.CatModel; import com.wasu.cs.model.HomeColumnModel; import com.wasu.module.datafetch.DataFetchListener.JsonListener; import com.wasu.module.datafetch.DataFetchModule; import com.wasu.util.StringUtils; public class HomeProtocol extends BaseProtocol { private int total; private CatModel cat; private int stime; private String bgImage; private Map cornerIconMap = new HashMap(); private List columnList = new ArrayList(); @Override public boolean from(JSONObject json) { boolean result = super.from(json); if(result) { json = json.optJSONObject("data"); JSONObject jsonObj = null; JSONArray jsonArr = null; JSONObject configObj = null; JSONArray marksJsonArr = null; if (null != json) { total = json.optInt("total", 0); bgImage = json.optString("bgImage"); jsonObj = json.optJSONObject("cat"); configObj = json.optJSONObject("config"); jsonArr = json.optJSONArray("elements"); } if(jsonObj != null) { cat = new CatModel(); cat.from(jsonObj); } stime = 0; if(configObj != null) { stime = configObj.optInt("stime", 0); marksJsonArr = configObj.optJSONArray("cornerMarks"); } if (null != marksJsonArr && marksJsonArr.length() > 0) { String cmark = null; String picUrl = null; for (int i = 0, len = marksJsonArr.length(); i < len; i++) { configObj = marksJsonArr.optJSONObject(i); cmark = null; picUrl = null; if(configObj != null) { cmark = configObj.optString("cmark", ""); picUrl = configObj.optString("picUrl", ""); } if(!StringUtils.isBlank(cmark) && !StringUtils.isBlank(picUrl)) { cornerIconMap.put(cmark, picUrl); } } } if(null != jsonArr && jsonArr.length() > 0) { HomeColumnModel model = null; for (int i=0, len=jsonArr.length(); i getColumnList() { return columnList; } public int getStime() { return stime; } public Map getCornerIconMap() { return cornerIconMap; } }