PageRenderTime 75ms CodeModel.GetById 71ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XInsert/src/XInsertReader.java

#
Java | 72 lines | 42 code | 6 blank | 24 comment | 0 complexity | feb5cc0beac1c09ec8ea2d74d2e7409d MD5 | raw file
 1/*
 2 * 13:44:51 17/06/99
 3 *
 4 * XInsertReader.java - Reads xml-insert files
 5 * Copyright (C) 1999 Romain Guy
 6 * www.chez.com/powerteam
 7 * powerteam@chez.com
 8 *
 9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24import java.io.*;
25import org.gjt.sp.util.Log;
26
27import org.xml.sax.helpers.XMLReaderFactory;
28import org.xml.sax.XMLReader;
29import org.xml.sax.InputSource;
30import org.xml.sax.SAXException;
31import org.xml.sax.SAXParseException;
32
33public class XInsertReader {
34  public XInsertReader() { }
35
36  public static boolean read(XTree tree, InputStream inputStream, String file) {
37    InputStreamReader reader = new InputStreamReader(inputStream);
38    XInsertHandler xmh = new XInsertHandler(tree);
39	try
40	{
41		XMLReader parser = XMLReaderFactory.createXMLReader();
42		parser.setErrorHandler(xmh);
43		parser.setContentHandler(xmh);
44		parser.setEntityResolver(xmh);
45		parser.parse(new InputSource(reader));
46	} catch(SAXParseException e) {
47      Log.log(Log.ERROR,tree,"XInsert: Error parsing grammar " + file);
48      Log.log(Log.ERROR,tree,"XInsert: Error occured at line " + e.getLineNumber() +
49                         ", column " + e.getColumnNumber());
50      Log.log(Log.ERROR,tree,"XInsert: " + e.getMessage());
51      return false;
52    } catch(IOException ioe) {
53    	Log.log(Log.ERROR,tree,"XInsert: Error parsing grammar " + file);
54    	Log.log(Log.ERROR,tree,ioe);
55    	return false;
56    } catch (Exception e) {
57      // Should NEVER happend !
58      e.printStackTrace();
59      return false;
60    } finally {
61		try {
62		  reader.close();
63		} catch (IOException ioe) { 
64				ioe.printStackTrace(); 
65		}
66	}
67    return true;
68  }
69}
70
71// End of XInsertReader.java
72