1 11 12 package org.eclipse.pde.internal.core.util; 13 14 import java.io.BufferedInputStream ; 15 import java.io.FileInputStream ; 16 import java.io.IOException ; 17 import java.io.InputStream ; 18 import java.net.MalformedURLException ; 19 import java.net.URL ; 20 21 import javax.xml.parsers.FactoryConfigurationError ; 22 import javax.xml.parsers.ParserConfigurationException ; 23 24 import org.eclipse.pde.internal.core.PDECore; 25 import org.xml.sax.SAXException ; 26 import org.xml.sax.helpers.DefaultHandler ; 27 28 32 public class SchemaUtil { 33 34 public static InputStream getInputStream(URL url) throws IOException { 35 if (url == null) { 36 throw new MalformedURLException ("URL specified is null"); } else if ("file".equals(url.getProtocol())) { return new BufferedInputStream (new FileInputStream (url.getFile())); 39 } 40 return new BufferedInputStream (url.openStream()); 41 } 42 43 public static void parseURL(URL url, DefaultHandler handler) { 44 InputStream input = null; 45 try { 46 input = getInputStream(url); 47 SAXParserWrapper parser = new SAXParserWrapper(); 48 parser.parse(input, handler); 49 } catch (MalformedURLException e) { 50 } catch (IOException e) { 55 PDECore.logException(e); 56 } catch (SAXException e) { 57 } catch (ParserConfigurationException e) { 61 PDECore.logException(e); 62 } catch (FactoryConfigurationError e) { 63 PDECore.logException(e); 64 } finally { 65 try { 66 if (input != null) 67 input.close(); 68 } catch (IOException e1) { 69 } 70 } 71 } 72 73 } 74 | Popular Tags |