1 5 package org.h2.tools.code; 6 7 import java.io.File ; 8 import java.io.FileInputStream ; 9 import java.io.FileOutputStream ; 10 import java.io.InputStreamReader ; 11 import java.io.OutputStreamWriter ; 12 import java.io.RandomAccessFile ; 13 14 import org.h2.server.web.PageParser; 15 import org.h2.util.IOUtils; 16 import org.h2.util.StringUtils; 17 18 public class PropertiesToUTF8 { 19 public static void main(String [] args) throws Exception { 20 File [] list = new File ("bin/org/h2/web/res").listFiles(); 21 for(int i=0; i<list.length; i++) { 22 File f = list[i]; 23 if(!f.getName().endsWith(".properties")) { 24 continue; 25 } 26 FileInputStream in = new FileInputStream (f); 27 InputStreamReader r = new InputStreamReader (in, "UTF-8"); 28 String s = IOUtils.readStringAndClose(r, -1); 29 in.close(); 30 String name = f.getName(); 31 if(name.startsWith("utf8")) { 32 s = PageParser.escapeHtml(s, false); 33 RandomAccessFile out = new RandomAccessFile (name.substring(4), "rw"); 34 out.write(s.getBytes()); 35 out.close(); 36 } else { 37 new CheckTextFiles().checkOrFixFile(f, false, false); 38 s = unescapeHtml(s); 39 s = StringUtils.javaDecode(s); 40 FileOutputStream out = new FileOutputStream ("utf8" + f.getName()); 41 OutputStreamWriter w = new OutputStreamWriter (out, "UTF-8"); 42 w.write(s); 43 w.close(); 44 out.close(); 45 } 46 } 47 } 48 49 private static String unescapeHtml(String s) { 50 String codes = "< < & & > > Ä \u00c4 Ö \u00d6 Ü \u00dc ä \u00e4 ö \u00f6 ü \u00fc ñ \u00f1 ó \u00f3 Í \u00cd ç \u00e7 &eagrave; \u00e8 ê \u00ea Ú \u00da á \u00e1 ú \u00fa é \u00e9 è \u00e8 î \u00ee"; 51 String [] list = StringUtils.arraySplit(codes, ' ', false); 52 for(int i=0; i<list.length; i+=2) { 53 s = StringUtils.replaceAll(s, list[i], list[i+1]); 54 } 55 if(s.indexOf("&") >= 0) { 56 throw new Error ("??? " + s); 57 } 58 return s; 59 } 60 } 61 | Popular Tags |