1 43 package net.jforum.view.install; 44 45 import java.io.BufferedReader ; 46 import java.io.FileReader ; 47 import java.io.IOException ; 48 import java.util.ArrayList ; 49 import java.util.List ; 50 51 55 public class ParseDBStructFile 56 { 57 public static List parse(String filename) throws IOException 58 { 59 List statements = new ArrayList (); 60 61 BufferedReader reader = null; 62 63 try { 64 reader = new BufferedReader (new FileReader (filename)); 65 StringBuffer sb = new StringBuffer (512); 66 String line = null; 67 68 boolean processing = false; 69 char delimiter = ';'; 70 String [] creators = { "CREATE INDEX", "CREATE TABLE", "CREATE SEQUENCE", "DROP TABLE", "IF EXISTS", 71 "DROP SEQUENCE", "DROP INDEX" }; 72 73 while ((line = reader.readLine()) != null) { 74 if (line.length() == 0) { 75 continue; 76 } 77 78 char charAt = line.charAt(0); 79 80 if (charAt == '-' || charAt == '#') { 82 continue; 83 } 84 85 if (processing) { 86 sb.append(line); 87 88 if (line.indexOf(delimiter) > -1) { 89 sb.delete(sb.length() - 1, sb.length()); 90 statements.add(sb.toString()); 91 processing = false; 92 } 93 } 94 else { 95 for (int i = 0; i < creators.length; i++) { 96 if (line.indexOf(creators[i]) > -1) { 97 sb.delete(0, sb.length()); 98 99 if (line.indexOf(delimiter) > -1) { 100 if (line.indexOf(';') > -1) { 101 line = line.replace(';', ' '); 102 } 103 104 statements.add(line); 105 } 106 else { 107 sb.append(line); 108 processing = true; 109 } 110 111 break; 112 } 113 } 114 } 115 } 116 } 117 finally { 118 if (reader != null) { 119 try { reader.close(); } catch (Exception e) {} 120 } 121 } 122 123 return statements; 124 } 125 } 126 | Popular Tags |