import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.alibaba.fastjson.JSON;
import com.sysware.framework.utils.ValidateUtil;
public class XmlUtil {
/**
* 根据文件夹路径获取文件夹的信息
*
*<hr>
* @author Hanjidong
* @date 2021年9月4日 下午1:10:01
* @since 0.0.1
* @param path
* @throws UnsupportedEncodingException
* @throws FileNotFoundException
* @throws DocumentException
* void
*/
public static List<Map<String,String>> getFolders(String path) throws UnsupportedEncodingException, FileNotFoundException, DocumentException{
SAXReader sax = new SAXReader();
InputStreamReader is = new InputStreamReader(new FileInputStream(path), "UTF-8");
Document doc = sax.read(is);
Element root = doc.getRootElement();
Element toolElement = root.element("TOOL");
if(toolElement == null){
return null;
}
Element extensionElement = toolElement.element("TOOL-EXTENSION");
if(extensionElement == null){
return null;
}
Element foldersElement = extensionElement.element("FOLDERS");
if(foldersElement == null){
return null;
}
System.out.println("foldersElement name:" + foldersElement.getName());
List<Map<String,String>> folderList = new ArrayList<Map<String,String>>();
@SuppressWarnings("unchecked")
Iterator<Element> it = foldersElement.elementIterator();
while (it.hasNext()) {
Element subNode = it.next();
Map<String,String> dataMap = new HashMap<String, String>();
dataMap.put(ConstantsDoors.IDENTIFIER, subNode.attributeValue("IDENTIFIER"));
dataMap.put(ConstantsDoors.FOLDER_DESC, subNode.attributeValue("DESC"));
dataMap.put(ConstantsDoors.FOLDER_NAME, subNode.attributeValue("LONG-NAME"));
dataMap.put(ConstantsDoors.FOLDER_DESC, subNode.attributeValue("DESC"));
folderList.add(dataMap);
}
return folderList;
}
}
06-19
1592
07-15
1009
11-05
131