1 11 package org.eclipse.pde.internal.core.builders; 12 13 import java.io.BufferedInputStream ; 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 17 import javax.xml.parsers.ParserConfigurationException ; 18 import javax.xml.parsers.SAXParser ; 19 import javax.xml.parsers.SAXParserFactory ; 20 21 import org.eclipse.core.resources.IFile; 22 import org.eclipse.core.runtime.CoreException; 23 import org.xml.sax.SAXException ; 24 25 public class ValidatingSAXParser { 26 27 private static SAXParserFactory fFactory; 28 29 public static void parse(IFile file, XMLErrorReporter reporter) { 30 InputStream stream = null; 31 try { 32 stream = new BufferedInputStream (file.getContents()); 33 getParser().parse(stream, reporter); 34 } catch (CoreException e) { 35 } catch (SAXException e) { 36 } catch (IOException e) { 37 } catch (ParserConfigurationException e) { 38 } finally { 39 try { 40 if (stream != null) 41 stream.close(); 42 } catch (IOException e1) { 43 } 44 } 45 } 46 47 private static SAXParser getParser() 48 throws ParserConfigurationException , SAXException { 49 if (fFactory == null) { 50 fFactory = SAXParserFactory.newInstance(); 51 } 52 return fFactory.newSAXParser(); 53 } 54 55 } 56 | Popular Tags |