bb3e7d07fc6c91b95fc192976621c1791458896b.svn-base 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.synyi.edc.util;
  2. import java.util.HashMap;
  3. import java.util.Iterator;
  4. import java.util.Map;
  5. import org.apache.commons.lang3.StringUtils;
  6. import org.dom4j.Document;
  7. import org.dom4j.Element;
  8. import org.dom4j.io.SAXReader;
  9. /**
  10. * XML工具类
  11. *
  12. */
  13. public class XmlUtils {
  14. private static Document doc = null;
  15. static{
  16. try{
  17. doc = new SAXReader().read(XmlUtils.class.getClassLoader().getResourceAsStream("synyi_sqlbuild.xml"));
  18. }catch (Exception e) {
  19. e.printStackTrace();
  20. }
  21. }
  22. /**
  23. * XML转为Map集合
  24. * @param doc
  25. * @return
  26. */
  27. private static Map<String, String> xmlToMap(){
  28. // 将字符串转为xml
  29. Map<String, String> msg = new HashMap<String, String>();
  30. Element root = doc.getRootElement();
  31. for (Iterator iterator = root.elementIterator(); iterator.hasNext();) {
  32. Element e = (Element) iterator.next();
  33. msg.put(e.getName(), e.getText());
  34. }
  35. return msg;
  36. }
  37. public static String getMapString(String key){
  38. if(StringUtils.isNotBlank(xmlToMap().get(key))){
  39. return xmlToMap().get(key).trim();
  40. }
  41. return "";
  42. }
  43. }