f054a4d6d955fff7df4f86990a3fdbc414907540.svn-base 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package com.sysmodel.xformmodel;
  2. import java.io.File;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import javax.xml.parsers.DocumentBuilder;
  7. import javax.xml.parsers.DocumentBuilderFactory;
  8. import org.apache.commons.logging.Log;
  9. import org.apache.commons.logging.LogFactory;
  10. import org.w3c.dom.Document;
  11. import org.w3c.dom.Element;
  12. import org.w3c.dom.NodeList;
  13. import com.sysmodel.XFormModelImpl;
  14. import com.sysmodel.xformmodel.impl.DojoInputTypeImpl;
  15. import com.sysmodel.xformmodel.impl.JsFunctionImpl;
  16. import com.sysmodel.xformmodel.impl.RegExpImpl;
  17. public class ResouceXMLLoader{
  18. private Log log = LogFactory.getLog(ResouceXMLLoader.class);
  19. Map<String, String> pageCssMap = new HashMap<String, String>();
  20. public boolean readResource(String filePath) {
  21. File xmlfile = new File(filePath);
  22. if (!xmlfile.exists()) {
  23. log.error("Resoucefile: " + filePath + " not exist");
  24. return false;
  25. }
  26. DocumentBuilderFactory domfactory = DocumentBuilderFactory.newInstance();
  27. try {
  28. DocumentBuilder builder = domfactory.newDocumentBuilder();
  29. Document document = builder.parse(xmlfile);
  30. // pageCss
  31. NodeList pageCss = document.getElementsByTagName("pageCss");
  32. readPageCsses(pageCss);
  33. // regExp
  34. NodeList regExp = document.getElementsByTagName("regExp");
  35. readRegExp(regExp);
  36. // jsFunction
  37. NodeList jsFunction = document.getElementsByTagName("jsFunction");
  38. readJsFunction(jsFunction);
  39. // jsFunction
  40. NodeList dojoInuptTypes = document.getElementsByTagName("dojoType");
  41. readDojoInuptTypes(dojoInuptTypes);
  42. } catch (Exception e) {
  43. log.error("load PageResouce error: ", e);
  44. }
  45. return true;
  46. }
  47. private void readPageCsses(NodeList pageCss) {
  48. for (int i = 0; i < pageCss.getLength(); i++) {
  49. Element element = (Element) pageCss.item(i);
  50. pageCssMap.put(element.getAttribute("code"), element.getAttribute("value"));
  51. }
  52. XFormModelImpl.getInstance().setPageCssMap(pageCssMap);
  53. }
  54. private void readRegExp(NodeList regExp) {
  55. ArrayList<RegExpImpl> arr = new ArrayList<RegExpImpl>();
  56. for (int i = 0; i < regExp.getLength(); i++) {
  57. RegExpImpl RegExpImpl = new RegExpImpl();
  58. Element element = (Element) regExp.item(i);
  59. RegExpImpl.setCode(element.getAttribute("code"));
  60. RegExpImpl.setDescription(element.getAttribute("description"));
  61. RegExpImpl.setName(element.getAttribute("name"));
  62. RegExpImpl.setValue(element.getAttribute("value"));
  63. arr.add(RegExpImpl);
  64. }
  65. XFormModelImpl.getInstance().setRegExps(arr);
  66. }
  67. private void readJsFunction(NodeList jsFunction) {
  68. ArrayList<JsFunctionImpl> arr = new ArrayList<JsFunctionImpl>();
  69. for (int i = 0; i < jsFunction.getLength(); i++) {
  70. JsFunctionImpl JsFunctionImpl = new JsFunctionImpl();
  71. Element element = (Element) jsFunction.item(i);
  72. JsFunctionImpl.setCode(element.getAttribute("code"));
  73. JsFunctionImpl.setDescription(element.getAttribute("description"));
  74. JsFunctionImpl.setName(element.getAttribute("name"));
  75. JsFunctionImpl.setValue(element.getAttribute("value"));
  76. arr.add(JsFunctionImpl);
  77. }
  78. XFormModelImpl.getInstance().setJsFunctions(arr);
  79. }
  80. private void readDojoInuptTypes(NodeList dojoInuptTypes) {
  81. ArrayList<DojoInputTypeImpl> arr = new ArrayList<DojoInputTypeImpl>();
  82. for (int i = 0; i < dojoInuptTypes.getLength(); i++) {
  83. DojoInputTypeImpl DojoInputType = new DojoInputTypeImpl();
  84. Element element = (Element) dojoInuptTypes.item(i);
  85. DojoInputType.setCode(element.getAttribute("code"));
  86. DojoInputType.setName(element.getAttribute("name"));
  87. DojoInputType.setValue(element.getAttribute("value"));
  88. DojoInputType.setType(element.getAttribute("type"));
  89. arr.add(DojoInputType);
  90. }
  91. XFormModelImpl.getInstance().setDojoInuptTypes(arr);
  92. }
  93. }