⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlutil.java

📁 一个非常好的FRAMWRK!是一个外国组织做的!不!
💻 JAVA
字号:
package com.jdon.util;

import java.util.*;
import java.io.File;

import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;


import com.jdon.util.Debug;



public class XmlUtil {

  public final static String module = XmlUtil.class.getName();
  

  public static  Map loadMapping(String fileName, String nodeName, String keyName,
                          String valueName) {
    Map map = new HashMap();
    FileLocator fileLocator = new FileLocator();
    try {
      String xmlFile = fileLocator.getConfFile(fileName);

      Debug.logVerbose(" mapping file:" + xmlFile, module);

      SAXBuilder builder = new SAXBuilder();
      Document doc = builder.build(new File(xmlFile));

      Debug.logVerbose(" got mapping file ", module);

      // Get the root element
      Element root = doc.getRootElement();

      List mappings = root.getChildren(nodeName);
      Iterator i = mappings.iterator();
      while (i.hasNext()) {
        Element mapping = (Element) i.next();
        String key = mapping.getChild(keyName).getTextTrim();
        String value = mapping.getChild(valueName).getTextTrim();
         Debug.logVerbose(" get the " + key + "=" + value, module);
        map.put(key, value);

      }
      Debug.logVerbose(" read finished", module);

    } catch (Exception ex) {
      Debug.logError(" error: " + ex, module);
    }

    return map;

  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -