381297d7c2a8706030e46c766d1681f594d9a604.svn-base 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package xin.glue.ui.common.component;
  2. import java.util.Collections;
  3. import java.util.Comparator;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import com.posdata.glue.msg.util.PosMessageUtil;
  8. import com.posdata.glue.util.xml.PosXMLUtil;
  9. public class PosMessageMap {
  10. public static Map getMessageMap(String MsgID) {
  11. return getMessageMap(MsgID, null);
  12. }
  13. public static Map getMessageMap(String MsgID, String layoutXML) {
  14. MsgID = MsgID.trim();
  15. if (layoutXML == null)
  16. layoutXML = "layout/" + MsgID + "-msg.xml";
  17. else
  18. layoutXML = "layout/" + layoutXML.trim() + "-msg.xml";
  19. Object obj = null;
  20. try {
  21. obj = (new PosXMLUtil()).loadXMLFromClasspath(layoutXML);
  22. } catch (Exception e) {
  23. e.printStackTrace();
  24. return null;
  25. }
  26. obj = PosMessageUtil.getSource(obj, "msgs");
  27. obj = PosMessageUtil.getSource(obj, "msg");
  28. Map map = null;
  29. if (PosMessageUtil.isList(obj)) {
  30. int count = ((List)obj).size();
  31. for (int i=0; i<count; i++) {
  32. map = (Map)PosMessageUtil.getSource(obj, String.valueOf(i));
  33. if (map.get("id").equals(MsgID)) break;
  34. }
  35. } else map = (Map) obj;
  36. obj = PosMessageUtil.getSource(map, "attribute");
  37. Map fields = new HashMap();
  38. if (PosMessageUtil.isList(obj)) {
  39. int count = ((List)obj).size();
  40. Collections.sort((List)obj, new Comparator() {
  41. public int compare(Object o1, Object o2) {
  42. Map m1 = (Map)o1;
  43. Map m2 = (Map)o2;
  44. return (Integer.parseInt(m1.get("seq").toString()) - Integer.parseInt(m2.get("seq").toString()));
  45. }});
  46. for (int i=0; i<count; i++) {
  47. map = (Map)PosMessageUtil.getSource(obj, String.valueOf(i));
  48. fields.put(map.get("id"), map.get("length"));
  49. }
  50. }
  51. return fields;
  52. }
  53. }