1 20 21 package freecs.util; 22 23 import java.io.File ; 24 import java.io.FileInputStream ; 25 import java.io.FileReader ; 26 import java.util.Enumeration ; 27 import java.util.Iterator ; 28 import java.util.Properties ; 29 import java.util.TreeSet ; 30 31 36 public class MessageTemplateFinder { 37 static TreeSet v = new TreeSet (); 38 static Properties oldprops = new Properties (); 39 40 public static void main(String [] args) { 41 if (args == null || args.length<1) { 42 System.out.println ("please specify the path to the sourcefolder"); 43 System.exit(1); 44 } 45 String base = args[0]; 46 if (args.length > 1 && args[1]!=null && args[1].length()>0) { 47 try { 48 FileInputStream fis = new FileInputStream (args[1]); 49 oldprops.load(fis); 50 fis.close(); 51 } catch (Exception e) { 52 System.out.println ("old properties-file wasn't found"); 53 e.printStackTrace(); 54 } 55 } 56 File basef = new File (base); 57 if (!basef.exists() || !basef.isDirectory()) { 58 System.out.println ("The path specified is not correct"); 59 System.exit (1); 60 } 61 System.out.println ("Searching..."); 62 search (basef); 63 64 v.add("message.user.join.server"); 66 v.add("message.q"); 67 v.add("message.kh.personal"); 68 v.add("message.user.leaving.server"); 69 v.add("message.user.leaving.server.kicked"); 70 71 System.out.println("Found templates:------------------------------------\r\n"); 72 for (Iterator e = v.iterator(); e.hasNext(); ) { 73 String cs = (String ) e.next(); 74 System.out.print(cs); 75 String propval = oldprops.getProperty(cs); 76 if (propval!=null) { 77 for (int i = 0; i < (36 - cs.length()); i++) 78 System.out.print (" "); 79 System.out.print("= "); 80 System.out.print(propval); 81 oldprops.remove(cs); 82 } 83 System.out.print("\r\n"); 84 } 85 System.out.println("----------------------- Values from old-properties-file, which have not been found in source\r\n"); 86 for (Enumeration e = oldprops.keys(); e.hasMoreElements(); ) { 87 String k = (String ) e.nextElement(); 88 System.out.print(k); 89 for (int i = 0; i < (36 - k.length()); i++) 90 System.out.print (" "); 91 System.out.print ("= "); 92 System.out.println (oldprops.getProperty(k)); 93 } 94 } 95 96 public static void search(File f) { 97 System.out.print("searching "); 98 if (f.isDirectory()) { 99 System.out.print("DIRECTORY: "); 100 System.out.println (f.getName()); 101 File [] farr = f.listFiles(); 102 for (int i = 0; i<farr.length; i++) 103 search (farr[i]); 104 } else if (f.isFile()) { 105 System.out.print("file: "); 106 System.out.println (f.getName()); 107 String cntnt = null; 108 try { 109 FileReader fr = new FileReader (f); 110 char fcnt[] = new char[(int) f.length()]; 111 int read = fr.read(fcnt); 112 cntnt=String.copyValueOf(fcnt); 113 } catch (Exception e) { 114 e.printStackTrace(); 115 } 116 int idx; 117 while ((idx = cntnt.indexOf(".msgTemplate")) != -1) { 118 cntnt = cntnt.substring(idx+12).trim(); 119 if (!cntnt.startsWith("=")) 120 continue; 121 cntnt = cntnt.substring(1).trim(); 122 if (!cntnt.startsWith("\"")) 123 continue; 124 cntnt = cntnt.substring(1); 125 int idx2 = cntnt.indexOf("\""); 126 if (idx2 == -1) 127 continue; 128 String cs = cntnt.substring(0, idx2); 129 if (!v.contains(cs)) 130 v.add(cs); 131 } 132 } 133 } 134 } 135 | Popular Tags |