java,
分享于 点击 7128 次 点评:103
java,
/**
2. * 初始化数据字典
3. */
4. public static void initSysDic() {
5. try {
6. SAXReader reader = new SAXReader();
7. Document document = reader.read(new File(
8. "src/main/resources/system/sysDic.xml"));
9.
10. LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, String>>> sysDic = buildSysDic(document);
11.
12. SysDicUtil.setSysDic(sysDic);
13.
14. } catch (Exception e) {
15. e.printStackTrace();
16. }
17. }
18.
19.
20.@SuppressWarnings("unchecked")
21. public static LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, String>>> buildSysDic(Document document) {
22. String xpath = "dics/table";
23.
24.
25. List<Node> tables = document.selectNodes(xpath);
26.
27. return handleTables(tables);
28. }
29.
30./**
31. * 处理一组table
32. *
33. * @param tables
34. * @return
35. */
36.
37. private static LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, String>>> handleTables(
38. List<Node> tables) {
39. LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, String>>> tableMap = new LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, String>>>();
40.
41. Node table = null;
42. String id = null;
43. LinkedHashMap<String, LinkedHashMap<String, String>> field = null;
44. for (int i = 0, len = tables.size(); i < len; i++) {
45. table = tables.get(i);
46.
47. id = table.selectSingleNode("@id").getText();
48. System.out.println(id);
49.
50. field = handleFields(table.selectNodes("field"));
51.
52. tableMap.put(id, field);
53. }
54. return tableMap;
55. }
56.
57.
58./**
59. * 处理一组field
60. *
61. * @param fields
62. * @return
63. */
64. private static LinkedHashMap<String, LinkedHashMap<String, String>> handleFields(
65. List<Node> fields) {
66. LinkedHashMap<String, LinkedHashMap<String, String>> fieldMap = new LinkedHashMap<String, LinkedHashMap<String, String>>();
67.
68. Node field = null;
69. String id = null;
70. LinkedHashMap<String, String> row = null;
71. for (int i = 0, len = fields.size(); i < len; i++) {
72. field = fields.get(i);
73.
74. id = field.selectSingleNode("@id").getText();
75. System.out.println(id);
76. row = handleRows(field.selectNodes("row"));
77.
78. fieldMap.put(id, row);
79.
80. }
81.
82. return fieldMap;
83. }
84.
85.
86./**
87. * 处理一组row
88. *
89. * @param rows
90. * @return
91. */
92. private static LinkedHashMap<String, String> handleRows(List<Node> rows) {
93. LinkedHashMap<String, String> rowMap = new LinkedHashMap<String, String>();
94.
95. Node row = null;
96. String key = null;
97. String value = null;
98. for (int i = 0, len = rows.size(); i < len; i++) {
99. row = rows.get(i);
100.
101. key = row.selectSingleNode("value").getText();
102. value = row.selectSingleNode("desc").getText();
103. rowMap.put(key, value);
104.
105. System.out.println(key + " " + value);
106. }
107.
108. return rowMap;
109. }
相关文章
- 暂无相关文章
用户点评