KickJava   Java API By Example, From Geeks To Geeks.

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


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