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

📄 conffilechecker.java

📁 可以导出一个项目的所有文件的目录结构
💻 JAVA
字号:
package codeexport.conf;

import java.io.File;
import java.util.List;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

//import codeexport.util.InfoOutput;

public class ConfFileChecker {
//	/**
//	 * the instance of InfoOutput
//	 */
//	private static InfoOutput infoOutput = InfoOutput.getInstance();
	
	/**
	 * check directory configure file
	 * 
	 * @param filePath the path of the configure file
	 * @return the list of all the UnitConf
	 */
	public static boolean check(File confFile) {
		if(!isXmlFile(confFile)){
			return false;
		}
		
		try {
			SAXReader reader = new SAXReader();
			Document document = reader.read(confFile);
			
			Element rootE = document.getRootElement();
			List elements = rootE.elements();
			if((elements == null) || (elements.size() == 0)){
				return false;
			}
			
			return check(elements);
		} catch (DocumentException de) {
			de.printStackTrace();
			return false;
		}
	}
	
	private static boolean check(List elements){
		if((elements == null) || (elements.size() == 0)){
			return true;
		}
		
		for(int i = 0;i < elements.size();i++){
			Element element = (Element)elements.get(i);
			if(!check(element)){
				return false;
			}
		}
		
		return true;
	}
	
	private static boolean check(Element element){
		String name = element.getName();
		if((!"directory".equals(name)) || (!"file".equals(name))){
			return false;
		}
		
		if(element.attribute("name") == null){
			return false;
		}
		
		return check(element.elements());
	}
	
	private static boolean isXmlFile(File file){
		if(!file.exists()){
			return false;
		}
		
		if(file.isDirectory()){
			return false;
		}
		
		return file.getName().endsWith(".xml");
	}
	
	public String toString(Element element){
		StringBuffer sb = new StringBuffer();
		
		sb.append(element.getName());
		sb.append("[");
		List attributes = element.attributes();
		for(int i = 0;i < attributes.size();i++){
			Attribute attri = (Attribute)attributes.get(i);
			sb.append(attri.getName());
			sb.append("=");
			sb.append(attri.getValue());
			sb.append(",");
		}
		sb.append("]");
		
		
		return sb.toString();
	}
}

⌨️ 快捷键说明

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