6a789befd26d282a1a36efce8bcb8cb2688cdc34.svn-base 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. package com.sysmodel.configLoader;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import java.util.Map;
  6. import java.util.Set;
  7. import org.apache.commons.logging.Log;
  8. import org.apache.commons.logging.LogFactory;
  9. import com.sysmodel.XFormModel;
  10. import com.sysmodel.collectmodel.xmlmanager.CollectXMLSave;
  11. import com.sysmodel.collectmodel.xmlmodel.able.FormCollection;
  12. import com.sysmodel.collectmodel.xmlmodel.impl.FormCollectionImpl;
  13. import com.sysmodel.listmodel.xmlmanager.ListXMLSave;
  14. import com.sysmodel.listmodel.xmlmodel.able.FormList;
  15. import com.sysmodel.listmodel.xmlmodel.impl.FormListImpl;
  16. import com.sysmodel.xformmodel.able.DojoInputType;
  17. import com.sysmodel.xformmodel.able.RegExp;
  18. import com.sysmodel.xformmodel.impl.DojoInputTypeImpl;
  19. import com.sysmodel.xformmodel.impl.JsFunctionImpl;
  20. import com.sysmodel.xformmodel.impl.RegExpImpl;
  21. import com.sysmodel.xformmodel.impl.TbEtymaImpl;
  22. public class XFormModelImpl implements XFormModel{
  23. private static final Log log = LogFactory.getLog(Object.class);
  24. /**
  25. * 采集页面配置存储容器
  26. */
  27. private Map<String, FormCollection> FormCollections = new HashMap<String, FormCollection>();
  28. /**
  29. * 列表页面配置存储容器
  30. */
  31. private Map<String, FormList> FormLists = new HashMap<String, FormList>();
  32. /**
  33. * 加载的文件路径
  34. */
  35. public Map<String, String> fileLoadPath = null;
  36. /**
  37. * 采集列表页面引用的CSS配置路径
  38. */
  39. private String filePathOfCss = "";
  40. /**
  41. * WEB-INF/PageResouce.xml pageCss存储容器
  42. */
  43. @SuppressWarnings("rawtypes")
  44. private Map pageCssMap = new HashMap();
  45. /**
  46. * js 正则表达式存放集合
  47. */
  48. private ArrayList<RegExpImpl> regExps = new ArrayList<RegExpImpl>();
  49. /**
  50. * JS函数存放集合
  51. */
  52. private ArrayList<JsFunctionImpl> jsFunctions = new ArrayList<JsFunctionImpl>();
  53. /**
  54. * JS函数存放集合
  55. */
  56. private ArrayList<DojoInputTypeImpl> dojoInuptTypes = new ArrayList<DojoInputTypeImpl>();
  57. /**
  58. * 数据库表词根存放集合
  59. */
  60. private ArrayList<TbEtymaImpl> tbEtymas = new ArrayList<TbEtymaImpl>();
  61. /**
  62. * 静态私有化构造函数
  63. */
  64. private static XFormModelImpl XFormModel = null;
  65. public XFormModelImpl() {
  66. }
  67. public static XFormModelImpl getInstance() {
  68. return XFormModel;
  69. }
  70. public static XFormModelImpl getInstance(Map<String, String> fileLoadPath) {
  71. if (XFormModel == null) {
  72. XFormModel = new XFormModelImpl();
  73. } else {
  74. XFormModel.clear();
  75. }
  76. XFormModel.fileLoadPath = fileLoadPath;
  77. String LoadPath = fileLoadPath.get("PageCollection").toString();
  78. CollectXMLLoader reader = new CollectXMLLoader();
  79. if (reader.readConfigFile(LoadPath)) {
  80. log.info("load PageCollection.xml success");
  81. }
  82. LoadPath = fileLoadPath.get("PageList").toString();
  83. ListXMLLoader FormListReader = new ListXMLLoader();
  84. if (FormListReader.readConfigFile(LoadPath)) {
  85. log.info("load PageList.xml success");
  86. }
  87. LoadPath = fileLoadPath.get("PageResouce").toString();
  88. ResourceXMLLoader ResouceLoader = new ResourceXMLLoader();
  89. if (ResouceLoader.readResource(LoadPath)) {
  90. log.info("load PageResouce.xml success");
  91. }
  92. return XFormModel;
  93. }
  94. private void clear() {
  95. this.FormCollections.clear();
  96. this.FormLists.clear();
  97. this.pageCssMap.clear();
  98. }
  99. /**
  100. * 根据配置编号找到FormCollection Parameters:pageid Returns:FormCollection
  101. */
  102. public FormCollection getFormCollection(String pageid) {
  103. Object obj = FormCollections.get(pageid);
  104. if (obj == null)
  105. return null;
  106. else
  107. return (FormCollection) obj;
  108. }
  109. /**
  110. * 根据配置编号找到FormList Parameters:listid Returns:FormList
  111. */
  112. public FormList getFormList(String listid) {
  113. Object obj = FormLists.get(listid);
  114. if (obj == null)
  115. return null;
  116. else
  117. return (FormList) obj;
  118. }
  119. /**
  120. * 返回所有的FormCollection配置集合 Returns:FormCollection 集合
  121. */
  122. @SuppressWarnings("rawtypes")
  123. public ArrayList<FormCollection> getFormCollections() {
  124. ArrayList<FormCollection> list = new ArrayList<FormCollection>();
  125. Set set = this.FormCollections.entrySet();
  126. Iterator iterator = set.iterator();
  127. while (iterator.hasNext()) {
  128. Map.Entry mapentry = ((Map.Entry) iterator.next());
  129. list.add((FormCollection) mapentry.getValue());
  130. }
  131. return list;
  132. }
  133. /**
  134. * 根据CSS配置的名称获得CSS的配置信息 Parameters:name Returns:
  135. */
  136. public String getCSSValue(String key) {
  137. return (String) pageCssMap.get(key);
  138. }
  139. /**
  140. * 返回所有的指定模块下的FormList配置集合 Returns:FormList 集合
  141. */
  142. @SuppressWarnings({ "rawtypes" })
  143. public ArrayList<FormListImpl> getFormLists() {
  144. ArrayList<FormListImpl> list = new ArrayList<FormListImpl>();
  145. Set set = this.FormLists.entrySet();
  146. Iterator iterator = set.iterator();
  147. while (iterator.hasNext()) {
  148. Map.Entry mapentry = (Map.Entry) iterator.next();
  149. list.add((FormListImpl) mapentry.getValue());
  150. }
  151. return list;
  152. }
  153. /**
  154. * 返回所有的指定模块下的FormList配置集合 Parameters:type 模块编号 Returns:FormList 集合
  155. */
  156. @SuppressWarnings({ "unchecked", "rawtypes" })
  157. public ArrayList getFormListByType(String type) {
  158. ArrayList<FormList> list = new ArrayList<FormList>();
  159. Set set = this.FormLists.entrySet();
  160. Iterator iterator = set.iterator();
  161. while (iterator.hasNext()) {
  162. Map.Entry mapentry = (Map.Entry) iterator.next();
  163. FormListImpl FormList = (FormListImpl) mapentry.getValue();
  164. if (FormList.getType().equals(type))
  165. list.add(FormList);
  166. }
  167. return list;
  168. }
  169. /**
  170. * 返回所有的指定模块下的FormCollection配置集合 Parameters:type 模块编号 Returns:FormCollection
  171. * 集合
  172. */
  173. @SuppressWarnings({ "unchecked", "rawtypes" })
  174. public ArrayList getFormCollectionsByType(String type) {
  175. ArrayList<FormCollection> list = new ArrayList<FormCollection>();
  176. Set set = this.FormCollections.entrySet();
  177. Iterator iterator = set.iterator();
  178. while (iterator.hasNext()) {
  179. Map.Entry mapentry = (Map.Entry) iterator.next();
  180. FormCollectionImpl FormCollection = (FormCollectionImpl) mapentry.getValue();
  181. if (FormCollection.getType().equals(type))
  182. list.add(FormCollection);
  183. }
  184. return list;
  185. }
  186. /**
  187. * 根据配置KEY获得配置信息 Parameters:key Returns:
  188. */
  189. public String getPropertyValue(String key) {
  190. return (String) pageCssMap.get(key);
  191. }
  192. /**
  193. * 根据指定的路径保存配置文件 其中包括: PageCollection.xml PageList.xml PageResouce.xml
  194. * Parameters:savePath Returns:
  195. */
  196. public boolean saveXFormModelToFiles() {
  197. CollectXMLSave CollectXMLSave = new CollectXMLSave();
  198. ListXMLSave ListXMLSave = new ListXMLSave();
  199. ListXMLSave.saveToXMLFile(fileLoadPath.get("PageList").toString());
  200. CollectXMLSave.saveToXMLFile(fileLoadPath.get("PageCollection").toString());
  201. return true;
  202. }
  203. /**
  204. * 在内存重增加一个采集页面
  205. *
  206. * @param pageid
  207. * @param FormCollection
  208. */
  209. public void addFormCollection(String pageid, FormCollection FormCollection) {
  210. FormCollections.put(pageid, FormCollection);
  211. }
  212. /**
  213. * 在内存重删除一个采集页面
  214. *
  215. * @param pageid
  216. */
  217. public void deleteFormCollection(String pageid) {
  218. FormCollections.remove(pageid);
  219. }
  220. /**
  221. * 在内存重增加一个列表多项
  222. *
  223. * @param listid
  224. * @param FormList
  225. */
  226. public void addFormList(String listid, FormList FormList) {
  227. FormLists.put(listid, FormList);
  228. }
  229. /**
  230. * 在内存重删除一个列表多项
  231. *
  232. * @param listid
  233. */
  234. public void deleteFormList(String listid) {
  235. FormLists.remove(listid);
  236. }
  237. @SuppressWarnings("rawtypes")
  238. public Map getPageCssMap() {
  239. return pageCssMap;
  240. }
  241. public String getFilePathOfCss() {
  242. return filePathOfCss;
  243. }
  244. public void setFilePathOfCss(String filePathOfCss) {
  245. this.filePathOfCss = filePathOfCss;
  246. }
  247. @SuppressWarnings({ "rawtypes" })
  248. public ArrayList getJsFunctions() {
  249. return jsFunctions;
  250. }
  251. public String getJsFunctionByCode(String code) {
  252. String value = "";
  253. for (int i = 0; i < jsFunctions.size(); i++) {
  254. JsFunctionImpl JsFunctionImpl = (JsFunctionImpl) jsFunctions.get(i);
  255. if (JsFunctionImpl.getCode().equals(code)) {
  256. value = JsFunctionImpl.getValue();
  257. }
  258. }
  259. return value;
  260. }
  261. @SuppressWarnings({ "rawtypes", "unchecked" })
  262. public void setJsFunctions(ArrayList jsFunctions) {
  263. this.jsFunctions = jsFunctions;
  264. }
  265. @SuppressWarnings("rawtypes")
  266. public ArrayList getRegExps() {
  267. return regExps;
  268. }
  269. public RegExp getRegExpByCode(String code) {
  270. for (int i = 0; i < regExps.size(); i++) {
  271. RegExp tempRegExpObj = (RegExp) regExps.get(i);
  272. if (tempRegExpObj.getCode().equals(code))
  273. return tempRegExpObj;
  274. }
  275. return null;
  276. }
  277. @SuppressWarnings({ "unchecked", "rawtypes" })
  278. public void setRegExps(ArrayList regExps) {
  279. this.regExps = regExps;
  280. }
  281. @SuppressWarnings("rawtypes")
  282. public void setPageCssMap(Map pageCssMap) {
  283. this.pageCssMap = pageCssMap;
  284. }
  285. public ArrayList<DojoInputTypeImpl> getDojoInuptTypes() {
  286. return dojoInuptTypes;
  287. }
  288. public void setDojoInuptTypes(ArrayList<DojoInputTypeImpl> dojoInuptTypes) {
  289. this.dojoInuptTypes = dojoInuptTypes;
  290. }
  291. public ArrayList<TbEtymaImpl> getTbEtymas() {
  292. return tbEtymas;
  293. }
  294. public void setTbEtymas(ArrayList<TbEtymaImpl> tbEtymas) {
  295. this.tbEtymas = tbEtymas;
  296. }
  297. public DojoInputType getDojoInputTypeByCode(String code) {
  298. for (int i = 0; i < dojoInuptTypes.size(); i++) {
  299. DojoInputType tempTypeObj = (DojoInputType) dojoInuptTypes.get(i);
  300. if (tempTypeObj.getCode().equals(code))
  301. return tempTypeObj;
  302. }
  303. return null;
  304. }
  305. /**
  306. * 根据构件类型获得DOJO校验的类新集合
  307. *
  308. * @param type
  309. * @return
  310. */
  311. public ArrayList<DojoInputType> getDojoInuptTypesByType(String type) {
  312. ArrayList<DojoInputType> result = new ArrayList<DojoInputType>();
  313. for (int i = 0; i < dojoInuptTypes.size(); i++) {
  314. DojoInputType tempTypeObj = (DojoInputType) dojoInuptTypes.get(i);
  315. if (type.equals(tempTypeObj.getType()))
  316. result.add(tempTypeObj);
  317. }
  318. return result;
  319. }
  320. }