1 16 package com.ibatis.db.sqlmap.upgrade; 17 18 import java.io.BufferedReader ; 19 import java.io.IOException ; 20 import java.io.Reader ; 21 import java.io.StringReader ; 22 23 31 public class DocTypeReader extends Reader { 32 33 private Reader reader; 34 private String docType; 35 36 public DocTypeReader(Reader in) throws IOException { 37 BufferedReader lineReader = new BufferedReader (in); 38 StringBuffer buffer = new StringBuffer (); 39 StringBuffer docBuffer = new StringBuffer (); 40 String line = null; 41 while ((line = lineReader.readLine()) != null) { 42 if (line.indexOf("<!DOCTYPE") > -1) { 43 docBuffer.append(line); 44 while (line.indexOf(">") < 0) { 45 line = lineReader.readLine(); 46 docBuffer.append(" "); 47 docBuffer.append(line.trim()); 48 } 49 line = lineReader.readLine(); 50 } 51 buffer.append(line); 52 buffer.append("\n"); 53 } 54 reader = new StringReader (buffer.toString()); 55 docType = docBuffer.toString(); 56 } 57 58 public String getDocType() { 59 return docType; 60 } 61 62 public int read(char cbuf[], int off, int len) throws IOException { 63 return reader.read(cbuf, off, len); 64 } 65 66 public void close() throws IOException { 67 reader.close(); 68 } 69 70 } 71 | Popular Tags |