1 6 7 package org.contineo.core.text.parser; 8 9 import java.io.BufferedReader ; 10 import java.io.File ; 11 import java.io.FileInputStream ; 12 import java.io.IOException ; 13 import java.io.InputStream ; 14 import java.io.InputStreamReader ; 15 16 import org.apache.log4j.Level; 17 import org.apache.log4j.Logger; 18 import org.contineo.core.LoggingManager; 19 23 public class PSParser implements Parser { 24 25 28 private StringBuffer content = new StringBuffer (); 29 30 34 private Logger logger; 35 36 39 private String version = ""; 40 private BufferedReader reader; 41 42 43 public PSParser(File file) { 44 logger = LoggingManager.getLogger(this.getClass()); 45 init(file); 46 } 47 48 protected void init(File file) { 49 try { 50 InputStream in = new FileInputStream (file); 51 reader = new BufferedReader (new InputStreamReader (in)); 52 String line = reader.readLine(); 53 if (line != null && line.length() >= 3) 54 { 55 version = line.substring(line.length()-3); 56 if (version.startsWith("2")) 57 parse_v2(); 58 if (version.startsWith("3")) 59 parse_v3(); 60 } 61 } 62 catch (Exception ex) { 63 if (logger.isEnabledFor(Level.ERROR)) 64 logger.error((ex.getMessage())); 65 } 66 } 67 68 protected void parse_v2() throws IOException { 69 boolean isComment = false; 70 boolean isText = false; 71 boolean isConnector = false; 72 int ichar = 0; 73 while ((ichar = reader.read()) > 0) { 74 if (isConnector) { 75 if (ichar < 108) 76 content.append((char)32); 77 isConnector = false; 78 } 79 if (ichar == 37) 80 isComment = true; 81 if (ichar == 10 && isComment) 82 isComment = false; 83 if (ichar == 41 && isText ) { 84 isConnector = true; 85 isText = false; 86 } 87 if (isText) 88 content.append((char)ichar); 89 if (ichar == 40 && !isComment) 90 isText = true; 91 } 92 reader.close(); 93 } 94 95 protected void parse_v3() throws IOException { 96 StringBuffer stmt = new StringBuffer (); 97 boolean isComment = false; 98 boolean isText = false; 99 boolean isBMP = false; 100 boolean isStore = false; 101 int store = 0; 102 int ichar = 0; 103 while ((ichar = reader.read()) > 0) { 104 if (ichar == 37) 105 isComment = true; 106 if (ichar == 10 && isComment) 107 isComment = false; 108 if (ichar == 41 && isText ) 109 isText = false; 110 if (isText && !isBMP) 111 content.append((char)ichar); 112 if (ichar == 40 && !isComment && !isBMP) 113 isText = true; 114 if (isStore) { 115 if (store == 9 || ichar == 32 || ichar == 10) { 116 isStore = false; 117 store = 0; 118 if (stmt.toString().equals("BEGINBITM")) { 119 isText = false; 120 isBMP = true; 121 } 122 if (stmt.toString().equals("ENDBITMAP")) 123 isBMP = false; 124 stmt.delete(0,stmt.length()); 125 } 126 else { 127 stmt.append((char)ichar); 128 store++; 129 } 130 } 131 if (!isComment && !isStore && (ichar == 66 || ichar == 69)) { 132 isStore = true; 133 stmt.append((char)ichar); 134 store++; 135 } 136 } 137 reader.close(); 138 } 139 140 144 public StringBuffer getContent() { 145 return content; 146 } 147 148 152 public String getVersion() { 153 return version; 154 } 155 156 159 public String getAuthor() { 160 return ""; 161 } 162 163 166 public String getSourceDate() { 167 return ""; 168 } 169 170 173 public String getKeywords() { 174 return ""; 175 } 176 177 180 public String getTitle() { 181 return ""; 182 } 183 } 184 | Popular Tags |