| 1 package s2b; 2 3 import java.util.regex.Pattern ; 4 import java.util.regex.Matcher ; 5 import java.io.BufferedReader ; 6 import java.io.BufferedWriter ; 7 import java.io.FileReader ; 8 import java.io.FileWriter ; 9 import java.io.File ; 10 11 16 17 21 public class FormatDtd { 22 23 24 public FormatDtd() { 25 } 26 27 private static final String USAGE = 28 "java s2b.FormatDtd <originaldtd> <newdtd>"; 29 30 public static void usage() { 31 System.out.println(USAGE); 32 System.exit(1); 33 } 34 35 private static void generate(String origDtd, String genDtd) { 36 BufferedReader fis = null; 37 BufferedWriter fos = null; 38 try { 39 FileReader f = new FileReader (origDtd); 40 fis = new BufferedReader (f); 41 FileWriter outF = new FileWriter (genDtd); 42 fos = new BufferedWriter (outF); 43 String line = null; 44 String outLine = null; 45 while((line=fis.readLine()) != null) { 46 if(line == null) { 48 continue; 49 } 50 if (line.startsWith("<!ENTITY")) { 51 if (line.endsWith(">")){ continue; 54 } else { fis.readLine(); 56 continue; 57 } 58 } 59 60 outLine = line; 61 outLine = line.replaceAll("property", "element-property"); 62 outLine = outLine.replaceAll("system-element-property", "system-property"); 63 outLine = outLine.replaceAll("%.*;", "CDATA "); 64 outLine = outLine.replaceAll("\t", " "); 65 fos.write(outLine); 68 fos.write("\n"); 69 } 70 } catch(Exception e) { 71 e.printStackTrace(); 72 } finally { 73 try { 74 fis.close(); 75 } catch(Exception e){} 76 77 try { 78 fos.close(); 79 } catch(Exception e){} 80 } 81 } 82 85 public static void main (String args[]) { 86 87 if(args.length != 2) 88 usage(); 89 90 String origDtd = args[0]; 91 String genDtd = args[1]; 92 93 System.out.println("origdtd " + origDtd); 94 System.out.println("path " + genDtd); 95 generate(origDtd, genDtd); 96 } 97 98 } 99 | Popular Tags |