StringCheck.java 4.72 KB
Newer Older
Lee Jaebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.imageio.ImageIO;

import jp.agentec.adf.util.FileUtil;
import jp.agentec.adf.util.StringUtil;


public class StringCheck {
	private static final String HTML_PATH_STR = "stringCheck.html";
	private static final String HTML_PATH_ARR = "arrayCheck.html";
	private static final String ARRAYS_XML = "arrays.xml";
	private static final String STRINGS_XML = "strings.xml";
	private static final String EMPTY = "★★EMPTY★★";
	private static final String bgcolor = "white";
	private static final boolean ONLY_PROBLEM = false;

	public static void main(String[] args) throws IOException {
		
		File current = new File(".");
		File baseDir = new File(FileUtil.getParentPath(FileUtil.getParentPath(current.getAbsolutePath())) + "ABVJE_Res_Default_Android\\res");

		execute(baseDir, STRINGS_XML, HTML_PATH_STR);
		
//		baseDir = new File(FileUtil.getParentPath(FileUtil.getParentPath(current.getAbsolutePath())) + "ABVJE_UI_Android\\res");
//
//		execute(baseDir, ARRAYS_XML, HTML_PATH_ARR);
	}

	public static void execute(File baseDir, String xmlFile, String output) throws FileNotFoundException, IOException {
		List<String> allNameList = new ArrayList<String>();
		List<String> dirList = Arrays.asList(new String[]{"values","values-ja","values-ko"});
		Map<String, String>[] valMap = (Map<String, String>[])new Map[dirList.size()];
		for (int i = 0; i < valMap.length; i++) {
			valMap[i] = new HashMap<String, String>();
		}
		for (int i = 0; i < dirList.size(); i++) {
			String dir = dirList.get(i);
			FileReader fr = new FileReader(baseDir + "\\" + dir + "\\" + xmlFile);
			BufferedReader br = new BufferedReader(fr);
			String line;
			while ((line=br.readLine()) != null) {
				String name = StringUtil.extractRegexString(line, "name=\"(.*?)\"", 1);
				if (name != null) {
					if (!allNameList.contains(name)) {
						allNameList.add(name);
					}
					String val = StringUtil.extractRegexString(line, ">(.*?)<\\/", 1);
					if (StringUtil.isNullOrEmpty(val)) {
						val = EMPTY;
					}
					valMap[i].put(name, val);
				}
			}
		}
		
		StringBuffer sb = new StringBuffer();
		sb.append("<html>\n");
		sb.append("<head>\n");
		sb.append("</head>\n");
		sb.append("<body bgcolor=\"" + bgcolor + "\" \"><table border=1>\n");
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("key");
		sb.append("</td>");
		for (String dir : dirList) {
			sb.append("<td>");
			sb.append(dir);
			sb.append("</td>");
		}
		sb.append("</tr>\n");

		for (String key : allNameList) {
			if (ONLY_PROBLEM) {
				boolean set = true;
				for (int i = 0; i < dirList.size(); i++) {
					String val = valMap[i].get(key);
					if (val == null || val.equals(EMPTY)) {
						set = false;
						break;
					}
				}
				if (set) {
					continue;
				}
			}
			
			sb.append("<tr>");
			sb.append("<td>");
			sb.append(key);
			sb.append("</td>");
			for (int i = 0; i < dirList.size(); i++) {
				sb.append("<td>");
				String val = valMap[i].get(key);
				if (val == null) {
					val = "★★★★★";
				}
				else if (!dirList.get(i).equals("values-ja")) {
					if (containsJapanese(val)) {
						val = "★★★★★" + val;
					}
				}
				sb.append(val);
				sb.append("</td>");
			}
			sb.append("</tr>\n");
		}

		sb.append("</table></body></html>");

		FileWriter fw = new FileWriter(output);
		fw.write(sb.toString());
		fw.flush();
		fw.close();
	}

	private static BufferedImage loadImage(File file) {
		try {
			FileInputStream in = new FileInputStream(file);
			BufferedImage rv = ImageIO.read(in);
			in.close();
			return rv;
		} catch(IOException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static boolean containsJapanese(String str) {
		for(int i = 0 ; i < str.length() ; i++) {
			char ch = str.charAt(i);
			Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(ch);

			if (Character.UnicodeBlock.HIRAGANA.equals(unicodeBlock))
				return true;

			if (Character.UnicodeBlock.KATAKANA.equals(unicodeBlock) && ch != '・')
				return true;

			if (ch >= '。' && ch <= '゚') { // 半角カタカナ
				return true;
			}
			
//			if (Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS.equals(unicodeBlock)) // 韓国語でも使われる
//				return true;

			if (Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS.equals(unicodeBlock))
				return true;

//			if (Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION.equals(unicodeBlock)) // 韓国語でも使われる
//				return true;
		}
		return false;
	}
}