KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > builders > ValidatingSAXParser


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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