懒人配置动特殊数据权限,dom4j解析元数据

dom4j下载:http://sourceforge.net/projects/dom4j/files/latest/download?source=files

上一篇要配置特殊数据权限

http://xy0792.iteye.com/blog/1592637

需要一直找单据全路径和bosType

<special-data-permission>
            <name>com.kingdee.eas.fi.gl.app.Voucher</name>
            <type>2652E01E</type>
 </special-data-permission>

 

如果单据很多,就写一个代码处理,读取实体文件,以下是读取文件,不读取分录,不解析基础资料,只对单据做特殊数据权限,需要导入dom4j,解析元数据。

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

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

public class Main {

	/**
	 * @param args
	 * @throws DocumentException
	 */
	public static void main(String[] args) throws DocumentException {
		File f = new File(
				"E:\\workspace\\Shine\\metadata\\com\\kingdee\\eas\\shine");
		List<File> lstFiles = lstFiles(f, null);
		SAXReader reader = new SAXReader();

		for (Iterator iterator = lstFiles.iterator(); iterator.hasNext();) {
			File file = (File) iterator.next();
			Document xmlDoc = reader.read(file);
			Element root = xmlDoc.getRootElement();
			String strpackage = root.element("package").getData().toString();
			if (strpackage.indexOf("basedata") <= 0) {
				String fullName = strpackage + "."
						+ root.element("name").getData().toString();
				String bosType = root.element("bosType").getData().toString();
				System.out.println("\t\t<special-data-permission>");
				System.out.println("\t\t<name>" + fullName + "</name>");
				System.out.println("\t\t<type>" + bosType + "</type>");
				System.out.println("\t\t</special-data-permission>");
			}
		}
	}

	public static List<File> lstFiles(File f, List<File> fs) {
		if (fs == null) {
			fs = new ArrayList<File>();
		}
		if (f.isDirectory()) {
			File[] files = f.listFiles();
			if (files != null) {
				String lastName = null;
				for (int i = 0; i < files.length; i++) {
					File file = files[i];
					if (file.isDirectory()) {
						lstFiles(files[i], fs);
					} else {
						String name = file.getName();
						if (name.endsWith(".entity")) {
							name = name.substring(0, name.indexOf("."));
							if (lastName != null) {
								if (!name.startsWith(lastName)) {
									fs.add(file);
									lastName = name;
								}
							} else {
								fs.add(file);
								lastName = name;
							}

						}
					}
				}
			}
		} else {
			String name = f.getName();
			if (name.endsWith(".entity")) {
				fs.add(f);
			}
		}
		return fs;
	}
}
 

你可能感兴趣的:(dom4j)