| | |
| | | package com.dy.common.util; |
| | | |
| | | import java.io.FileWriter; |
| | | import java.net.URL; |
| | | import java.util.List; |
| | | |
| | | import org.jdom2.Document; |
| | | import org.jdom2.Element; |
| | | import org.jdom2.input.SAXBuilder; |
| | | import org.jdom2.output.Format; |
| | | import org.jdom2.output.XMLOutputter; |
| | | |
| | | @SuppressWarnings("unused") |
| | | public class ConfigXml { |
| | | |
| | | import java.io.FileWriter; |
| | | import java.net.URL; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 创建Document对象 |
| | | * @param clazz 参考类 |
| | | * @param filePath 配置文件路径 |
| | | * @return 返回结果 返回结果返回 doc对象 |
| | | * @throws Exception 抛出异常 抛出异常 |
| | | * @Author: liurunyu |
| | | * @Date: 2024/8/21 15:27 |
| | | * @Description |
| | | */ |
| | | public Document createDom(Class<?> clazz, String filePath) throws Exception { |
| | | if(clazz == null){ |
| | | throw new Exception("class对象为空!"); |
| | | } |
| | | if(filePath == null || filePath.equals("")){ |
| | | throw new Exception("配置文件路径名称为空!"); |
| | | } |
| | | if(!filePath.startsWith("/")){ |
| | | filePath = "/" + filePath ; |
| | | } |
| | | URL configFileURL = clazz.getResource(filePath); |
| | | if (configFileURL == null) { |
| | | throw new Exception("没有得到" + filePath + "配置!"); |
| | | } |
| | | return this.createDom(configFileURL) ; |
| | | } |
| | | public class ConfigXml { |
| | | |
| | | /** |
| | | * 创建Document对象 |
| | |
| | | * @return 返回结果 返回结果返回 doc对象 |
| | | * @throws Exception 抛出异常 抛出异常 |
| | | */ |
| | | public Document createDom(URL configFileURL) throws Exception { |
| | | protected Document doCreateDom(URL configFileURL) throws Exception { |
| | | if (configFileURL == null) { |
| | | throw new Exception("没有得到配置文件!", null); |
| | | } |