1 50 51 package com.lowagie.text.xml; 52 53 import java.io.IOException ; 54 import java.io.InputStream ; 55 import java.io.Reader ; 56 import java.util.HashMap ; 57 58 import javax.xml.parsers.ParserConfigurationException ; 59 import javax.xml.parsers.SAXParser ; 60 import javax.xml.parsers.SAXParserFactory ; 61 62 import org.xml.sax.InputSource ; 63 import org.xml.sax.SAXException ; 64 65 import com.lowagie.text.DocListener; 66 import com.lowagie.text.ExceptionConverter; 67 68 71 72 public class XmlParser { 73 74 75 protected SAXParser parser; 76 77 80 81 public XmlParser() { 82 try { 83 parser = SAXParserFactory.newInstance().newSAXParser(); 84 } 85 catch(ParserConfigurationException pce) { 86 throw new ExceptionConverter(pce); 87 } 88 catch(SAXException se) { 89 throw new ExceptionConverter(se); 90 } 91 } 92 93 98 99 public void go(DocListener document, InputSource is) { 100 try { 101 parser.parse(is, new SAXiTextHandler(document)); 102 } 103 catch(SAXException se) { 104 throw new ExceptionConverter(se); 105 } 106 catch(IOException ioe) { 107 throw new ExceptionConverter(ioe); 108 } 109 } 110 111 117 118 public void go(DocListener document, InputSource is, String tagmap) { 119 try { 120 parser.parse(is, new SAXmyHandler(document, new TagMap(tagmap))); 121 } 122 catch(SAXException se) { 123 throw new ExceptionConverter(se); 124 } 125 catch(IOException ioe) { 126 throw new ExceptionConverter(ioe); 127 } 128 } 129 130 136 137 public void go(DocListener document, InputSource is, InputStream tagmap) { 138 try { 139 parser.parse(is, new SAXmyHandler(document, new TagMap(tagmap))); 140 } 141 catch(SAXException se) { 142 throw new ExceptionConverter(se); 143 } 144 catch(IOException ioe) { 145 throw new ExceptionConverter(ioe); 146 } 147 } 148 149 155 156 public void go(DocListener document, InputSource is, HashMap tagmap) { 157 try { 158 parser.parse(is, new SAXmyHandler(document, tagmap)); 159 } 160 catch(SAXException se) { 161 throw new ExceptionConverter(se); 162 } 163 catch(IOException ioe) { 164 throw new ExceptionConverter(ioe); 165 } 166 } 167 168 173 174 public void go(DocListener document, String file) { 175 try { 176 parser.parse(file, new SAXiTextHandler(document)); 177 } 178 catch(SAXException se) { 179 throw new ExceptionConverter(se); 180 } 181 catch(IOException ioe) { 182 throw new ExceptionConverter(ioe); 183 } 184 } 185 186 192 193 public void go(DocListener document, String file, String tagmap) { 194 try { 195 parser.parse(file, new SAXmyHandler(document, new TagMap(tagmap))); 196 } 197 catch(SAXException se) { 198 throw new ExceptionConverter(se); 199 } 200 catch(IOException ioe) { 201 throw new ExceptionConverter(ioe); 202 } 203 } 204 205 211 212 public void go(DocListener document, String file, HashMap tagmap) { 213 try { 214 parser.parse(file, new SAXmyHandler(document, tagmap)); 215 } 216 catch(SAXException se) { 217 throw new ExceptionConverter(se); 218 } 219 catch(IOException ioe) { 220 throw new ExceptionConverter(ioe); 221 } 222 } 223 224 229 230 public static void parse(DocListener document, InputSource is) { 231 XmlParser p = new XmlParser(); 232 p.go(document, is); 233 } 234 235 241 242 public static void parse(DocListener document, InputSource is, String tagmap) { 243 XmlParser p = new XmlParser(); 244 p.go(document, is, tagmap); 245 } 246 247 253 254 public static void parse(DocListener document, InputSource is, HashMap tagmap) { 255 XmlParser p = new XmlParser(); 256 p.go(document, is, tagmap); 257 } 258 259 264 265 public static void parse(DocListener document, String file) { 266 XmlParser p = new XmlParser(); 267 p.go(document, file); 268 } 269 270 276 277 public static void parse(DocListener document, String file, String tagmap) { 278 XmlParser p = new XmlParser(); 279 p.go(document, file, tagmap); 280 } 281 282 288 289 public static void parse(DocListener document, String file, HashMap tagmap) { 290 XmlParser p = new XmlParser(); 291 p.go(document, file, tagmap); 292 } 293 294 299 300 public static void parse(DocListener document, InputStream is) { 301 XmlParser p = new XmlParser(); 302 p.go(document, new InputSource (is)); 303 } 304 305 311 312 public static void parse(DocListener document, InputStream is, String tagmap) { 313 XmlParser p = new XmlParser(); 314 p.go(document, new InputSource (is), tagmap); 315 } 316 317 323 324 public static void parse(DocListener document, InputStream is, HashMap tagmap) { 325 XmlParser p = new XmlParser(); 326 p.go(document, new InputSource (is), tagmap); 327 } 328 329 334 335 public static void parse(DocListener document, Reader is) { 336 XmlParser p = new XmlParser(); 337 p.go(document, new InputSource (is)); 338 } 339 340 346 347 public static void parse(DocListener document, Reader is, String tagmap) { 348 XmlParser p = new XmlParser(); 349 p.go(document, new InputSource (is), tagmap); 350 } 351 352 358 359 public static void parse(DocListener document, Reader is, HashMap tagmap) { 360 XmlParser p = new XmlParser(); 361 p.go(document, new InputSource (is), tagmap); 362 } 363 } | Popular Tags |