分类:
2008-09-12 09:14:23
一个自动查找多语言Resource Bundle的properties文件是否包含有重复项的工具,如果有重复Item,则提示出来,便于删除重复的资源项。包括两个功能:1、查找同一个文件中是否有重复项。2、查找多语言的各Bundle文件中的Item是否完全一致,有否缺漏。
package com.utstar.nms.vmm.spring.i18n.converter;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
public class RedundancyChecker {
public final static String filepath_en_US="conf/spring/resources/Vmm_en_US.properties";
public final static String filepath_zh_CN="conf/spring/resources/Vmm_zh_CN.properties";
public final static String filepath_zh_TW="conf/spring/resources/Vmm_zh_TW.properties";
public Properties loadFile(String path)
{
Properties prop = null;
try
{
BufferedInputStream inBuff = new BufferedInputStream(
new FileInputStream(path));
prop = new Properties();
prop.load(inBuff);
inBuff.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return prop;
}
public boolean isKeysTheSameInTwoFiles(String filepath1,String filepath2)
{
boolean result=true;
int count=0;
Properties props1=loadFile(filepath1);
Properties props2=loadFile(filepath2);
Enumeration keys1 = props1.keys();
String fileName1=filepath1.substring(filepath1.lastIndexOf("/")+1);
String fileName2=filepath2.substring(filepath2.lastIndexOf("/")+1);
while(keys1.hasMoreElements())
{
String key1 =(String)keys1.nextElement();
if(!props2.containsKey(key1))
{
System.err.println("ERROR when "+fileName1+"-->"+fileName2);
System.err.println(count+++":key ["+key1+"] in "+fileName1+" not contained in "+fileName2);
result=false;
}
}
if(result==true)
{
System.out.println(fileName1+"-->"+fileName2+" keys the same");
}
return result;
}
public boolean isKeysDuplicateInOneFile(String filepath)
{
boolean result= true;
BufferedReader br= null;
Hashtable hash=new Hashtable();
String filename=filepath.substring(filepath.lastIndexOf("/")+1,filepath.length());
try
{
[1]